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.clank.launcher.swing.SwingHelper.java

/**
 * Asks the user a binary yes or no question.
 *
 * @param parentComponent the component/*from   w  w  w  .ja  va 2 s . c  o m*/
 * @param message the message to display
 * @param title the title string for the dialog
 * @return whether 'yes' was selected
 */
public static boolean confirmDialog(final Component parentComponent, @NonNull final String message,
        @NonNull final String title) {
    if (SwingUtilities.isEventDispatchThread()) {
        return JOptionPane.showConfirmDialog(parentComponent, message, title,
                JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
    } else {
        // Use an AtomicBoolean to pass the result back from the
        // Event Dispatcher Thread
        final AtomicBoolean yesSelected = new AtomicBoolean();

        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    yesSelected.set(confirmDialog(parentComponent, title, message));
                }
            });
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }

        return yesSelected.get();
    }
}

From source file:com.aw.swing.mvp.binding.BindingComponent.java

protected void updateUI() {
    if (!initialized && !uiReadOnly) {
        return;/*from  ww  w .  j ava 2 s  .  c o  m*/
    }
    if (SwingUtilities.isEventDispatchThread()) {
        updateUIInternal();
    } else {
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    updateUIInternal();
                }
            });
        } catch (Throwable e) {
            throw new AWSystemException("Problems updating the UI:" + this, e);
        }

    }
}

From source file:org.jdesktop.swingworker.AccumulativeRunnable.java

/**
 * {@inheritDoc}/*from  w w  w .  ja  va2s . c  o m*/
 *
 * <p>
 * If {@see #isNotifyOnEDT} is {@code true} and called off the
 * <i>Event Dispatch Thread</i> this implementation uses 
 * {@code SwingUtilities.invokeLater} to send out the notification
 * on the <i>Event Dispatch Thread</i>. This ensures  listeners
 * are only ever notified on the <i>Event Dispatch Thread</i>.
 *
 * @throws NullPointerException if {@code evt} is 
 *         {@code null}
 * @since 1.6
 */
public void firePropertyChange(final PropertyChangeEvent evt) {
    if (evt == null) {
        throw new NullPointerException();
    }
    if (! isNotifyOnEDT()
        || SwingUtilities.isEventDispatchThread()) {
        super.firePropertyChange(evt);
    } else {
        SwingUtilities.invokeLater(
            new Runnable() {
                public void run() {
                    firePropertyChange(evt);
                }
            });
    }
}

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

private void unlock() {
    if (!SwingUtilities.isEventDispatchThread()) {
        String errMsg = "unlock is not on the EDT but it should be";
        IllegalStateException ex = new IllegalStateException(errMsg);
        LOG.log(Level.SEVERE, errMsg, ex);
        throw ex;
    }/*from  w w  w .  j  av  a  2  s. c  om*/
    lockCount--;
    if (lockCount < 0) {
        String errMsg = "lockCount is less than zero: " + lockCount;
        IllegalStateException ex = new IllegalStateException(errMsg);
        LOG.log(Level.SEVERE, errMsg, ex);
        throw ex;
    }
    updateLockState();
    if (lockCount == 0) {
        firePropertyChange(LOCK_PROPERTY, true, false);
    }
}

From source file:com.kenai.redminenb.issue.RedmineIssue.java

void opened() {
    if (Redmine.LOG.isLoggable(Level.FINE)) {
        Redmine.LOG.log(Level.FINE, "issue {0} open start", new Object[] { getID() });
    }//from   w  w  w. j a v  a 2s .  c  o m
    String refresh = System.getProperty("org.netbeans.modules.bugzilla.noIssueRefresh"); // NOI18N
    if (refresh != null && refresh.equals("true")) { // NOI18N
        return;
    }
    if (SwingUtilities.isEventDispatchThread()) {
        new SwingWorker<Object, Object>() {
            @Override
            protected Object doInBackground() throws Exception {
                refresh();
                return null;
            };
        }.execute();
    } else {
        refresh();
    }
    repository.scheduleForRefresh(getID());
    if (Redmine.LOG.isLoggable(Level.FINE)) {
        Redmine.LOG.log(Level.FINE, "issue {0} open finish", new Object[] { getID() });
    }
}

From source file:SwingTypeTester8.java

private void setScore() {
    if (SwingUtilities.isEventDispatchThread())
        setText(Integer.toString(score));
    else/* w  w  w  . j a va2  s.co m*/
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    setText(Integer.toString(score));
                }
            });
        } catch (InterruptedException ie) {
        } catch (InvocationTargetException ite) {
        }
}

From source file:SwingTypeTester9.java

private void error() {
    t.interrupt();/*from  w w w  . jav a  2s.com*/
    if (SwingUtilities.isEventDispatchThread())
        closeDown();
    else
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                closeDown();
            }
        });
}

From source file:org.nbheaven.sqe.codedefects.history.controlcenter.panels.SQEHistoryPanel.java

private void updateView() {
    if (!SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                updateView();/*from w w  w  . java 2s. com*/
            }
        });
        return;
    }

    assert SwingUtilities.isEventDispatchThread();

    // Update per project view first
    perProjectDataSet.removeAllSeries();
    XYSeries error = new XYSeries("Error", true, false);
    XYSeries warning = new XYSeries("Warning", true, false);
    XYSeries info = new XYSeries("Info", true, false);

    if (null != activeHistory) {
        int i = 1;
        for (History.Entry entry : activeHistory) {
            QualityResultStatistic result = entry.get(getSelectedProviders());
            error.add(new XYDataItem(i, result.getCodeDefectCount(CodeDefectSeverity.ERROR)));
            warning.add(new XYDataItem(i, result.getCodeDefectCount(CodeDefectSeverity.WARNING)));
            info.add(new XYDataItem(i, result.getCodeDefectCount(CodeDefectSeverity.INFO)));
            i++;
        }
        clearHistoryButton.setEnabled(!activeHistory.isEmpty());
    }

    perProjectDataSet.addSeries(error);
    perProjectDataSet.addSeries(warning);
    perProjectDataSet.addSeries(info);

    invalidate();
    revalidate();
    repaint();
}

From source file:de.codesourcery.flocking.ui.NumberInputField.java

/**
 * To be invoked when this input components
 * underlying {@link IModel} has changed
 * and thus this component needs repainting.
 *//*ww w .ja  va 2  s .c  o  m*/
public void modelChanged() {

    final Number n = model.getObject();

    final int sliderValue = calcSliderValue(n);

    final Runnable r = new Runnable() {

        @Override
        public void run() {
            selfTriggeredEvent = true;
            slider.setValue(sliderValue);
            textField.setText(numberToString(n));
            selfTriggeredEvent = false;
        }
    };

    if (SwingUtilities.isEventDispatchThread()) {
        r.run();
    } else {
        try {
            SwingUtilities.invokeAndWait(r);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}