/** Runs the runnable in event queue, either immediatelly, * or it posts it into the queue. */ private static void doEvent(Runnable run) { if (EventQueue.isDispatchThread()) { run.run(); } else { EventQueue.invokeLater(run); } }
/** @return true iff current thread is EventDispatchThread */ static boolean isDispatchThread() { boolean dispatch = EventQueue.isDispatchThread(); if (!dispatch && (Utilities.getOperatingSystem() == Utilities.OS_SOLARIS)) { // on solaris the event queue is not always recognized correctly // => try to guess by name dispatch = (Thread.currentThread().getClass().getName().indexOf("EventDispatchThread") >= 0); // NOI18N } return dispatch; }
@Override public KeyStroke readInput() { if(EventQueue.isDispatchThread()) { throw new UnsupportedOperationException("Cannot call SwingTerminal.readInput() on the AWT thread"); } return super.readInput(); } }
@Override protected void repaint() { if(EventQueue.isDispatchThread()) { component.repaint(); } else { EventQueue.invokeLater(new Runnable() { @Override public void run() { component.repaint(); } }); } }
private static void doPerformAction(Action action, final ActionInvoker.ActionRunnable r) { assert java.awt.EventQueue.isDispatchThread() : "Action " + action.getClass().getName() + " may not be invoked from the thread " + Thread.currentThread().getName() + ", only the event queue: http://www.netbeans.org/download/4_1/javadoc/OpenAPIs/apichanges.html#actions-event-thread"; if (r.async && !r.needsToBeSynchronous()) { Runnable r2 = new Runnable() { public void run() { r.doRun(); } }; RP.post(r2); } else { r.run(); } }
/** current thread will sleep until wakeMeUp is called * if wakeMeUp was already called then the thread will not sleep */ public synchronized void sleep() { boolean wasInterrupted = false; try { while (!signal) { try { long start = System.currentTimeMillis(); wait(); if (LOG.isLoggable(Level.FINE) && EventQueue.isDispatchThread() && (System.currentTimeMillis() - start) > 1000) { LOG.log(Level.WARNING, toString(), new IllegalStateException("blocking on a mutex from EQ")); } return; } catch (InterruptedException e) { wasInterrupted = true; LOG.log(Level.FINE, null, e); } } } finally { left = true; if (wasInterrupted) { // #129003 Thread.currentThread().interrupt(); } } }
public @Override InputSource resolveEntity(String publicID, String systemID) throws IOException, SAXException { if (result == null) { result = Lookup.getDefault().lookupResult(EntityCatalog.class); } for (EntityCatalog res : result.allInstances()) { // using resolver's method because EntityCatalog extends EntityResolver InputSource is = res.resolveEntity(publicID, systemID); if (is != null) { return is; } } if (systemID != null && systemID.startsWith("http")) { // NOI18N Logger.getLogger(EntityCatalog.class.getName()).log( /* More of a problem when blocking EQ; cf. #157850: */ EventQueue.isDispatchThread() ? Level.WARNING : Level.FINE, "No resolver found for {0}", systemID); } return null; } }
public void render(GCModel model, FileOutputStream outputStream) throws IOException { GCPreferences gcPreferences = new GCPreferences(); gcPreferences.load(); Dimension d = new Dimension(gcPreferences.getWindowWidth(), gcPreferences.getWindowHeight()); BufferedImage image = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = image.createGraphics(); graphics.setBackground(Color.WHITE); graphics.clearRect(0, 0, image.getWidth(), image.getHeight()); ChartDrawingParameters params = new ChartDrawingParameters(model, gcPreferences, d, graphics, image, outputStream); if (EventQueue.isDispatchThread()) { drawAndSaveToStream(params); } else { new SwingChartToStreamHelper().execute(params); } }
@Override public void updateModel(final int totalSize, final int screenHeight) { if(!EventQueue.isDispatchThread()) { EventQueue.invokeLater(new Runnable() { @Override
/** Called when model changes. Regenerates the model. */ public void stateChanged(ChangeEvent ev) { //assert EventQueue.isDispatchThread(); if (!EventQueue.isDispatchThread()) { new IllegalStateException("This must happen in the event thread!").printStackTrace(); } // change in keys or in submenu model // checkVisibility(); }
private static void doEvent(Runnable run) { if (EventQueue.isDispatchThread()) { run.run(); } else { EventQueue.invokeLater(run); } }
public static void invokeAndWait (Runnable runnable) { if (EventQueue.isDispatchThread()) { runnable.run(); return; } try { EventQueue.invokeAndWait(runnable); } catch (InterruptedException ex) { } catch (InvocationTargetException ex) { throw new RuntimeException(ex); } }
public boolean isEnabled() { assert EventQueue.isDispatchThread(); boolean r = global.isEnabled(type, selectMode, performer); previousEnabled = r; return r; }
public Object getValue(String key) { if ("enabler".equals(key)) { // NOI18N // special API to support re-enablement assert EventQueue.isDispatchThread(); updateState(); } return null; }
/** @return true iff current thread is EventDispatchThread */ private static boolean isDispatchThread() { boolean dispatch = EventQueue.isDispatchThread(); if (!dispatch && (BaseUtilities.getOperatingSystem() == BaseUtilities.OS_SOLARIS)) { // on solaris the event queue is not always recognized correctly // => try to guess by name dispatch = (Thread.currentThread().getClass().getName().indexOf("EventDispatchThread") >= 0); // NOI18N } return dispatch; }
/** Listener to changes of some properties. * Multicast - reacts to keymap changes and ancestor changes * together. */ public void propertyChange(final PropertyChangeEvent ev) { //assert EventQueue.isDispatchThread(); if (!EventQueue.isDispatchThread()) { new IllegalStateException("This must happen in the event thread!").printStackTrace(); } updateState(ev.getPropertyName()); }
private static void doPerformAction(Action action, final ActionInvoker.ActionRunnable r) { assert java.awt.EventQueue.isDispatchThread() : "Action " + action.getClass().getName() + " may not be invoked from the thread " + Thread.currentThread().getName() + ", only the event queue: http://www.netbeans.org/download/4_1/javadoc/OpenAPIs/apichanges.html#actions-event-thread"; if (r.async && !r.needsToBeSynchronous()) { Runnable r2 = new Runnable() { public void run() { r.doRun(); } }; RP.post(r2); } else { r.run(); } }
/** Invoked when an action occurs. */ public void actionPerformed(final java.awt.event.ActionEvent e) { assert EventQueue.isDispatchThread(); final javax.swing.Action a = findAction(); if (a != null) { ActionInvoker.invokeAction(a, e, async, null); } }
public boolean isEnabled() { assert EventQueue.isDispatchThread(); javax.swing.Action a = findAction(); return a == null ? false : a.isEnabled(); }
public void actionPerformed(final ActionEvent e) { assert EventQueue.isDispatchThread(); if (getDelegate() instanceof Action) { if (!((Action)getDelegate()).isEnabled()) { Toolkit.getDefaultToolkit().beep(); // Do not fire newValue == null (see #165838) firePropertyChange("enabled", null, isEnabled()); // NOI18N return; } } boolean async = Boolean.TRUE.equals(map.get("asynchronous")); // NOI18N Runnable ar = new Runnable() { public void run() { getDelegate().actionPerformed(e); } }; ActionInvoker.invokeAction(this, e, async, ar); }