List of usage examples for javax.swing SwingWorker execute
public final void execute()
From source file:interactivespaces.service.image.vision.opencv.swing.OpenCvMatPanel.java
/** * Draw an OpenCV image in the panel.//from w ww . j a va 2 s . c o m * * @param opencvImage * the image to draw */ public void drawImage(final Mat opencvImage) { SwingWorker<BufferedImage, Void> worker = new SwingWorker<BufferedImage, Void>() { @Override protected BufferedImage doInBackground() throws Exception { return MatUtils.matToBufferedImage(opencvImage); } @Override protected void done() { try { image = get(); repaint(); if (releaseAfterDraw) { opencvImage.release(); } } catch (InterruptedException e) { log.info("Swing worker for rendering Mat images interrupted"); } catch (ExecutionException e) { log.error("Error during Swing worker for rendering Mat images", e); } } }; worker.execute(); }
From source file:edu.ku.brc.specify.tasks.subpane.lm.LifeMapperPane.java
/** * @param urlStr//from ww w . j av a 2 s . c o m * @param listener */ public static void getImageFromWeb(final String urlStr, final BufferedImageFetcherIFace listener) { //System.out.println(urlStr); SwingWorker<BufferedImage, BufferedImage> worker = new SwingWorker<BufferedImage, BufferedImage>() { @Override protected BufferedImage doInBackground() throws Exception { try { URL url = new URL(urlStr); return ImageIO.read(url); } catch (IOException e) { } return null; } @Override protected void done() { try { BufferedImage img = get(); listener.imageFetched(img); return; } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } listener.error(); super.done(); } }; worker.execute(); }
From source file:com.enderville.enderinstaller.ui.Installer.java
@Override public void hyperlinkUpdate(final HyperlinkEvent e) { if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) { return;//from w w w . j av a 2 s. c o m } SwingWorker<Object, Object> worker = new SwingWorker<Object, Object>() { @Override protected Object doInBackground() throws Exception { try { String url = e.getURL().toExternalForm(); Desktop.getDesktop().browse(URI.create(url)); } catch (Exception e) { e.printStackTrace(); } return null; } }; worker.execute(); }
From source file:es.emergya.ui.base.plugins.PluginContainer.java
public void cleanUp() { SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() { @Override//from ww w .j a v a 2 s. c om protected Object doInBackground() throws Exception { for (AbstractPlugin ap : PluginContainer.this.plugins) try { if (ap instanceof CleanUp) ((CleanUp) ap).cleanUp(); } catch (Throwable t) { log.error("Error on cleanUp " + ap, t); } for (DetachedTab t : window.getPluginContainer().getPane().getDetachedTabs()) try { t.dispose(); } catch (Throwable e) { log.error("Error on dispose " + t, e); } return null; } }; sw.execute(); }
From source file:com.cch.aj.entryrecorder.frame.SearchJFrame.java
private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed BusyJFrame bf = new BusyJFrame(); bf.setVisible(true);/* ww w.ja va 2 s . c o m*/ SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { List<Entry> list = entrySearchService.Search(txtShift.getText(), txtProduct.getText(), txtBatch.getText()); DefaultTableModel model = (DefaultTableModel) tblSearch.getModel(); model.setRowCount(0); for (Entry entry : list) { model.addRow(new Object[] { entry.getId(), entry.getShift(), entry.getProductId().getCode(), (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(entry.getCreateDate()) }); } return null; } @Override protected void done() { bf.setVisible(false); } }; worker.execute(); }
From source file:com.mirth.connect.client.ui.NotificationDialog.java
private void doSave() { final Properties personPreferences = new Properties(); if (!StringUtils.equals(checkForNotifications, Boolean.toString(checkForNotificationsSetting))) { personPreferences.put("checkForNotifications", Boolean.toString(checkForNotificationsSetting)); }//from ww w .j av a 2 s. c om if (!StringUtils.equals(showNotificationPopup, Boolean.toString(notificationCheckBox.isSelected()))) { personPreferences.put("showNotificationPopup", Boolean.toString(notificationCheckBox.isSelected())); } Set<Integer> currentArchivedNotifications = notificationModel.getArchivedNotifications(); if (!archivedNotifications.equals(currentArchivedNotifications)) { personPreferences.put("archivedNotifications", ObjectXMLSerializer.getInstance().serialize(currentArchivedNotifications)); } if (!personPreferences.isEmpty()) { final String workingId = parent.startWorking("Saving notifications settings..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { public Void doInBackground() { try { parent.mirthClient.setUserPreferences(parent.getCurrentUser(parent).getId(), personPreferences); } catch (ClientException e) { parent.alertThrowable(parent, e); } return null; } @Override public void done() { parent.stopWorking(workingId); } }; worker.execute(); } parent.updateNotificationTaskName(unarchivedCount); this.dispose(); }
From source file:com.mirth.connect.client.ui.SettingsPanelDatabaseTasks.java
public void doCancelDatabaseTask() { DatabaseTask databaseTask = (DatabaseTask) taskTable.getValueAt(taskTable.getSelectedRow(), 1); if (databaseTask.getStatus() != Status.RUNNING) { getFrame().alertError(getFrame(), "Task \"" + databaseTask.getName() + "\" is not currently running."); return;//from w ww . ja v a 2 s .c o m } if (!getFrame().alertOption(getFrame(), "Are you sure you want to cancel the selected database task?")) { return; } final String workingId = getFrame().startWorking("Cancelling database task..."); final String taskId = databaseTask.getId(); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { @Override public Void doInBackground() throws ClientException { getFrame().mirthClient.cancelDatabaseTask(taskId); return null; } @Override public void done() { try { get(); } catch (Throwable t) { if (t instanceof ExecutionException) { t = t.getCause(); } getFrame().alertThrowable(getFrame(), t, "Error cancelling database task: " + t.getMessage()); } finally { getFrame().stopWorking(workingId); doRefresh(); } } }; worker.execute(); }
From source file:com.mirth.connect.client.ui.SettingsPanelMap.java
public void doRefresh() { if (PlatformUI.MIRTH_FRAME.alertRefresh()) { return;/*from w w w. j a v a2 s . com*/ } final String workingId = getFrame().startWorking("Loading " + getTabName() + " settings..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { Map<String, ConfigurationProperty> configurationMap = null; public Void doInBackground() { try { configurationMap = getFrame().mirthClient.getConfigurationMap(); } catch (ClientException e) { getFrame().alertThrowable(getFrame(), e); } return null; } @Override public void done() { // null if it failed to get the map settings or if confirmLeave returned false if (configurationMap != null) { updateConfigurationTable(configurationMap); } getFrame().stopWorking(workingId); } }; worker.execute(); }
From source file:be.ac.ua.comp.scarletnebula.gui.windows.GUI.java
public GUI() { chooseLookAndFeel();//from www . ja va 2s. co m setTitle("Scarlet Nebula"); setSize(700, 400); setDefaultCloseOperation(EXIT_ON_CLOSE); final ImageIcon icon = new ImageIcon(getClass().getResource("/images/icon48.png")); setIconImage(icon.getImage()); addToolbar(); final JPanel mainPanel = getMainPanel(); add(mainPanel); addMenubar(); setKeyboardAccelerators(); setLocationRelativeTo(null); setLocationByPlatform(true); setVisible(true); // Last but not least, we construct a cloudmanager object, which will // cause it to load all providers and thus servers. // We also register ourselves as an observer for linking and unlinking // servers so we can update the serverlist. CloudManager.get().addServerLinkUnlinkObserver(this); (new SwingWorkerWithThrobber<Object, Object>(newThrobber("Loading servers...")) { @Override protected Object doInBackground() throws Exception { try { CloudManager.get().loadAllLinkedServers(); // now start refreshing all servers if necessary for (final CloudProvider cloudprovider : CloudManager.get().getLinkedCloudProviders()) { { for (final Server server : cloudprovider.listLinkedServers()) { if (server.getStatus() == VmState.PENDING) { server.refreshUntilServerHasState(VmState.RUNNING); } if (server.getStatus() == VmState.REBOOTING) { server.refreshUntilServerHasState(VmState.RUNNING); } if (server.getStatus() == VmState.STOPPING) { server.refreshUntilServerHasState(VmState.TERMINATED); } } } } } catch (final Exception e) { log.error("Error while getting servers", e); } return null; } }).execute(); // If there are no linked cloudproviders, start the new provider wizard if (CloudManager.get().getLinkedCloudProviders().size() == 0) { final SwingWorker<Object, Object> welcomeWizardWorker = new SwingWorker<Object, Object>() { @Override protected Object doInBackground() throws Exception { new WelcomeWizard(GUI.this); return null; } }; welcomeWizardWorker.execute(); } }
From source file:com.dfki.av.sudplan.vis.VisualizationPanel.java
/** * Adds a GeoTiff file to the world wind model. * * @param file the {@link File} to add.//from w ww. j a va2 s . c o m * @throws IllegalArgumentException if file == null * @throws IOException */ public void addGeoTiffLayer(File file) throws IOException { if (file == null) { String msg = "file == null"; log.error(msg); throw new IllegalArgumentException(msg); } final File geotiffFile = file; SwingWorker workerThread = new SwingWorker() { @Override protected Object doInBackground() throws Exception { SurfaceImageLayer layer = new SurfaceImageLayer(); layer.setPickEnabled(false); layer.setValue(AVKey.DISPLAY_NAME, geotiffFile.getName()); layer.addImage(geotiffFile.getAbsolutePath()); ApplicationTemplate.insertBeforePlacenames(wwd, layer); return null; } }; workerThread.execute(); }