Example usage for java.awt EventQueue invokeLater

List of usage examples for java.awt EventQueue invokeLater

Introduction

In this page you can find the example usage for java.awt EventQueue invokeLater.

Prototype

public static void invokeLater(Runnable runnable) 

Source Link

Document

Causes runnable to have its run method called in the #isDispatchThread dispatch thread of Toolkit#getSystemEventQueue the system EventQueue .

Usage

From source file:phex.gui.macosx.GURLHandler.java

/** Called by the native code */
private void callback(final String uriStr) {
    // currently we only accept magnets through this interface...
    if (!uriStr.startsWith("magnet")) {
        return;//from   ww  w  .  j  a va 2s .c  o m
    }

    Runnable runner = new Runnable() {
        public void run() {
            try {
                URI uri = new URI(uriStr, true);
                // dont add already downloading urns.
                SwarmingManager swarmingMgr = GUIRegistry.getInstance().getServent().getDownloadService();
                swarmingMgr.addFileToDownload(uri, true);
            } catch (URIException exp) {
                return;
            }
        }
    };
    EventQueue.invokeLater(runner);
}

From source file:org.anarres.filechooser.impl.vfs2.VFSJFileChooserTest.java

@Test
public void testFileChooser() throws Exception {
    StandardFileSystemManager manager = new StandardFileSystemManager();
    manager.init();/*from   w  w  w . j  a  v  a 2  s.c  o m*/

    final FileObject root = manager.resolveFile("ram:/");
    FileObject foo = root.resolveFile("foo");
    foo.createFolder();
    foo.resolveFile("foo0").createFile();
    foo.resolveFile("foo1").createFile();
    root.resolveFile("bar").createFile();

    EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            try {
                CommonsVfs2JFileChooser chooser = new CommonsVfs2JFileChooser();
                chooser.setMultiSelectionEnabled(true);
                chooser.setCurrentDirectory(root);
                VFSJFileChooser.RETURN_TYPE ret = chooser.showOpenDialog(null);
                LOG.info("RETURN_TYPE = " + ret);
                LOG.info("Selected FO  = " + chooser.getSelectedFile());
                LOG.info("Selected FOs = " + Arrays.toString(chooser.getSelectedFiles()));
                print(chooser.getSelectedFile());
                for (FileObject file : chooser.getSelectedFiles()) {
                    print(file);
                }
            } catch (FileSystemException e) {
                throw new RuntimeException(e);
            }
        }
    });

    Robot robot = BasicRobot.robotWithCurrentAwtHierarchy();
    robot.waitForIdle();

    VFSJFileChooserFixture<FileObject> chooser = VFSJFileChooserFinder.<FileObject>findFileChooser()
            .using(robot);
    // Thread.sleep(2000);
    chooser.setCurrentDirectory(foo);
    // Thread.sleep(2000);
    chooser.approve();
}

From source file:net.rptools.maptool.client.AppSetup.java

public static void installLibrary(final String libraryName, final File root) throws IOException {
    // Add as a resource root
    AppPreferences.addAssetRoot(root);/* ww  w . j  a v a 2s  . c  o m*/
    if (MapTool.getFrame() != null) {
        MapTool.getFrame().addAssetRoot(root);

        // License
        File licenseFile = new File(root, "License.txt");
        if (!licenseFile.exists()) {
            licenseFile = new File(root, "license.txt");
        }
        if (licenseFile.exists()) {
            final File licenseFileFinal = licenseFile;
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    try {
                        JTextPane pane = new JTextPane();
                        pane.setPage(licenseFileFinal.toURI().toURL());
                        JOptionPane.showMessageDialog(MapTool.getFrame(), pane, "License for " + libraryName,
                                JOptionPane.INFORMATION_MESSAGE);
                    } catch (MalformedURLException e) {
                        log.error("Could not load license file: " + licenseFileFinal, e);
                    } catch (IOException e) {
                        log.error("Could not load license file: " + licenseFileFinal, e);
                    }
                }
            });
        }
    }
    new SwingWorker<Object, Object>() {
        @Override
        protected Object doInBackground() throws Exception {
            AssetManager.searchForImageReferences(root, AppConstants.IMAGE_FILE_FILTER);
            return null;
        }
    }.execute();
}

From source file:org.eclipse.om2m.ipu.sample.GUI.java

/**
 * Initiate The GUI.// ww w  . j av a2 s.c o m
 */
public static void init() {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            logServiceTracker = new ServiceTracker(FrameworkUtil.getBundle(GUI.class).getBundleContext(),
                    org.osgi.service.log.LogService.class.getName(), null);
            logServiceTracker.open();
            logservice = (LogService) logServiceTracker.getService();

            try {
                frame = new GUI();
                frame.setVisible(true);
            } catch (Exception e) {

                LOGGER.error("GUI init Error", e);
                logservice.log(LogService.LOG_ERROR, "GUI init Error");

            }
        }
    });
}

From source file:support.SystemMonitorGui.java

private void startGui() {
    XYSeries series = new XYSeries("Rate", false);
    XYPlot plot = createChartFrame(series);
    ValueAxis xAxis = plot.getDomainAxis();
    ValueAxis yAxis = plot.getRangeAxis();
    xAxis.setRange(0, TIME_RANGE);//from ww  w  .  j ava 2 s .  c  o  m
    yAxis.setRange(Y_RANGE_MIN, Y_RANGE_UPPER_INITIAL);

    long initialTimestamp = System.currentTimeMillis();
    EntryAddedListener<Long, Double> entryAddedListener = event -> {
        long x = event.getKey() - initialTimestamp;
        double y = event.getValue() / SCALE_Y;
        EventQueue.invokeLater(() -> {
            series.add(x, y);
            xAxis.setRange(max(0, x - TIME_RANGE), max(TIME_RANGE, x));
            yAxis.setRange(Y_RANGE_MIN, max(series.getMaxY(), Y_RANGE_UPPER_INITIAL));
        });
        hzMap.remove(event.getKey());
    };
    entryListenerId = hzMap.addEntryListener(entryAddedListener, true);
}

From source file:iqq.app.core.service.impl.EventServiceImpl.java

@Override
public void broadcast(final UIEvent event) {
    if (EventQueue.isDispatchThread()) {
        doBroadcast(event);/* w  ww  . jav a 2 s  .  c o m*/
    } else {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                doBroadcast(event);
            }
        });
    }
}

From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.standalone.StandaloneShutdownDialog.java

private void displayShutdownDialog() {
    String serverId = ServerDetector.getServerId();
    log.info("Running in: " + (serverId != null ? serverId : "unknown server"));
    log.info("Console: " + ((System.console() != null) ? "available" : "not available"));
    log.info("Headless: " + (GraphicsEnvironment.isHeadless() ? "yes" : "no"));

    // Show this only when run from the standalone JAR via a double-click
    if (System.console() == null && !GraphicsEnvironment.isHeadless() && ServerDetector.isWinstone()) {
        log.info("If you are running WebAnno in a server environment, please use '-Djava.awt.headless=true'");

        EventQueue.invokeLater(new Runnable() {
            @Override//from ww  w . j  a v  a2s .c o  m
            public void run() {
                final JOptionPane optionPane = new JOptionPane(new JLabel(
                        "<HTML>WebAnno is running now and can be accessed via <a href=\"http://localhost:8080\">http://localhost:8080</a>.<br>"
                                + "WebAnno works best with the browsers Google Chrome or Safari.<br>"
                                + "Use this dialog to shut WebAnno down.</HTML>"),
                        JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_OPTION, null,
                        new String[] { "Shutdown" });

                final JDialog dialog = new JDialog((JFrame) null, "WebAnno", true);
                dialog.setContentPane(optionPane);
                dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
                dialog.addWindowListener(new WindowAdapter() {
                    @Override
                    public void windowClosing(WindowEvent we) {
                        // Avoid closing window by other means than button
                    }
                });
                optionPane.addPropertyChangeListener(new PropertyChangeListener() {
                    @Override
                    public void propertyChange(PropertyChangeEvent aEvt) {
                        if (dialog.isVisible() && (aEvt.getSource() == optionPane)
                                && (aEvt.getPropertyName().equals(JOptionPane.VALUE_PROPERTY))) {
                            System.exit(0);
                        }
                    }
                });
                dialog.pack();
                dialog.setVisible(true);
            }
        });
    } else {
        log.info("Running in server environment or from command line: disabling interactive shutdown dialog.");
    }
}

From source file:jgnash.ui.report.compiled.IncomeExpensePieChart.java

public static void show() {

    EventQueue.invokeLater(() -> {
        final IncomeExpensePieChart chart = new IncomeExpensePieChart();

        final JPanel p = chart.createPanel();
        final GenericCloseDialog d = new GenericCloseDialog(p, ResourceUtils.getString("Title.AccountBalance"));
        d.pack();//from   w ww .  ja  va2s  .  c o  m
        d.setModal(false);

        d.setVisible(true);
    });
}

From source file:jgnash.ui.report.compiled.PayeePieChart.java

public static void show() {

    EventQueue.invokeLater(() -> {
        PayeePieChart chart = new PayeePieChart();

        JPanel p = chart.createPanel();
        GenericCloseDialog d = new GenericCloseDialog(p, ResourceUtils.getString("Title.AccountBalance"));
        d.pack();/*from ww w  .  j  a va2s  .com*/

        d.setMinimumSize(d.getSize());

        DialogUtils.addBoundsListener(d);

        d.setModal(false);

        d.setVisible(true);
    });
}

From source file:jgnash.ui.report.compiled.MonthlyAccountBalanceChartCompare.java

public static void show() {

    EventQueue.invokeLater(() -> {
        MonthlyAccountBalanceChartCompare chart = new MonthlyAccountBalanceChartCompare();

        JPanel p = chart.createPanel();
        GenericCloseDialog d = new GenericCloseDialog(p, ResourceUtils.getString("Title.AccountBalance"));
        d.pack();//from w  w w.j a  v a  2 s .c o m
        d.setModal(false);

        d.setVisible(true);
    });
}