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:com.skcraft.launcher.bootstrap.Downloader.java
private void execute() throws Exception { SwingUtilities.invokeAndWait(new Runnable() { @Override/*w ww .jav a 2s.c o m*/ public void run() { Bootstrap.setSwingLookAndFeel(); dialog = new DownloadFrame(Downloader.this); dialog.setVisible(true); dialog.setDownloader(Downloader.this); } }); File finalFile = new File(bootstrap.getBinariesDir(), System.currentTimeMillis() + ".jar.pack"); File tempFile = new File(finalFile.getParentFile(), finalFile.getName() + ".tmp"); URL updateUrl = HttpRequest.url(bootstrap.getProperties().getProperty("latestUrl")); log.info("Reading update URL " + updateUrl + "..."); try { String data = HttpRequest.get(updateUrl).execute().expectResponseCode(200).returnContent() .asString("UTF-8"); Object object = JSONValue.parse(data); URL url; if (object instanceof JSONObject) { String rawUrl = String.valueOf(((JSONObject) object).get("url")); if (rawUrl != null) { url = HttpRequest.url(rawUrl.trim()); } else { log.warning("Did not get valid update document - got:\n\n" + data); throw new IOException("Update URL did not return a valid result"); } } else { log.warning("Did not get valid update document - got:\n\n" + data); throw new IOException("Update URL did not return a valid result"); } checkInterrupted(); log.info("Downloading " + url + " to " + tempFile.getAbsolutePath()); httpRequest = HttpRequest.get(url); httpRequest.execute().expectResponseCode(200).saveContent(tempFile); finalFile.delete(); tempFile.renameTo(finalFile); } finally { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { dialog.setDownloader(null); dialog.dispose(); } }); } LauncherBinary binary = new LauncherBinary(finalFile); List<LauncherBinary> binaries = new ArrayList<LauncherBinary>(); binaries.add(binary); bootstrap.launchExisting(binaries, false); }
From source file:com.codecrate.shard.ui.event.commandbus.EventDispatcherThreadActionCommandExecutor.java
public void execute(Map params) { if (!SwingUtilities.isEventDispatchThread()) { LOG.debug("Redirecting execution of " + delegate + " to event dispatch thread"); try {/*from w w w. ja va 2 s . c o m*/ SwingUtilities.invokeAndWait(new Runnable() { public void run() { delegate.execute(); } }); } catch (Exception e) { throw new RuntimeException("Error executing " + delegate + " on event dispatch thread"); } } else { delegate.execute(params); } }
From source file:ch.descabato.browser.BackupBrowser.java
public static void main2(final String[] args) throws InterruptedException, InvocationTargetException, SecurityException, IOException { if (args.length > 1) throw new IllegalArgumentException( "SYNTAX: java... " + BackupBrowser.class.getName() + " [initialPath]"); SwingUtilities.invokeAndWait(new Runnable() { @Override// w w w .j a va2 s .co m public void run() { tryLoadSubstanceLookAndFeel(); final JFrame f = new JFrame("OtrosVfsBrowser demo"); f.addWindowListener(finishedListener); Container contentPane = f.getContentPane(); contentPane.setLayout(new BorderLayout()); DataConfiguration dc = null; final PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); File favoritesFile = new File("favorites.properties"); propertiesConfiguration.setFile(favoritesFile); if (favoritesFile.exists()) { try { propertiesConfiguration.load(); } catch (ConfigurationException e) { e.printStackTrace(); } } dc = new DataConfiguration(propertiesConfiguration); propertiesConfiguration.setAutoSave(true); final VfsBrowser comp = new VfsBrowser(dc, (args.length > 0) ? args[0] : null); comp.setSelectionMode(SelectionMode.FILES_ONLY); comp.setMultiSelectionEnabled(true); comp.setApproveAction(new AbstractAction(Messages.getMessage("demo.showContentButton")) { @Override public void actionPerformed(ActionEvent e) { FileObject[] selectedFiles = comp.getSelectedFiles(); System.out.println("Selected files count=" + selectedFiles.length); for (FileObject selectedFile : selectedFiles) { try { FileSize fileSize = new FileSize(selectedFile.getContent().getSize()); System.out.println(selectedFile.getName().getURI() + ": " + fileSize.toString()); Desktop.getDesktop() .open(new File(new URI(selectedFile.getURL().toExternalForm()))); // byte[] bytes = readBytes(selectedFile.getContent().getInputStream(), 150 * 1024l); // JScrollPane sp = new JScrollPane(new JTextArea(new String(bytes))); // JDialog d = new JDialog(f); // d.setTitle("Content of file: " + selectedFile.getName().getFriendlyURI()); // d.getContentPane().add(sp); // d.setSize(600, 400); // d.setVisible(true); } catch (Exception e1) { LOGGER.error("Failed to read file", e1); JOptionPane.showMessageDialog(f, (e1.getMessage() == null) ? e1.toString() : e1.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } } }); comp.setCancelAction(new AbstractAction(Messages.getMessage("general.cancelButtonText")) { @Override public void actionPerformed(ActionEvent e) { f.dispose(); try { propertiesConfiguration.save(); } catch (ConfigurationException e1) { e1.printStackTrace(); } System.exit(0); } }); contentPane.add(comp); f.pack(); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }); while (!finished) Thread.sleep(100); }
From source file:com.raphfrk.craftproxyclient.gui.GUIManager.java
public static JSONObject getPreviousLoginDetails() { JSONObject loginInfo = AuthManager.refreshAccessToken(); if (loginInfo == null) { return null; }/*from w w w .j av a 2 s .c o m*/ final AtomicInteger option = new AtomicInteger(); Runnable r = new Runnable() { public void run() { option.set(JOptionPane.showConfirmDialog(CraftProxyClient.getGUI(), "Login as " + AuthManager.getUsername() + "?", "Login", JOptionPane.YES_NO_OPTION)); } }; if (SwingUtilities.isEventDispatchThread()) { r.run(); } else { try { SwingUtilities.invokeAndWait(r); } catch (InvocationTargetException | InterruptedException e) { return null; } } if (option.get() == 0) { return loginInfo; } else { return null; } }
From source file:Receiver.java
public void init() { //Execute a job on the event-dispatching thread; creating this applet's GUI. try {/*from ww w. j av a 2 s .c o m*/ SwingUtilities.invokeAndWait(new Runnable() { public void run() { ctrLbl = new JLabel(""); add(ctrLbl); } }); } catch (Exception e) { System.err.println("Could not create applet's GUI"); } }
From source file:MenuChooserApplet.java
public void init() { //Execute a job on the event-dispatching thread; creating this applet's GUI. try {/*from ww w .j a va 2 s . c o m*/ SwingUtilities.invokeAndWait(new Runnable() { public void run() { display = new MenuItemChooser(); add(display); } }); } catch (Exception e) { System.err.println("createGUI didn't complete successfully"); } }
From source file:integratedprogressdemo.WeatherApplet.java
public void init() { //Execute a job on the event-dispatching thread; creating this applet's GUI. try {/*from w w w . j ava2 s . co m*/ SwingUtilities.invokeAndWait(new Runnable() { public void run() { WeatherData newContentPane = WeatherData.getWeatherDataPanel(false); add(newContentPane); } }); } catch (Exception e) { System.err.println("createGUI didn't complete successfully"); } }
From source file:TextEditorApplet.java
public void init() { //Execute a job on the event-dispatching thread; creating this applet's GUI. try {// w ww . java2 s .co m SwingUtilities.invokeAndWait(new Runnable() { public void run() { createGUI(); } }); } catch (Exception e) { System.err.println("createGUI didn't complete successfully"); } }
From source file:customprogressindicatordemo.WeatherApplet.java
public void init() { //Execute a job on the event-dispatching thread; creating this applet's GUI. try {// w w w .j av a 2 s . co m SwingUtilities.invokeAndWait(new Runnable() { public void run() { WeatherData newContentPane = new WeatherData(); add(newContentPane); } }); } catch (Exception e) { System.err.println("createGUI didn't complete successfully"); } }
From source file:HelloWorld.java
public void init() { //Execute a job on the event-dispatching thread; creating this applet's GUI. try {//from w w w .jav a 2s. c om SwingUtilities.invokeAndWait(new Runnable() { public void run() { JLabel lbl = new JLabel("Hello World"); add(lbl); } }); } catch (Exception e) { System.err.println("createGUI didn't complete successfully"); } }