public void execute(ChartDrawingParameters params) throws IOException { try { SwingUtilities.invokeAndWait(() -> { try { drawAndSaveToStream(params); } catch (IOException e) { this.ioException = e; } }); } catch (InterruptedException | InvocationTargetException e) { // may look a bit strange, but allows to defer exception handling to a place, where it makes sense. ioException = new IOException(e); } if (ioException != null) { throw ioException; } } }
@Override public void execute(Runnable command) { if (SwingUtilities.isEventDispatchThread()) { command.run(); return; } try { SwingUtilities.invokeAndWait(command); } catch (InterruptedException e) { throw new IllegalStateException(e); } catch (InvocationTargetException e) { throw new IllegalStateException(e); } } }
public void create(boolean waitFor){ if (SwingUtilities.isEventDispatchThread()) { initInEDT(); } else { try { if (waitFor) { try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { initInEDT(); } }); } catch (InterruptedException ex) { listener.handleError("Interrupted", ex); } } else { SwingUtilities.invokeLater(new Runnable() { public void run() { initInEDT(); } }); } } catch (InvocationTargetException ex) { throw new AssertionError(); // can never happen } } }
private void lookupPlayer(String playerName) { executor.execute(() -> { try { SwingUtilities.invokeAndWait(() -> { if (!navButton.isSelected()) { navButton.getOnSelect().run(); } }); } catch (InterruptedException | InvocationTargetException e) { throw new RuntimeException(e); } hiscorePanel.lookup(playerName); }); } }
} else { try { SwingUtilities.invokeAndWait(runnable); } catch (InterruptedException e) { LOG.log(Level.WARNING, "Error notifying propertyChangeListener", e);
SwingUtilities.invokeAndWait(guiStarter);
public void visualize() { try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() {
SwingUtilities.invokeAndWait(() ->
SwingUtilities.invokeAndWait(() ->
SwingUtilities.invokeAndWait(() -> clientUi.paint(graphics));
public static void invokeAndWait(Runnable runnable) { try { SwingUtilities.invokeAndWait(runnable); } catch (Exception ex) { throw new RuntimeException("Error invoking runnable in UI thread.", ex); } }
private void doAppendOnEDT(final TextDialog dialog, final String text, final int indent) { try { SwingUtilities.invokeAndWait( new Runnable() { @Override public void run() { dialog.append(text, indent); } }); } catch (InterruptedException ex) { LOGGER.severe("Interrupted while appending text"); } catch (InvocationTargetException ex) { LOGGER.log(Level.SEVERE, "Unable to append text", ex); } }
SwingUtilities.invokeAndWait(() ->
public static void showIt(final BufferedImage pImage, final String pTitle) { try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { JFrame frame = new JFrame(pTitle); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationByPlatform(true); JPanel pane = new JPanel(new BorderLayout()); GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); BufferedImageIcon icon = new BufferedImageIcon(ImageUtil.accelerate(pImage, gc)); JScrollPane scroll = new JScrollPane(new JLabel(icon)); scroll.setBorder(null); pane.add(scroll); frame.setContentPane(pane); frame.pack(); frame.setVisible(true); } }); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (InvocationTargetException e) { throw new RuntimeException(e); } }
/** Display the chart in a Swing JFrame */ public JFrame displayChart() { // Create and set up the window. final JFrame frame = new JFrame(windowTitle); // Schedule a job for the event-dispatching thread: // creating and showing this application's GUI. try { javax.swing.SwingUtilities.invokeAndWait( new Runnable() { @Override public void run() { frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); XChartPanel<T> chartPanel = new XChartPanel<T>(charts.get(0)); chartPanels.add(chartPanel); frame.add(chartPanel); // Display the window. frame.pack(); frame.setVisible(true); } }); } catch (InterruptedException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } return frame; }
/** * Add the error reporting mecanism on top of the JVM in order to * intercept and process the error to Github. */ public static void setUncaughtExceptionHandler() { // Regular Exception Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler()); // Event dispatching thread Exception try { SwingUtilities.invokeAndWait(() -> // We are in the event dispatching thread Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler()) ); } catch (InvocationTargetException | InterruptedException e) { LOGGER.error("Unhandled Exception on ExceptionUtil", e); } }
/** * Prompts for file name to save an image. * * @param parent parent component (may be {@code null}) * @param workingDir the initial directory * @return the selected file or {@code null} if the dialog was cancelled */ public static File showSaveFile(final Component parent, final File workingDir) { final File[] file = new File[1]; if (SwingUtilities.isEventDispatchThread()) { file[0] = doShow(parent, workingDir, SAVE_DIALOG); } else { try { SwingUtilities.invokeAndWait( new Runnable() { @Override public void run() { file[0] = doShow(parent, workingDir, SAVE_DIALOG); } }); } catch (InterruptedException ex) { LOGGER.log(Level.SEVERE, "Thread interrupted while prompting for file", ex); } catch (InvocationTargetException ex) { LOGGER.log(Level.SEVERE, "Unexpected problem while prompting for file", ex); } } return file[0]; }
/** * Prompts for file name to read an image. * * @param parent parent component (may be {@code null}) * @param workingDir the initial directory * @return the selected file or {@code null} if the dialog was cancelled */ public static File showOpenFile(final Component parent, final File workingDir) { final File[] file = new File[1]; if (SwingUtilities.isEventDispatchThread()) { file[0] = doShow(parent, workingDir, OPEN_DIALOG); } else { try { SwingUtilities.invokeAndWait( new Runnable() { @Override public void run() { file[0] = doShow(parent, workingDir, OPEN_DIALOG); } }); } catch (InterruptedException ex) { LOGGER.log(Level.SEVERE, "Thread interrupted while prompting for file", ex); } catch (InvocationTargetException ex) { LOGGER.log(Level.SEVERE, "Unexpected problem while prompting for file", ex); } } return file[0]; }
@Override public void run(final RunNotifier runNotifier) { try { SwingUtilities.invokeAndWait(() -> SwingRunner.super.run(runNotifier)); } catch (InterruptedException | InvocationTargetException e) { e.printStackTrace(); } }
@Override public void setVisible(boolean value) { super.setVisible(value); if (value) { this.toFront(); } if (modal) { this.setClosable(false); if (value) { startModal(); } else if (SwingUtilities.isEventDispatchThread()) { stopModal(); } else { try { SwingUtilities.invokeAndWait(() -> stopModal()); } catch (InterruptedException ex) { LOGGER.fatal("MageDialog error", ex); } catch (InvocationTargetException ex) { LOGGER.fatal("MageDialog error", ex); } } } }