Example usage for javax.swing SwingUtilities invokeLater

List of usage examples for javax.swing SwingUtilities invokeLater

Introduction

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

Prototype

public static void invokeLater(Runnable doRun) 

Source Link

Document

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

Usage

From source file:org.atomspace.pi2c.runtime.Server.java

private static void addWindowsShutdownHandle() {
    Runnable guiCreator = new Runnable() {
        public void run() {
            // create a swing window
            JFrame macroWindow = new JFrame("MacroServer");
            macroWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            macroWindow.setSize(250, 70);
            macroWindow.setVisible(true);
            JButton button = new JButton("SHUTDOWN");
            button.addActionListener(new ActionListener() {
                @Override/*w ww.ja v a 2  s.  c  o m*/
                public void actionPerformed(ActionEvent e) {
                    System.out.println("STOPPING SERVER, PLEASE WAIT...");
                    System.exit(0);
                }
            });
            macroWindow.getContentPane().add(button);
        }
    };
    SwingUtilities.invokeLater(guiCreator);
}

From source file:net.sf.maltcms.chromaui.charts.tools.ChartTools.java

/**
 *
 * @param p//from   w w w . ja  va  2s .com
 * @param sps
 */
public static void changePaintScale(final XYPlot p, final PaintScale sps) {
    if (p.getRenderer() instanceof XYBlockRenderer) {
        Runnable r = new Runnable() {
            @Override
            public void run() {
                XYBlockRenderer renderer = (XYBlockRenderer) p.getRenderer();
                Logger.getLogger(ChartTools.class.getName()).info("Setting paintscale");
                renderer.setPaintScale(sps);
                if (p instanceof FastHeatMapPlot) {
                    Logger.getLogger(ChartTools.class.getName()).info("Resetting data image");
                    FastHeatMapPlot fhp = (FastHeatMapPlot) p;
                    fhp.resetDataImage();
                }
                p.notifyListeners(new PlotChangeEvent(p));
            }
        };
        SwingUtilities.invokeLater(r);
    }
}

From source file:net.sf.profiler4j.console.util.task.LongTaskExecutorDialog.java

public void runTask(final LongTask task) {
    label.setText("Executing long-running task...");
    task.setDialog(this);
    Thread t = new Thread("PROFILER4J_TASK") {
        public void run() {
            log.debug("TASK STARTED");
            try {
                task.executeInBackground();
            } catch (final Exception e) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        log.error("Caught task error", e);
                        error = e;//from   ww  w.j  a va  2  s .c  om
                    };
                });
            } finally {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        log.debug("TASK COMPLETED");
                        if (error != null) {
                            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
                            progressBar.setIndeterminate(false);
                            setSize(486, 379);
                            setVisible(true);
                            toFront();
                            ((JComponent) statusTextArea.getParent()).revalidate();
                            StringWriter sw = new StringWriter();
                            PrintWriter pw = new PrintWriter(sw);
                            error.printStackTrace(pw);
                            statusTextArea.setText(sw.toString());
                            statusTextArea.setCaretPosition(0);
                            task.setError(error);
                        } else {
                            setVisible(false);
                            dispose();
                        }
                    }
                });
            }
        };
    };
    t.setName("LongTaskRunner");
    t.setPriority(Thread.MIN_PRIORITY);
    t.setDaemon(false);
    t.start();

    setLocation(getLocation().x, getLocation().y - 120);
    setVisible(true);
}

From source file:de.fhg.igd.swingrcp.ActionAdapter.java

/**
 * @see Action#run()/*from   w w  w. j  a  v  a2s .  c om*/
 */
@Override
public void run() {
    // execute action
    SwingUtilities.invokeLater(new Runnable() {

        /**
         * @see Runnable#run()
         */
        @Override
        public void run() {
            action.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null));
        }

    });
}

From source file:com.eightbitmage.moonscript.debugger.MoonDebugProcess.java

public void sessionInitialized() {
    super.sessionInitialized();
    ProgressManager.getInstance().run(new Task.Backgroundable(null, "Connecting to debugger", false) {

        public void run(@NotNull ProgressIndicator indicator) {
            indicator.setText("Connecting to debugger...");
            log.debug("connecting");
            try {
                controller.waitForConnect();

                log.debug("connected");
                indicator.setText("... Debugger connected");

                getSession().rebuildViews();

                registerBreakpoints();/*from w ww  .  ja  va 2 s . c  om*/

                controller.resume();
            } catch (final Exception e) {

                if (executionResult != null && executionResult.getProcessHandler() != null)
                    executionResult.getProcessHandler().destroyProcess();

                if (!myClosing)
                    SwingUtilities.invokeLater(new Runnable() {

                        public void run() {
                            Messages.showErrorDialog((new StringBuilder())
                                    .append("Unable to establish connection with debugger:\n")
                                    .append(e.getMessage()).toString(), "Connecting to debugger");
                        }
                    });
            }
        }
    });
}

From source file:it.imtech.configuration.StartWizard.java

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override//ww  w .j  a va2 s  .  co m
        public void run() {
            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) {
                logger.error(ex.getMessage());
            } catch (InstantiationException ex) {
                logger.error(ex.getMessage());
            } catch (IllegalAccessException ex) {
                logger.error(ex.getMessage());
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                logger.error(ex.getMessage());
            }

            StartWizard.getInstance();
        }
    });
}

From source file:edu.ku.brc.specify.config.init.SpecifyDBSetupWizardFrame.java

/**
 * @throws HeadlessException/*from w  ww.  j a  va 2  s.com*/
 */
public SpecifyDBSetupWizardFrame() throws HeadlessException {
    super();

    UIRegistry.loadAndPushResourceBundle("specifydbsetupwiz");

    new MacOSAppHandler(this);

    UIRegistry.setTopWindow(this);

    // Now initialize
    AppPreferences localPrefs = AppPreferences.getLocalPrefs();
    localPrefs.setDirPath(UIRegistry.getAppDataDir());

    AppPrefsCache.setUseLocalOnly(true);
    SpecifyAppPrefs.setSkipRemotePrefs(true);
    SpecifyAppPrefs.initialPrefs();

    Specify.adjustLocaleFromPrefs();

    ImageIcon helpIcon = IconManager.getIcon(SpecifyDBSetupWizard.getIconName(), IconSize.Std32); //$NON-NLS-1$
    HelpMgr.initializeHelp("SpecifyHelp", helpIcon.getImage()); //$NON-NLS-1$

    JMenuBar menuBar = createMenus();
    if (menuBar != null) {
        setJMenuBar(menuBar);
    }
    UIRegistry.register(UIRegistry.MENUBAR, menuBar);

    setIconImage(
            IconManager.getIcon(SpecifyDBSetupWizard.getIconName(), IconManager.IconSize.NonStd).getImage());

    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

    SpecifyDBSetupWizard wizPanel = new SpecifyDBSetupWizard(SpecifyDBSetupWizard.WizardType.Institution,
            new SpecifyDBSetupWizard.WizardListener() {
                @Override
                public void cancelled() {
                    setVisible(false);
                    //dispose();
                    doExit(true);
                }

                @Override
                public void hide() {
                    setVisible(false);
                }

                @Override
                public void finished() {
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            dispose();
                            doExit(true);
                        }
                    });
                }

                @Override
                public void panelChanged(String title) {
                    setTitle(getAppTitle(title));
                }

                @Override
                public void helpContextChanged(String helpTarget) {
                    if (getHelpMenuItem() != null) {
                        HelpMgr.registerComponent(getHelpMenuItem(), helpTarget);
                    }
                }

            });

    setTitle(getAppTitle(getResourceString("MAIN_TITLE")));

    setContentPane(wizPanel);

    pack();
}

From source file:org.nekorp.workflow.desktop.view.BitacoraView.java

@Override
public void updateModel(Object origen, String property, Object value) {
    if (!ignore.remove(value)) {
        LinkedList<EventoVB> param = (LinkedList<EventoVB>) value;
        LinkedList<EventoVB> borrar = new LinkedList<>();
        for (EventoVB obj : modelo) {
            if (!param.contains(obj)) {
                borrar.add(obj);/*w  ww  . j a  v a2s.  com*/
            }
        }
        for (EventoVB x : borrar) {
            removeEvento(x);
        }
        for (int i = 0; i < param.size(); i++) {
            if (this.modelo.size() > i) {
                if (!param.get(i).equals(this.modelo.get(i))) {
                    this.modelo.add(i, param.get(i));
                    addEventoView(this.modelo.get(i), i);
                }
            } else {
                this.modelo.add(param.get(i));
                addEventoView(this.modelo.get(i), i);
            }
        }
        this.updateUI();
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                jScrollPane1.getVerticalScrollBar().setValue(jScrollPane1.getVerticalScrollBar().getMaximum());
            }
        });
    }
}

From source file:be.ac.ua.comp.scarletnebula.gui.Graph.java

/**
 * Registers a new datapoint for the stream named streamname, which was
 * measured at value, at time time.//from  w  ww .  ja v a  2s  .  c  o  m
 * 
 * @param datapoint
 *            The datapoint to add.
 * @param time
 *            The time at which this measurement was made
 */
@Override
public void newDataPoint(final RegularTimePeriod time, final Datapoint datapoint) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            final String dataStreamName = datapoint.getDatastream();
            if (datastreams.containsKey(dataStreamName)) {
                datastreams.get(dataStreamName).addOrUpdate(time, datapoint.getValue());
            }

            for (final Server server : serversToRefresh) {
                server.serverChanged();
            }
        }
    });
}