List of usage examples for javax.swing SwingUtilities isEventDispatchThread
public static boolean isEventDispatchThread()
From source file:eu.lp0.cursus.ui.AboutDialog.java
public void display() { assert (SwingUtilities.isEventDispatchThread()); prefs.display(getOwner()); }
From source file:com.raphfrk.craftproxyclient.gui.GUIManager.java
public static JSONObject getNewLoginDetails() { final AtomicReference<LoginDialog> login = new AtomicReference<LoginDialog>(); Runnable r = (new Runnable() { public void run() { login.set(new LoginDialog(CraftProxyClient.getGUI())); login.get().setVisible(true); login.get().dispose();/*from w ww .j a v a 2 s.c om*/ } }); if (SwingUtilities.isEventDispatchThread()) { r.run(); } else { try { SwingUtilities.invokeAndWait(r); } catch (InvocationTargetException | InterruptedException e) { return null; } } return AuthManager.authAccessToken(login.get().getEmail(), login.get().getPassword()); }
From source file:eu.delving.sip.base.VisualFeedback.java
@Override public void alert(final String message) { if (SwingUtilities.isEventDispatchThread()) { inYourFace(message, null);/*from w w w . jav a2s . co m*/ } else { execWait(new Runnable() { @Override public void run() { inYourFace(message, null); } }); } }
From source file:CheckThreadViolationRepaintManager.java
private void checkThreadViolations(JComponent c) { if (!SwingUtilities.isEventDispatchThread() && (completeCheck || c.isShowing())) { boolean repaint = false; boolean fromSwing = false; boolean imageUpdate = false; StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); for (StackTraceElement st : stackTrace) { if (repaint && st.getClassName().startsWith("javax.swing.")) { fromSwing = true;// w ww. j ava2s . c om } if (repaint && "imageUpdate".equals(st.getMethodName())) { imageUpdate = true; } if ("repaint".equals(st.getMethodName())) { repaint = true; fromSwing = false; } } if (imageUpdate) { // assuming it is java.awt.image.ImageObserver.imageUpdate(...) // image was asynchronously updated, that's ok return; } if (repaint && !fromSwing) { // no problems here, since repaint() is thread safe return; } // ignore the last processed component if (lastComponent != null && c == lastComponent.get()) { return; } lastComponent = new WeakReference<JComponent>(c); violationFound(c, stackTrace); } }
From source file:SwingThreading.java
private void incrementLabel() { tickCounter++;//from w w w . j a v a 2 s . co m Runnable code = new Runnable() { public void run() { counter.setText(String.valueOf(tickCounter)); } }; if (SwingUtilities.isEventDispatchThread()) { code.run(); } else { SwingUtilities.invokeLater(code); } }
From source file:eu.delving.sip.base.VisualFeedback.java
@Override public void alert(final String message, final Throwable throwable) { if (SwingUtilities.isEventDispatchThread()) { inYourFace(message, throwable);//from ww w . ja v a 2 s. co m } else { execWait(new Runnable() { @Override public void run() { inYourFace(message, throwable); } }); } }
From source file:Main.java
/** * Runs arbitrary code in the Event Dispatch Thread. * //from www .java 2s . c o m * @param runnable the {@code Runnable} to run in the Event Dispatch Thread */ public static void runInEDT(final Runnable runnable) { if (runnable != null) { if (SwingUtilities.isEventDispatchThread()) { runnable.run(); } else { invokeAndWait(runnable); } } }
From source file:org.mn.z80util.testbench.MZ80TestBench.java
private void createAndShowGUI() { // See above/*from w w w . j av a 2s .c om*/ if (!SwingUtilities.isEventDispatchThread()) { System.err.println("Attempting to construct the GUI from outside " + "of event dispatch thread! This is an error. Please check " + "your code modifications."); System.exit(1); } /* Initializes the GUI frame */ GUI = new JFrame("Mikko's Z80 Testbench - (C) Mikko Nummelin, 2009"); GUI.setLayout(new BorderLayout()); GUI.setIconImage(LogoFactory.createLogo()); GUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); leftPanel = new JPanel(); leftPanel.setLayout(new GridLayout(3, 1)); // The first processor information firstProcessorPanel = new JPanel(); firstProcessorPanel.setLayout(new GridLayout(2, 1)); firstProcessorPanel.setBorder(BorderFactory.createTitledBorder("Processor 1")); firstProcessorPanel.add(new JLabel(processor1.getClass().getName())); firstProcessorStatus = new JLabel("-"); firstProcessorPanel.add(firstProcessorStatus); leftPanel.add(firstProcessorPanel); // The second processor information secondProcessorPanel = new JPanel(); secondProcessorPanel.setLayout(new GridLayout(2, 1)); secondProcessorPanel.setBorder(BorderFactory.createTitledBorder("Processor 2")); secondProcessorPanel.add(new JLabel(processor2.getClass().getName())); secondProcessorStatus = new JLabel("-"); secondProcessorPanel.add(secondProcessorStatus); leftPanel.add(secondProcessorPanel); // The progress bar panel progressBarPanel = new JPanel(); progressBarPanel.setLayout(new GridLayout(3, 1)); progressBarPanel.setBorder(BorderFactory.createTitledBorder("Progress")); progressBar = new JProgressBar(0, 0x6bf); progressBarPanel.add(progressBar); statusMessage = new JLabel("-"); progressBarPanel.add(statusMessage); executedCommand = new JLabel("-"); progressBarPanel.add(executedCommand); leftPanel.add(progressBarPanel); GUI.add(leftPanel, BorderLayout.WEST); // The action button panel actionPanel = new JPanel(); okCancelButton = new JButton("Cancel"); okCancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); actionPanel.add(okCancelButton); GUI.add(actionPanel, BorderLayout.SOUTH); // The image panel imagePanel = new JPanel(); java.net.URL imgURL = getClass().getResource("/Z80-pinout.png"); img = new ImageIcon(imgURL); imagePanel.add(new JLabel(img)); GUI.add(imagePanel, BorderLayout.EAST); GUI.pack(); GUI.setResizable(false); GUI.setVisible(true); }
From source file:org.jtheque.ui.impl.UIUtilsImpl.java
@Override public boolean askUserForConfirmation(final String text, final String title) { boolean yes = false; Window parent = null;/*from w ww.ja v a2 s .c om*/ if (SimplePropertiesCache.get(MAIN_VIEW_CACHE, Window.class) != null) { parent = SimplePropertiesCache.get(MAIN_VIEW_CACHE, Window.class); } final Window p = parent; final int[] response = new int[1]; if (SwingUtilities.isEventDispatchThread()) { response[0] = JOptionPane.showConfirmDialog(parent, text, title, JOptionPane.YES_NO_OPTION); } else { try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { response[0] = JOptionPane.showConfirmDialog(p, text, title, JOptionPane.YES_NO_OPTION); } }); } catch (InterruptedException e) { LoggerFactory.getLogger(getClass()).error(e.getMessage(), e); } catch (InvocationTargetException e) { LoggerFactory.getLogger(getClass()).error(e.getMessage(), e); } } if (response[0] == JOptionPane.YES_OPTION) { yes = true; } return yes; }
From source file:WorkThreadPool.java
/** * Adds a work request to the queue.// www .ja v a 2 s . co m * * @param run * The runnable * @param inAWT * If true, will be executed in AWT thread. Otherwise, will be * executed in work thread */ public void addWorkRequest(Runnable run, boolean inAWT) { if (threads == null) { run.run(); return; } synchronized (lock) { // {{{ if there are no requests, execute AWT requests immediately if (started && inAWT && requestCount == 0 && awtRequestCount == 0) { // Log.log(Log.DEBUG,this,"AWT immediate: " + run); if (SwingUtilities.isEventDispatchThread()) run.run(); else SwingUtilities.invokeLater(run); return; } // }}} Request request = new Request(run); // {{{ Add to AWT queue... if (inAWT) { if (firstAWTRequest == null && lastAWTRequest == null) firstAWTRequest = lastAWTRequest = request; else { lastAWTRequest.next = request; lastAWTRequest = request; } awtRequestCount++; // if no requests are running, requestDone() // will not be called, so we must queue the // AWT runner ourselves. if (started && requestCount == 0) queueAWTRunner(); } // }}} // {{{ Add to work thread queue... else { if (firstRequest == null && lastRequest == null) firstRequest = lastRequest = request; else { lastRequest.next = request; lastRequest = request; } requestCount++; } // }}} lock.notifyAll(); } }