List of usage examples for javax.swing SwingWorker execute
public final void execute()
From source file:es.emergya.ui.plugins.AdminPanel.java
public void changeRow(final int fila, final int destino) { SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() { @Override/*from w w w .j a v a2 s .c om*/ protected void done() { ((MyTableModel) table.getModel()).changeRow(fila, destino); } @Override protected Object doInBackground() throws Exception { return null; } }; sw.execute(); }
From source file:org.eumetsat.metop.visat.SounderInfoView.java
private void updateSpectrumDataset(final Ifov selectedIfov, final EpsFile epsFile) { final SwingWorker<XYSeries, Object> worker = new SwingWorker<XYSeries, Object>() { @Override//from w ww . jav a 2s .c o m protected XYSeries doInBackground() throws Exception { return createSpectrumPlotXYSeries(readSceneRadiances(epsFile, selectedIfov)); } @Override protected void done() { try { spectrumDataset.removeAllSeries(); final XYSeries series = get(); spectrumDataset.addSeries(series); } catch (InterruptedException e) { spectrumPlot.setNoDataMessage(IO_ERROR); } catch (ExecutionException e) { spectrumPlot.setNoDataMessage(IO_ERROR); } } }; worker.execute(); }
From source file:com.mirth.connect.client.ui.SettingsPanelAdministrator.java
public boolean doSave() { if (dashboardRefreshIntervalField.getText().length() == 0) { getFrame().alertWarning(this, "Please enter a valid interval time."); return false; }/* w ww. j ava2s .c o m*/ if (messageBrowserPageSizeField.getText().length() == 0) { getFrame().alertWarning(this, "Please enter a valid message browser page size."); return false; } if (eventBrowserPageSizeField.getText().length() == 0) { getFrame().alertWarning(this, "Please enter a valid event browser page size."); return false; } if (autoCompleteDelayField.isEnabled() && StringUtils.isBlank(autoCompleteDelayField.getText())) { getFrame().alertWarning(this, "Please enter a valid auto-complete activation delay."); return false; } int interval = Integer.parseInt(dashboardRefreshIntervalField.getText()); int messageBrowserPageSize = Integer.parseInt(messageBrowserPageSizeField.getText()); int eventBrowserPageSize = Integer.parseInt(eventBrowserPageSizeField.getText()); if (interval <= 0) { getFrame().alertWarning(this, "Please enter an interval time that is larger than 0."); } else if (messageBrowserPageSize <= 0) { getFrame().alertWarning(this, "Please enter an message browser page size larger than 0."); } else if (eventBrowserPageSize <= 0) { getFrame().alertWarning(this, "Please enter an event browser page size larger than 0."); } else { userPreferences.putInt("intervalTime", interval); userPreferences.putInt("messageBrowserPageSize", messageBrowserPageSize); userPreferences.putInt("eventBrowserPageSize", eventBrowserPageSize); userPreferences.putBoolean("messageBrowserFormat", formatYesRadio.isSelected()); userPreferences.putBoolean("textSearchWarning", textSearchWarningYesRadio.isSelected()); if (importChannelLibrariesAskRadio.isSelected()) { userPreferences.remove("importChannelCodeTemplateLibraries"); } else { userPreferences.putBoolean("importChannelCodeTemplateLibraries", importChannelLibrariesYesRadio.isSelected()); } if (exportChannelLibrariesAskRadio.isSelected()) { userPreferences.remove("exportChannelCodeTemplateLibraries"); } else { userPreferences.putBoolean("exportChannelCodeTemplateLibraries", exportChannelLibrariesYesRadio.isSelected()); } } final String workingId = getFrame().startWorking("Saving " + getTabName() + " settings..."); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { public Void doInBackground() { try { getFrame().mirthClient.setUserPreference(currentUser.getId(), "checkForNotifications", Boolean.toString(checkForNotificationsYesRadio.isSelected())); } catch (ClientException e) { getFrame().alertThrowable(getFrame(), e); } return null; } @Override public void done() { getFrame().setSaveEnabled(false); getFrame().stopWorking(workingId); } }; worker.execute(); RSTAPreferences rstaPreferences = MirthRSyntaxTextArea.getRSTAPreferences(); for (int row = 0; row < shortcutKeyTable.getRowCount(); row++) { ActionInfo actionInfo = (ActionInfo) shortcutKeyTable.getModel().getValueAt(row, ACTION_INFO_COLUMN); KeyStroke keyStroke = (KeyStroke) shortcutKeyTable.getModel().getValueAt(row, KEY_COLUMN); rstaPreferences.getKeyStrokeMap().put(actionInfo.getActionMapKey(), keyStroke); } MirthRSyntaxTextArea.updateKeyStrokePreferences(userPreferences); AutoCompleteProperties autoCompleteProperties = rstaPreferences.getAutoCompleteProperties(); autoCompleteProperties.setActivateAfterLetters(autoCompleteIncludeLettersCheckBox.isSelected()); autoCompleteProperties.setActivateAfterOthers(autoCompleteCharactersField.getText()); autoCompleteProperties.setActivationDelay(NumberUtils.toInt(autoCompleteDelayField.getText())); MirthRSyntaxTextArea.updateAutoCompletePreferences(userPreferences); return true; }
From source file:it.unibas.spicygui.controllo.spicy.ActionFindConfidenceMappings.java
@Override public void performAction() { Properties config = new Properties(); config.setProperty(IComputeQuality.class.getSimpleName(), "it.unibas.spicy.findmappings.strategies.computequality.ComputeQualityMatchAverage"); Application.reset(config);//from w w w. j a v a2s .c om executeInjection(); mappingFinder.cleanUp(); Scenario scenario = (Scenario) modello.getBean(Costanti.CURRENT_SCENARIO); MappingTask mappingTask = scenario.getMappingTask(); if (mappingTask.getTargetProxy().getInstances().isEmpty()) { NotifyDescriptor nd = new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.WARNING_NOT_TARGET_INSTANCES), DialogDescriptor.WARNING_MESSAGE); DialogDisplayer.getDefault().notify(nd); return; } checkValueCorrespondenceInMappingTask(mappingTask); SwingWorker swingWorker = new SwingWorker() { private Scenario scenario; @Override protected Object doInBackground() throws Exception { scenario = (Scenario) modello.getBean(Costanti.CURRENT_SCENARIO); MappingTask mappingTask = scenario.getMappingTask(); List<AnnotatedMappingTask> bestMappingTasks = mappingFinder.findBestMappings(mappingTask); modello.putBean(Costanti.BEST_MAPPING_TASKS, bestMappingTasks); IOProvider.getDefault().getIO(Costanti.FLUSSO_SPICY, false).select(); return true; } @Override protected void done() { try { if ((Boolean) get() && !isCancelled()) { actionViewSpicy.performActionWithScenario(this.scenario); actionViewBestMappings.performActionWithScenario(this.scenario); } } catch (InterruptedException ex) { logger.error(ex); } catch (ExecutionException ex) { logger.error(ex); } } }; swingWorker.execute(); }
From source file:it.unibas.spicygui.controllo.spicy.ActionFindMappings.java
@Override public void performAction() { Properties config = new Properties(); config.setProperty(IComputeQuality.class.getSimpleName(), "it.unibas.spicy.findmappings.strategies.computequality.ComputeQualityStructuralAnalysis"); Application.reset(config);/* ww w .j a va2 s.co m*/ executeInjection(); mappingFinder.cleanUp(); Scenario scenario = (Scenario) modello.getBean(Costanti.CURRENT_SCENARIO); MappingTask mappingTask = scenario.getMappingTask(); if (mappingTask.getTargetProxy().getInstances().isEmpty()) { NotifyDescriptor nd = new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.WARNING_NOT_TARGET_INSTANCES), DialogDescriptor.WARNING_MESSAGE); DialogDisplayer.getDefault().notify(nd); return; } checkValueCorrespondenceInMappingTask(mappingTask); SwingWorker swingWorker = new SwingWorker() { private Scenario scenario; @Override protected Object doInBackground() throws Exception { scenario = (Scenario) modello.getBean(Costanti.CURRENT_SCENARIO); MappingTask mappingTask = scenario.getMappingTask(); List<AnnotatedMappingTask> bestMappingTasks = mappingFinder.findBestMappings(mappingTask); modello.putBean(Costanti.BEST_MAPPING_TASKS, bestMappingTasks); IOProvider.getDefault().getIO(Costanti.FLUSSO_SPICY, false).select(); return true; } @Override protected void done() { try { if ((Boolean) get() && !isCancelled()) { actionViewSpicy.performActionWithScenario(this.scenario); actionViewBestMappings.performActionWithScenario(this.scenario); } } catch (InterruptedException ex) { logger.error(ex); } catch (ExecutionException ex) { logger.error(ex); } } }; swingWorker.execute(); }
From source file:edu.ku.brc.specify.config.init.PrintTableHelper.java
/** * @param table//from www. ja v a2 s . c om * @param pageTitle */ public void printGrid(final String pageTitle) { final PageSetupDlg pageSetup = new PageSetupDlg(); pageSetup.createUI(); pageSetup.setPageTitle(pageTitle); pageSetup.setVisible(true); if (pageSetup.isCancelled()) { return; } UIRegistry.writeSimpleGlassPaneMsg(getResourceString("JasperReportFilling"), 24); SwingWorker<Integer, Integer> backupWorker = new SwingWorker<Integer, Integer>() { protected JasperPrint jp = null; /* (non-Javadoc) * @see javax.swing.SwingWorker#doInBackground() */ @Override protected Integer doInBackground() throws Exception { if (printTable != null) { try { DynamicReport dr = buildReport(printTable.getModel(), pageSetup); JRDataSource ds = new JRTableModelDataSource(printTable.getModel()); jp = DynamicJasperHelper.generateJasperPrint(dr, new ClassicLayoutManager(), ds); } catch (Exception ex) { ex.printStackTrace(); } } return null; } @Override protected void done() { super.done(); UIRegistry.clearSimpleGlassPaneMsg(); if (jp != null) { reportFinished(jp, pageTitle); } } }; backupWorker.execute(); }
From source file:es.emergya.ui.plugins.AdminPanel.java
public void setCuenta(final int showed, final int total) { SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() { @Override//from w w w . ja v a 2s.co m protected Object doInBackground() throws Exception { setSize(total); return null; } @Override protected void done() { cuenta.setText("(" + showed + "/" + total + ")"); filters.updateUI(); } }; sw.execute(); }
From source file:it.illinois.adsc.ema.softgrid.monitoring.ui.SPMainFrame.java
@Override public void stopIEDServers() { SwingWorker iedWorker = new SwingWorker() { @Override/*from w w w. j a v a 2 s.c o m*/ protected Object doInBackground() throws Exception { messageHandler.addLogMessage("Stop all operations...!"); stopMonitor(); messageHandler.addLogMessage("Close all windows...!"); windowClosing(null); messageHandler.addLogMessage("exit IED server...!"); setVisible(false); messageHandler.addLogMessage("Stop all IED threads...!"); SoftGridController.killAll(); System.exit(0); return null; } }; iedWorker.execute(); }
From source file:mainGUI.TrainingJFrame.java
private void saveNetwork(final NeuralNet net, final String filename) { SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() { @Override//from w ww .j ava 2 s .c o m protected Boolean doInBackground() throws Exception { try { // Serialize data object to a file ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(filename)); out.writeObject(net); out.close(); } catch (IOException e) { e.printStackTrace(); } return true; } @Override protected void done() { System.out.println(filename + " saved"); } }; worker.execute(); System.out.println("Saving file " + filename); }
From source file:es.emergya.ui.gis.popups.SDSDialog.java
public SDSDialog(Recurso r) { super();//from w w w . j a va 2s .co m setAlwaysOnTop(true); setResizable(false); iconTransparente = LogicConstants.getIcon("48x48_transparente"); iconEnviando = LogicConstants.getIcon("anim_enviando"); destino = r; setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { super.windowClosing(e); cancel.doClick(); } }); // setPreferredSize(new Dimension(400, 150)); setTitle(i18n.getString("window.sds.titleBar") + " " + r.getIdentificador()); try { setIconImage(((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame() .getIconImage()); } catch (Throwable e) { LOG.error("There is no icon image", e); } JPanel base = new JPanel(); base.setBackground(Color.WHITE); base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS)); // Icono del titulo JPanel title = new JPanel(new FlowLayout(FlowLayout.LEADING)); final JLabel titleLabel = new JLabel(i18n.getString("window.sds.title"), LogicConstants.getIcon("tittleventana_icon_enviarsds"), JLabel.LEFT); titleLabel.setFont(LogicConstants.deriveBoldFont(12f)); title.add(titleLabel); title.setOpaque(false); base.add(title); // Espacio para el mensaje sds = new JTextArea(7, 40); sds.setLineWrap(true); final JScrollPane sdsp = new JScrollPane(sds); sdsp.setOpaque(false); sdsp.setBorder(new TitledBorder(BorderFactory.createLineBorder(Color.BLACK), i18n.getString("Admin.message") + "\t (0/" + maxChars + ")")); sds.setDocument(new PlainDocument() { @Override public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { if (this.getLength() + str.length() <= maxChars) { super.insertString(offs, str, a); } } }); sds.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { updateChars(e); } @Override public void insertUpdate(DocumentEvent e) { updateChars(e); } @Override public void changedUpdate(DocumentEvent e) { updateChars(e); } private void updateChars(DocumentEvent e) { ((TitledBorder) sdsp.getBorder()).setTitle( i18n.getString("Admin.message") + "\t (" + sds.getText().length() + "/" + maxChars + ")"); sdsp.repaint(); send.setEnabled(!sds.getText().isEmpty()); notification.setForeground(Color.WHITE); notification.setText("PLACEHOLDER"); } }); base.add(sdsp); // Area para mensajes JPanel notificationArea = new JPanel(); notificationArea.setOpaque(false); notification = new JLabel("TEXT"); notification.setForeground(Color.WHITE); notificationArea.add(notification); base.add(notificationArea); JPanel buttons = new JPanel(); buttons.setOpaque(false); buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS)); send = new JButton(i18n.getString("Buttons.send"), LogicConstants.getIcon("ventanacontextual_button_enviarsds")); send.addActionListener(this); send.setEnabled(false); buttons.add(send); buttons.add(Box.createHorizontalGlue()); progressIcon = new JLabel(iconTransparente); buttons.add(progressIcon); buttons.add(Box.createHorizontalGlue()); cancel = new JButton(i18n.getString("Buttons.cancel"), LogicConstants.getIcon("button_cancel")); cancel.addActionListener(this); buttons.add(cancel); base.add(buttons); getContentPane().add(base); pack(); int x; int y; Container myParent; try { myParent = ((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame() .getContentPane(); java.awt.Point topLeft = myParent.getLocationOnScreen(); Dimension parentSize = myParent.getSize(); Dimension mySize = getSize(); if (parentSize.width > mySize.width) x = ((parentSize.width - mySize.width) / 2) + topLeft.x; else x = topLeft.x; if (parentSize.height > mySize.height) y = ((parentSize.height - mySize.height) / 2) + topLeft.y; else y = topLeft.y; setLocation(x, y); } catch (Throwable e1) { LOG.error("There is no basic window!", e1); } this.addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent arg0) { deleteErrorMessage(); } @Override public void windowClosed(WindowEvent arg0) { deleteErrorMessage(); } private void deleteErrorMessage() { SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() { @Override protected Object doInBackground() throws Exception { if (bandejaSalida != null) { MessageGenerator.remove(bandejaSalida.getId()); } bandejaSalida = null; return null; } @Override protected void done() { super.done(); SDSDialog.this.sds.setText(""); SDSDialog.this.sds.setEnabled(true); SDSDialog.this.sds.repaint(); SDSDialog.this.progressIcon.setIcon(iconTransparente); SDSDialog.this.progressIcon.repaint(); SDSDialog.this.notification.setText(""); SDSDialog.this.notification.repaint(); } }; sw.execute(); } }); }