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:com.excilys.ebi.gatling.recorder.ui.component.RunningFrame.java

@Subscribe
public void onSecuredHostConnectionEvent(final SecuredHostConnectionEvent event) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            if (!hostsCertificate.contains(event.getHostURI()))
                hostsCertificate.addElement(event.getHostURI());
        }//ww  w .java  2s  .  c om
    });
}

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

public void notifyHistoryItemChanged(final HistoryReference href) {
    if (!View.isInitialised() || EventQueue.isDispatchThread()) {
        this.historyTableModel.refreshEntryRow(href.getHistoryId());
    } else {//from  w ww.  j a v a  2  s  .co  m
        EventQueue.invokeLater(new Runnable() {

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

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

@Subscribe
public void onRequestReceivedEvent(final RequestReceivedEvent event) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            if (event.getRequest().getMethod() == HttpMethod.CONNECT)
                return;

            String header = event.getRequest().getHeader("Proxy-Authorization");
            if (header != null) {
                // Split on " " and take 2nd group (Basic
                // credentialsInBase64==)
                String credentials = new String(Base64.decodeBase64(header.split(" ")[1].getBytes()));
                configuration.getProxy().setUsername(credentials.split(":")[0]);
                configuration.getProxy().setPassword(credentials.split(":")[1]);
            }//  ww w  .j av  a 2  s . co  m

            if (addRequest(event.getRequest())) {
                if (lastRequest != null) {
                    Date newRequest = new Date();
                    long diff = newRequest.getTime() - lastRequest.getTime();
                    long pauseMin, pauseMax;
                    PauseType pauseType;
                    if (diff < 1000) {
                        pauseMin = (diff / 100l) * 100;
                        pauseMax = pauseMin + 100;
                        pauseType = PauseType.MILLISECONDS;
                    } else {
                        pauseMin = diff / 1000l;
                        pauseMax = pauseMin + 1;
                        pauseType = PauseType.SECONDS;
                    }
                    lastRequest = newRequest;
                    pause = new PauseEvent(pauseMin, pauseMax, pauseType);
                }
            }
        }
    });
}

From source file:org.exist.launcher.Launcher.java

private PopupMenu createMenu() {

    final PopupMenu popup = new PopupMenu();
    startItem = new MenuItem("Start server");
    popup.add(startItem);/*from   ww w .  ja v a  2  s.  c o  m*/
    startItem.addActionListener(actionEvent -> {
        if (jetty.isPresent()) {
            jetty.ifPresent(server -> {
                if (server.isStarted()) {
                    showTrayMessage("Server already started", TrayIcon.MessageType.WARNING);
                } else {
                    server.run(new String[] { jettyConfig.toAbsolutePath().toString() }, null);
                    if (server.isStarted()) {
                        showTrayMessage("eXist-db server running on port " + server.getPrimaryPort(),
                                TrayIcon.MessageType.INFO);
                    }
                }
                setServiceState();
            });
        } else if (runningAsService.isPresent()) {
            showTrayMessage("Starting the eXistdb service. Please wait...", TrayIcon.MessageType.INFO);
            if (runningAsService.get().start()) {
                showTrayMessage("eXistdb service started", TrayIcon.MessageType.INFO);
            } else {
                showTrayMessage("Starting eXistdb service failed", TrayIcon.MessageType.ERROR);
            }
            setServiceState();
        }
    });

    stopItem = new MenuItem("Stop server");
    popup.add(stopItem);
    stopItem.addActionListener(actionEvent -> {
        if (jetty.isPresent()) {
            jetty.get().shutdown();
            setServiceState();
            showTrayMessage("eXist-db stopped", TrayIcon.MessageType.INFO);
        } else if (runningAsService.isPresent()) {
            if (runningAsService.get().stop()) {
                showTrayMessage("eXistdb service stopped", TrayIcon.MessageType.INFO);
            } else {
                showTrayMessage("Stopping eXistdb service failed", TrayIcon.MessageType.ERROR);
            }
            setServiceState();
        }
    });

    popup.addSeparator();
    final MenuItem configItem = new MenuItem("System Configuration");
    popup.add(configItem);
    configItem.addActionListener(e -> EventQueue.invokeLater(() -> {
        configDialog.open(false);
        configDialog.toFront();
        configDialog.repaint();
        configDialog.requestFocus();
    }));

    if (SystemUtils.IS_OS_WINDOWS) {
        canUseServices = true;
    } else {
        isRoot((root) -> canUseServices = root);
    }

    final String requiresRootMsg;
    if (canUseServices) {
        requiresRootMsg = "";
    } else {
        requiresRootMsg = " (requires root)";
    }

    installServiceItem = new MenuItem("Install as service" + requiresRootMsg);

    popup.add(installServiceItem);
    installServiceItem.setEnabled(canUseServices);
    installServiceItem.addActionListener(e -> SwingUtilities.invokeLater(this::installAsService));

    uninstallServiceItem = new MenuItem("Uninstall service" + requiresRootMsg);
    popup.add(uninstallServiceItem);
    uninstallServiceItem.setEnabled(canUseServices);
    uninstallServiceItem.addActionListener(e -> SwingUtilities.invokeLater(this::uninstallService));

    if (SystemUtils.IS_OS_WINDOWS) {
        showServices = new MenuItem("Show services console");
        popup.add(showServices);
        showServices.addActionListener(e -> SwingUtilities.invokeLater(this::showServicesConsole));
    }
    popup.addSeparator();

    final MenuItem toolbar = new MenuItem("Show tool window");
    popup.add(toolbar);
    toolbar.addActionListener(actionEvent -> EventQueue.invokeLater(() -> {
        utilityPanel.toFront();
        utilityPanel.setVisible(true);
    }));

    MenuItem item;

    if (Desktop.isDesktopSupported()) {
        popup.addSeparator();
        final Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Desktop.Action.BROWSE)) {
            dashboardItem = new MenuItem("Open Dashboard");
            popup.add(dashboardItem);
            dashboardItem.addActionListener(actionEvent -> dashboard(desktop));
            eXideItem = new MenuItem("Open eXide");
            popup.add(eXideItem);
            eXideItem.addActionListener(actionEvent -> eXide(desktop));
            item = new MenuItem("Open Java Admin Client");
            popup.add(item);
            item.addActionListener(actionEvent -> client());
            monexItem = new MenuItem("Open Monitoring and Profiling");
            popup.add(monexItem);
            monexItem.addActionListener(actionEvent -> monex(desktop));
        }
        if (desktop.isSupported(Desktop.Action.OPEN)) {
            popup.addSeparator();
            item = new MenuItem("Open exist.log");
            popup.add(item);
            item.addActionListener(new LogActionListener());
        }

        popup.addSeparator();
        quitItem = new MenuItem("Quit (and stop server)");
        popup.add(quitItem);
        quitItem.addActionListener(actionEvent -> shutdown(false));

        setServiceState();
    }
    return popup;
}

From source file:org.parosproxy.paros.model.SiteNode.java

private void nodeChanged() {
    if (this.siteMap == null) {
        return;/*from w  ww  .j  a v a2  s. c om*/
    }
    if (EventQueue.isDispatchThread()) {
        nodeChangedEventHandler();
    } else {
        try {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    nodeChangedEventHandler();
                }
            });
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}

From source file:org.parosproxy.paros.control.MenuFileControl.java

public boolean openSession(String session) {
    final Object[] opened = { Boolean.TRUE };
    File sessionFile = new File(session);
    waitMessageDialog = view.getWaitMessageDialog(Constant.messages.getString("menu.file.loadSession"));
    log.info("opening session file " + sessionFile.getAbsolutePath());
    control.openSession(sessionFile, new SessionListener() {

        @Override//  w  ww .  j  a va  2s .c  om
        public void sessionSnapshot(Exception e) {
        }

        @Override
        public void sessionSaved(Exception e) {
        }

        @Override
        public void sessionOpened(final File file, final Exception e) {
            if (EventQueue.isDispatchThread()) {
                if (e != null) {
                    view.showWarningDialog(Constant.messages.getString("menu.file.openSession.error"));
                    log.error("error opening session file " + model.getSession().getFileName(), e);
                    opened[0] = Boolean.FALSE;
                }

                view.getSiteTreePanel().getTreeSite().setModel(model.getSession().getSiteTree());

                if (waitMessageDialog != null) {
                    waitMessageDialog.setVisible(false);
                    waitMessageDialog = null;
                }
            } else {
                EventQueue.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        sessionOpened(file, e);
                    }
                });
            }
        }
    });
    waitMessageDialog.setVisible(true);

    return opened[0] == Boolean.TRUE;
}

From source file:phex.gui.tabs.download.DownloadTransferTableModel.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  2s. com*/
    }
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            int position = event.getPosition();
            if (event.getType() == ContainerEvent.Type.ADDED) {
                fireTableChanged(new TableModelEvent(DownloadTransferTableModel.this, position, position,
                        TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
            } else if (event.getType() == ContainerEvent.Type.REMOVED) {
                fireTableChanged(new TableModelEvent(DownloadTransferTableModel.this, position, position,
                        TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE));
            }
        }
    });
}

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

/**
 * @return//from  w  w w. ja v  a  2  s .c  om
 * 
 */
@Override
protected JMenu makeMenu() {
    if (this.menu == null) {
        this.menu = new JMenu();
        JMenuItem start = new JMenuItem("Start");
        start.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        start();
                    }
                });
            }
        });
        this.menu.add(start);
        JMenuItem stop = new JMenuItem("Stop");
        stop.addActionListener(new ActionListener() {

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

    return this.menu;
}

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

/**
 * Initialize the contents of the frame.
 *///w w w. j a  va  2  s . co  m
private void initGUI() {
    mMainGui.setLayout(new MigLayout("insets 0 0 0 0 ", "[grow,fill]", "[grow,fill]"));

    /**
     * Setup main JFrame window
     */
    mTitle = SystemProperties.getInstance().getApplicationName();
    mMainGui.setTitle(mTitle);
    mMainGui.setBounds(100, 100, 1280, 800);
    mMainGui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Set preferred sizes to influence the split
    mSpectralPanel.setPreferredSize(new Dimension(1280, 300));
    mControllerPanel.setPreferredSize(new Dimension(1280, 500));

    mSplitPane = new JideSplitPane(JideSplitPane.VERTICAL_SPLIT);
    mSplitPane.setDividerSize(5);
    mSplitPane.add(mSpectralPanel);
    mSplitPane.add(mControllerPanel);

    mBroadcastStatusVisible = SystemProperties.getInstance().get(PROPERTY_BROADCAST_STATUS_VISIBLE, false);

    //Show broadcast status panel when user requests - disabled by default
    if (mBroadcastStatusVisible) {
        mSplitPane.add(getBroadcastStatusPanel());
    }

    mMainGui.add(mSplitPane, "cell 0 0,span,grow");

    /**
     * Menu items
     */
    JMenuBar menuBar = new JMenuBar();
    mMainGui.setJMenuBar(menuBar);

    JMenu fileMenu = new JMenu("File");
    menuBar.add(fileMenu);

    JMenuItem logFilesMenu = new JMenuItem("Logs & Recordings");
    logFilesMenu.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            try {
                Desktop.getDesktop().open(getHomePath().toFile());
            } catch (Exception e) {
                mLog.error("Couldn't open file explorer");

                JOptionPane.showMessageDialog(mMainGui,
                        "Can't launch file explorer - files are located at: " + getHomePath().toString(),
                        "Can't launch file explorer", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    fileMenu.add(logFilesMenu);

    JMenuItem settingsMenu = new JMenuItem("Icon Manager");
    settingsMenu.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            mIconManager.showEditor(mMainGui);
        }
    });
    fileMenu.add(settingsMenu);

    fileMenu.add(new JSeparator());

    JMenuItem exitMenu = new JMenuItem("Exit");
    exitMenu.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });

    fileMenu.add(exitMenu);

    JMenu viewMenu = new JMenu("View");

    viewMenu.add(new BroadcastStatusVisibleMenuItem(mControllerPanel));

    menuBar.add(viewMenu);

    JMenuItem screenCaptureItem = new JMenuItem("Screen Capture");

    screenCaptureItem.setMnemonic(KeyEvent.VK_C);
    screenCaptureItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.ALT_MASK));

    screenCaptureItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            try {
                Robot robot = new Robot();

                final BufferedImage image = robot.createScreenCapture(mMainGui.getBounds());

                SystemProperties props = SystemProperties.getInstance();

                Path capturePath = props.getApplicationFolder("screen_captures");

                if (!Files.exists(capturePath)) {
                    try {
                        Files.createDirectory(capturePath);
                    } catch (IOException e) {
                        mLog.error("Couldn't create 'screen_captures' " + "subdirectory in the "
                                + "SDRTrunk application directory", e);
                    }
                }

                String filename = TimeStamp.getTimeStamp("_") + "_screen_capture.png";

                final Path captureFile = capturePath.resolve(filename);

                EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            ImageIO.write(image, "png", captureFile.toFile());
                        } catch (IOException e) {
                            mLog.error("Couldn't write screen capture to " + "file [" + captureFile.toString()
                                    + "]", e);
                        }
                    }
                });
            } catch (AWTException e) {
                mLog.error("Exception while taking screen capture", e);
            }
        }
    });

    menuBar.add(screenCaptureItem);
}

From source file:org.zaproxy.zap.extension.multiFuzz.impl.http.HttpFuzzerContentPanel.java

private void addFuzzResult(final String name, final String custom, final HttpFuzzRequestRecord.State state,
        final ArrayList<String> pay, final HttpMessage msg) {

    if (EventQueue.isDispatchThread()) {
        addFuzzResultToView(name, custom, state, pay, msg);
        return;// w w  w  . j ava  2  s . c o  m
    }
    try {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                addFuzzResultToView(name, custom, state, pay, msg);
            }
        });
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}