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.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java

/**
 * Remove multiple rows from a table/*from w w  w  .  j a v  a2  s.co  m*/
 */
protected void removeRows() {
    if (spreadsheet.rowsToDelete != null && spreadsheet.rowsToDelete.length > 0) {
        for (final int i : Utils.arrayToList(spreadsheet.rowsToDelete)) {
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    removeRow(i);
                }
            });
        }
    }

    spreadsheet.getTable().addNotify();

    spreadsheet.currentState = Spreadsheet.DEFAULT_STATE;
}

From source file:xtrememp.XtremeMP.java

protected void setStatus(String text) {
    final String status = (text != null) ? text : "";
    if (EventQueue.isDispatchThread()) {
        statusLabel.setText(status);// w w  w.  j av  a  2s .c o  m
    } else {
        EventQueue.invokeLater(() -> {
            statusLabel.setText(status);
        });
    }
}

From source file:tax.MainForm.java

private void afmTextSKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_afmTextSKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        String text = afmTextS.getText();

        if (text.length() == 9) {
            try {
                int num = Integer.parseInt(text);
            } catch (Exception e) {
                afmTextS.setText("");
                return;
            }/*from w w w  . ja v a 2s .c om*/

            //                Util.fadeInAndOut(afmTextS, Util.darkGreen);
            addNameBut.doClick();
        } else {
            Util.fadeInAndOut(afmTextS, Util.darkOrange);
        }
    } else if (!evt.isActionKey() && !evt.isAltDown() && !evt.isControlDown() && !evt.isShiftDown()
            && !evt.isMetaDown() && (evt.getKeyCode() != KeyEvent.VK_BACK_SPACE)
            && (evt.getKeyCode() != KeyEvent.VK_DELETE) && (evt.getKeyCode() != KeyEvent.VK_ESCAPE)) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                String text = afmTextS.getText();
                int afmLength = text.length();

                while (lastAFMTextSLength == afmLength) {
                    try {
                        Thread.sleep(100);
                        System.out.println("text: " + text);
                        System.out.println(lastAFMTextSLength + " " + afmLength);
                        return;
                    } catch (InterruptedException ex) {
                        Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    text = afmTextS.getText();
                    afmLength = text.length();
                }

                try {
                    int num = Integer.decode(text);
                    if (afmLength > 9) {
                        if (text.length() > 0)
                            afmTextS.setText(text.substring(0, afmLength - 1));
                        else
                            afmTextS.setText("");
                        return;
                    }
                } catch (Exception e) {
                    if (text.length() > 0)
                        afmTextS.setText(text.substring(0, afmLength - 1));
                    else
                        afmTextS.setText("");
                    return;
                }

                lastAFMTextSLength = afmLength;
            }
        });
    }
}

From source file:ca.uhn.hl7v2.testpanel.model.conn.AbstractConnection.java

private void setHohSignatureKeystoreStatus(final WorkingStatusBean theStatusBean) {
    final WorkingStatusBean oldValue = myHohSignatureKeystoreStatus;
    myHohSignatureKeystoreStatus = theStatusBean;
    EventQueue.invokeLater(new Runnable() {
        @Override//from   www.  j  a va2 s .  c om
        public void run() {
            firePropertyChange(HOH_SIGNATURE_KEYSTORE_STATUS, oldValue, theStatusBean);
        }
    });
}

From source file:net.sf.nmedit.jsynth.clavia.nordmodular.NordModular.java

public void comUpdateStatus() {
    if (EventQueue.isDispatchThread()) {
        __comUpdateStatusImpl();//from   ww w . ja  va  2  s  .  c o  m
    } else {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                __comUpdateStatusImpl();
            }
        });
    }
}

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

protected void pasteUpdated(Transferable transferable) {
    String text;/* w  w w  .j a  v a2  s .c o  m*/

    if (!transferable.isDataFlavorSupported(DataFlavor.stringFlavor))
        return;

    try {
        text = transferable.getTransferData(DataFlavor.stringFlavor).toString();
    } catch (IOException ex) {
        Utils.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
        return;
    } catch (UnsupportedFlavorException ex) {
        Utils.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
        return;
    }

    try {
        final URL platformUrl = new URL(text);
        new SwingWorker<PlatformPackInfo, Void>() {
            @Override
            protected PlatformPackInfo doInBackground() throws Exception {
                PlatformPackInfo info = RestObject.getRestObject(PlatformPackInfo.class,
                        platformUrl.toString());

                //Don't let people jerk us around with non-platform sites- make sure this is a real pack
                //on the technic platform
                return platformApi.getPlatformPackInfo(info.getName());
            }

            @Override
            public void done() {
                PlatformPackInfo result;
                try {
                    result = get();

                    if (result == null)
                        return;
                } catch (ExecutionException ex) {
                    //We eat these two exceptions because they are almost certainly caused by
                    //the pasted text not being relevant to this program
                    return;
                } catch (InterruptedException ex) {
                    return;
                }

                if (!packRepo.getInstalledPacks().containsKey(result.getName())) {
                    packRepo.put(new InstalledPack(result.getName(), true, InstalledPack.RECOMMENDED));
                }

                packRepo.setSelectedSlug(result.getName());
                modpackSelector.forceRefresh();

                LauncherFrame.this.setExtendedState(JFrame.ICONIFIED);

                EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        LauncherFrame.this.setExtendedState(JFrame.NORMAL);
                        EventQueue.invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                LauncherFrame.this.selectTab("modpacks");
                            }
                        });
                    }
                });
            }
        }.execute();
    } catch (MalformedURLException ex) {
        return;
    }
}

From source file:com.zigabyte.stock.stratplot.StrategyPlotter.java

/** Runs the simuation in a separate thread.
    Called from the run button, uses separate thread so UI
    can continue to update. **///  w w  w.j a  v  a 2s. c om
protected void runSimulationInThread() {
    Thread thread = new Thread() {
        public void run() {
            try {
                if (StrategyPlotter.this.histories == null)
                    throw new NullPointerException("No market data loaded");
                runSimulation();
            } catch (Throwable t) {
                showErrorDialog(t);
            } finally {
                EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        runButton.setCursor(null); // clear wait cursor
                    }
                });
            }
        }
    };
    thread.start();
}

From source file:ca.uhn.hl7v2.testpanel.ui.editor.Hl7V2MessageEditorPanel.java

/**
 * @param theMessage/*  www  . j  a v a 2s .c  o  m*/
 *            the message to set
 */
public void setMessage(Hl7V2MessageCollection theMessage) {
    Validate.isTrue(myMessage == null);

    myMessage = theMessage;

    myShowCombo.setModel(new ShowComboModel());

    // Prepopulate the "send to interface" combo to the last value it had
    if (StringUtils.isNotBlank(myMessage.getLastSendToInterfaceId())) {
        for (int i = 0; i < myOutboundInterfaceComboModelShadow.size(); i++) {
            if (myOutboundInterfaceComboModelShadow.get(i).getId()
                    .equals(myMessage.getLastSendToInterfaceId())) {
                myOutboundInterfaceCombo.setSelectedIndex(i);
                break;
            }
        }
    }

    updateEncodingButtons();
    myRdbtnEr7.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent theE) {
            removeHighlights();
            myMessage.setEncoding(Hl7V2EncodingTypeEnum.ER_7);
        }
    });
    myRdbtnXml.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent theE) {
            removeHighlights();
            myMessage.setEncoding(Hl7V2EncodingTypeEnum.XML);
        }
    });

    try {
        myDisableCaretUpdateHandling = true;
        updateMessageEditor();
    } finally {
        myDisableCaretUpdateHandling = false;
    }

    myMessageListeneer = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent theEvt) {
            if (myDontRespondToSourceMessageChanges) {
                return;
            }
            try {
                myDisableCaretUpdateHandling = true;
                updateMessageEditor();
            } finally {
                myDisableCaretUpdateHandling = false;
            }
        }
    };
    myMessage.addPropertyChangeListener(Hl7V2MessageCollection.SOURCE_MESSAGE_PROPERTY, myMessageListeneer);

    mySelectedPathListener = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent theEvt) {
            String path = myMessage.getHighlitedPath();
            if (path == null) {
                path = "";
            }

            int index = path.indexOf('/');
            if (index > -1) {
                path = path.substring(index);
            }

            myTerserPathTextField.setText(path);
        }
    };
    myMessage.addPropertyChangeListener(Hl7V2MessageCollection.PROP_HIGHLITED_PATH, mySelectedPathListener);

    myTreePanel.setMessage(myMessage);

    myRangeListener = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent theEvt) {
            if (theEvt.getNewValue() == null || !myFollowToggle.isSelected()) {
                return;
            }
            Range range = (Range) theEvt.getNewValue();

            // myMessageScrollPane.getHorizontalScrollBar().setValue(0);

            // myMessageEditor.select(range.getStart(), range.getEnd());
            // myMessageEditor.setCaretPosition(range.getStart());

            myMessageEditor.setCaretPosition(range.getStart());
            myMessageEditor.moveCaretPosition(range.getEnd());

            myMessageEditor.setCaretPosition(range.getEnd());
            myMessageEditor.moveCaretPosition(range.getStart());

            // myMessageEditor.grabFocus();
            myMessageEditor.repaint();

            String substring = myMessage.getSourceMessage().substring(range.getStart(), range.getEnd());
            ourLog.info("Selected range set to " + range + " which is " + substring);
        }
    };
    myMessage.addPropertyChangeListener(Hl7V2MessageCollection.PROP_HIGHLITED_RANGE, myRangeListener);

    myProfileComboboxModel.update();

    // Window Title
    myWindowTitleListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent theEvt) {
            updateWindowTitle();
        }
    };
    myMessage.addPropertyChangeListener(Hl7V2MessageCollection.SAVED_PROPERTY, myWindowTitleListener);
    myMessage.addPropertyChangeListener(Hl7V2MessageCollection.PROP_SAVE_FILENAME, myWindowTitleListener);
    updateWindowTitle();

    EventQueue.invokeLater(new Runnable() {

        public void run() {
            myMessageEditor.setCaretPosition(0);
            myMessageEditor.grabFocus();
        }
    });

}

From source file:com.t3.client.ui.T3Frame.java

private JComponent createTokenTreePanel() {
    final JTree tree = new JTree();
    tokenPanelTreeModel = new TokenPanelTreeModel(tree);
    tree.setModel(tokenPanelTreeModel);/*from   w  ww .  j  a  v  a2s. co m*/
    tree.setCellRenderer(new TokenPanelTreeCellRenderer());
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    tree.addMouseListener(new MouseAdapter() {
        // TODO: Make this a handler class, not an aic
        @Override
        public void mousePressed(MouseEvent e) {
            // tree.setSelectionPath(tree.getPathForLocation(e.getX(), e.getY()));
            TreePath path = tree.getPathForLocation(e.getX(), e.getY());
            if (path == null) {
                return;
            }
            Object row = path.getLastPathComponent();
            int rowIndex = tree.getRowForLocation(e.getX(), e.getY());
            if (SwingUtilities.isLeftMouseButton(e)) {
                if (!SwingUtil.isShiftDown(e)) {
                    tree.clearSelection();
                }
                tree.addSelectionInterval(rowIndex, rowIndex);

                if (row instanceof Token) {
                    if (e.getClickCount() == 2) {
                        Token token = (Token) row;
                        getCurrentZoneRenderer().clearSelectedTokens();
                        getCurrentZoneRenderer().centerOn(new ZonePoint(token.getX(), token.getY()));

                        // Pick an appropriate tool
                        getToolbox().setSelectedTool(token.isToken() ? PointerTool.class : StampTool.class);
                        getCurrentZoneRenderer().setActiveLayer(token.getLayer());
                        getCurrentZoneRenderer().selectToken(token.getId());
                        getCurrentZoneRenderer().requestFocusInWindow();
                    }
                }
            }
            if (SwingUtilities.isRightMouseButton(e)) {
                if (!isRowSelected(tree.getSelectionRows(), rowIndex) && !SwingUtil.isShiftDown(e)) {
                    tree.clearSelection();
                    tree.addSelectionInterval(rowIndex, rowIndex);
                }
                final int x = e.getX();
                final int y = e.getY();
                EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        Token firstToken = null;
                        Set<GUID> selectedTokenSet = new HashSet<GUID>();
                        for (TreePath path : tree.getSelectionPaths()) {
                            if (path.getLastPathComponent() instanceof Token) {
                                Token token = (Token) path.getLastPathComponent();
                                if (firstToken == null) {
                                    firstToken = token;
                                }
                                if (AppUtil.playerOwns(token)) {
                                    selectedTokenSet.add(token.getId());
                                }
                            }
                        }
                        if (!selectedTokenSet.isEmpty()) {
                            try {
                                if (firstToken.isStamp()) {
                                    new StampPopupMenu(selectedTokenSet, x, y, getCurrentZoneRenderer(),
                                            firstToken).showPopup(tree);
                                } else {
                                    new TokenPopupMenu(selectedTokenSet, x, y, getCurrentZoneRenderer(),
                                            firstToken).showPopup(tree);
                                }
                            } catch (IllegalComponentStateException icse) {
                                log.info(tree.toString(), icse);
                            }
                        }
                    }
                });
            }
        }
    });
    TabletopTool.getEventDispatcher().addListener(new AppEventListener() {
        @Override
        public void handleAppEvent(AppEvent event) {
            tokenPanelTreeModel.setZone((Zone) event.getNewValue());
        }
    }, TabletopTool.ZoneEvent.Activated);
    return tree;
}

From source file:ca.uhn.hl7v2.testpanel.model.conn.AbstractConnection.java

private void setTlsKeystoreStatus(final WorkingStatusBean theStatusBean) {
    final WorkingStatusBean oldValue = myTlsKeystoreStatus;
    myTlsKeystoreStatus = theStatusBean;
    EventQueue.invokeLater(new Runnable() {
        @Override//from w w w  .j a v  a  2 s  .co m
        public void run() {
            firePropertyChange(TLS_KEYSTORE_STATUS, oldValue, theStatusBean);
        }
    });
}