Example usage for java.awt EventQueue isDispatchThread

List of usage examples for java.awt EventQueue isDispatchThread

Introduction

In this page you can find the example usage for java.awt EventQueue isDispatchThread.

Prototype

public static boolean isDispatchThread() 

Source Link

Document

Returns true if the calling thread is Toolkit#getSystemEventQueue the current AWT EventQueue 's dispatch thread.

Usage

From source file:org.zaproxy.zap.extension.plugnhack.ExtensionPlugNHack.java

@Override
public void sessionChanged(final Session session) {
    if (EventQueue.isDispatchThread()) {
        sessionChangedEventHandler(session);

    } else {//  www .  j  a  v a2 s . c o m
        try {
            EventQueue.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    sessionChangedEventHandler(session);
                }
            });
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }
}

From source file:org.zaproxy.zap.extension.spider.ExtensionSpider.java

@Override
public void sessionChanged(final Session session) {
    if (EventQueue.isDispatchThread()) {
        sessionChangedEventHandler(session);
    } else {/*from  w  w  w .j av a 2s .c o m*/
        try {
            EventQueue.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    sessionChangedEventHandler(session);
                }
            });
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}

From source file:org.zaproxy.zap.extension.spider.ExtensionSpider.java

private void addScanToUi(final SpiderScan scan) {
    if (!EventQueue.isDispatchThread()) {
        EventQueue.invokeLater(new Runnable() {

            @Override// w w  w .j a v a 2  s  .c  o m
            public void run() {
                addScanToUi(scan);
            }
        });
        return;
    }

    this.getSpiderPanel().scannerStarted(scan);
    scan.setListener(getSpiderPanel()); // So the UI gets updated
    this.getSpiderPanel().switchView(scan);
    this.getSpiderPanel().setTabFocus();
}

From source file:org.zaproxy.zap.extension.spiderAjax.SpiderThread.java

private void notifyMessage(final HttpMessage httpMessage, final int historyType, final ResourceState state) {
    try {//w ww .ja v  a  2  s .c o  m
        if (extension.getView() != null && !EventQueue.isDispatchThread()) {
            EventQueue.invokeLater(new Runnable() {

                @Override
                public void run() {
                    notifyMessage(httpMessage, historyType, state);
                }
            });
            return;
        }

        HistoryReference historyRef = new HistoryReference(session, historyType, httpMessage);
        if (state == ResourceState.PROCESSED) {
            historyRef.setCustomIcon("/resource/icon/10/spiderAjax.png", true);
            session.getSiteTree().addPath(historyRef, httpMessage);
        }

        notifySpiderListenersFoundMessage(historyRef, httpMessage, state);
    } catch (Exception e) {
        logger.error(e);
    }
}

From source file:org.zaproxy.zap.extension.zest.ExtensionZest.java

@Override
public void optionsLoaded() {
    if (getView() == null || EventQueue.isDispatchThread()) {
        // Convert scripts loaded on start into real Zest scripts
        for (ScriptType type : this.getExtScript().getScriptTypes()) {
            for (ScriptWrapper script : this.getExtScript().getScripts(type)) {
                if (ZestScriptEngineFactory.NAME.equals(script.getEngineName())) {
                    this.scriptAdded(script, false);
                }/*from   ww  w . j  av a  2s .c o m*/
            }
        }
    } else {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                optionsLoaded();
            }
        });
    }
}

From source file:org.zaproxy.zap.model.Context.java

public void restructureSiteTree() {
    if (EventQueue.isDispatchThread()) {
        restructureSiteTreeEventHandler();
    } else {/*from   w  w  w . j  a  v a 2  s  .  c o  m*/
        try {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    restructureSiteTreeEventHandler();
                }
            });
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}

From source file:uk.ac.ucl.cs.cmic.giftcloud.util.GiftCloudUtils.java

/**
 * Runs a given method on the EDT, which may or may not be the current thread
 *
 * @param runnable//www .ja  va2  s  .  co  m
 * @throws InterruptedException
 * @throws InvocationTargetException
 */
public static void runNowOnEdt(final Runnable runnable) throws InterruptedException, InvocationTargetException {
    if (EventQueue.isDispatchThread()) {
        runnable.run();
    } else {
        java.awt.EventQueue.invokeAndWait(runnable);
    }
}

From source file:uk.ac.ucl.cs.cmic.giftcloud.util.GiftCloudUtils.java

/**
 * Runs a given method on the EDT, which may or may not be the current thread. If it is not the current thread, the call will be asynchronous
 *
 * @param runnable//from   w  w w . ja v  a  2 s  .  c  om
 */
public static void runLaterOnEdt(final Runnable runnable) {
    if (EventQueue.isDispatchThread()) {
        runnable.run();
    } else {
        java.awt.EventQueue.invokeLater(runnable);
    }
}

From source file:xtrememp.XtremeMP.java

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

From source file:xtrememp.XtremeMP.java

@Override
public void acUpdateTime(int value) {
    StringBuilder timeText = new StringBuilder();
    if (currentPli != null) {
        String formattedLength = currentPli.getFormattedLength();
        long duration = TimeUnit.MILLISECONDS.toSeconds(value);
        if (Utilities.isNullOrEmpty(formattedLength)) {
            timeText.append(currentPli.getFormattedLength(duration));
        } else {// w  w w .  jav  a 2  s. c o m
            timeText.append(currentPli.getFormattedLength(duration));
            timeText.append(" / ");
            timeText.append(formattedLength);
        }
    } else {
        timeText.append(Utilities.ZERO_TIMER);
    }

    final String timeStr = timeText.toString();
    final int seekValue = (currentPli == null) ? 0 : value;
    if (EventQueue.isDispatchThread()) {
        seekSlider.setValue(seekValue);
        timeLabel.setText(timeStr);
    } else {
        EventQueue.invokeLater(() -> {
            seekSlider.setValue(seekValue);
            timeLabel.setText(timeStr);
        });
    }
}