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:se.nawroth.asciidoc.browser.AsciidocBrowserApplication.java

public static void main(final String[] args) {
    EventQueue.invokeLater(new Runnable() {
        @Override/* w  w w . j  a  v  a2 s  .c  om*/
        public void run() {
            try {
                JFrame.setDefaultLookAndFeelDecorated(true);
                JDialog.setDefaultLookAndFeelDecorated(true);
                System.setProperty("sun.awt.noerasebackground", "true");
                UIManager.setLookAndFeel(new AsciidocBrowserSubstanceSkin());
                AsciidocBrowserApplication browser = new AsciidocBrowserApplication(args);
                browser.setVisible(true);
                settingsDialog = new SettingsDialog();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

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

/**
 * @return//  ww w  . ja  v  a 2 s . c  om
 * 
 */
@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
            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(2.0d, 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() * 1000d);
                            setSleepTimeMillis(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);

        JLabel whereLabel = new JLabel("Where clause: ");
        this.whereField = new JTextField(this.where);
        this.whereField.setPreferredSize(new Dimension(200, 20));
        this.whereField.setToolTipText("Insert a valid SQL 'WHERE' clause here.");
        this.whereButton = new JButton("Load data");
        this.whereButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        updateWhere();

                        loadAllData();
                    }
                });
            }
        });

        this.controlPanel.add(whereLabel);
        this.controlPanel.add(this.whereField);
        this.controlPanel.add(this.whereButton);
    }

    return this.controlPanel;
}

From source file:org.parosproxy.paros.extension.manualrequest.ManualRequestEditorDialog.java

protected void postSend() {
    EventQueue.invokeLater(new Runnable() {

        @Override// w w  w.  jav a2s. co m
        public void run() {
            // redraw, as message may have changed after sending
            getRequestPanel().updateContent();
        }
    });
}

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

/**
 * Adds a {@link LogGUI} with the given logData to the log pane as a task to
 * do on the EventQueue.// w  w  w  . ja  v a  2 s  .co m
 */
private void addLogGUI(final File log, final LogDataHolder logData) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            final LogGUI logGUI = new LogGUI(log, logData, !logData.isDetailedLog());
            logGUI.setGanttPanelButtonListener(new GanttPaneButtonListener() {
                public void areaCategoryCustomizerPressed(final TurnrundownGantt turnrundownChart) {
                    new LocationCategoryCustomizer(gui, turnrundownChart);
                }

                public void familiarColorizerPressed(final TurnrundownGantt turnrundownChart) {
                    new FamiliarUsageCustomizer(gui, turnrundownChart);
                }
            });

            gui.addLogTab(logGUI);
        }
    });
}

From source file:org.sleuthkit.autopsy.keywordsearch.ExtractedContentViewer.java

private void scrollToCurrentHit() {
    final MarkupSource source = panel.getSelectedSource();
    if (source == null || !source.isSearchable()) {
        return;/*w  w  w . j  a v a2  s . c  o m*/
    }

    // using invokeLater to wait for ComboBox selection to complete
    EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            panel.scrollToAnchor(source.getAnchorPrefix() + Integer.toString(source.currentItem()));
        }
    });
}

From source file:atlas.kingj.roi.FrmMain.java

/**
 * Launch the application.//from ww  w.  j  a  v  a 2  s  . c o m
 */
public static void main(String[] args) {
    try {
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Throwable e) {
        e.printStackTrace();
    }
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                window = new FrmMain();
                window.frmTitanRoiCalculator.setVisible(true);
                window.btnNewMachine.requestFocusInWindow();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

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

private void colorInputText() {
    EventQueue.invokeLater(() -> {
        try {//from w w w.  j av  a  2 s .  c o  m
            String inputText = jTextPaneDocument.getText(0, jTextPaneDocument.getLength());
            StringBuilder inputMut = new StringBuilder(inputText);
            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()));
                jTextPaneDocument.setCharacterAttributes(start, string.length(), styles[i++ % styles.length],
                        true);
            }
        } catch (BadLocationException ex) {
            Logger.getLogger(DController.class.getName()).log(Level.SEVERE, null, ex);
        }
    });
}

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

public LauncherFrame(final ResourceLoader resources, final ImageRepository<IUserType> skinRepository,
        final UserModel userModel, final TechnicSettings settings, final ModpackSelector modpackSelector,
        final ImageRepository<ModpackModel> iconRepo, final ImageRepository<ModpackModel> logoRepo,
        final ImageRepository<ModpackModel> backgroundRepo, final Installer installer,
        final ImageRepository<AuthorshipInfo> avatarRepo, final IPlatformApi platformApi,
        final LauncherDirectories directories, final IInstalledPackRepository packRepository,
        final StartupParameters params, final DiscoverInfoPanel discoverInfoPanel) {
    setSize(FRAME_WIDTH, FRAME_HEIGHT);//from  w w w  . j  av a  2  s  . co m
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    this.userModel = userModel;
    this.skinRepository = skinRepository;
    this.settings = settings;
    this.modpackSelector = modpackSelector;
    this.iconRepo = iconRepo;
    this.logoRepo = logoRepo;
    this.backgroundRepo = backgroundRepo;
    this.installer = installer;
    this.avatarRepo = avatarRepo;
    this.platformApi = platformApi;
    this.directories = directories;
    this.packRepo = packRepository;
    this.params = params;
    this.discoverInfoPanel = discoverInfoPanel;

    //Handles rebuilding the frame, so use it to build the frame in the first place
    relocalize(resources);

    selectTab("discover");

    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            LauncherMain.consoleFrame.setVisible(settings.getShowConsole());
        }
    });

    setLocationRelativeTo(null);
}

From source file:org.zaproxy.zap.extension.jxbrowserlinux64.selenium.JxBrowserProvider.java

private void cleanUpBrowser(final int requesterId, final BrowserPanel browserPanel) {
    if (View.isInitialised()) {
        EventQueue.invokeLater(new Runnable() {

            @Override//w  w w .j a va2 s. co  m
            public void run() {
                if (!requesterToZbf.containsKey(requesterId)) {
                    return;
                }

                cleanUpBrowserImpl(requesterId, browserPanel);
            }
        });
    } else {
        synchronized (this) {
            if (!requesterToZbf.containsKey(requesterId)) {
                return;
            }
            cleanUpBrowserImpl(requesterId, browserPanel);
        }
    }
}

From source file:eu.delving.sip.Application.java

public static void main(final String[] args) throws StorageException {
    storageFinder.setArgs(args);/*from  w w w  . j ava2  s .  co  m*/
    Runtime rt = Runtime.getRuntime();
    int totalMemory = (int) (rt.totalMemory() / 1024 / 1024);
    System.out.println("Total memory: " + totalMemory);
    if (totalMemory < 900) {
        memoryNotConfigured();
    } else {
        EventQueue.invokeLater(LAUNCH);
    }
}