Java Code Examples for java.awt.EventQueue#isDispatchThread()

The following examples show how to use java.awt.EventQueue#isDispatchThread() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JmxModelImpl.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable {
    if (LOGGER.isLoggable(Level.FINE)) {
        // Check if MBeanServerConnection call is performed on EDT
        if (EventQueue.isDispatchThread()) {
            Throwable thrwbl = new Throwable();

            LOGGER.log(Level.FINE, createTracedMessage("MBeanServerConnection call " +  // NOI18N
                    "performed on Event Dispatch Thread!", thrwbl));    // NOI18N
        }
    }
    // Invoke MBeanServerConnection call
    try {
        return method.invoke(conn, args);
    } catch (InvocationTargetException e) {
        throw e.getCause();
    }
}
 
Example 2
Source File: MainFrameLoadSaveHelper.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
void loadAnalysis(final URL url) {

        Runnable runnable = () -> {
            mainFrame.acquireDisplayWait();
            try {
                Project project = new Project();
                project.setGuiCallback(mainFrame.getGuiCallback());
                BugLoader.loadBugs(mainFrame, project, url);
                project.getSourceFinder(); // force source finder to be
                // initialized
                mainFrame.updateBugTree();
            } finally {
                mainFrame.releaseDisplayWait();
            }
        };
        if (EventQueue.isDispatchThread()) {
            new Thread(runnable, "Analysis loading thread").start();
        } else {
            runnable.run();
        }
    }
 
Example 3
Source File: ExtensionScriptsUI.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public void engineRemoved(final ScriptEngineWrapper scriptEngineWrapper) {
    if (getView() == null) {
        return;
    }

    if (!EventQueue.isDispatchThread()) {
        try {
            EventQueue.invokeAndWait(
                    new Runnable() {

                        @Override
                        public void run() {
                            engineRemoved(scriptEngineWrapper);
                        }
                    });
        } catch (InvocationTargetException | InterruptedException e) {
            LOGGER.error("Failed to update the UI:", e);
        }
        return;
    }

    ScriptNode node = getSelectedNode();
    if (node != null && node.getUserObject() instanceof ScriptWrapper) {
        ScriptWrapper scriptWrapper = (ScriptWrapper) node.getUserObject();
        if (ExtensionScript.hasSameScriptEngine(scriptWrapper, scriptEngineWrapper)) {
            displayType(scriptWrapper.getType());
        }
    }
}
 
Example 4
Source File: ViewUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static void nodeRename(final Node n, final String newStr) {
    // bugfix #21589 don't update name if there is not any change
    if (n.getName().equals(newStr)) {
        return;
    }
    if (EventQueue.isDispatchThread() && Boolean.TRUE.equals(n.getValue("slowRename"))) { // NOI18N
        RP.post(new Runnable() {
            @Override
            public void run() {
                nodeRename(n, newStr);
            }
        });
        return;
    }
    try {
        n.setName(newStr);
    } catch (IllegalArgumentException exc) {
        boolean needToAnnotate = Exceptions.findLocalizedMessage(exc) == null;

        // annotate new localized message only if there is no localized message yet
        if (needToAnnotate) {
            String msg = NbBundle.getMessage(
                    TreeViewCellEditor.class, "RenameFailed", n.getName(), newStr
                );
            Exceptions.attachLocalizedMessage(exc, msg);
        }

        Exceptions.printStackTrace(exc);
    }
}
 
Example 5
Source File: WebServicesHintsProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void rescan(){
    if (javaSrc == null) {
        javaSrc = JavaSource.forFileObject(file);
    }
    if (javaSrc != null){
        try{
            if(EventQueue.isDispatchThread()) {
                wsHintsTask.schedule(100);
            } else {
                javaSrc.runUserActionTask(new ProblemFinderCompControl(file), true);
            }
        } catch (IOException e){
        }
    }
}
 
Example 6
Source File: FrameworksOptionsPanelController.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setCurrentSubcategory(String subpath) {
    EventQueue.isDispatchThread();
    super.setCurrentSubcategory(subpath);
    if (subpath != null
            && panel != null) {
        subpath = FRAMEWORKS_AND_TOOLS_OPTIONS_PATH + "/" + subpath; //NOI18N
        AdvancedOption option = id2option.get(subpath);
        if (option != null) {
            panel.setSelecteOption(option);
        }
    }
}
 
Example 7
Source File: KnockoutTC.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the content of this {@code TopComponent}.
 */
final void update() {
    if (EventQueue.isDispatchThread()) {
        PageModel pageModel = PageInspectorImpl.getDefault().getPage();
        if (currentPanel != null) {
            if (pageModel == currentPanel.getPageModel()) {
                return;
            } else {
                currentPanel.dispose();
            }
        }
        removeAll();
        currentPanel = new KnockoutPanel((WebKitPageModel)pageModel);
        if (lastKnockoutPageModel != null) {
            PageModel knockoutPageModel = lastKnockoutPageModel.get();
            if (knockoutPageModel != null && knockoutPageModel == pageModel) {
                currentPanel.knockoutUsed(lastKnockoutVersion);
            }
        }
        add(currentPanel);
        ((KnockoutTCLookup)getLookup()).setPanel(currentPanel);
        revalidate();
        repaint();
    } else {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                update();
            }
        });
    }
}
 
Example 8
Source File: ListRepaint.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void paint(final Graphics g) {
    super.paint(g);
    if (!EventQueue.isDispatchThread()) {
        throw new RuntimeException("Wrong thread");
    }
    test();
}
 
Example 9
Source File: BreakpointsEngineListener.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void breakpointAdded (final Breakpoint breakpoint) {
    final boolean[] started = new boolean[] { false };
    if (!EventQueue.isDispatchThread() && debugger.accessLock.readLock().tryLock()) { // Was already locked or can be easily acquired
        try {
            createBreakpointImpl (breakpoint);
        } finally {
            debugger.accessLock.readLock().unlock();
        }
        return ;
    } // Otherwise:
    debugger.getRequestProcessor().post(new Runnable() {
        @Override
        public void run() {
            debugger.accessLock.readLock().lock();
            try {
                synchronized (started) {
                    started[0] = true;
                    started.notify();
                }
                createBreakpointImpl (breakpoint);
            } finally {
                debugger.accessLock.readLock().unlock();
            }
        }
    });
    if (!EventQueue.isDispatchThread()) { // AWT should not wait for debugger.LOCK
        synchronized (started) {
            if (!started[0]) {
                try {
                    started.wait();
                } catch (InterruptedException iex) {}
            }
        }
    }
}
 
Example 10
Source File: RepositoryInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private NBGitConfig getNetbeansConfig (File root) {
    if (root == null) {
        return null;
    }
    if (nbConfig == null) {
        nbConfig = new NBGitConfig(root);
    }
    if (!EventQueue.isDispatchThread()) {
        nbConfig.refresh();
    }
    return nbConfig;
}
 
Example 11
Source File: DiffResultsView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void showDiffError (final String s) {
    Runnable inAWT = new Runnable() {
        @Override
        public void run() {
            setBottomComponent(new NoContentPanel(s));
        }
    };
    if (EventQueue.isDispatchThread()) {
        inAWT.run();
    } else {
        EventQueue.invokeLater(inAWT);
    }
}
 
Example 12
Source File: SwingToolkit.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
static TimerTask newDebugTask () {
	return new TimerTask() {
		public void run () {
			if (!EventQueue.isDispatchThread()) {
				EventQueue.invokeLater(this);
				return;
			}
			for (TableLayout layout : debugLayouts)
				layout.drawDebug();
			timer.schedule(newDebugTask(), 250);
		}
	};
}
 
Example 13
Source File: SearchHistoryPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void showDiff(final RepositoryRevision.Event revision) {
    Runnable r = new Runnable() {
        @Override
        public void run() {
            tbDiff.setSelected(true);
            refreshComponents(true);
            diffView.select(revision);
        }
    };
    if(EventQueue.isDispatchThread()) {
        r.run();
    } else {
        EventQueue.invokeLater(r);
    }
}
 
Example 14
Source File: CloneDocumentAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public CloneDocumentAction() {
    putValue(NAME, NbBundle.getMessage(CloneDocumentAction.class, "CTL_CloneDocumentAction"));
    TopComponent.getRegistry().addPropertyChangeListener(
        WeakListeners.propertyChange(this, TopComponent.getRegistry()));
    // #126355 - may be called outside dispatch thread
    if (EventQueue.isDispatchThread()) {
        updateEnabled();
    } else {
        SwingUtilities.invokeLater(this);
    }
}
 
Example 15
Source File: SvnModuleConfig.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public List<RepositoryConnection> getRecentUrls() {
    Preferences prefs = getPreferences();
    List<String> urls = Utils.getStringList(prefs, KEY_RECENT_URL);
    List<RepositoryConnection> ret = new ArrayList<RepositoryConnection>(urls.size());
    List<RepositoryConnection> withPassword = new LinkedList<RepositoryConnection>();
    for (String urlString : urls) {
        RepositoryConnection rc = RepositoryConnection.parse(urlString);
        if (rc.getPassword() != null || rc.getCertPassword() != null) {
            withPassword.add(rc);
        } else {
            if(getUrlCredentials().containsKey(rc.getUrl())) {
                Object[] creds = getUrlCredentials().get(rc.getUrl());
                if(creds.length < 3) continue; //skip garbage
                rc = new RepositoryConnection(rc.getUrl(), (String)creds[0], (char[])creds[1], rc.getExternalCommand(), rc.getSavePassword(), rc.getCertFile(), (char[])creds[2], rc.getSshPortNumber());
            } else if (!EventQueue.isDispatchThread()) {
                char[] password = rc.getSavePassword() ? KeyringSupport.read(KEY_PASSWORD, rc.getUrl().toString()) : null;
                char[] certPassword = rc.getCertFile().isEmpty() ? null : KeyringSupport.read(KEY_CERT_PASSWORD, rc.getUrl().toString());
                rc = new RepositoryConnection(rc.getUrl(), rc.getUsername(), password, rc.getExternalCommand(), rc.getSavePassword(), rc.getCertFile(), certPassword, rc.getSshPortNumber());
            }
            ret.add(rc);
        }
    }
    // there's an old-style connection with password set
    // rewrite these connections with the new version with no password included
    if (withPassword.size() > 0) {
        for (RepositoryConnection conn : withPassword) {
            insertRecentUrl(conn);
        }
        return getRecentUrls();
    }
    return ret;
}
 
Example 16
Source File: InputContext.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see java.awt.im.InputContext#removeNotify
 * @exception NullPointerException when the component is null.
 */
public synchronized void removeNotify(Component component) {
    if (component == null) {
        throw new NullPointerException();
    }

    if (inputMethod == null) {
        if (component == currentClientComponent) {
            currentClientComponent = null;
        }
        return;
    }

    // We may or may not get a FOCUS_LOST event for this component,
    // so do the deactivation stuff here too.
    if (component == awtFocussedComponent) {
        focusLost(component, false);
    }

    if (component == currentClientComponent) {
        if (isInputMethodActive) {
            // component wasn't the one that had the focus
            deactivateInputMethod(false);
        }
        inputMethod.removeNotify();
        if (clientWindowNotificationEnabled && addedClientWindowListeners()) {
            removeClientWindowListeners();
        }
        currentClientComponent = null;
        if (inputMethod instanceof InputMethodAdapter) {
            ((InputMethodAdapter) inputMethod).setClientComponent(null);
        }

        // removeNotify() can be issued from a thread other than the event dispatch
        // thread.  In that case, avoid possible deadlock between Component.AWTTreeLock
        // and InputMethodContext.compositionAreaHandlerLock by releasing the composition
        // area on the event dispatch thread.
        if (EventQueue.isDispatchThread()) {
            ((InputMethodContext)this).releaseCompositionArea();
        } else {
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    ((InputMethodContext)InputContext.this).releaseCompositionArea();
                }
            });
        }
    }
}
 
Example 17
Source File: CThreading.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
static boolean isEventQueue() {
    return EventQueue.isDispatchThread();
}
 
Example 18
Source File: RenameAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected void performAction(final Node[] activatedNodes) {
    if (activatedNodes == null || activatedNodes.length == 0) {
        return;
    }
    Node n = activatedNodes[0]; // we supposed that one node is activated
    
    // for slow FS perform rename out of EDT
    if (EventQueue.isDispatchThread() && Boolean.TRUE.equals(n.getValue("slowRename"))) { // NOI18N
        RP.post(new Runnable() {
            @Override
            public void run() {
                performAction(activatedNodes);
            }
        });
        return;
    }

    NotifyDescriptor.InputLine dlg = new NotifyDescriptor.InputLine(
            NbBundle.getMessage(RenameAction.class, "CTL_RenameLabel"),
            NbBundle.getMessage(RenameAction.class, "CTL_RenameTitle")
        );
    dlg.setInputText(n.getName());

    if (NotifyDescriptor.OK_OPTION.equals(DialogDisplayer.getDefault().notify(dlg))) {
        String newname = null;

        try {
            newname = dlg.getInputText();

            if (!newname.equals("")) {
                n.setName(dlg.getInputText()); // NOI18N
            }
        } catch (IllegalArgumentException e) {
            // determine if "printStackTrace"  and  "new annotation" of this exception is needed
            boolean needToAnnotate = Exceptions.findLocalizedMessage(e) == null;

            // annotate new localized message only if there is no localized message yet
            if (needToAnnotate) {
                Exceptions.attachLocalizedMessage(e,
                                                  NbBundle.getMessage(RenameAction.class,
                                                                      "MSG_BadFormat",
                                                                      n.getName(),
                                                                      newname));
            }

            Exceptions.printStackTrace(e);
        }
    }
}
 
Example 19
Source File: CThreading.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
static boolean isEventQueue() {
    return EventQueue.isDispatchThread();
}
 
Example 20
Source File: CThreading.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
static boolean isEventQueue() {
    return EventQueue.isDispatchThread();
}