List of usage examples for javax.swing SwingUtilities isEventDispatchThread
public static boolean isEventDispatchThread()
From source file:net.sf.jabref.gui.JabRefFrame.java
/** * Sets the indeterminate status of the progress bar. * <p>/*ww w . ja v a 2 s . c o m*/ * If not called on the event dispatch thread, this method uses * SwingUtilities.invokeLater() to do the actual operation on the EDT. */ public void setProgressBarIndeterminate(final boolean value) { if (SwingUtilities.isEventDispatchThread()) { progressBar.setIndeterminate(value); } else { SwingUtilities.invokeLater(() -> progressBar.setIndeterminate(value)); } }
From source file:net.sf.jabref.gui.JabRefFrame.java
/** * Sets the maximum value of the progress bar. Always call this method * before using the progress bar, to set a maximum value appropriate to * the task at hand./*from w ww. j av a2s.c om*/ * <p> * If not called on the event dispatch thread, this method uses * SwingUtilities.invokeLater() to do the actual operation on the EDT. */ public void setProgressBarMaximum(final int value) { if (SwingUtilities.isEventDispatchThread()) { progressBar.setMaximum(value); } else { SwingUtilities.invokeLater(() -> progressBar.setMaximum(value)); } }
From source file:de.huxhorn.lilith.swing.MainFrame.java
public void showView(ViewContainer<?> container) { // we need this since this method might also be called by a different thread ShowViewRunnable runnable = new ShowViewRunnable(container); if (SwingUtilities.isEventDispatchThread()) { runnable.run();/* ww w. j a v a 2 s.c o m*/ } else { SwingUtilities.invokeLater(runnable); } }
From source file:com.diversityarrays.kdxplore.curate.TrialDataEditor.java
/** * We want the Samples that were selected in the VisualisationTool. * * @param toolId/* w w w. j ava 2 s .c om*/ * @param toolInstanceId */ private void handleVisToolSelectionChanged(String toolInstanceId) { curationTable.clearSelection(); fieldLayoutView.clearSelection(); toolController.updateSelectedSamplesExceptFor(toolInstanceId); curationTableSelectionModel.updateSampleSelection(); fieldLayoutView.updateSelectedMeasurements( "TrialDataEditor.updateSampleSelectionExceptFor(" + toolInstanceId + ")"); if (SwingUtilities.isEventDispatchThread()) { curationTable.repaint(); } else { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { curationTable.repaint(); } }); } }
From source file:JNLPAppletLauncher.java
private void checkNoDDrawAndUpdateDeploymentProperties() { if (!getBooleanParameter("noddraw.check")) return;//from w w w. j a va2 s . c o m if (System.getProperty("os.name").toLowerCase().startsWith("windows") && !"true".equalsIgnoreCase(System.getProperty("sun.java2d.noddraw"))) { if (!SwingUtilities.isEventDispatchThread()) { try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { updateDeploymentPropertiesImpl(); } }); } catch (Exception e) { } } else { updateDeploymentPropertiesImpl(); } } }
From source file:com.hexidec.ekit.EkitCore.java
/** * Convenience method for setting the document text *///from w ww.j a v a2 s . c om public void setDocumentText(final String sText) { // log.debug("> setDocumentText"); // log.debug("> setDocumentText(\"" + sText + "\")"); if (SwingUtilities.isEventDispatchThread()) { jtpMain.setText(sText); } else { // Evita deadlock try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { jtpMain.setText(sText); } }); } catch (Exception e) { log.error("Falha ao aplicar texto ao editor.", e); } } purgeUndos(); htmlDoc.resetDirty(); // log.debug("< setDocumentText"); }
From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryBldrPane.java
public void selectQFP(final QueryFieldPanel qfp) { if (!SwingUtilities.isEventDispatchThread()) { //apparently this never happens, but... runSelectQFP(qfp);//w w w .j ava 2 s. co m } else { if (selectedQFP != null) { selectedQFP.setSelected(false); selectedQFP.repaint(); } selectedQFP = qfp; if (selectedQFP != null) { selectedQFP.setSelected(true); selectedQFP.repaint(); //scrollQueryFieldsToRect(selectedQFP.getBounds()); } updateMoverBtns(); if (qfp != null) { FieldQRI fqri = qfp.getFieldQRI(); if (fqri != null) { displayField(fqri); } } } }
From source file:org.apache.cayenne.modeler.Application.java
/** * Reinitializes ModelerClassLoader from preferences. *///from w ww . ja va2 s. c o m @SuppressWarnings("unchecked") public void initClassLoader() { final FileClassLoadingService classLoader = new FileClassLoadingService(); // init from preferences... Preferences classLoaderPreference = Application.getInstance().getPreferencesNode(ClasspathPreferences.class, ""); Collection details = new ArrayList<>(); String[] keys = null; ArrayList<String> values = new ArrayList<>(); try { keys = classLoaderPreference.keys(); for (String cpKey : keys) { values.add(classLoaderPreference.get(cpKey, "")); } } catch (BackingStoreException e) { // do nothing } for (int i = 0; i < values.size(); i++) { details.add(values.get(i)); } if (details.size() > 0) { // transform preference to file... Transformer transformer = new Transformer() { public Object transform(Object object) { String pref = (String) object; return new File(pref); } }; classLoader.setPathFiles(CollectionUtils.collect(details, transformer)); } this.modelerClassLoader = classLoader; // set as EventDispatch thread default class loader if (SwingUtilities.isEventDispatchThread()) { Thread.currentThread().setContextClassLoader(classLoader.getClassLoader()); } else { SwingUtilities.invokeLater(new Runnable() { public void run() { Thread.currentThread().setContextClassLoader(classLoader.getClassLoader()); } }); } }
From source file:org.apache.cayenne.modeler.util.LongRunningTask.java
/** * Starts current task, and blocks current thread until the task is done. *//*from w w w .j ava 2 s . com*/ public synchronized T startAndWait() { // running from Event Dispatch Thread is bad, as this will block the timers... if (SwingUtilities.isEventDispatchThread()) { throw new CayenneRuntimeException( "Can't block EventDispatchThread. Call 'startAndWait' from another thread."); } start(); if (finished) { return result; } try { wait(); } catch (InterruptedException e) { setCanceled(true); } notifyAll(); return result; }
From source file:org.apache.jmeter.util.JMeterUtils.java
/** * Run the runnable in AWT Thread if current thread is not AWT thread * otherwise runs call {@link SwingUtilities#invokeAndWait(Runnable)} * @param synchronous flag, whether we will wait for the AWT Thread to finish its job. * @param runnable {@link Runnable}/*from w w w . j av a 2 s. c o m*/ */ public static void runSafe(boolean synchronous, Runnable runnable) { if (SwingUtilities.isEventDispatchThread()) { runnable.run(); } else { if (synchronous) { try { SwingUtilities.invokeAndWait(runnable); } catch (InterruptedException e) { log.warn("Interrupted in thread " + Thread.currentThread().getName(), e); } catch (InvocationTargetException e) { throw new Error(e); } } else { SwingUtilities.invokeLater(runnable); } } }