List of usage examples for java.awt EventQueue invokeAndWait
public static void invokeAndWait(Runnable runnable) throws InterruptedException, InvocationTargetException
From source file:Filter3dTest.java
/** * Enters full screen mode and changes the display mode. If the specified * display mode is null or not compatible with this device, or if the * display mode cannot be changed on this system, the current display mode * is used./*w w w. j av a 2s.c om*/ * <p> * The display uses a BufferStrategy with 2 buffers. */ public void setFullScreen(DisplayMode displayMode) { final JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setUndecorated(true); frame.setIgnoreRepaint(true); frame.setResizable(false); device.setFullScreenWindow(frame); if (displayMode != null && device.isDisplayChangeSupported()) { try { device.setDisplayMode(displayMode); } catch (IllegalArgumentException ex) { } // fix for mac os x frame.setSize(displayMode.getWidth(), displayMode.getHeight()); } // avoid potential deadlock in 1.4.1_02 try { EventQueue.invokeAndWait(new Runnable() { public void run() { frame.createBufferStrategy(2); } }); } catch (InterruptedException ex) { // ignore } catch (InvocationTargetException ex) { // ignore } }
From source file:org.parosproxy.paros.extension.ExtensionLoader.java
/** * Init all extensions with the same View * @param view the View that need to be applied *///from w ww .j a va 2s . c om private void initViewAllExtension(final View view, double progressFactor) { if (view == null) { return; } final double factorPerc = progressFactor / getExtensionCount(); for (int i = 0; i < getExtensionCount(); i++) { final Extension extension = getExtension(i); try { EventQueue.invokeAndWait(new Runnable() { @Override public void run() { extension.initView(view); view.addSplashScreenLoadingCompletion(factorPerc); } }); } catch (Exception e) { logExtensionInitError(extension, e); } } }
From source file:org.zaproxy.zap.extension.autoupdate.ExtensionAutoUpdate.java
boolean uninstallAddOnsWithView(final Window caller, final Set<AddOn> addOns, final boolean updates, final Set<AddOn> failedUninstallations) { if (addOns == null || addOns.isEmpty()) { return true; }/*w w w .j av a2 s . c o m*/ if (!EventQueue.isDispatchThread()) { try { EventQueue.invokeAndWait(new Runnable() { @Override public void run() { uninstallAddOnsWithView(caller, addOns, updates, failedUninstallations); } }); } catch (InvocationTargetException | InterruptedException e) { logger.error("Failed to uninstall add-ons:", e); return false; } return failedUninstallations.isEmpty(); } final Window parent = getWindowParent(caller); final UninstallationProgressDialogue waitDialogue = new UninstallationProgressDialogue(parent, addOns); waitDialogue.addAddOnUninstallListener(new AddOnUninstallListener() { @Override public void uninstallingAddOn(AddOn addOn, boolean updating) { if (updating) { String message = MessageFormat.format( Constant.messages.getString("cfu.output.replacing") + "\n", addOn.getName(), Integer.valueOf(addOn.getFileVersion())); getView().getOutputPanel().append(message); } } @Override public void addOnUninstalled(AddOn addOn, boolean update, boolean uninstalled) { if (uninstalled) { if (!update && addonsDialog != null) { addonsDialog.notifyAddOnUninstalled(addOn); } String message = MessageFormat.format( Constant.messages.getString("cfu.output.uninstalled") + "\n", addOn.getName(), Integer.valueOf(addOn.getFileVersion())); getView().getOutputPanel().append(message); } else { if (addonsDialog != null) { addonsDialog.notifyAddOnFailedUninstallation(addOn); } String message; if (update) { message = MessageFormat.format( Constant.messages.getString("cfu.output.replace.failed") + "\n", addOn.getName(), Integer.valueOf(addOn.getFileVersion())); } else { message = MessageFormat.format( Constant.messages.getString("cfu.output.uninstall.failed") + "\n", addOn.getName(), Integer.valueOf(addOn.getFileVersion())); } getView().getOutputPanel().append(message); } } }); SwingWorker<Void, UninstallationProgressEvent> a = new SwingWorker<Void, UninstallationProgressEvent>() { @Override protected void process(List<UninstallationProgressEvent> events) { waitDialogue.update(events); } @Override protected Void doInBackground() { UninstallationProgressHandler progressHandler = new UninstallationProgressHandler() { @Override protected void publishEvent(UninstallationProgressEvent event) { publish(event); } }; for (AddOn addOn : addOns) { if (!uninstall(addOn, updates, progressHandler)) { failedUninstallations.add(addOn); } } if (!failedUninstallations.isEmpty()) { logger.warn("Not all add-ons were successfully uninstalled: " + failedUninstallations); } return null; } }; waitDialogue.bind(a); a.execute(); waitDialogue.setSynchronous(updates); waitDialogue.setVisible(true); return failedUninstallations.isEmpty(); }