List of usage examples for javax.swing SwingUtilities invokeAndWait
public static void invokeAndWait(final Runnable doRun) throws InterruptedException, InvocationTargetException
doRun.run()
to be executed synchronously on the AWT event dispatching thread. From source file:net.pandoragames.far.ui.swing.component.listener.OperationCallBackListener.java
/** * {@inheritDoc}/*from w w w . j a va2 s .c om*/ */ public void operationStarted(OperationType type) { for (ComponentContainer comp : startComponents) { if ((comp.type == type) || (comp.type == OperationType.ANY)) { try { SwingUtilities.invokeAndWait(new EnDisableComponent(comp.component, comp.endisFlag)); } catch (Exception itx) { logger.error(itx.getClass().getName() + " notifying " + comp.component.getName() + " (" + comp.component.getClass().getName() + "): " + itx.getMessage(), itx); } } } }
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 ww w . j ava 2s . c o m } }); 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:net.landora.video.utils.UIUtils.java
public static void invokeInSwingThread(Runnable r) { if (EventQueue.isDispatchThread()) { r.run();//from w w w.j a va 2 s . co m } else { try { SwingUtilities.invokeAndWait(r); } catch (Exception ex) { throw new RuntimeException(ex); } } }
From source file:au.com.jwatmuff.eventmanager.util.GUIUtils.java
/** * Makes a frame visible and blocks the caller until the frame is closed. * // w w w.j ava2 s. c om * @param frame */ public static void runModalJFrame(final JFrame frame) { // there may be a much better way of implementing this, i don't know.. class RunningFlag { boolean value = true; } final RunningFlag flag = new RunningFlag(); final Thread t = Thread.currentThread(); try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { frame.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent arg0) { synchronized (t) { flag.value = false; t.notifyAll(); } } }); frame.setVisible(true); } }); synchronized (t) { while (flag.value == true) try { t.wait(); } catch (InterruptedException e) { } } } catch (InterruptedException e) { log.error(e); } catch (InvocationTargetException e2) { log.error(e2); } }
From source file:com.mirth.connect.client.ui.StatusBar.java
public void setServerTime(Calendar serverTime) { timeOffset = serverTime.getTimeInMillis() - Calendar.getInstance().getTimeInMillis(); serverTimeZone = serverTime.getTimeZone().getID(); localTimeZone = Calendar.getInstance().getTimeZone().getID(); new Thread() { @Override// w w w. j av a2s . c o m public void run() { while (!Thread.currentThread().isInterrupted()) { try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { timezoneLabel.setText(convertLocalToServerTime() + " " + timezoneText); } }); Thread.sleep(30000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (InvocationTargetException e) { } } } }.start(); }
From source file:com.qspin.qtaste.testapi.impl.generic.UtilityImpl.java
@Override public String getUserStringValue(final String message, final Object defaultValue) throws QTasteException { final StringBuilder valueBuilder = new StringBuilder(); try {// w w w . j a va2 s . co m SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { String value = JOptionPane.showInputDialog(message, defaultValue); valueBuilder.append(value); } }); } catch (Exception e) { throw new QTasteException("Error while showing user input dialog", e); } return valueBuilder.toString(); }
From source file:ShowDocument.java
public void destroy() { //Execute a job on the event-dispatching thread: //creating this applet's GUI. try {// www.ja v a 2s .c om SwingUtilities.invokeAndWait(new Runnable() { public void run() { destroyGUI(); } }); } catch (Exception e) { } }
From source file:edu.oregonstate.eecs.mcplan.domains.frogger.FroggerVisualization.java
public FroggerVisualization(final FroggerSimulator sim, final FroggerParameters params, final int scale) { if (sim != null) { this.sim = sim; this.state = sim.state(); }//from ww w .j a v a 2 s.c o m this.scale = scale; try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { final JFrame frame = new JFrame(); final Container cp = frame.getContentPane(); cp.setLayout(new BorderLayout()); draw_panel_ = new DrawPanel(params); final Dimension d = new Dimension(scale * params.road_length + 20, scale * (params.lanes + 2) + 20); draw_panel_.setPreferredSize(d); draw_panel_.setSize(d); cp.add(draw_panel_, BorderLayout.CENTER); control_panel_ = new ControlPanel(); cp.add(control_panel_, BorderLayout.SOUTH); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable(false); frame.pack(); frame.setVisible(true); } }); } catch (final Exception ex) { throw new RuntimeException(ex); } if (sim != null) { updateStateOnEDT(sim.state()); } }
From source file:edu.oregonstate.eecs.mcplan.domains.sailing.SailingVisualization.java
public SailingVisualization(final SailingFsssModel sim, final int scale) { if (sim != null) { this.sim = sim; this.state = sim.initialState(); }/* ww w. j a v a2s .c om*/ this.scale = scale; final SailingTerrain[][] circuit = state.terrain; try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { frame = new JFrame(); final Container cp = frame.getContentPane(); cp.setLayout(new BorderLayout()); draw_panel_ = new DrawPanel(circuit); final Dimension d = new Dimension(scale * circuit[0].length + 20, scale * circuit.length + 20); draw_panel_.setPreferredSize(d); draw_panel_.setSize(d); cp.add(draw_panel_, BorderLayout.CENTER); control_panel_ = new ControlPanel(); cp.add(control_panel_, BorderLayout.SOUTH); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable(false); frame.pack(); frame.setVisible(true); } }); } catch (final Exception ex) { throw new RuntimeException(ex); } if (sim != null) { updateStateOnEDT(state); } }
From source file:edu.oregonstate.eecs.mcplan.domains.racegrid.RacegridVisualization.java
public RacegridVisualization(final RacegridSimulator sim, final TerrainType[][] circuit, final int scale) { if (sim != null) { this.sim = sim; this.state = sim.state(); }//from w w w .j a v a 2 s . c om this.scale = scale; try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { frame = new JFrame(); final Container cp = frame.getContentPane(); cp.setLayout(new BorderLayout()); draw_panel_ = new DrawPanel(circuit); final Dimension d = new Dimension(scale * circuit[0].length + 20, scale * circuit.length + 20); draw_panel_.setPreferredSize(d); draw_panel_.setSize(d); cp.add(draw_panel_, BorderLayout.CENTER); control_panel_ = new ControlPanel(); cp.add(control_panel_, BorderLayout.SOUTH); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable(false); frame.pack(); frame.setVisible(true); } }); } catch (final Exception ex) { throw new RuntimeException(ex); } if (sim != null) { updateStateOnEDT(sim.state()); } }