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:xtrememp.XtremeMP.java

public void init(String[] args) {
    // Process arguments
    Option urlOption = OptionBuilder.withArgName("URL").hasArg().withDescription("Open from URL").create("url");
    Options options = new Options();
    options.addOption("help", false, "print help information");
    options.addOption("version", false, "print the version information");
    options.addOption(urlOption);//  www  .  jav a  2  s .  c om
    CommandLineParser parser = new PosixParser();
    try {
        final CommandLine line = parser.parse(options, args);
        if (line.hasOption("h") || line.hasOption("help")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("xtrememp", options);
            System.exit(0);
        }
        if (line.hasOption("version")) {
            StringBuilder appVersion = new StringBuilder(tr("Application.title"));
            appVersion.append(" ").append(currentVersion);
            appVersion.append(" [").append(tr("Dialog.About.Codename"));
            appVersion.append(" ").append(tr("Application.version.codename"));
            appVersion.append("]");
            System.out.println(appVersion.toString());
            System.exit(0);
        }

        // Initialize JIntellitype
        if (OSUtils.IS_OS_WINDOWS) {
            String libraryLocation = (OSUtils.IS_ARCH_X64) ? "\\native\\JIntellitype64.dll"
                    : "\\native\\JIntellitype.dll";
            JIntellitype.setLibraryLocation(OSUtils.USER_DIR + libraryLocation);
            if (JIntellitype.isJIntellitypeSupported()) {
                JIntellitype.getInstance().addIntellitypeListener(this);
            }
        }

        // Initialize audio engine
        audioPlayer = new AudioPlayer();
        audioPlayer.addPlaybackListener(this);
        String mixerName = Settings.getMixerName();
        if (!Utilities.isNullOrEmpty(mixerName)) {
            audioPlayer.setMixerName(mixerName);
        }

        // Launch gui
        EventQueue.invokeLater(() -> {
            if (!OSUtils.IS_OS_WINDOWS_7 && !OSUtils.IS_OS_WINDOWS_VISTA) {
                JFrame.setDefaultLookAndFeelDecorated(true);
                JDialog.setDefaultLookAndFeelDecorated(true);
            }
            UIManager.put(SubstanceLookAndFeel.FOCUS_KIND, SubstanceConstants.FocusKind.NONE);
            SubstanceLookAndFeel.setSkin(Settings.getSkin());

            //Turn on Substance animations if required
            guiEffectsStateChanged(Settings.isUIEffectsEnabled());

            StringBuilder appTitle = new StringBuilder(tr("Application.title"));
            appTitle.append(" ").append(currentVersion);
            mainFrame = new JFrame(appTitle.toString());
            mainFrame.setIconImages(Utilities.getIconImages());

            Rectangle boundsRect = Settings.getMainFrameBounds();
            if (boundsRect.x <= 0 || boundsRect.y <= 0) {
                mainFrame.setSize(boundsRect.width, boundsRect.height);
                // Center the frame.
                mainFrame.setLocationRelativeTo(null);
            } else {
                mainFrame.setBounds(boundsRect);
            }
            mainFrame.addWindowListener(new WindowAdapter() {

                @Override
                public void windowClosing(WindowEvent ev) {
                    exit();
                }
                //                    @Override
                //                    public void windowIconified(WindowEvent e) {
                //                        if (Toolkit.getDefaultToolkit().isFrameStateSupported(JFrame.ICONIFIED)) {
                //                            getMainFrame().setExtendedState(JFrame.ICONIFIED);
                //                        }
                //                        getMainFrame().setVisible(false);
                //                    }
                //
                //                    @Override
                //                    public void windowDeiconified(WindowEvent e) {
                //                        if (Toolkit.getDefaultToolkit().isFrameStateSupported(JFrame.NORMAL)) {
                //                            getMainFrame().setExtendedState(JFrame.NORMAL);
                //                        }
                //                        getMainFrame().setVisible(true);
                //                    }
            });
            createMenuBar();
            createPanels();

            // Set a minimum size for this frame.
            mainFrame.setMinimumSize(new Dimension(532, 244));

            playlist = playlistManager.getPlaylist();
            playlist.addPlaylistListener(XtremeMP.this);

            // Restore playlist settings : play mode
            playlist.setPlayMode(Settings.getPlayMode());

            List<String> argList = Arrays.asList(line.getArgs());
            List<File> fileList = new ArrayList<>();
            if (argList.isEmpty()) {
                File playlistFile = new File(Settings.getCacheDir(), Utilities.DEFAULT_PLAYLIST);
                if (playlistFile.exists()) {
                    playlistManager.loadPlaylist(playlistFile.getAbsolutePath());
                }
            } else {
                playlistManager.setFirstLoad(true);
                if (argList.size() == 1) {
                    File file = new File(argList.get(0));
                    if (audioFileFilter.accept(file)) {
                        fileList.add(file);
                        playlistManager.addFiles(fileList, true);
                    } else if (playlistFileFilter.accept(file)) {
                        playlistManager.loadPlaylist(file.getAbsolutePath());
                    }
                } else {
                    for (String arg : argList) {
                        File file = new File(arg);
                        if (audioFileFilter.accept(file)) {
                            fileList.add(file);
                        }
                    }
                    playlistManager.addFiles(fileList, true);
                }
            }

            mainFrame.setVisible(true);
        });
    } catch (ParseException exp) {
        logger.error("Parsing failed.", exp.getMessage());
    }
}

From source file:com.excilys.ebi.gatling.recorder.ui.component.RunningFrame.java

@Subscribe
public void onShowConfigurationFrameEvent(ShowConfigurationFrameEvent event) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            setVisible(false);//w  w w  . jav  a 2s. c  om
        }
    });
}

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

/**
 * //from ww w.  j ava2s.co  m
 * @return
 */
private JPanel makeControlPanel() {
    if (this.controlPanel == null) {
        this.controlPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));

        JButton startButton = new JButton("Start");
        startButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        start();
                    }
                });
            }
        });
        this.controlPanel.add(startButton);
        JButton stopButton = new JButton("Stop");
        stopButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        stop();
                    }
                });
            }
        });
        this.controlPanel.add(stopButton);

        JLabel sleepTimeLabel = new JLabel("Time between points in seconds:");
        this.controlPanel.add(sleepTimeLabel);
        double spinnerMin = 0.1d;
        double spinnerMax = 10000.0d;
        SpinnerModel model = new SpinnerNumberModel(DEFAULT_INTERVAL_MILLIS / SECONDS_TO_MILLISECONDS,
                spinnerMin, spinnerMax, 0.1d);
        JSpinner sleepTimeSpinner = new JSpinner(model);
        sleepTimeSpinner.setToolTipText("Select time using controls or manual input within the range of "
                + spinnerMin + " to " + spinnerMax + ".");

        sleepTimeSpinner.addChangeListener(new ChangeListener() {

            @Override
            public void stateChanged(ChangeEvent e) {
                Object source = e.getSource();
                if (source instanceof JSpinner) {
                    final JSpinner spinner = (JSpinner) source;

                    EventQueue.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            Double value = (Double) spinner.getValue();
                            value = Double.valueOf(value.doubleValue() * SECONDS_TO_MILLISECONDS);
                            FakeInputPlugin.this.sleepTimeMillis = value.longValue();
                        }
                    });
                } else
                    log.warn("Unsupported ChangeEvent, need JSpinner as source: " + e);
            }
        });
        // catch text change events without loosing the focus
        // JSpinner.DefaultEditor editor = (DefaultEditor) sleepTimeSpinner.getEditor();
        // not implemented, can be done using KeyEvent, but then it hast to be checked where in the text
        // field the keystroke was etc. --> too complicated.

        this.controlPanel.add(sleepTimeSpinner);
    }

    return this.controlPanel;
}

From source file:org.ut.biolab.medsavant.shared.util.MiscUtils.java

/**
 * Invoke the given runnable on the AWT event thread.
 *
 * @param r the action to be invoked//w  ww  . j a  v  a 2s . c o  m
 */
public static void invokeLaterIfNecessary(Runnable r) {
    if (EventQueue.isDispatchThread()) {
        r.run();
    } else {
        EventQueue.invokeLater(r);
    }
}

From source file:com.excilys.ebi.gatling.recorder.ui.component.RunningFrame.java

@Subscribe
public void onShowRunningFrameEvent(ShowRunningFrameEvent event) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            setVisible(true);/*from w ww . ja v a2  s . c  om*/
            clearOldRunning();
            configuration = Configuration.getInstance();
            startDate = new Date();
            proxy = new GatlingHttpProxy(configuration.getPort(), configuration.getSslPort(),
                    configuration.getProxy());
            proxy.start();
        }
    });
}

From source file:phex.gui.tabs.download.SWCandidateTableModel.java

@EventTopicSubscriber(topic = PhexEventTopics.Download_Candidate)
public void onDownloadCandidateEvent(String topic, final ContainerEvent event) {
    if (downloadFile != ((SWDownloadCandidate) event.getSource()).getDownloadFile()) {
        return;/*from w  w w.j  a v a 2  s  . c om*/
    }
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            int position = event.getPosition();
            if (event.getType() == ContainerEvent.Type.ADDED) {
                fireTableChanged(new TableModelEvent(SWCandidateTableModel.this, position, position,
                        TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
            } else if (event.getType() == ContainerEvent.Type.REMOVED) {
                fireTableChanged(new TableModelEvent(SWCandidateTableModel.this, position, position,
                        TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE));
            }
        }
    });
}

From source file:phex.gui.tabs.download.SWDownloadTableModel.java

@EventTopicSubscriber(topic = PhexEventTopics.Download_File)
public void onDownloadFileEvent(String topic, final ContainerEvent event) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            int position = event.getPosition();
            if (event.getType() == ContainerEvent.Type.ADDED) {
                fireTableChanged(new TableModelEvent(SWDownloadTableModel.this, position, position,
                        TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
            } else if (event.getType() == ContainerEvent.Type.REMOVED) {
                fireTableChanged(new TableModelEvent(SWDownloadTableModel.this, position, position,
                        TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE));
            }//from  w  ww  .  j  a v a  2s .  com
        }
    });
}

From source file:org.parosproxy.paros.extension.history.ExtensionHistory.java

public void removeFromHistoryList(final HistoryReference href) {
    if (!View.isInitialised() || EventQueue.isDispatchThread()) {
        this.historyTableModel.removeEntry(href.getHistoryId());
        historyIdToRef.remove(Integer.valueOf(href.getHistoryId()));
    } else {/*w  ww . j  ava  2s  .  co m*/
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                removeFromHistoryList(href);
            }
        });
    }
}

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

@Override
public void readURI(final HttpMessage msg) {
    // Add the read message to the Site Map (tree or db structure)
    try {//w w w  .jav a 2  s . c  om
        final HistoryReference historyRef = new HistoryReference(extension.getModel().getSession(),
                HistoryReference.TYPE_SPIDER, msg);

        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                SessionStructure.addPath(Model.getSingleton().getSession(), historyRef, msg);
            }
        });

    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}

From source file:eu.ggnet.dwoss.receipt.unit.UnitView.java

private void updateValidationStatus(JComponent component, Survey vs, StringBuilder sb) {
    EventQueue.invokeLater(() -> {
        component.setToolTipText(vs.getMessage());
        component.setForeground(vs.getStatus().getColor());
    });/*w  w  w.  ja  v  a2 s  . c om*/
    sb.append("- ").append(component.getName()).append(": ").append(vs.getStatus()).append(" : ")
            .append(vs.getMessage()).append("\n");
}