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:au.org.ala.delta.intkey.model.IntkeyContext.java

/**
 * Execute the supplied command pattern object representing the invocation
 * of a directive/*w  ww  .java  2  s  . co m*/
 * 
 * @param invoc
 *            a command pattern object representing the invocation of a
 *            directive
 */
public synchronized void executeDirective(IntkeyDirectiveInvocation invoc) {
    // record correct insertion index in case execution of directive results
    // in further directives being
    // run (such as in the case of the File Input directive).
    int executedDirectivesIndex = _executedDirectives.size();

    // Record correct insertion index for the directive call here so that if
    // unsuccessful the directive call can be removed from the log. It is
    // necessary to add the directive call to the log here to ensure that it
    // appears above any subsequent status messages in the log.
    int logInsertionIndex = _logCache.size();

    // The use directive is a special case. The use directive logic handles
    // appending to the log itself.
    if (!(invoc instanceof UseDirectiveInvocation)) {
        if (!_processingDirectivesFile || (_processingInputFile && _displayInput)) {
            appendToLog("*" + invoc.toString());
        }
    }

    // If this is a long running directive and we are on the event dispatch
    // thread, run the task in the
    // background using a SwingWorker.
    if (invoc instanceof LongRunningIntkeyDirectiveInvocation && SwingUtilities.isEventDispatchThread()
            && !_processingInputFile && !_processingDirectivesFile) {
        LongRunningIntkeyDirectiveInvocation<?> longInvoc = (LongRunningIntkeyDirectiveInvocation<?>) invoc;
        LongRunningDirectiveSwingWorker worker = new LongRunningDirectiveSwingWorker(longInvoc, this, _appUI,
                executedDirectivesIndex, logInsertionIndex);
        worker.execute();
    } else {
        try {
            boolean success = invoc.execute(this);
            if (success) {
                handleDirectiveExecutionComplete(invoc, executedDirectivesIndex);
            } else {
                handleDirectiveExecutionFailed(invoc, logInsertionIndex);
            }
        } catch (IntkeyDirectiveInvocationException ex) {
            _appUI.displayErrorMessage(ex.getMessage());
        }
    }
}

From source file:au.com.jwatmuff.eventmanager.gui.scoreboard.ScoreboardDisplayPanel.java

@Override
public void handleScoreboardUpdate(ScoreboardUpdate update, ScoreboardModel model) {

    //        log.info("handleScoreboardUpdate");

    // Force updates onto the GUI thread
    if (!SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(() -> handleScoreboardUpdate(update, model));
        return;/*  w w  w. j a v  a 2 s.co  m*/
    }

    updateColors();

    switch (update) {
    case TIMER:
        updateTimer();
        break;
    case HOLDDOWN:
        updateHolddownTimer();
        break;
    case MODE:
        updateResult();
        showHolddownTimer(model.isHolddownActivated());
        if (model.isHolddownActivated())
            updateHolddownTimer();
        updateColors();
        updateNoFight();
        updateImages(false);
        updatePendingFight();
        updateDivision();
        break;
    case SCORE:
        updateScore();
        updateShido();
        updateResult();
        break;
    case PENDING_SCORE:
        updatePendingScores();
        break;
    case UNDO_AVAILABLE:
        break;
    case GOLDEN_SCORE:
        updateGoldenScore();
        break;
    case SIREN:
        break;
    case FIGHT_PENDING:
        updatePendingFight();
        updateDivision();
        break;
    case ALL:
        updateTimer();
        updateHolddownTimer();
        updatePlayers();
        updateDivision();
        updateScore();
        updateShido();
        updatePendingScores();
        updateColors();
        updateNoFight();
        updateImages(false);
        updateGoldenScore();
        updatePendingFight();
        break;
    default:
        log.info("Unknown update event: " + update);
    }
    this.repaint(); // Hoping this will fix intermittent delay issue - very hard to test
    // delay seems to be due to render issue because resizing window brings it into sync
    // only seems to affect entry scoreboard
    // maybe something else is updating gui off the main thread?
}

From source file:org.owasp.webscarab.plugin.sessionid.swing.SessionIDPanel.java

public void sessionIDAdded(final String key, final int index) {
    if (SwingUtilities.isEventDispatchThread()) {
        if (index == 0) {
            _sessionIDNames.addElement(key);
        }/*w  ww .j a v  a  2  s.co  m*/
        if (key.equals(_key)) {
            _sidd.fireDatasetChanged();
            _tableModel.fireTableRowsInserted(index, index);
        }
    } else {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                sessionIDAdded(key, index);
            }
        });
    }
}

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

/**
 * Appends the given string at the end of the contained in this panel
 * document./*from  w ww .  ja  va2  s.  c o  m*/
 *
 * Note: Currently, it looks like appendMessageToEnd is only called for
 * messages that are already converted to HTML. So It is quite possible that
 * we can remove the content type without any issues.
 *
 * @param original the message string to append
 * @param contentType the message's content type
 */
public void appendMessageToEnd(final String original, final String contentType) {
    if (!SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                appendMessageToEnd(original, contentType);
            }
        });
        return;
    }

    if (original == null) {
        return;
    }

    final String message;
    if (ChatHtmlUtils.HTML_CONTENT_TYPE.equalsIgnoreCase(contentType)) {
        message = original;
    } else {
        message = StringEscapeUtils.escapeHtml4(original);
    }

    synchronized (scrollToBottomRunnable) {
        Element root = document.getDefaultRootElement();

        try {
            document.insertBeforeEnd(
                    // the body element
                    root.getElement(root.getElementCount() - 1),
                    // the message to insert
                    message);

            // Need to call explicitly scrollToBottom, because for some
            // reason the componentResized event isn't fired every time we
            // add text.
            SwingUtilities.invokeLater(scrollToBottomRunnable);
        } catch (BadLocationException e) {
            logger.error("Insert in the HTMLDocument failed.", e);
        } catch (IOException e) {
            logger.error("Insert in the HTMLDocument failed.", e);
        }
    }

    String lastElemContent = getElementContent(lastMessageUID, message);

    if (lastElemContent != null) {
        finishMessageAdd(lastElemContent);
    }
}

From source file:org.owasp.webscarab.plugin.sessionid.swing.SessionIDPanel.java

public void sessionIDsChanged() {
    if (SwingUtilities.isEventDispatchThread()) {
        _key = null;/*from  w  ww  . j a  v a  2  s . com*/
        _sessionIDNames.clear();
        int count = _model.getSessionIDNameCount();
        for (int i = 0; i < count; i++) {
            _sessionIDNames.addElement(_model.getSessionIDName(i));
        }
        _sidd.fireDatasetChanged();
        _tableModel.fireTableDataChanged();
        updateStats();
    } else {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                sessionIDsChanged();
            }
        });
    }
}

From source file:SwingWorker.java

/**
 * {@inheritDoc}//w w w  .jav  a2s .co  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:ee.ioc.cs.vsle.editor.Editor.java

public Canvas newSchemeTab(VPackage pkg, InputStream inputStream) {
    assert SwingUtilities.isEventDispatchThread();

    Canvas c = new Canvas(pkg, new File(pkg.getPath()).getParent() + File.separator);
    c.loadScheme(inputStream);/*  w ww .  j a  v a 2s. c  o  m*/
    addCanvas(c);
    return c;
}

From source file:org.owasp.webscarab.plugin.sessionid.swing.SessionIDPanel.java

public void calculatorChanged(final String key) {
    if (key.equals(_key)) {
        if (SwingUtilities.isEventDispatchThread()) {
            _sidd.fireDatasetChanged();//from  w  w w.  j av  a2  s  .c o  m
            _tableModel.fireTableDataChanged();
            updateStats();
        } else {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    calculatorChanged(key);
                }
            });
        }
    }
}

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

/**
 * Invokes {@code done} on the EDT.//from   w ww . ja  v a 2  s  .  com
 */
private void doneEDT() {
    Runnable doDone = 
        new Runnable() {
            public void run() {
                done();
            }
        };
    if (SwingUtilities.isEventDispatchThread()) {
        doDone.run();
    } else {
        doSubmit.add(doDone);
    }
}

From source file:org.owasp.webscarab.plugin.sessionid.swing.SessionIDPanel.java

public void setEnabled(final boolean enabled) {
    if (SwingUtilities.isEventDispatchThread()) {
        mainTabbedPane.setEnabled(enabled);
        testButton.setEnabled(enabled);/* w w  w  .j av a 2 s .  com*/
        fetchButton.setEnabled(enabled);
        // FIXME do the rest
    } else {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                setEnabled(enabled);
            }
        });
    }
}