Re: [OpenMap Users] EDT violations & openmap.synchronousThreading

From: Don Dietrick <dietrick_at_bbn.com>
Date: Fri, 20 Feb 2009 13:39:49 -0500

Hi Carsten

Thanks for the update - I haven't had a chance to look at this, but I
will before the next release. It'll be a lot easier with the code
you've provided.

- Don

On Feb 16, 2009, at 3:45 AM, Carsten Ø. Madsen wrote:

> Hello
>
> I did this to get OpenMap to run with Substance 5.1. It seems to fix
> the EDT violations that Substance is complaining about.
>
> Maybe SwingUtilities.invokeLater would be more appropriate than
> SwingWorker.
>
> BR
> Carsten
>
> package dk.navicon.openmap.gui;
>
> import javax.swing.SwingUtilities;
>
> import com.bbn.openmap.Layer;
> import com.bbn.openmap.util.SwingWorker;
>
> public class LayersPanelEDTSafe extends
> com.bbn.openmap.gui.LayersPanel {
>
> class MyWorker extends SwingWorker {
>
> private Layer[] layers;
>
> public MyWorker(Layer[] inLayers) {
> layers = inLayers.clone();
> }
>
> _at_Override
> public void finished() {
> try {
> LayersPanelEDTSafe.super.setLayers(layers);
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> _at_Override
> public Object construct() {
> return null;
> }
>
> }
>
> _at_Override
> public void setLayers(Layer[] inLayers) {
> if (SwingUtilities.isEventDispatchThread())
> super.setLayers(inLayers);
> else
> new MyWorker(inLayers).execute();
> }
>
> }
>
> package dk.navicon.openmap.gui;
>
> import java.awt.Font;
> import java.awt.GridBagConstraints;
> import java.awt.GridBagLayout;
> import java.awt.Insets;
>
> import javax.swing.JLabel;
> import javax.swing.JPanel;
> import javax.swing.JProgressBar;
> import javax.swing.SwingConstants;
>
> import com.bbn.openmap.InformationDelegator;
> import com.bbn.openmap.gui.StatusLightPanel;
> import com.bbn.openmap.util.Debug;
>
> public class InformationDelegatorEDTSafe extends
> InformationDelegator {
>
> private String fudgeString = " ";
>
> _at_Override
> public void initInfoWidgets() {
>
> Debug.message("info", "InformationDelegator.initInfoWidgets");
>
> GridBagLayout gridbag = new GridBagLayout();
> GridBagConstraints c = new GridBagConstraints();
>
> setFont(new Font("Helvetica", Font.PLAIN, 9));
> setLayout(gridbag);
>
> progressBar = new JProgressBar();
> gridbag.setConstraints(progressBar, c);
> add(progressBar);
> progressBar.setVisible(false);
>
> JPanel infoLinePanel = new JPanel();
> c.weightx = 1;
> c.anchor = GridBagConstraints.WEST;
> c.fill = GridBagConstraints.HORIZONTAL;
>
> gridbag.setConstraints(infoLinePanel, c);
>
> GridBagLayout gridbag2 = new GridBagLayout();
> GridBagConstraints c2 = new GridBagConstraints();
> infoLinePanel.setLayout(gridbag2);
>
> infoLineHolder = new JLabel(fudgeString);
> c2.weightx = 1;
> c2.fill = GridBagConstraints.HORIZONTAL;
> c2.anchor = GridBagConstraints.WEST;
> c2.insets = new Insets(3, 10, 3, 10);
> gridbag2.setConstraints(infoLineHolder, c2);
> infoLinePanel.add(infoLineHolder);
>
> infoLineHolder2 = new JLabel(fudgeString, SwingConstants.RIGHT);
> c2.weightx = 0;
> c2.anchor = GridBagConstraints.EAST;
> gridbag2.setConstraints(infoLineHolder2, c2);
> infoLinePanel.add(infoLineHolder2);
>
> addInfoLine(COORDINATE_INFO_LINE, infoLineHolder);
> addInfoLine(MAP_OBJECT_INFO_LINE, infoLineHolder2);
>
> add(infoLinePanel);
> infoLinePanel.setVisible(showInfoLine);
>
> c.weightx = 0;
> c.anchor = GridBagConstraints.EAST;
> statusBar = new StatusLightPanelEDTSafe();
> gridbag.setConstraints(statusBar, c);
> add(statusBar);
> statusBar.setVisible(showLights);
> }
>
> }
>
> package dk.navicon.openmap.gui;
>
> import javax.swing.SwingUtilities;
>
> import com.bbn.openmap.Layer;
> import com.bbn.openmap.gui.StatusLightPanel;
> import com.bbn.openmap.util.SwingWorker;
>
> public class StatusLightPanelEDTSafe extends StatusLightPanel {
>
> class MyWorker extends SwingWorker {
>
> private Layer[] layers;
>
> public MyWorker(Layer[] inLayers) {
> layers = inLayers.clone();
>
> }
>
> _at_Override
> public void finished() {
> try {
> StatusLightPanelEDTSafe.super.listenToLayers(layers);
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> _at_Override
> public Object construct() {
> return null;
> }
>
> }
>
> protected void listenToLayers(Layer[] newLayers) {
> if (SwingUtilities.isEventDispatchThread())
> super.listenToLayers(newLayers);
> else
> new MyWorker(newLayers).execute();
> }
> }
>
> package dk.navicon.openmap.gui;
>
> import javax.swing.SwingUtilities;
>
> import com.bbn.openmap.Layer;
> import com.bbn.openmap.util.SwingWorker;
>
> public class LayersMenuEDTSafe extends
> com.bbn.openmap.gui.LayersMenu {
>
> class MyWorker extends SwingWorker {
>
> private Layer[] layers;
>
> public MyWorker(Layer[] inLayers) {
> layers = inLayers.clone();
>
> }
>
> _at_Override
> public void finished() {
> try {
> LayersMenuEDTSafe.super.setLayers(layers);
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> _at_Override
> public Object construct() {
> return null;
> }
>
> }
>
> _at_Override
> public void setLayers(Layer[] inLayers) {
> if (SwingUtilities.isEventDispatchThread())
> super.setLayers(inLayers);
> else
> new MyWorker(inLayers).execute();
> }
>
> }
>
>
>
>
>
>
> Carsten Ø. Madsen wrote:
>> Hello
>>
>> I'm trying to run OM under the Substance 5 LAF but I get the
>> following error:
>>
>> org.jvnet.substance.api.UiThreadingViolationException: Component
>> creation must be done on Event Dispatch Thread
>> at
>> org
>> .jvnet
>> .substance
>> .utils
>> .SubstanceCoreUtilities
>> .testComponentCreationThreadingViolation
>> (SubstanceCoreUtilities.java:2322)
>> at
>> org
>> .jvnet
>> .substance.SubstanceSeparatorUI.createUI(SubstanceSeparatorUI.java:
>> 53)
>> at sun.reflect.GeneratedMethodAccessor30.invoke(Unknown Source)
>> at
>> sun
>> .reflect
>> .DelegatingMethodAccessorImpl
>> .invoke(DelegatingMethodAccessorImpl.java:25)
>> at java.lang.reflect.Method.invoke(Method.java:597)
>> at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:36)
>> at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
>> at
>> sun
>> .reflect
>> .DelegatingMethodAccessorImpl
>> .invoke(DelegatingMethodAccessorImpl.java:25)
>> at java.lang.reflect.Method.invoke(Method.java:597)
>> at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:243)
>> at javax.swing.UIDefaults.getUI(UIDefaults.java:751)
>> at javax.swing.UIManager.getUI(UIManager.java:1012)
>> at javax.swing.JSeparator.updateUI(JSeparator.java:122)
>> at javax.swing.JSeparator.<init>(JSeparator.java:89)
>> at javax.swing.JSeparator.<init>(JSeparator.java:70)
>> at com.bbn.openmap.gui.LayersMenu.setLayers(LayersMenu.java:268)
>> at com.bbn.openmap.gui.LayersMenu.setLayers(LayersMenu.java:242)
>> at com.bbn.openmap.event.LayerSupport.fireLayer(LayerSupport.java:
>> 91)
>> at com.bbn.openmap.event.LayerSupport
>> $SetLayerRunnable.doIt(LayerSupport.java:176)
>> at com.bbn.openmap.event.LayerSupport
>> $SetLayerRunnable.run(LayerSupport.java:168)
>> at java.lang.Thread.run(Thread.java:619)
>>
>> If I run with openmap.synchronousThreading=true the problem
>> disappears. Is there a way to make LayersMenu create the Swing
>> comps. in the EDT and still run openmap.synchronousThreading=false.
>>
>> Also, I think it is a bug that the Swing comps can be created
>> outside the EDT?
>>
>> BR
>> Carsten
>>
>> --
>> [To unsubscribe to this list send an email to "majdart_at_bbn.com"
>> with the following text in the BODY of the message "unsubscribe
>> openmap-users"]
>
> --
> [To unsubscribe to this list send an email to "majdart_at_bbn.com"
> with the following text in the BODY of the message "unsubscribe
> openmap-users"]

--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Fri Feb 20 2009 - 13:40:27 EST

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:09 EDT