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.parosproxy.paros.extension.autoupdate.ExtensionAutoUpdate.java

/**
 * This method initializes menuItemEncoder   
 *    //from   w  w  w . j a  v  a  2 s .c o  m
 * @return javax.swing.JMenuItem   
 */
private JMenuItem getMenuItemCheckUpdate() {
    if (menuItemCheckUpdate == null) {
        menuItemCheckUpdate = new JMenuItem();
        menuItemCheckUpdate.setText("Check for Updates...");
        if (!Constant.isWindows() && !Constant.isLinux()) {
            menuItemCheckUpdate.setEnabled(false);
        }
        menuItemCheckUpdate.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent e) {

                Thread t = new Thread(new Runnable() {
                    public void run() {
                        manualCheckStarted = true;
                        newestVersionName = getNewestVersionName();

                        if (waitDialog != null) {
                            waitDialog.hide();
                            waitDialog = null;
                        }
                        EventQueue.invokeLater(new Runnable() {
                            public void run() {

                                if (newestVersionName == null) {
                                    getView().showMessageDialog(
                                            "There is no new update available.  Paros may periodically check for update.");
                                } else if (newestVersionName.equals("")) {
                                    getView().showWarningDialog(
                                            "Error encountered.  Please check manually for new updates.");

                                } else {
                                    int result = getView()
                                            .showConfirmDialog("There is a newer version of Paros: "
                                                    + newestVersionName.replaceAll("\\.dat", "")
                                                    + "\nProceed to download?");
                                    if (result == JOptionPane.OK_OPTION) {
                                        waitDialog = getView().getWaitMessageDialog("Download in progress...");
                                        Thread t = new Thread(new Runnable() {
                                            public void run() {
                                                ExtensionAutoUpdate.this.download(false);
                                            }
                                        });
                                        t.start();
                                        waitDialog.show();

                                    }
                                }

                            }
                        });

                    }
                });
                waitDialog = getView().getWaitMessageDialog("Checking if newer version exists...");
                t.start();
                waitDialog.show();
            }

        });

    }
    return menuItemCheckUpdate;
}

From source file:org.fseek.simon.swing.util.TreeUtil.java

private static void addFiles(File[] files, final LinkTreeNode root, final DefaultTreeModel model,
        boolean showFiles, boolean showHidden) {
    for (int i = 0; i < files.length; i++) {
        if (Thread.interrupted()) {
            break;
        }/*from w w w .jav a 2 s . c om*/
        File f = files[i];
        if (f.isDirectory() || showFiles == true) {
            final LinkTreeNode childNode = new DefaultLinkTreeNode(f, new IconChangedListener() {
                @Override
                public void iconChanged(final LinkTreeNode node, Icon newIcon) {
                    EventQueue.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            model.nodeChanged(node);
                        }
                    });
                }
            });
            final int index = i;
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    model.insertNodeInto(childNode, root, index);
                }
            });
            AddChildsThread create = AddChildsThread.create(model, childNode, false, showFiles, showHidden,
                    true);
            if (create.isAlive() && create.isFake() == false) {
                create.interrupt();
                try {
                    create.join();
                    create = AddChildsThread.create(model, childNode, false, showFiles, showHidden, true);
                    create.start();
                } catch (InterruptedException ex) {
                    return;
                }
            } else if (create.isAlive() == false) {
                create.start();
            }
        }
    }
}

From source file:eu.europeana.sip.gui.SipCreatorGUI.java

public static void main(final String[] args) throws ClassNotFoundException {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                SipCreatorGUI sipCreatorGUI = new SipCreatorGUI();
                sipCreatorGUI.setVisible(true);
            } catch (FileStoreException e) {
                JOptionPane.showMessageDialog(null, "Unable to create the file store");
                e.printStackTrace();/*from   ww w  . java 2 s  .co  m*/
            }
        }
    });
}

From source file:pl.mcpg.brainfuckjava.Start.java

private static void runGUI() {
    EventQueue.invokeLater(() -> {
        try {//  www  . j a v  a 2  s  . c om
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
        } catch (Exception e) {
            e.printStackTrace();
        }
        new ProgramFrame().setVisible(true);
    });
}

From source file:com.ln.gui.Main.java

public void swingupd() {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                String av = "Updates available!";
                JOptionPane pane1 = new JOptionPane(av, JOptionPane.WARNING_MESSAGE,
                        JOptionPane.DEFAULT_OPTION);
                JDialog dialog1 = pane1.createDialog("Update");
                dialog1.setLocationRelativeTo(null);
                dialog1.setVisible(true);
                dialog1.setAlwaysOnTop(true);
                Updatechecker upd = new Updatechecker();
                upd.setVisible(true);//from  ww w  .  j  a va  2 s  .  c  o m
                upd.setLocationRelativeTo(rootPane);
                upd.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            } catch (Exception e) {
            }
        }
    });
}

From source file:org.kontalk.view.View.java

private View(Control control) {
    mControl = control;//from  w w w .  j  a  v  a 2s.c o m

    WebLookAndFeel.install();

    ToolTipManager.sharedInstance().setInitialDelay(200);

    mUserListView = new UserListView(this, UserList.getInstance());
    UserList.getInstance().addObserver(mUserListView);
    mThreadListView = new ThreadListView(this, ThreadList.getInstance());
    ThreadList.getInstance().addObserver(mThreadListView);

    mThreadView = new ThreadView(this);
    ThreadList.getInstance().addObserver(mThreadView);
    // text field
    mSendTextArea = new WebTextArea();
    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            mSendTextArea.requestFocusInWindow();
        }
    });

    mSendTextArea.setMargin(5);
    mSendTextArea.setLineWrap(true);
    mSendTextArea.setWrapStyleWord(true);
    mSendTextArea.getDocument().addDocumentListener(new DocumentChangeListener() {
        @Override
        public void documentChanged(DocumentEvent e) {
            View.this.handleKeyTypeEvent();
        }
    });

    // send button
    mSendButton = new WebButton(Tr.tr("Send"));
    // for showing the hotkey tooltip
    TooltipManager.addTooltip(mSendButton, Tr.tr("Send Message"));
    mSendButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Component focusOwner = mMainFrame.getFocusOwner();
            if (focusOwner != mSendTextArea)
                return;

            View.this.callSendText();
        }
    });

    // status bar
    WebStatusBar statusBar = new WebStatusBar();
    mStatusBarLabel = new WebStatusLabel(" ");
    statusBar.add(mStatusBarLabel);

    // main frame
    mMainFrame = new MainFrame(this, mUserListView, mThreadListView, mThreadView, mSendTextArea, mSendButton,
            statusBar);
    mMainFrame.setVisible(true);

    // tray
    this.setTray();

    // hotkeys
    this.setHotkeys();

    // notifier
    MessageList.getInstance().addObserver(new Notifier(this));

    this.statusChanged();
}

From source file:net.sradonia.gui.SplashScreen.java

/**
 * Changes the visibility of the splash screen window. The window will automatically be disposed when it's hidden.
 * //w w w .j a  va  2 s .c om
 * @param visible
 *            the visibility of the splash screen
 */
public void setVisible(boolean visible) {
    if (visible && !isVisible()) {
        log.info("displaying splash screen");
        updateSplash();
        window.setVisible(true);
        if (timeoutActive)
            timer.setRunning(true);
    } else if (!visible && isVisible()) {
        log.info("hiding splash screen");
        timer.setRunning(false);
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                window.dispose();
            }
        });
    }
}

From source file:org.parosproxy.paros.extension.manualrequest.http.impl.HttpPanelSender.java

private void persistAndShowMessage(HttpMessage httpMessage) {
    if (!EventQueue.isDispatchThread()) {
        EventQueue.invokeLater(() -> persistAndShowMessage(httpMessage));
        return;/*from ww w. j  a va2 s .co  m*/
    }

    try {
        Session session = Model.getSingleton().getSession();
        HistoryReference ref = new HistoryReference(session, HistoryReference.TYPE_ZAP_USER, httpMessage);
        final ExtensionHistory extHistory = getHistoryExtension();
        if (extHistory != null) {
            extHistory.addHistory(ref);
        }
        SessionStructure.addPath(Model.getSingleton().getSession(), ref, httpMessage);
    } catch (HttpMalformedHeaderException | DatabaseException e) {
        logger.warn("Failed to persist message sent:", e);
    }
}

From source file:InterruptibleSocketTest.java

/**
 * Connects to the test server, using blocking I/O
 *///  w  w w.  ja  va 2  s . c o m
public void connectBlocking() throws IOException {
    messages.append("Blocking:\n");
    Socket sock = new Socket("localhost", 8189);
    try {
        in = new Scanner(sock.getInputStream());
        while (!Thread.currentThread().isInterrupted()) {
            messages.append("Reading ");
            if (in.hasNextLine()) {
                String line = in.nextLine();
                messages.append(line);
                messages.append("\n");
            }
        }
    } finally {
        sock.close();
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                messages.append("Socket closed\n");
                interruptibleButton.setEnabled(true);
                blockingButton.setEnabled(true);
            }
        });
    }
}

From source file:org.kse.gui.crypto.DUpgradeCryptoStrength.java

public static void main(String[] args) throws Exception {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    EventQueue.invokeLater(new Runnable() {
        @Override//w  ww  .j  a v a2 s  . c o  m
        public void run() {
            try {
                DUpgradeCryptoStrength dialog = new DUpgradeCryptoStrength(new JFrame());
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }

                    @Override
                    public void windowDeactivated(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}