Example usage for javax.swing SwingUtilities isEventDispatchThread

List of usage examples for javax.swing SwingUtilities isEventDispatchThread

Introduction

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

Prototype

public static boolean isEventDispatchThread() 

Source Link

Document

Returns true if the current thread is an AWT event dispatching thread.

Usage

From source file:com.archivas.clienttools.arcmover.gui.panels.ProfilePanel.java

/**
 * Updates the path combo box and the file list to reflect the specified directory
 *
 * @param path//w w w. jav a 2s .c o  m
 *            -
 * @throws Exception
 */
private void setPathAndFileListToDirectory(String path) {
    // pathCombo.setSelectedItem() causes the action listener for the pathCombo to be fired,
    // which will update the file list
    if (!SwingUtilities.isEventDispatchThread()) {
        String errMsg = "setPathAndFileListToDirectory is not on the EDT but it should be";
        IllegalStateException ex = new IllegalStateException(errMsg);
        LOG.log(Level.SEVERE, errMsg, ex);
        throw ex;
    }
    pathCombo.setSelectedItem(path);
}

From source file:hermes.browser.HermesBrowser.java

/**
 * Show an error dialog with the given message, will dispatch to the evet
 * thread if needed./*  w ww.ja  v a2 s.  c  o  m*/
 * 
 * @param message
 */
public void showErrorDialog(final String message) {
    Runnable r = new Runnable() {
        public void run() {
            JOptionPane.showMessageDialog(HermesBrowser.this, message, "Error", JOptionPane.ERROR_MESSAGE);
        }
    };

    if (SwingUtilities.isEventDispatchThread()) {
        r.run();
    } else {
        SwingUtilities.invokeLater(r);
    }
}

From source file:net.java.sip.communicator.impl.gui.main.chat.ChatWritePanel.java

/**
 * Updates the status of the given chat transport in the send via selector
 * box and notifies the user for the status change.
 * @param chatTransport the <tt>chatTransport</tt> to update
 *//*from   ww w .j  a v a  2  s  .c  o  m*/
public void updateChatTransportStatus(final ChatTransport chatTransport) {
    // We need to be sure that the following code is executed in the event
    // dispatch thread.
    if (!SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                updateChatTransportStatus(chatTransport);
            }
        });
        return;
    }

    if (transportSelectorBox != null)
        transportSelectorBox.updateTransportStatus(chatTransport);
}

From source file:net.java.sip.communicator.impl.gui.main.chat.ChatPanel.java

/**
 * Refreshes write area editor pane. Deletes all existing text
 * content.//w  ww .  j  a  va  2  s .co m
 */
public void refreshWriteArea() {
    if (!SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                refreshWriteArea();
            }
        });
        return;
    }

    this.writeMessagePanel.clearWriteArea();
}

From source file:com.archivas.clienttools.arcmover.gui.panels.ProfilePanel.java

/**
 * This sets the file list for this panel to the files in the given directory. Can throw a
 * StorageAdapterException when getting the file list for the directory. The actual work on the
 * fileList is completed on the EDT for thread safety.
 * /*from  w w w.  j av a2  s .co  m*/
 * @param dir
 *            The directory to display
 * @param colsToDisplay
 *            Columns to display in the file list
 * @throws Exception
 *             An exception thrown by dir.getFileList or SwingUtilities.invokeAndWait
 */
private void setFileListToDirectory(ArcMoverDirectory dir, List<String> colsToDisplay) throws Exception {
    // Should not be run on the EDT
    if (SwingUtilities.isEventDispatchThread()) {
        String errMsg = "setFileListToDirectory is on the EDT but it should not be";
        IllegalStateException ex = new IllegalStateException(errMsg);
        LOG.log(Level.SEVERE, errMsg, ex);
        throw ex;
    }
    List<ArcMoverFile> files = dir.getFileList(UI_FIRST_BATCH_SIZE);
    int badElementCnt = dir.getFileListBadElementCnt();

    List<ArcMoverFile> sortedDirs = new ArrayList<ArcMoverFile>();
    List<ArcMoverFile> sortedFiles = new ArrayList<ArcMoverFile>();
    List<ArcMoverFile> sortedSymlinks = new ArrayList<ArcMoverFile>();
    ArcMoverFile mostRecentVersion = null;
    boolean isVersionList = dir.isVersionList();

    for (ArcMoverFile f : files) {
        // if f is a directory or is a link to a directory, show as directory
        if (f.isDirectory()) {
            sortedDirs.add(f);
        } else if (f.isSymlink()) {
            sortedSymlinks.add(f);
        } else {
            if (mostRecentVersion == null) {
                if (f.getMetadata().hasVersionNumber()) {
                    mostRecentVersion = f;
                }
            } else {
                if (isVersionList && f.getMetadata().hasVersionNumber()) {
                    mostRecentVersion.setLatestVersion(false);

                    if (f.getMetadata().getVersionNumber() > mostRecentVersion.getMetadata()
                            .getVersionNumber()) {
                        mostRecentVersion = f;
                    }
                }
            }

            sortedFiles.add(f);
        }
    }

    if (mostRecentVersion != null) {
        mostRecentVersion.setLatestVersion(true);
    }

    Collections.sort(sortedDirs);
    Collections.sort(sortedSymlinks);

    if (isVersionList) {
        Collections.sort(sortedFiles, ArcMoverVersionedFileComparator.getInstance());
    } else {
        Collections.sort(sortedFiles, ArcMoverFileDefaultComparator.getInstance());
    }

    files.clear();
    files.addAll(sortedDirs);
    files.addAll(sortedSymlinks);
    files.addAll(sortedFiles);

    GUIHelper.invokeAndWait(
            getFileListRunner(colsToDisplay, files, isVersionList, badElementCnt, dir.getPath()),
            "get file list");
}

From source file:hermes.browser.HermesBrowser.java

/**
 * Show an error message with the message from the exception and also log it
 * to Log4j./*from   ww w.j  a  v  a2s.co m*/
 * 
 * @param message
 * @param t
 */
public void showErrorDialog2(final String message, final Throwable t) {
    log.error(t.getMessage(), t);

    Runnable r = new Runnable() {
        public void run() {
            if (t instanceof PyException) {
                PyException pyT = (PyException) t;

                JOptionPane.showMessageDialog(HermesBrowser.this, message + ": " + pyT.traceback.dumpStack(),
                        "Error", JOptionPane.ERROR_MESSAGE);
            } else {

                JOptionPane.showMessageDialog(HermesBrowser.this, message + ": " + t.getMessage(), "Error",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    };

    if (SwingUtilities.isEventDispatchThread()) {
        r.run();
    } else {
        SwingUtilities.invokeLater(r);
    }
}

From source file:net.java.sip.communicator.impl.gui.main.chat.ChatWritePanel.java

/**
 * Removes the given chat status state from the send via selector box.
 *
 * @param chatTransport the transport to remove
 *//*from www . j  av a 2s.co m*/
public void removeChatTransport(final ChatTransport chatTransport) {
    // We need to be sure that the following code is executed in the event
    // dispatch thread.
    if (!SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                removeChatTransport(chatTransport);
            }
        });
        return;
    }

    if (transportSelectorBox != null)
        transportSelectorBox.removeChatTransport(chatTransport);

    if (transportSelectorBox != null && transportSelectorBox.getMenu().getItemCount() == 1
            && ConfigurationUtils.isHideAccountSelectionWhenPossibleEnabled()) {
        transportSelectorBox.setVisible(false);
    }
}

From source file:hermes.browser.HermesBrowser.java

public void showErrorDialog(final String message, final Throwable t) {
    Runnable r = new Runnable() {
        public void run() {
            String detail = null;

            if (t instanceof PyException) {
                StringBuffer s = new StringBuffer();
                PyException pyT = (PyException) t;
                pyT.traceback.dumpStack(s);

                detail = s.toString();//from   ww w .ja v a 2 s  .  c  o m
            } else {
                StringWriter s = new StringWriter();
                PrintWriter p = new PrintWriter(s);
                t.printStackTrace(p);
                detail = s.toString();
            }

            JideOptionPane optionPane = new JideOptionPane(message, JOptionPane.ERROR_MESSAGE,
                    JideOptionPane.CLOSE_OPTION, UIManager.getIcon("OptionPane.errorIcon"));
            optionPane.setTitle(message);

            if (detail != null) {
                optionPane.setDetails(detail);
            }
            JDialog dialog = optionPane.createDialog(HermesBrowser.this, "Error");
            dialog.setResizable(true);
            dialog.pack();
            dialog.setVisible(true);
        }
    };

    if (SwingUtilities.isEventDispatchThread()) {
        r.run();
    } else {
        SwingUtilities.invokeLater(r);
    }
}

From source file:com.diversityarrays.kdxplore.trials.TrialExplorerPanel.java

private void handleTrialDataLoadResult(final String fromWhere, final TrialLoadResult lr) {
    if (lr.cause != null) {
        lr.cause.printStackTrace();// w ww .  j  a v  a 2  s .  c  o  m
        messagePrinter.println(lr.cause.getMessage());
    } else {
        if (!SwingUtilities.isEventDispatchThread()) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    handleTrialDataLoadResult(fromWhere, lr);
                }
            });
            return;
        }

        if (lr.hasAnyDownloadErrors() || lr.hasAnyDownloadWarnings()) {
            reportDownloadErrorsAndWarnings(fromWhere, lr);
            return;
        }

        // FIXME loadTrialData: need to store lr.plots into the database.
        // But this needs to first check if the plots already exist because
        // this method
        // can be called either on the initial Trial load or from
        // "refreshTrialData".
        // The latter could be quite complex unless we just discard all of
        // the
        // Plots. But this could then cause a problem because we might have
        // other records
        // (e.g. Samples) that refer to the plotIds of the extant plots.

        // FIXME loadTrialData: need to resolve the List<core.Trait> against
        // the kdsmart Traits
        // in the Trait table in kdxploreDatabase.

        try {
            storeToDatabase(fromWhere, lr);
        } catch (IOException e) {
            MsgBox.error(TrialExplorerPanel.this, e.getMessage(), fromWhere);
        } catch (CreateItemException e) {
            MsgBox.error(TrialExplorerPanel.this, e.getMessage(), fromWhere);
        } catch (TrialStoreException e) {
            StringBuilder sb = new StringBuilder("<HTML>Trait Load Problems:<ul>");
            for (Pair<com.diversityarrays.daldb.core.Trait, String> pair : lr.traitLoadErrors) {
                com.diversityarrays.daldb.core.Trait dalTrait = pair.first;

                sb.append("<li>").append(StringUtil.htmlEscape(dalTrait.getTraitName())).append("<br>")
                        .append(StringUtil.htmlEscape(pair.second)).append("</li>");
            }
            sb.append("</ul>");

            JLabel msg = new JLabel(sb.toString());
            JScrollPane sp = new JScrollPane(msg);
            JOptionPane.showMessageDialog(TrialExplorerPanel.this, sp, "Trial Load: " + fromWhere,
                    JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:javazoom.jlgui.player.amp.PlayerUI.java

/**
 * Process STATEUPDATED event.//  w ww  . j  ava2  s.  c om
 * @param event
 */
public void processStateUpdated(BasicPlayerEvent event) {
    log.debug("Player:" + event + " (EDT=" + SwingUtilities.isEventDispatchThread() + ")");
    /*-- End Of Media reached --*/
    int state = event.getCode();
    Object obj = event.getDescription();
    if (state == BasicPlayerEvent.EOM) {
        if ((playerState == PAUSE) || (playerState == PLAY)) {
            playlist.nextCursor();
            playlistUI.nextCursor();
            PlaylistItem pli = playlist.getCursor();
            setCurrentSong(pli);
        }
    } else if (state == BasicPlayerEvent.PLAYING) {
        lastScrollTime = System.currentTimeMillis();
        posValueJump = false;
        if (audioInfo.containsKey("basicplayer.sourcedataline")) {
            if (ui.getAcAnalyzer() != null) {
                ui.getAcAnalyzer().setupDSP((SourceDataLine) audioInfo.get("basicplayer.sourcedataline"));
                ui.getAcAnalyzer().startDSP((SourceDataLine) audioInfo.get("basicplayer.sourcedataline"));
            }
        }
    } else if (state == BasicPlayerEvent.SEEKING) {
        posValueJump = true;
    } else if (state == BasicPlayerEvent.SEEKED) {
        try {
            theSoundPlayer
                    .setGain(((double) ui.getAcVolume().getValue() / (double) ui.getAcVolume().getMaximum()));
            theSoundPlayer.setPan((float) ui.getAcBalance().getValue() / 10.0f);
        } catch (BasicPlayerException e) {
            log.debug(e);
        }
    } else if (state == BasicPlayerEvent.OPENING) {
        if ((obj instanceof URL) || (obj instanceof InputStream)) {
            showTitle(ui.getResource("title.buffering"));
        }
    } else if (state == BasicPlayerEvent.STOPPED) {
        if (ui.getAcAnalyzer() != null) {
            ui.getAcAnalyzer().stopDSP();
            ui.getAcAnalyzer().repaint();
        }
    }
}