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:org.zaproxy.zap.GuiBootstrap.java

@Override
public int start() {
    EventQueue.invokeLater(new Runnable() {

        @Override/*from  w ww  . j a v a  2s.c o  m*/
        public void run() {
            startImpl();
        }
    });
    return 0;
}

From source file:com.mgmtp.perfload.loadprofiles.ui.AppFrame.java

/**
 * Launch the application.//www. ja va 2s. co  m
 */
public static void main(final String[] args) {
    File baseDir = new File(System.getProperty("basedir", "."));

    final Injector inj = Guice.createInjector(new AppModule(baseDir));
    final ConfigController configCtrl = inj.getInstance(ConfigController.class);

    try {
        UIManager.setLookAndFeel(configCtrl.getLookAndFeelClassName());
    } catch (Exception ex) {
        LOG.error(ex.getMessage(), ex);
    }

    ExceptionHandler exceptionHandler = inj.getInstance(ExceptionHandler.class);
    Thread.setDefaultUncaughtExceptionHandler(exceptionHandler);

    // This is necessary because an UncaughtExceptionHandler does not work in modal dialogs
    System.setProperty("sun.awt.exception.handler", ExceptionHandler.class.getName());

    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            try {
                AppFrame frame = inj.getInstance(AppFrame.class);

                Rectangle bounds = configCtrl.getFrameBounds();
                if (bounds != null) {
                    frame.setBounds(bounds);
                }
                ImageIcon icon = new ImageIcon(
                        getResource("com/mgmtp/perfload/loadprofiles/ui/perfLoad_Logo_bild_64x64.png"));
                frame.setIconImage(icon.getImage());
                frame.updateLists();
                frame.updateGraph();
                frame.addTableListeners();
                frame.setUpEventBus();
                frame.setExtendedState(configCtrl.getFrameState());
                frame.setVisible(true);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });
}

From source file:com.willwinder.ugs.nbp.core.actions.ConnectDisconnectAction.java

@Override
public void UGSEvent(UGSEvent cse) {
    if (cse != null && cse.isStateChangeEvent()) {
        EventQueue.invokeLater(this::updateIconAndText);
    }//from w ww . java 2 s.c  o  m
}

From source file:net.sf.xmm.moviemanager.MovieManager.java

MovieManager(Object applet) {

    SysUtil.getAppMode();/*from w  ww  .j  a  va2 s  .  co  m*/

    movieManager = this;
    dialogMovieManager = new DialogMovieManager(applet);

    EventQueue.invokeLater(new Runnable() {
        public final void run() {

            /* Disable HTTPClient logging output */
            //System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); //$NON-NLS-1$ //$NON-NLS-2$
            //System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");

            //System.setProperty("apache.commons.logging.simplelog.defaultlog", "OFF");

            //System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger");
            //System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");

            // System.setProperty("log4j.logger.org.apache.commons.httpclient", "OFF");

            //URL configFile = FileUtil.getFileURL("log4j.properties"); //$NON-NLS-1$

            //PropertyConfigurator.configure(configFile);

            log = Logger.getRootLogger();

            /* Writes the date. */
            log.debug("Log Start: " + new Date(System.currentTimeMillis())); //$NON-NLS-1$
            log.debug("Starting applet"); //$NON-NLS-1$

            /* Loads the config */
            config.loadConfig();

            /* Must be executed before the JFrame (MovieManager) object is created. */
            if (lookAndFeelManager.getDefaultLookAndFeelDecorated()) {
                DialogMovieManager.setDefaultLookAndFeelDecorated(true);
            }

            /* Starts the MovieManager. */
            MovieManager.getDialog().setUp();

            /* Loads the database. */
            databaseHandler.loadDatabase();
        }
    });
}

From source file:de.atomfrede.tools.evalutation.ui.plant.PlantListPanel.java

/**
 * Rebuilding the interface after a plant was added or removed
 *//*from  ww  w  . j a v  a  2  s.com*/
private void rebuild() {
    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            try {
                invalidate();
                initialize();
                revalidate();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:simplealbum.mvc.autocomplete.JTextPaneX.java

protected void colorStyledDocument(final DefaultStyledDocument document) {
    EventQueue.invokeLater(new Runnable() {

        @Override/*from  w ww. j  av a2s. c o  m*/
        public void run() {
            String input = "";
            try {
                input = document.getText(0, document.getLength());
            } catch (BadLocationException ex) {
                Logger.getLogger(JTextPaneX.class.getName()).log(Level.SEVERE, null, ex);
            }

            StringBuilder inputMut = new StringBuilder(input);
            String[] split = StringUtils.split(inputMut.toString());
            int i = 0;
            for (String string : split) {
                int start = inputMut.indexOf(string);
                int end = start + string.length();
                inputMut.replace(start, end, StringUtils.repeat(" ", string.length()));
                document.setCharacterAttributes(start, string.length(), styles[i++ % styles.length], true);
            }
        }
    });
}

From source file:jgnash.ui.commodity.SecuritiesHistoryDialog.java

public static void showDialog(final JFrame parent) {

    EventQueue.invokeLater(() -> {
        SecuritiesHistoryDialog d = new SecuritiesHistoryDialog(parent);
        d.setVisible(true);//w w  w.  j  ava2  s.  c  om
    });
}

From source file:net.phyloviz.project.action.LoadDataSetAction.java

@Override
public void actionPerformed(ActionEvent ae) {

    final JDialog dialog = createLoadingDialog();

    EventQueue.invokeLater(new Runnable() {

        public void run() {
            Properties prop = new Properties();
            String propFileName = "config.properties.pviz";

            String projectDir = getProjectLocation();
            File visualization = new File(projectDir, VIZ_FOLDER);
            try {
                InputStream inputStream = new FileInputStream(new File(projectDir, propFileName));
                prop.load(inputStream);/*from  ww w  .j  a  v  a2  s .c  o  m*/

                StatusDisplayer.getDefault().setStatusText("Loading DataSet...");

                String dataSetName = prop.getProperty("dataset-name");
                if (dataSetAlreadyOpened(dataSetName)) {
                    JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
                            "DataSet already opened!");
                    WindowManager.getDefault().findTopComponent("DataSetExplorerTopComponent").requestActive();

                } else {

                    String typingFactory = prop.getProperty("typing-factory"),
                            typingFile = prop.getProperty("typing-file"),
                            populationFactory = prop.getProperty("population-factory"),
                            populationFile = prop.getProperty("population-file"),
                            populationFK = prop.getProperty("population-foreign-key"),
                            algorithmOutput = prop.getProperty("algorithm-output"),
                            algorithmOutputFactory = prop.getProperty("algorithm-output-factory"),
                            algorithmOutputDistanceProvider = prop.getProperty("algorithm-output-distance"),
                            algorithmOutputLevel = prop.getProperty("algorithm-output-level"),
                            visualizations = prop.getProperty("visualization"),
                            vizfilter = prop.getProperty("visualization-filter"),
                            vizpalette = prop.getProperty("visualization-palette");

                    String[] algoOutput = algorithmOutput != null ? algorithmOutput.split(",")
                            : new String[] { "" };
                    String[] algoOutputFactory = algorithmOutputFactory != null
                            ? algorithmOutputFactory.split(",")
                            : new String[] { "" };
                    String[] algoOutputDistance = algorithmOutputDistanceProvider != null
                            ? algorithmOutputDistanceProvider.split(",")
                            : new String[] { "" };
                    String[] algoOutputLevel = algorithmOutputLevel != null ? algorithmOutputLevel.split(",")
                            : new String[] { "" };
                    String[] viz = visualizations != null ? visualizations.split(",") : new String[] {};

                    if (dataSetName != null && (!dataSetName.equals(""))) {

                        DataSet ds = new DataSet(dataSetName);

                        StatusDisplayer.getDefault().setStatusText("Loading typing data...");

                        TypingFactory tf = null;
                        TypingData<? extends AbstractProfile> td = null;

                        Collection<? extends ProjectTypingDataFactory> tfLookup = (Lookup.getDefault()
                                .lookupAll(ProjectTypingDataFactory.class));
                        for (ProjectTypingDataFactory ptdi : tfLookup) {
                            if (ptdi.getClass().getName().equals(typingFactory)) {
                                tf = (TypingFactory) ptdi;
                                td = ptdi.onLoad(new FileReader(new File(projectDir, typingFile)));
                                td.setDescription(tf.toString());
                                ds.add(ptdi);
                            }
                        }

                        Population pop = null;
                        if (populationFile != null && (!populationFile.equals("")) && populationFK != null) {

                            StatusDisplayer.getDefault().setStatusText("Loading isolate data...");
                            pop = ((PopulationFactory) Class.forName(populationFactory).newInstance())
                                    .loadPopulation(new FileReader(new File(projectDir, populationFile)));
                            ds.add(pop);

                            int key = Integer.parseInt(populationFK);
                            StatusDisplayer.getDefault().setStatusText("Integrating data...");
                            td = tf.integrateData(td, pop, key);
                            ds.setPopKey(key);
                        }

                        int v_i = 0;
                        Collection<? extends ProjectItemFactory> pifactory = (Lookup.getDefault()
                                .lookupAll(ProjectItemFactory.class));
                        for (int i = 0; i < algoOutput.length; i++) {

                            for (ProjectItemFactory pif : pifactory) {
                                String pifName = pif.getClass().getName();
                                if (pifName.equals(algoOutputFactory[i])) {

                                    Visualization v = new Visualization();
                                    PersistentVisualization pv = null;
                                    if (viz.length > v_i
                                            && viz[v_i].split("\\.")[0].equals(algoOutput[i].split("\\.")[2])) {
                                        try (FileInputStream fileIn = new FileInputStream(
                                                new File(visualization, viz[v_i++]))) {

                                            try (ObjectInputStream in = new ObjectInputStream(fileIn)) {

                                                pv = (PersistentVisualization) in.readObject();

                                            }

                                        } catch (IOException | ClassNotFoundException e) {
                                            Exceptions.printStackTrace(e);
                                        }
                                        v.pv = pv;
                                        if (vizfilter != null) {
                                            TreeFilter treefilter = loadTreeFilter(visualization, vizfilter);
                                            v.filter = treefilter.filter;
                                            DataModel dm = treefilter.datamodel
                                                    .equals(TypingData.class.getCanonicalName()) ? td : pop;
                                            v.category = loadCategoryPalette(visualization, vizpalette, dm,
                                                    v.filter);
                                        }
                                    }
                                    StatusDisplayer.getDefault().setStatusText("Loading algorithms...");
                                    AbstractDistance ad = null;
                                    Collection<? extends DistanceProvider> dpLookup = (Lookup.getDefault()
                                            .lookupAll(DistanceProvider.class));
                                    for (DistanceProvider dp : dpLookup) {
                                        if (dp.getClass().getCanonicalName().equals(algoOutputDistance[i])) {
                                            ad = dp.getDistance(td);
                                        }
                                    }

                                    ProjectItem pi = pif.loadData(ds, td, projectDir, algoOutput[i], ad,
                                            Integer.parseInt(algoOutputLevel[i]));
                                    if (pi != null) {
                                        pi.addVisualization(v);
                                        td.add(pi);
                                    } else {
                                        return;
                                    }
                                }
                            }
                        }

                        ds.add(td);

                        Lookup.getDefault().lookup(DataSetTracker.class).add(ds);
                        StatusDisplayer.getDefault().setStatusText("Dataset loaded.");
                        WindowManager.getDefault().findTopComponent("DataSetExplorerTopComponent")
                                .requestActive();

                    } else {
                        Exceptions.printStackTrace(new IllegalArgumentException("DataSet name not found!"));
                    }
                }
            } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException
                    | NumberFormatException e) {
                Exceptions.printStackTrace(e);
            }
            dialog.dispose();
        }
    });

    dialog.setVisible(true);
}

From source file:org.parosproxy.paros.extension.update.ExtensionUpdate.java

/**
 * This method initializes menuItemEncoder
 * //from  w w w  .j a  v  a 2s  .c  o  m
 * @return javax.swing.JMenuItem
 */
private JMenuItem getMenuItemCheckUpdate() {
    if (menuItemCheckUpdate == null) {
        menuItemCheckUpdate = new JMenuItem();
        menuItemCheckUpdate.setText("Check for updates...");
        if (!Constant.isWindows() && !Constant.isLinux() && !Constant.isOSX()) {
            menuItemCheckUpdate.setEnabled(false);
        }
        menuItemCheckUpdate.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent e) {

                Thread t = new Thread(new Runnable() {
                    public void run() {
                        manualCheckStarted = true;
                        newestVersionName = getNewestVersionName();

                        if (waitDialog != null) {
                            waitDialog.setVisible(false);
                            waitDialog = null;
                        }
                        EventQueue.invokeLater(new Runnable() {
                            public void run() {

                                if (newestVersionName == null) {
                                    getView().showMessageDialog("Sorry, no update available.");
                                } else if (newestVersionName.equals("")) {
                                    getView().showWarningDialog(
                                            "Error encountered. Please check manually for new updates.");
                                } else {
                                    newestVersionName = newestVersionName.replaceAll("\\.zip", "");
                                    newestVersionName = newestVersionName.replaceAll("\\.dmg", "");
                                    getView().showMessageDialog("A new version of " + Constant.PROGRAM_NAME
                                            + " is available: " + newestVersionName + "\nPlease update!");
                                }

                            }
                        });
                    }
                });

                waitDialog = getView().getWaitMessageDialog("Checking if newer version exists...");
                t.start();
                waitDialog.setVisible(true);
            }
        });
    }
    return menuItemCheckUpdate;
}

From source file:com.josescalia.tumblr.app.MainFrame.java

/**
 * @param args the command line arguments
 *//*from w  w  w.j  a va 2  s  . com*/
public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
     */
    try {
        for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    }
    //</editor-fold>

    /* Create and display the form */
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            new MainFrame().setVisible(true);
        }
    });
}