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.n52.ifgicopter.spf.input.LastDataPostgisInputPlugin.java

@Override
protected JPanel makeControlPanel() {
    if (this.controlPanel == null) {
        this.controlPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));

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

            @Override// w  w  w  .j  av  a 2  s . c  om
            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 minTimeLabel = new JLabel("Mimium time database queries in milliseconds:");
        this.controlPanel.add(minTimeLabel);
        SpinnerModel model = new SpinnerNumberModel(this.minimumMillisBetweenRequests, 10d, 3600000d, 10d);
        JSpinner sleepTimeSpinner = new JSpinner(model);
        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() * 1000d);
                            setMinimumMillisBetweenRequests(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.fit.cssbox.scriptbox.demo.tester.JavaScriptTesterUIPresenter.java

public void showWindow() {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                JFrame window = tester.getWindow();
                window.setExtendedState(JFrame.MAXIMIZED_BOTH);
                window.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();//from  ww w .j  av  a2  s.  c o m
                JOptionPane.showMessageDialog(tester.getWindow(), "Unable to run application.",
                        "Internal error", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
}

From source file:me.mayo.telnetkek.MainPanel.java

public final void updatePlayerList(final String selectedPlayerName) {
    EventQueue.invokeLater(() -> {
        playerListTableModel.fireTableDataChanged();

        MainPanel.this.txtNumPlayers.setText("" + playerList.size());

        if (selectedPlayerName != null) {
            final JTable table = MainPanel.this.tblPlayers;
            final ListSelectionModel selectionModel = table.getSelectionModel();

            playerList.stream().filter((player) -> (player.getName().equals(selectedPlayerName)))
                    .forEach((player) -> {
                        selectionModel.setSelectionInterval(0,
                                table.convertRowIndexToView(playerList.indexOf(player)));
                    });/*www  . j  av a 2 s .  c o m*/
        }
    });
}

From source file:phex.gui.tabs.upload.UploadFilesTableModel.java

@EventTopicSubscriber(topic = PhexEventTopics.Upload_State)
public void onUploadStateEvent(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(UploadFilesTableModel.this, position, position,
                        TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
            } else if (event.getType() == ContainerEvent.Type.REMOVED) {
                fireTableChanged(new TableModelEvent(UploadFilesTableModel.this, position, position,
                        TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE));
            }//w  ww.  ja  v  a  2s .c  o m
        }
    });
}

From source file:org.moeaframework.examples.gp.regression.SymbolicRegressionGUI.java

/**
 * Updates the GUI with a new intermediate solution.
 * //from  w  ww  .  j a  va 2s  .c  o m
 * @param solution the new solution
 * @param generation the current generation count
 * @param maxGenerations the maximum generations being run
 */
public void update(Solution solution, int generation, int maxGenerations) {
    this.solution = solution;
    this.generation = generation;
    this.maxGenerations = maxGenerations;

    if (EventQueue.isDispatchThread()) {
        updateOnEventQueue();
    } else {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                updateOnEventQueue();
            }

        });
    }
}

From source file:com.bsoft.baseframe.baseframe_utils.beanUtils.Classgenerator.java

public static void init() {
    EventQueue.invokeLater(new Runnable() {
        @Override/*from w ww  .j a v a 2  s .  c  o m*/
        public void run() {
            JFrame frame = new Classgenerator();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
            frame.setResizable(false);
        }
    });
}

From source file:com.googlecode.logVisualizer.LogVisualizer.java

private LogVisualizer() {
    try {//  w w  w.  ja  v a 2 s.c  o  m
        final String wantedLaf = Settings.getSettingString("LookAndFeel");
        LookAndFeelInfo usedLaf = null;
        for (final LookAndFeelInfo lafi : UIManager.getInstalledLookAndFeels())
            if (lafi.getName().equals(wantedLaf)) {
                usedLaf = lafi;
                break;
            }

        if (usedLaf != null)
            UIManager.setLookAndFeel(usedLaf.getClassName());
        else
            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    } catch (final Exception e) {
        e.printStackTrace();
    }

    gui = new LogVisualizerGUI(new LogLoaderListener() {
        public void loadMafiaLog(final File file) {
            loadLog(file, new MafiaLogParser(file, Settings.getSettingBoolean("Include mafia log notes")));
        }

        public void loadPreparsedLog(final File file) {
            loadLog(file, new PreparsedLogParser(file));
        }

        public void loadXMLLog(final File file) {
            try {
                final LogDataHolder logData = XMLLogReader.parseXMLLog(file);
                addLogGUI(file, logData);
            } catch (final FileAccessException e) {
                e.printStackTrace();
                JOptionPane.showMessageDialog(gui, "A problem occurred while reading the file.",
                        "Error occurred", JOptionPane.ERROR_MESSAGE);
            } catch (final XMLAccessException e) {
                e.printStackTrace();
                JOptionPane.showMessageDialog(gui, "A problem occurred while parsing the XML.",
                        "Error occurred", JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    gui.setSize(800, 600);
    RefineryUtilities.centerFrameOnScreen(gui);
    gui.setVisible(true);

    if (Settings.getSettingBoolean("First program startup")) {
        final JLabel text = new JLabel(
                "<html>Note that <b>for the purpose of logging your own runs with KolMafia, it is best</b> to "
                        + "turn on all options but <i>Log adventures left instead of adventures used</i> under "
                        + "<i>General->Preferences->Session Logs</i> in KolMafia."
                        + "<br><br><br>This informational popup will only be displayed this once.</html>");
        text.setPreferredSize(new Dimension(550, 100));
        JOptionPane.showMessageDialog(gui, text, "KolMafia logging options", JOptionPane.INFORMATION_MESSAGE);

        Settings.setSettingBoolean("First program startup", false);
    }

    if (Settings.getSettingBoolean("Check Updates"))
        new Thread(new Runnable() {
            public void run() {
                if (ProjectUpdateViewer.isNewerVersionUploaded())
                    EventQueue.invokeLater(new Runnable() {
                        public void run() {
                            UpdateDialog.showDialog(gui);
                        }
                    });
            }
        }).start();
}

From source file:nz.co.fortytwo.freeboard.installer.InstalManager.java

public static void main(String[] args) {
    System.out.println("Current dir:" + new File(".").getAbsolutePath());
    try {//from  w w  w  .j  a  v  a  2 s . co  m
        for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (UnsupportedLookAndFeelException e) {
        // handle exception
    } catch (ClassNotFoundException e) {
        // handle exception
    } catch (InstantiationException e) {
        // handle exception
    } catch (IllegalAccessException e) {
        // handle exception
    }
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            new InstalManager("FreeBoard - Install Manager").setVisible(true);
        }
    });
}

From source file:io.github.dsheirer.gui.SDRTrunk.java

public SDRTrunk() {
    mLog.info("*******************************************************************");
    mLog.info("**** sdrtrunk: a trunked radio and digital decoding application ***");
    mLog.info("****  website: https://github.com/dsheirer/sdrtrunk             ***");
    mLog.info("*******************************************************************");
    mLog.info("Memory Logging Format: [Used/Allocated PercentUsed%]");
    mLog.info("Host CPU Cores:        " + Runtime.getRuntime().availableProcessors());
    mLog.info("Host OS Name:          " + System.getProperty("os.name"));
    mLog.info("Host OS Arch:          " + System.getProperty("os.arch"));
    mLog.info("Host OS Version:       " + System.getProperty("os.version"));
    mLog.info("Host Max Java Memory:  " + FileUtils.byteCountToDisplaySize(Runtime.getRuntime().maxMemory()));

    //Setup the application home directory
    Path home = getHomePath();/*from   w w w.  j ava  2  s  .  c o m*/

    ThreadPool.logSettings();

    mLog.info("Home path: " + home.toString());

    //Load properties file
    if (home != null) {
        loadProperties(home);
    }

    //Log current properties setting
    SystemProperties.getInstance().logCurrentSettings();

    TunerConfigurationModel tunerConfigurationModel = new TunerConfigurationModel();
    TunerModel tunerModel = new TunerModel(tunerConfigurationModel);

    mIconManager = new IconManager();

    mSettingsManager = new SettingsManager(tunerConfigurationModel);

    AliasModel aliasModel = new AliasModel();

    ChannelModel channelModel = new ChannelModel();

    ChannelMapModel channelMapModel = new ChannelMapModel();

    EventLogManager eventLogManager = new EventLogManager();

    RecorderManager recorderManager = new RecorderManager();

    SourceManager sourceManager = new SourceManager(tunerModel, mSettingsManager);

    ChannelProcessingManager channelProcessingManager = new ChannelProcessingManager(channelModel,
            channelMapModel, aliasModel, eventLogManager, recorderManager, sourceManager);
    channelProcessingManager.addAudioPacketListener(recorderManager);

    channelModel.addListener(channelProcessingManager);

    ChannelSelectionManager channelSelectionManager = new ChannelSelectionManager(channelModel);
    channelModel.addListener(channelSelectionManager);

    AliasActionManager aliasActionManager = new AliasActionManager();
    channelProcessingManager.addMessageListener(aliasActionManager);

    AudioManager audioManager = new AudioManager(sourceManager.getMixerManager());
    channelProcessingManager.addAudioPacketListener(audioManager);

    mBroadcastModel = new BroadcastModel(mIconManager);

    channelProcessingManager.addAudioPacketListener(mBroadcastModel);

    MapService mapService = new MapService(mIconManager);
    channelProcessingManager.addMessageListener(mapService);

    mControllerPanel = new ControllerPanel(audioManager, aliasModel, mBroadcastModel, channelModel,
            channelMapModel, channelProcessingManager, mIconManager, mapService, mSettingsManager,
            sourceManager, tunerModel);

    mSpectralPanel = new SpectralDisplayPanel(channelModel, channelProcessingManager, mSettingsManager);

    TunerSpectralDisplayManager tunerSpectralDisplayManager = new TunerSpectralDisplayManager(mSpectralPanel,
            channelModel, channelProcessingManager, mSettingsManager);
    tunerModel.addListener(tunerSpectralDisplayManager);
    tunerModel.addListener(this);

    PlaylistManager playlistManager = new PlaylistManager(aliasModel, mBroadcastModel, channelModel,
            channelMapModel);

    playlistManager.init();

    mLog.info("starting main application gui");

    //Initialize the GUI
    initGUI();

    tunerModel.requestFirstTunerDisplay();

    //Start the gui
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                mMainGui.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:edu.ku.brc.specify.dbsupport.cleanuptools.GeoChooserDlg.java

/**
 * //  w ww. j a  v a2s . c  om
 */
private void calcProgress() {
    if (progressBar != null) {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                int percent = geoTotal == 0 ? 0 : (int) (((double) processedCount * 100.0) / (double) geoTotal);
                progressBar.setValue(percent);
                progressBar.repaint();
            }
        });
    }
}