Example usage for javax.swing SwingUtilities invokeLater

List of usage examples for javax.swing SwingUtilities invokeLater

Introduction

In this page you can find the example usage for javax.swing SwingUtilities invokeLater.

Prototype

public static void invokeLater(Runnable doRun) 

Source Link

Document

Causes doRun.run() to be executed asynchronously on the AWT event dispatching thread.

Usage

From source file:com.mirth.connect.client.ui.editors.MapperPanel.java

public void updateTable() {
    if (parent.getSelectedRow() != -1) {
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                parent.getTableModel().setValueAt(variableTextField.getText(), parent.getSelectedRow(),
                        parent.STEP_NAME_COL);
                parent.updateTaskPane(parent.getTableModel()
                        .getValueAt(parent.getSelectedRow(), parent.STEP_TYPE_COL).toString());
            }//from  www  . j  a  va 2 s  .  c  o m
        });
    }
}

From source file:net.sf.jabref.gui.fieldeditors.FileListEditorTransferHandler.java

@Override
public boolean importData(JComponent comp, Transferable t) {
    // If the drop target is the main table, we want to record which
    // row the item was dropped on, to identify the entry if needed:

    try {/*from w w  w.  j  a v  a  2  s  .c  o  m*/

        List<File> files = new ArrayList<>();
        // This flavor is used for dragged file links in Windows:
        if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            files.addAll((List<File>) t.getTransferData(DataFlavor.javaFileListFlavor));
        }

        if (t.isDataFlavorSupported(urlFlavor)) {
            URL dropLink = (URL) t.getTransferData(urlFlavor);
            LOGGER.debug("URL: " + dropLink);
        }

        // This is used when one or more files are pasted from the file manager
        // under Gnome. The data consists of the file paths, one file per line:
        if (t.isDataFlavorSupported(stringFlavor)) {
            String dropStr = (String) t.getTransferData(stringFlavor);
            files.addAll(EntryTableTransferHandler.getFilesFromDraggedFilesString(dropStr));
        }

        SwingUtilities.invokeLater(() -> {
            for (File file : files) {
                // Find the file's extension, if any:
                String name = file.getAbsolutePath();
                FileUtil.getFileExtension(name).ifPresent(extension -> ExternalFileTypes.getInstance()
                        .getExternalFileTypeByExt(extension).ifPresent(fileType -> {
                            if (droppedFileHandler == null) {
                                droppedFileHandler = new DroppedFileHandler(frame, frame.getCurrentBasePanel());
                            }
                            droppedFileHandler.handleDroppedfile(name, fileType, entryContainer.getEntry());
                        }));
            }
        });
        if (!files.isEmpty()) {
            // Found some files, return
            return true;
        }
    } catch (IOException ioe) {
        LOGGER.warn("Failed to read dropped data. ", ioe);
    } catch (UnsupportedFlavorException | ClassCastException ufe) {
        LOGGER.warn("Drop type error. ", ufe);
    }

    // all supported flavors failed
    StringBuilder logMessage = new StringBuilder("Cannot transfer input:");
    DataFlavor[] inflavs = t.getTransferDataFlavors();
    for (DataFlavor inflav : inflavs) {
        logMessage.append(' ').append(inflav);
    }
    LOGGER.warn(logMessage.toString());

    return false;
}

From source file:edu.ku.brc.specify.utilapps.CreateTextSchema.java

/**
 * @param args//  w  w  w  .j ava 2 s .  co m
 */
public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        @SuppressWarnings("synthetic-access") //$NON-NLS-1$
        public void run() {
            try {
                UIHelper.OSTYPE osType = UIHelper.getOSType();
                if (osType == UIHelper.OSTYPE.Windows) {
                    UIManager.setLookAndFeel(new PlasticLookAndFeel());
                    PlasticLookAndFeel.setPlasticTheme(new ExperienceBlue());

                } else if (osType == UIHelper.OSTYPE.Linux) {
                    UIManager.setLookAndFeel(new PlasticLookAndFeel());
                }
            } catch (Exception e) {
            }

            String schemaVersion = JOptionPane.showInputDialog("Enter Schema Version:");

            Locale.setDefault(currLang);

            try {
                ResourceBundle.getBundle("resources", Locale.getDefault()); //$NON-NLS-1$

            } catch (MissingResourceException ex) {
                Locale.setDefault(Locale.ENGLISH);
                UIRegistry.setResourceLocale(Locale.ENGLISH);
            }

            CreateTextSchema cts = new CreateTextSchema();
            cts.process(schemaVersion);

            //File file = XMLHelper.getConfigDir(specifyDescFileName);
            //file.delete();

            JOptionPane.showMessageDialog(null, "Done");
        }
    });
}

From source file:gda.gui.epics.EpicsMonitor.java

@Override
public void update(final Object theObserved, final Object changeCode) {
    if (callListenerOnSwingEventThread) {
        final EpicsMonitor mon = this;
        SwingUtilities.invokeLater(new Runnable() {
            @Override//from   w  w  w .ja  va2 s  .  co m
            public void run() {
                mon.updateSwingEventThread(theObserved, changeCode);
            }
        });
    } else {
        updateSwingEventThread(theObserved, changeCode);
    }
}

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

private void writeToConsoleImmediately(final ConsoleMessage message, final boolean isTelnetError) {
    SwingUtilities.invokeLater(() -> {
        if (isTelnetError && chkIgnoreErrors.isSelected()) {
            return;
        }//  w  ww.  j  a  v  a 2s. c  om

        final StyledDocument styledDocument = mainOutput.getStyledDocument();

        int startLength = styledDocument.getLength();

        try {
            styledDocument.insertString(styledDocument.getLength(),
                    message.getMessage() + System.lineSeparator(),
                    StyleContext.getDefaultStyleContext().addAttribute(SimpleAttributeSet.EMPTY,
                            StyleConstants.Foreground, message.getColor()));
        } catch (BadLocationException ex) {
            throw new RuntimeException(ex);
        }

        if (MainPanel.this.chkAutoScroll.isSelected() && MainPanel.this.mainOutput.getSelectedText() == null) {
            final JScrollBar vScroll = mainOutputScoll.getVerticalScrollBar();

            if (!vScroll.getValueIsAdjusting()) {
                if (vScroll.getValue() + vScroll.getModel().getExtent() >= (vScroll.getMaximum() - 50)) {
                    MainPanel.this.mainOutput.setCaretPosition(startLength);

                    final Timer timer = new Timer(10, (ActionEvent ae) -> {
                        vScroll.setValue(vScroll.getMaximum());
                    });
                    timer.setRepeats(false);
                    timer.start();
                }
            }
        }
    });
}

From source file:net.sf.nmedit.nordmodular.NMSynthDeviceContext.java

public void openOrSelectPatch(Slot slot) {
    NmSlot nmslot = (NmSlot) slot;/*from w w  w. ja v a2 s.c  o m*/

    NMPatch patch = nmslot.getPatch();

    if (patch != null) {
        // find out if patch is open

        DefaultDocumentManager dm = Nomad.sharedInstance().getDocumentManager();

        for (Document d : dm.getDocuments()) {
            if (d instanceof PatchDocument) {
                PatchDocument pd = (PatchDocument) d;
                if (pd.getPatch() == patch) {
                    // found -> select

                    dm.setSelection(d);

                    return;
                }
            }
        }

        // not found -> create document

        try {
            final PatchDocument pd = NmFileService.createPatchDoc(patch);

            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    DocumentManager dm = Nomad.sharedInstance().getDocumentManager();
                    dm.add(pd);
                    dm.setSelection(pd);

                }
            });

        } catch (Exception e) {

            Log log = LogFactory.getLog(getClass());
            if (log.isWarnEnabled()) {
                log.warn(e);
            }

            ExceptionDialog.showErrorDialog(Nomad.sharedInstance().getWindow().getRootPane(),

                    e.getMessage(), "could not open patch", e);

            return;
        }

        return;
    }

    try {
        slot.createRequestPatchWorker().requestPatch();
    } catch (SynthException e1) {
        e1.printStackTrace();
    }
}

From source file:com.romraider.logger.ecu.ui.handler.dash.DialGaugeStyle.java

private void resetMinMax(final double value) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            maxValue = MAX_VALUE * -1;/*from  w  w w.j av  a 2s.  c o  m*/
            minValue = MAX_VALUE;
            max.setValue(value);
            min.setValue(value);
        }
    });
}

From source file:mergedoc.ui.ButtonBar.java

/**
 * ???// w ww . ja  v a  2 s .  com
 * ?????????????????<br>
 * ????????
 * @param state 
 */
public void setState(final ButtonState state) {

    if (runListener == null || backListener == null || cancelListener == null || endListener == null) {
        String m = "?????????????";
        RuntimeException e = new IllegalStateException(m);
        log.fatal(m, e);
        throw e;
    }

    // ?
    final JLabel filler = new JLabel();
    int maxWidth = (int) ComponentFactory.createMaxDimension().getWidth();
    filler.setMaximumSize(new Dimension(maxWidth, 0));
    runButton = createButton();
    endButton = createButton();

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {

            // ??????
            removeAll();
            add(filler);
            add(runButton);
            add(ComponentFactory.createSpacer(10, 0));
            add(endButton);

            // ?
            state.apply();
        }
    });
}

From source file:com.frostwire.gui.library.DeviceDiscoveryClerk.java

private void handleDeviceStale(String key, InetAddress address, final Device device) {
    deviceCache.remove(key);//from w ww .  j av  a  2 s .c  o m

    LOG.info("Device Slate: " + device);

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            LibraryMediator.instance().handleDeviceStale(device);
            UPnPManager.instance().removeRemoteDevice(device.getUdn());
        }
    });
}

From source file:gisintegration.SimpleSwingBrowser.java

private void createScene() {
    Platform.runLater(new Runnable() {
        @Override//ww w  .j  a  v  a  2  s  . co m
        public void run() {

            WebView view = new WebView();
            engine = view.getEngine();

            //                engine.titleProperty().addListener(new ChangeListener<String>() {
            //                    @Override
            //                    public void changed(ObservableValue<? extends String> observable, String oldValue, final String newValue) {
            //                        SwingUtilities.invokeLater(new Runnable() {
            //                            @Override
            //                            public void run() {
            //                                SimpleSwingBrowser.this.setTitle(newValue);
            //                            }
            //                        });
            //                    }
            //                });

            engine.setOnStatusChanged(new EventHandler<WebEvent<String>>() {
                @Override
                public void handle(final WebEvent<String> event) {
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            lblStatus.setText(event.getData());
                        }
                    });
                }
            });

            //                engine.locationProperty().addListener(new ChangeListener<String>() {
            //                    @Override
            //                    public void changed(ObservableValue<? extends String> ov, String oldValue, final String newValue) {
            //                        SwingUtilities.invokeLater(new Runnable() {
            //                            @Override
            //                            public void run() {
            //                                txtURL.setText(newValue);
            //                            }
            //                        });
            //                    }
            //                });

            engine.getLoadWorker().workDoneProperty().addListener(new ChangeListener<Number>() {
                @Override
                public void changed(ObservableValue<? extends Number> observableValue, Number oldValue,
                        final Number newValue) {
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            progressBar.setValue(newValue.intValue());
                        }
                    });
                }
            });

            engine.getLoadWorker().exceptionProperty().addListener(new ChangeListener<Throwable>() {

                public void changed(ObservableValue<? extends Throwable> o, Throwable old,
                        final Throwable value) {
                    if (engine.getLoadWorker().getState() == FAILED) {
                        SwingUtilities.invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                JOptionPane.showMessageDialog(panel,
                                        (value != null) ? engine.getLocation() + "\n" + value.getMessage()
                                                : engine.getLocation() + "\nUnexpected error.",
                                        "Loading error...", JOptionPane.ERROR_MESSAGE);
                            }
                        });
                    }
                }
            });

            jfxPanel.setScene(new Scene(view));
        }
    });
}