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:it.flavianopetrocchi.jpdfbookmarks.JPdfBookmarks.java

/**
 * Start the application in the requested mode.
 *
 * @param args Arguments to select mode and pass files to process. Can be
 *             null.//from   w  w w . j a  v  a 2 s .c  om
 */
public void start(final String[] args) {
    if (args != null && args.length > 0) {
        setModeByCommandLine(args);
    }

    switch (mode) {
    case VERSION:
        out.println(version);
        break;
    case DUMP:
        dump();
        break;
    case SHOW_ON_OPEN:
        showOnOpen();
        break;
    case APPLY:
        apply();
        break;
    case GUI:
        //launchNewGuiInstance(inputFilePath, null);
        EventQueue.invokeLater(new GuiLauncher(inputFilePath));
        break;
    case HELP:
    default:
        printHelpMessage();

    }
}

From source file:org.bhavaya.ui.view.ChartView.java

protected void initImpl() {
    super.initImpl();

    analyticsModel = new AnalyticsTableModel(beanTable);
    analyticsModel.setGrouped(true);/*from   w ww . j av a  2 s. c om*/
    tableModelDataSet = new TableModelDataSet(analyticsModel);

    if (tableViewConfigurationToUseOnInit != null) {
        configureFromTableViewConfiguration(tableViewConfigurationToUseOnInit);
    } else if (configuration != null) {
        applyConfigToModels();
    }

    chartControl.init();

    setChartType(VERTICAL_BAR);
    setPlot3D(false);

    chartPanel.setMaximumDrawHeight(1200);
    chartPanel.setMaximumDrawWidth(1400);

    chartPanel.setBorder(BorderFactory.createLoweredBevelBorder());

    viewComponent = createViewComponent(chartPanel);

    //            pluggablePanel = new PluggablePanel(UIUtilities.createLoadingComponent("Waiting to load data"));

    ApplicationContext.getInstance().addGuiTask(new Task("ChartView loading data for " + getName()) {
        public void run() {
            try {
                //                        pluggablePanel.setPluggedComponent(UIUtilities.createLoadingComponent("Loading data..."));
                getBeanCollection().size(); //this ensures that a lazy beanCollection is inflated
                if (!isDisposed()) { // CriteriaBeanCollectionLoadDecorator may have disposed the view based a user request
                    EventQueue.invokeLater(new Runnable() {
                        public void run() {
                            try {
                                beanTable.setBeanCollection(getBeanCollection());
                                //                                        pluggablePanel.setPluggedComponent(BeanCollectionTableView.super.getComponent());
                            } catch (Exception e) {
                                log.error(e);
                                //                                        handleError(e);
                            }
                        }
                    });
                }
            } catch (Throwable e) {
                log.error(e);
                //                        handleError(e);
            }
        }
    });
}

From source file:org.zaproxy.zap.control.AddOnLoader.java

private void addAddOnImpl(AddOn ao) {
    if (AddOn.InstallationStatus.INSTALLED == ao.getInstallationStatus()) {
        return;/*w  ww.ja  v a2 s .c o m*/
    }

    if (this.blockList.contains(ao.getId())) {
        // Explicitly being added back, so remove from the block list
        this.blockList.remove(ao.getId());
        this.saveBlockList();
    }

    if (!isDynamicallyInstallable(ao)) {
        return;
    }

    AddOnRunRequirements reqs = calculateRunRequirements(ao, aoc.getInstalledAddOns());
    if (!reqs.isRunnable()) {
        ao.setInstallationStatus(AddOn.InstallationStatus.NOT_INSTALLED);
        return;
    }

    AddOnInstaller.install(createAndAddAddOnClassLoader(ao), ao);
    ao.setInstallationStatus(AddOn.InstallationStatus.INSTALLED);

    if (runnableAddOns.get(ao) == null) {
        runnableAddOns.put(ao, getRunnableExtensionsWithDeps(reqs));
        saveAddOnsRunState(runnableAddOns);
    }

    checkAndLoadDependentExtensions();
    checkAndInstallAddOnsNotInstalled();

    if (View.isInitialised()) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                View.getSingleton().refreshTabViewMenus();
            }
        });
    }
}

From source file:org.zaproxy.zap.extension.spiderAjax.SpiderThread.java

private void notifyMessage(final HttpMessage httpMessage, final int historyType, final ResourceState state) {
    try {/*from   w  ww.  ja  va  2 s  . co  m*/
        if (extension.getView() != null && !EventQueue.isDispatchThread()) {
            EventQueue.invokeLater(new Runnable() {

                @Override
                public void run() {
                    notifyMessage(httpMessage, historyType, state);
                }
            });
            return;
        }

        HistoryReference historyRef = new HistoryReference(session, historyType, httpMessage);
        if (state == ResourceState.PROCESSED) {
            historyRef.setCustomIcon("/resource/icon/10/spiderAjax.png", true);
            session.getSiteTree().addPath(historyRef, httpMessage);
        }

        notifySpiderListenersFoundMessage(historyRef, httpMessage, state);
    } catch (Exception e) {
        logger.error(e);
    }
}

From source file:org.n52.ifgicopter.spf.input.FakeInputPlugin.java

/**
 * // w  w  w  .j  a  va2s  .  co  m
 * @return
 */
private JLabel makeStatusLabel() {
    if (this.statusLabel == null)
        this.statusLabel = new JLabel();

    this.statusStringBuilder = new StringBuilder();
    this.statusStringBuilder.append("<html><p>");
    this.statusStringBuilder.append("<b>Status: </b>");
    this.statusStringBuilder.append(this.statusString);
    this.statusStringBuilder.append("</p><p><b>Center: </b>");
    this.statusStringBuilder.append(this.center);
    this.statusStringBuilder.append("</p><p><b>Angle: </b>");
    this.statusStringBuilder.append(this.angle);
    this.statusStringBuilder.append("</p><p><b>Altitude: </b>");
    this.statusStringBuilder.append(this.altitude);
    this.statusStringBuilder.append("</p></html>");

    EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            FakeInputPlugin.this.statusLabel.setText(FakeInputPlugin.this.statusStringBuilder.toString());
        }
    });
    return this.statusLabel;
}

From source file:net.technicpack.launcher.ui.LauncherFrame.java

public void launchCompleted() {
    if (installer.isCurrentlyRunning()) {
        EventQueue.invokeLater(new Runnable() {
            @Override//from w w w .ja va2  s . co m
            public void run() {
                launchCompleted();
            }
        });
        return;
    }

    installProgress.setVisible(false);
    installProgressPlaceholder.setVisible(true);

    userModel.setCurrentUser(userModel.getCurrentUser());

    invalidate();
}

From source file:org.nuclos.client.customcomp.resplan.ResPlanPanel.java

private void showInfoMessages() {
    if (infoMessages != null && infoButton.isVisible()) {
        StringBuilder sb = new StringBuilder("<html>");
        for (String message : infoMessages) {
            String escapedMessage = StringUtils.xmlEncode(message).replaceAll("\n", "<br/>");
            sb.append("<p>").append(escapedMessage).append("</p>");
        }//  w w w  .j  a  v a  2s. co m
        final String message = sb.toString();
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    Bubble bubble = new Bubble(infoButton, message, 8, Bubble.Position.SE);
                    bubble.setVisible(true);
                } catch (Exception e) {
                    LOG.error("showInfoMessages failed: " + e, e);
                }
            }
        });
    }
}

From source file:de.huxhorn.lilith.Lilith.java

private static void startLilith(String appTitle) {
    final Logger logger = LoggerFactory.getLogger(Lilith.class);

    uncaughtExceptionHandler = new UncaughtExceptionHandler();

    Thread.setDefaultUncaughtExceptionHandler(uncaughtExceptionHandler);

    // preventing duplicate instances...
    try {/*from  ww  w.  j a v  a 2  s .c o m*/
        JUnique.acquireLock(Lilith.class.getName(), Lilith::handleJUniqueMessage);
    } catch (AlreadyLockedException e) {
        if (logger.isInfoEnabled())
            logger.info("Detected running instance, quitting.");
        String result = JUnique.sendMessage(Lilith.class.getName(), "Show");
        if (logger.isDebugEnabled())
            logger.debug("JUnique result: {}", result);
        return;
    }
    // ok, we are the first instance this user has started...

    // install uncaught exception handler on event thread.
    EventQueue.invokeLater(() -> Thread.currentThread().setUncaughtExceptionHandler(uncaughtExceptionHandler));

    startUI(appTitle);
}

From source file:pl.edu.icm.visnow.system.main.VisNow.java

public static void main(final String[] args) {
    /*/* w w w .j ava2 s.co m*/
     * try { for (javax.swing.UIManager.LookAndFeelInfo info :
     * javax.swing.UIManager.getInstalledLookAndFeels()) { if
     * ("Nimbus".equals(info.getName())) {
     * javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } }
     * } catch (ClassNotFoundException ex) {
     * java.util.logging.LOGGER.getLogger(VisNow.class.getName()).log(java.util.logging.Level.SEVERE,
     * null, ex); } catch (InstantiationException ex) {
     * java.util.logging.LOGGER.getLogger(VisNow.class.getName()).log(java.util.logging.Level.SEVERE,
     * null, ex); } catch (IllegalAccessException ex) {
     * java.util.logging.LOGGER.getLogger(VisNow.class.getName()).log(java.util.logging.Level.SEVERE,
     * null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) {
     * java.util.logging.LOGGER.getLogger(VisNow.class.getName()).log(java.util.logging.Level.SEVERE,
     * null, ex); }
     */
    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {

            for (int i = 0; i < args.length; i++) {
                if (args[i].equals("-debug")) {
                    debug = true;
                }

                if (args[i].equals("-substancedebug")) {
                    substancedebug = true;
                }

                if (args[i].equals("-easy")) {
                    libraryLevel = SIMPLE_LIBRARY;
                    VERSION = VERSION_BASE + "-Simple";
                    allowGUISwitch = false;
                }

                if (args[i].equals("-full")) {
                    guiLevel = EXPERT_GUI;
                    libraryLevel = FULL_LIBRARY;
                    VERSION = VERSION_BASE + "-Pro";
                }
            }
            Locale.setDefault(Locale.US);

            renderSplashFrame(0.1f, "Initializing logging...");
            //TODO: test it see #initConfigDir
            //                initConfigDir();
            initLogging();
            startupInfo();
            renderSplashFrame(0.2f, "Initializing Java3D...");
            initJava3D();

            if (substancedebug) {
                try {

                    Class substance = Class.forName("org.jvnet.substance.SubstanceLookAndFeel");
                    Class selectedSkinClass;
                    if (guiLevel == SIMPLE_GUI) {
                        selectedSkinClass = Class.forName("org.jvnet.substance.skin.BusinessBlackSteelSkin");
                    } else {
                        @SuppressWarnings("unchecked")
                        Map<String, Object> skinInfoMap = (Map<String, Object>) substance
                                .getMethod("getAllSkins").invoke(null);
                        List<String> skinClassNameArray = new ArrayList<String>();
                        for (Object object : skinInfoMap.values()) {
                            String cn = (String) object.getClass().getMethod("getClassName").invoke(object);
                            LOGGER.info("Adding substance skin class: " + cn);
                            skinClassNameArray.add(cn);
                        }
                        int skinClassIdx = 0;
                        if (guiLevel == SIMPLE_GUI) {
                            skinClassIdx = 2;
                        } else {
                            skinClassIdx = new Random().nextInt(skinClassNameArray.size());
                        }
                        LOGGER.info("Selected skin: " + skinClassNameArray.get(skinClassIdx));
                        selectedSkinClass = Class.forName(skinClassNameArray.get(skinClassIdx));
                    }

                    //                        selectedSkinClass =Class.forName("org.jvnet.substance.skin.BusinessBlackSteelSkin");
                    javax.swing.UIManager
                            .setLookAndFeel("org.jvnet.substance.skin.SubstanceBusinessLookAndFeel");
                    Class skinClass = Class.forName("org.jvnet.substance.api.SubstanceSkin");
                    @SuppressWarnings("unchecked")
                    Method m = substance.getMethod("setSkin", skinClass);
                    m.invoke(null, selectedSkinClass.newInstance());
                    JFrame.setDefaultLookAndFeelDecorated(true);
                    JDialog.setDefaultLookAndFeelDecorated(true);
                } catch (Exception ex) {
                    LOGGER.error("Failed to set lf: " + ex.getMessage());
                }
            }

            //resize borders from tabbedPane
            //TODO: needs refactoring - initPresentation, initL&F or sth like that
            try {
                UIManager.getDefaults().put("TabbedPane.contentBorderInsets", new Insets(4, 0, 0, 0));
            } catch (Exception ex) {
                //this causes exception on MacOS X
            }

            try {
                visnow = new VisNow();

                int argsCount = 0;
                for (int i = 0; i < args.length; i++) {
                    if (!args[i].startsWith("-")) {
                        argsCount++;
                    }
                }
                String[] args2 = new String[argsCount];
                int c = 0;
                for (int i = 0; i < args.length; i++) {
                    if (!args[i].startsWith("-")) {
                        args2[c++] = args[i];
                    }
                }
                visnow.init(args2);
            } catch (VNSystemException ex) {
                Displayer.display(1010101010, ex, null, "Initialization failed.");
                return;
            }

            visnow.initUserMessages();
        }
    });

}

From source file:pl.kotcrab.arget.gui.MainWindow.java

private void processMenuEvent(MenuEvent event) {
    switch (event.type) {
    case ARGET_EDIT_OPTIONS:
        new OptionsDialog(this, profile);
        break;/*from  ww  w  .  j ava  2  s .  com*/
    case ARGET_LOGOUT:
        Settings.resetAutoLogin();
        dispose();

        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new LoginFrame();
            }
        });
        break;
    case ARGET_EXIT:
        dispose();
        ExitCleaner.forceExit();
        break;

    case SERVERS_ADD:
        new CreateServerInfoDialog(instance, new CreateServerDialogFinished() {

            @Override
            public void finished(ServerDescriptor info) {
                profile.servers.add(info);
                ProfileIO.saveProfile(profile);
                rebuildServersList();
            }
        });
        break;
    case SERVERS_MANAGE:
        new ManageServersDialog(instance, profile);
        break;
    case SERVERS_DISCONNECT:
        if (connection.isConnected())
            connection.requestDisconnect();
        else
            JOptionPane.showMessageDialog(instance,
                    "You need to be connected to a server to disconnect. Please connect to disconnect.",
                    "Error", JOptionPane.ERROR_MESSAGE);
        break;

    case CONTACTS_SHOW_PUBLIC_KEY: {
        String key = Base64.encodeBase64String(profile.rsa.getPublicKey().getEncoded());
        new DisplayPublicKeyDialog(instance, key);
        break;
    }
    case CONTACTS_ADD: {
        String key = Base64.encodeBase64String(profile.rsa.getPublicKey().getEncoded());
        new CreateContactDialog(instance, key, new CreateContactDialogFinished() {

            @Override
            public void finished(ContactInfo contact) {
                profile.contacts.add(contact);
                ProfileIO.saveProfile(profile);
                updateContacts();
            }
        });
        break;
    }
    case CONTACTS_REFRESH:
        connection.send(new KeychainRequest());
        break;

    case VIEW_SHOW_HOME:
        setCenterScreenTo(homePanel);
        break;
    case VIEW_SHOW_LOG:
        errorStatusPanel.clear();
        setCenterScreenTo(logPanel);
        break;

    case HELP_ABOUT:
        new AboutDialog(instance);
        break;
    default:
        Log.err(TAG, "Unknown menu event type: " + event.type);
        break;
    }
}