Example usage for javax.swing SwingUtilities invokeAndWait

List of usage examples for javax.swing SwingUtilities invokeAndWait

Introduction

In this page you can find the example usage for javax.swing SwingUtilities invokeAndWait.

Prototype

public static void invokeAndWait(final Runnable doRun) throws InterruptedException, InvocationTargetException 

Source Link

Document

Causes doRun.run() to be executed synchronously on the AWT event dispatching thread.

Usage

From source file:com.intellij.util.net.HttpConfigurable.java

@SuppressWarnings("MethodMayBeStatic")
private void runAboveAll(final Runnable runnable) {
    final Runnable throughSwing = new Runnable() {
        @Override/* w ww  .  j  a  v  a2 s .  c om*/
        public void run() {
            if (SwingUtilities.isEventDispatchThread()) {
                runnable.run();
                return;
            }
            try {
                SwingUtilities.invokeAndWait(runnable);
            } catch (InterruptedException e) {
                LOG.info(e);
            } catch (InvocationTargetException e) {
                LOG.info(e);
            }
        }
    };
    if (ProgressManager.getInstance().getProgressIndicator() != null) {
        if (ProgressManager.getInstance().getProgressIndicator().isModal()) {
            WaitForProgressToShow.runOrInvokeAndWaitAboveProgress(runnable);
        } else {
            throughSwing.run();
        }
    } else {
        throughSwing.run();
    }
}

From source file:com.all.i18n.DefaultMessages.java

public void setLocale(Locale locale) {
    this.locale = locale;
    try {//from  w w  w  . ja v a  2  s. c om
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                init();
            }
        });
    } catch (InterruptedException e) {
        log.error(e, e);
    } catch (InvocationTargetException e) {
        log.error(e, e);
    }
}

From source file:com.mightypocket.ashot.Mediator.java

void addDevice(final String deviceStr) {
    if (!devices.containsKey(deviceStr)) {
        try {/*  ww  w  . j  a v  a 2  s  . c  o  m*/
            SwingUtilities.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    JRadioButtonMenuItem item = new JRadioButtonMenuItem(deviceStr);
                    item.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            JRadioButtonMenuItem source = (JRadioButtonMenuItem) e.getSource();
                            String device = source.getText();
                            demon.connectTo(device);
                        }
                    });
                    devicesGroup.add(item);
                    devices.put(deviceStr, item);
                    menuFileDevices.add(item);
                    pcs.firePropertyChange(PROP_DEVICES, null, null);
                }
            });
        } catch (Exception ignore) {
        }
    }
}

From source file:org.rdv.viz.spectrum.SpectrumAnalyzerPanel.java

/**
 * Plots the power spectrum. This does the analysis in a seperate thread and
 * when done adds updates the chart on the EDT.
 *///from   ww w  .j  ava  2  s.co  m
private void plotSpectrum() {
    final double[] x = getData();

    fftExecutor.execute(new Runnable() {
        public void run() {
            final double[] X = psdWelch(fft, x, numberOfSamples, window, segmentSize, overlap);

            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    public void run() {
                        updateChart(X, sampleRate, segmentSize);
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:executor.TesterMainGUIMode.java

private void removecurrentChartPanel() {
    if (this.currentChartPanel != null) {
        try {/*from ww  w  .j  av a2  s  .  com*/
            SwingUtilities.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    TesterMainGUIMode.this.getContentPane().remove(TesterMainGUIMode.this.currentChartPanel);
                    TesterMainGUIMode.this.getContentPane().repaint();
                }
            });
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
}

From source file:net.sf.dsig.DSApplet.java

@Override
public void init() {
    super.init();

    // StrategyFactory service loader ----------------------------------- //
    strategyFactory = ServiceLoader.load(StrategyFactory.class).iterator().next();

    // Environment initialization --------------------------------------- //
    initProfiler.start("Environment init");
    Environment.getSingleton().setApplet(this);
    Environment.getSingleton().setProperties(UserHomeSettingsParser.parse());

    // Set the default java.logging logger for FINEST logging on
    // gr.ageorgiadis package when debug environmental parameter is set
    initProfiler.start("Logging init");
    if (Boolean.parseBoolean(Environment.getSingleton().getValue("debug"))) {
        System.out.println("\n*** Debug log enabled ***");

        Logger.getLogger("").getHandlers()[0].setLevel(Level.FINEST);
        Logger.getLogger("").setLevel(Level.INFO);

        Logger.getLogger("net.sf.dsig").setLevel(Level.FINEST);
    }//ww  w  . j a va 2s .c  o  m

    // Applet initialization through the Environment class -------------- //
    initProfiler.start("Applet init");
    Environment.getSingleton().init(this);

    // LiveConnect proxy initialization --------------------------------- //
    LiveConnectProxy.getSingleton().setApplet(this);

    // KeyStoreProxy initialization ------------------------------------- //
    try {
        KeyStoreProxyFactory factory = new KeyStoreProxyFactory();
        Environment.getSingleton().init(factory);

        keyStoreProxy = factory.createKeyStoreProxy();
    } catch (Exception e) {
        logger.error("Error while creating keyStoreProxy", e);

        createKeyStoreProxyException = e;
    }

    // Swing initialization --------------------------------------------- //
    initProfiler.start("Swing init");
    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                initSwing();
            }
        });
    } catch (Exception e) {
        logger.error("Swing initialization failed", e);
    }

    initProfiler.start("Starting");
}

From source file:com.mightypocket.ashot.Mediator.java

void removeDevice(final String deviceStr) {
    if (devices.containsKey(deviceStr)) {
        try {/*  w  w  w.  j a  v  a  2  s  .  c  o m*/
            SwingUtilities.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    JRadioButtonMenuItem item = devices.get(deviceStr);
                    devicesGroup.remove(item);
                    devices.remove(item.getText());
                    menuFileDevices.remove(item);
                    pcs.firePropertyChange(PROP_DEVICES, null, null);
                }
            });
        } catch (Exception ignore) {
        }
    }
}

From source file:com.igormaznitsa.zxpoly.MainForm.java

private void updateTracerWindowsForStep() {
    try {//from  www  .j a va 2  s  . c  o  m
        SwingUtilities.invokeAndWait(this.traceWindowsUpdater);
    } catch (InterruptedException ex) {
        log.log(Level.INFO, "Interrupted trace window updater");
    } catch (InvocationTargetException ex) {
        ex.printStackTrace();
        log.log(Level.SEVERE, "Error in trace window updater", ex);
    }
}

From source file:edu.mit.fss.examples.visual.gui.WorldWindVisualization.java

@Override
public void objectDiscovered(ObjectChangeEvent event) {
    if (event.getObject() instanceof Element) {
        final Element element = (Element) event.getObject();

        try {//from   w w w .j  a  v a  2 s. c o  m
            SwingUtilities.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    if (element instanceof OrbitalElement) {
                        // add element to options panel
                        OrbitalElement orbital = (OrbitalElement) element;
                        optionsPanel.addElement(orbital);
                        // add orbital shape to display layer
                        displayLayer.addRenderable(optionsPanel.getOrbitalShape(orbital));
                        // add footprint shape to display layer
                        displayLayer.addRenderable(optionsPanel.getFootprintShape(orbital));
                    } else if (element instanceof SurfaceElement) {
                        // add element to options panel
                        optionsPanel.addElement((SurfaceElement) element);
                        // update markers layer (cannot add individual markers)
                        markerLayer.setMarkers(optionsPanel.getSurfaceMarkers());
                    }
                }
            });
        } catch (InvocationTargetException | InterruptedException e) {
            logger.error(e);
        }
    }
}

From source file:com.microsoft.intellij.ui.AppInsightsMngmtPanel.java

private void createNewDilaog(final ApplicationInsightsManagementClient client) {
    try {//  w ww . j  av  a2 s .  c  o m
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                ApplicationManager.getApplication().invokeAndWait(new Runnable() {
                    @Override
                    public void run() {
                        ApplicationInsightsNewDialog dialog = new ApplicationInsightsNewDialog(client);
                        dialog.show();
                        if (dialog.isOK()) {
                            ApplicationInsightsResource resource = ApplicationInsightsNewDialog.getResource();
                            if (resource != null && !ApplicationInsightsResourceRegistry
                                    .getAppInsightsResrcList().contains(resource)) {
                                ApplicationInsightsResourceRegistry.getAppInsightsResrcList().add(resource);
                                AzureSettings.getSafeInstance(myProject).saveAppInsights();
                                ((InsightsTableModel) insightsTable.getModel()).setResources(getTableContent());
                                ((InsightsTableModel) insightsTable.getModel()).fireTableDataChanged();
                            }
                        }
                    }
                }, ModalityState.defaultModalityState());
            }
        });
    } catch (Exception ex) {
        AzurePlugin.log(ex.getMessage(), ex);
    }
}