javax.swing.SwingWorker Java Examples

The following examples show how to use javax.swing.SwingWorker. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XMBeanAttributes.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void refreshAttributes(final boolean stopCellEditing) {
    SwingWorker<Void,Void> sw = new SwingWorker<Void,Void>() {

       @Override
       protected Void doInBackground() throws Exception {
           SnapshotMBeanServerConnection mbsc =
           mbeansTab.getSnapshotMBeanServerConnection();
           mbsc.flush();
           return null;
       }

       @Override
       protected void done() {
           try {
               get();
               if (stopCellEditing) stopCellEditing();
               loadAttributes(mbean, mbeanInfo);
           } catch (Exception x) {
               if (JConsole.isDebug()) {
                   x.printStackTrace();
               }
           }
       }
    };
    mbeansTab.workerAdd(sw);
}
 
Example #2
Source File: bug6432565.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Toolkit.getDefaultToolkit().getSystemEventQueue().push(new EventProcessor());

    SwingWorker<Void, CharSequence> swingWorker =
        new SwingWorker<Void,CharSequence>() {
            @Override
            protected Void doInBackground() {
                publish(new String[] {"hello"});
                publish(new StringBuilder("world"));
                return null;
            }
            @Override
            protected void done() {
                isDone.set(true);
            }
        };
    swingWorker.execute();

    while (! isDone.get()) {
        Thread.sleep(100);
    }
    if (throwable.get() instanceof ArrayStoreException) {
        throw new RuntimeException("Test failed");
    }
}
 
Example #3
Source File: MainWindow.java    From PyramidShader with GNU General Public License v3.0 6 votes vote down vote up
private void executeOperatorInWorker(ThreadedGridOperator op, String message) {
    final OperatorWorker operatorWorker = new OperatorWorker(progressPanel,
            model.getGrid(), op);
    operatorWorker.resetProgressGUI(true);
    operatorWorker.setMessage(message);
    operatorWorker.addPropertyChangeListener(
            new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if ("state".equals(event.getPropertyName())
                    && SwingWorker.StateValue.DONE == event.getNewValue()) {
                if (operatorWorker.isCancelled() == false) {
                    model.setGrid(operatorWorker.getResultGrid());
                    settingsDialog.gridChanged();
                }
            }
        }
    });
    gridWorkerManager.start(operatorWorker, true, true);
}
 
Example #4
Source File: XSheet.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Unsubscribe button action.
 */
private void unregisterListener() {
    new SwingWorker<Boolean, Void>() {
        @Override
        public Boolean doInBackground() {
            return mbeanNotifications.unregisterListener(currentNode);
        }
        @Override
        protected void done() {
            try {
                if (get()) {
                    updateNotifications();
                    validate();
                }
            } catch (Exception e) {
                Throwable t = Utils.getActualException(e);
                if (JConsole.isDebug()) {
                    System.err.println("Problem removing listener");
                    t.printStackTrace();
                }
                showErrorDialog(t.getMessage(),
                        Messages.PROBLEM_REMOVING_LISTENER);
            }
        }
    }.execute();
}
 
Example #5
Source File: XMBeanAttributes.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void refreshAttributes(final boolean stopCellEditing) {
    SwingWorker<Void,Void> sw = new SwingWorker<Void,Void>() {

       @Override
       protected Void doInBackground() throws Exception {
           SnapshotMBeanServerConnection mbsc =
           mbeansTab.getSnapshotMBeanServerConnection();
           mbsc.flush();
           return null;
       }

       @Override
       protected void done() {
           try {
               get();
               if (stopCellEditing) stopCellEditing();
               loadAttributes(mbean, mbeanInfo);
           } catch (Exception x) {
               if (JConsole.isDebug()) {
                   x.printStackTrace();
               }
           }
       }
    };
    mbeansTab.workerAdd(sw);
}
 
Example #6
Source File: XSheet.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Unsubscribe button action.
 */
private void unregisterListener() {
    new SwingWorker<Boolean, Void>() {
        @Override
        public Boolean doInBackground() {
            return mbeanNotifications.unregisterListener(currentNode);
        }
        @Override
        protected void done() {
            try {
                if (get()) {
                    updateNotifications();
                    validate();
                }
            } catch (Exception e) {
                Throwable t = Utils.getActualException(e);
                if (JConsole.isDebug()) {
                    System.err.println("Problem removing listener");
                    t.printStackTrace();
                }
                showErrorDialog(t.getMessage(),
                        Messages.PROBLEM_REMOVING_LISTENER);
            }
        }
    }.execute();
}
 
Example #7
Source File: bug6432565.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Toolkit.getDefaultToolkit().getSystemEventQueue().push(new EventProcessor());

    SwingWorker<Void, CharSequence> swingWorker =
        new SwingWorker<Void,CharSequence>() {
            @Override
            protected Void doInBackground() {
                publish(new String[] {"hello"});
                publish(new StringBuilder("world"));
                return null;
            }
            @Override
            protected void done() {
                isDone.set(true);
            }
        };
    swingWorker.execute();

    while (! isDone.get()) {
        Thread.sleep(100);
    }
    if (throwable.get() instanceof ArrayStoreException) {
        throw new RuntimeException("Test failed");
    }
}
 
Example #8
Source File: CachingSwingWorkerTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void disasbleTimerUsage() {
	AccumulativeRunnable<Runnable> nonTimerAccumulativeRunnable =
		new AccumulativeRunnable<Runnable>() {
			@Override
			protected void run(List<Runnable> args) {
				for (Runnable runnable : args) {
					runnable.run();
				}
			}
		};

	Object key = getInstanceField("DO_SUBMIT_KEY", SwingWorker.class);

	AppContext appContext = AppContext.getAppContext();
	appContext.put(key, nonTimerAccumulativeRunnable);
}
 
Example #9
Source File: XMBeanAttributes.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private void refreshAttributes(final boolean stopCellEditing) {
    SwingWorker<Void,Void> sw = new SwingWorker<Void,Void>() {

       @Override
       protected Void doInBackground() throws Exception {
           SnapshotMBeanServerConnection mbsc =
           mbeansTab.getSnapshotMBeanServerConnection();
           mbsc.flush();
           return null;
       }

       @Override
       protected void done() {
           try {
               get();
               if (stopCellEditing) stopCellEditing();
               loadAttributes(mbean, mbeanInfo);
           } catch (Exception x) {
               if (JConsole.isDebug()) {
                   x.printStackTrace();
               }
           }
       }
    };
    mbeansTab.workerAdd(sw);
}
 
Example #10
Source File: XMBeanAttributes.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void refreshAttributes(final boolean stopCellEditing) {
    SwingWorker<Void,Void> sw = new SwingWorker<Void,Void>() {

       @Override
       protected Void doInBackground() throws Exception {
           SnapshotMBeanServerConnection mbsc =
           mbeansTab.getSnapshotMBeanServerConnection();
           mbsc.flush();
           return null;
       }

       @Override
       protected void done() {
           try {
               get();
               if (stopCellEditing) stopCellEditing();
               loadAttributes(mbean, mbeanInfo);
           } catch (Exception x) {
               if (JConsole.isDebug()) {
                   x.printStackTrace();
               }
           }
       }
    };
    mbeansTab.workerAdd(sw);
}
 
Example #11
Source File: bug6432565.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Toolkit.getDefaultToolkit().getSystemEventQueue().push(new EventProcessor());

    SwingWorker<Void, CharSequence> swingWorker =
        new SwingWorker<Void,CharSequence>() {
            @Override
            protected Void doInBackground() {
                publish(new String[] {"hello"});
                publish(new StringBuilder("world"));
                return null;
            }
            @Override
            protected void done() {
                isDone.set(true);
            }
        };
    swingWorker.execute();

    while (! isDone.get()) {
        Thread.sleep(100);
    }
    if (throwable.get() instanceof ArrayStoreException) {
        throw new RuntimeException("Test failed");
    }
}
 
Example #12
Source File: XMBeanAttributes.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private void refreshAttributes(final boolean stopCellEditing) {
    SwingWorker<Void,Void> sw = new SwingWorker<Void,Void>() {

       @Override
       protected Void doInBackground() throws Exception {
           SnapshotMBeanServerConnection mbsc =
           mbeansTab.getSnapshotMBeanServerConnection();
           mbsc.flush();
           return null;
       }

       @Override
       protected void done() {
           try {
               get();
               if (stopCellEditing) stopCellEditing();
               loadAttributes(mbean, mbeanInfo);
           } catch (Exception x) {
               if (JConsole.isDebug()) {
                   x.printStackTrace();
               }
           }
       }
    };
    mbeansTab.workerAdd(sw);
}
 
Example #13
Source File: XSheet.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Unsubscribe button action.
 */
private void unregisterListener() {
    new SwingWorker<Boolean, Void>() {
        @Override
        public Boolean doInBackground() {
            return mbeanNotifications.unregisterListener(currentNode);
        }
        @Override
        protected void done() {
            try {
                if (get()) {
                    updateNotifications();
                    validate();
                }
            } catch (Exception e) {
                Throwable t = Utils.getActualException(e);
                if (JConsole.isDebug()) {
                    System.err.println("Problem removing listener");
                    t.printStackTrace();
                }
                showErrorDialog(t.getMessage(),
                        Messages.PROBLEM_REMOVING_LISTENER);
            }
        }
    }.execute();
}
 
Example #14
Source File: bug6432565.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Toolkit.getDefaultToolkit().getSystemEventQueue().push(new EventProcessor());

    SwingWorker<Void, CharSequence> swingWorker =
        new SwingWorker<Void,CharSequence>() {
            @Override
            protected Void doInBackground() {
                publish(new String[] {"hello"});
                publish(new StringBuilder("world"));
                return null;
            }
            @Override
            protected void done() {
                isDone.set(true);
            }
        };
    swingWorker.execute();

    while (! isDone.get()) {
        Thread.sleep(100);
    }
    if (throwable.get() instanceof ArrayStoreException) {
        throw new RuntimeException("Test failed");
    }
}
 
Example #15
Source File: ClassySharkPanel.java    From android-classyshark with Apache License 2.0 6 votes vote down vote up
private void readMappingFile(final File resultFile) {
    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
        private TokensMapper reverseMappings;

        @Override
        protected Void doInBackground() throws Exception {
            reverseMappings = silverGhost.readMappingFile(resultFile);
            return null;
        }

        protected void done() {
            silverGhost.addMappings(reverseMappings);
        }
    };

    worker.execute();
}
 
Example #16
Source File: XMBeanAttributes.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void refreshAttributes(final boolean stopCellEditing) {
    SwingWorker<Void,Void> sw = new SwingWorker<Void,Void>() {

       @Override
       protected Void doInBackground() throws Exception {
           SnapshotMBeanServerConnection mbsc =
           mbeansTab.getSnapshotMBeanServerConnection();
           mbsc.flush();
           return null;
       }

       @Override
       protected void done() {
           try {
               get();
               if (stopCellEditing) stopCellEditing();
               loadAttributes(mbean, mbeanInfo);
           } catch (Exception x) {
               if (JConsole.isDebug()) {
                   x.printStackTrace();
               }
           }
       }
    };
    mbeansTab.workerAdd(sw);
}
 
Example #17
Source File: XSheet.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Unsubscribe button action.
 */
private void unregisterListener() {
    new SwingWorker<Boolean, Void>() {
        @Override
        public Boolean doInBackground() {
            return mbeanNotifications.unregisterListener(currentNode);
        }
        @Override
        protected void done() {
            try {
                if (get()) {
                    updateNotifications();
                    validate();
                }
            } catch (Exception e) {
                Throwable t = Utils.getActualException(e);
                if (JConsole.isDebug()) {
                    System.err.println("Problem removing listener");
                    t.printStackTrace();
                }
                showErrorDialog(t.getMessage(),
                        Messages.PROBLEM_REMOVING_LISTENER);
            }
        }
    }.execute();
}
 
Example #18
Source File: SwingWorkerPropertyChangeAdapter.java    From blog with Apache License 2.0 6 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent evt) {
	String propertyName = evt.getPropertyName();
	if ("state".equals(propertyName)) {
		StateValue state = (StateValue) evt.getNewValue();
		switch (state) {
		case PENDING:
		case STARTED:
			started();
			break;
		case DONE:
			SwingWorker<?, ?> future = (SwingWorker<?, ?>) evt.getSource();
			boolean cancelled = future.isCancelled();
			done(cancelled);
		}
	}
}
 
Example #19
Source File: XSheet.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Subscribe button action.
 */
private void registerListener() {
    new SwingWorker<Void, Void>() {
        @Override
        public Void doInBackground()
                throws InstanceNotFoundException, IOException {
            mbeanNotifications.registerListener(currentNode);
            return null;
        }
        @Override
        protected void done() {
            try {
                get();
                updateNotifications();
                validate();
            } catch (Exception e) {
                Throwable t = Utils.getActualException(e);
                if (JConsole.isDebug()) {
                    System.err.println("Problem adding listener");
                    t.printStackTrace();
                }
                showErrorDialog(t.getMessage(),
                        Messages.PROBLEM_ADDING_LISTENER);
            }
        }
    }.execute();
}
 
Example #20
Source File: ExceptionSafePlugin.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void executeSwingWorker(SwingWorker<?, ?> sw) {
    try {
        sw.execute();
    } catch (RuntimeException e) {
        handleException(e);
    }
}
 
Example #21
Source File: SchemaNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void setupNames() {
    boolean connected = connection.isConnected();
    final MetadataModel metaDataModel = connection.getMetadataModel();
    if (connected && metaDataModel != null) {
        new SwingWorker() {
            @Override
            protected Object doInBackground() throws Exception {
                try {
                    metaDataModel.runReadAction(
                            new Action<Metadata>() {
                        @Override
                        public void run(Metadata metaData) {
                            Schema schema = schemaHandle.resolve(metaData);
                            toggleImportantInfo.setDefault(schema.isDefault());
                            toggleImportantInfo.setImportant(connection.isImportantSchema(name));
                            renderNames(schema);
                        }
                    });
                    return null;
                } catch (MetadataModelException e) {
                    NodeRegistry.handleMetadataModelException(this.getClass(), connection, e, true);
                    return null;
                }
            }
        }.run();
    }
}
 
Example #22
Source File: LaserChronNUPlasmaMultiCollFaradayTRAFileHandler.java    From ET_Redux with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param loadDataTask the value of loadRawDataPropertyChangeListener
 * @param usingFullPropagation the value of usingFullPropagation
 * @param leftShadeCount the value of leftShadeCount
 * @param ignoreFirstFractions the value of ignoreFirstFractions
 * @param inLiveMode the value of inLiveMode
 */
@Override
public void getAndLoadRawIntensityDataFile(SwingWorker loadDataTask, boolean usingFullPropagation, int leftShadeCount, int ignoreFirstFractions, boolean inLiveMode) {

    if (rawDataFile != null) {
        // create fractions from raw data and perform corrections and calculate ratios
         tripoliFractions = loadRawDataFile(loadDataTask, usingFullPropagation, leftShadeCount, ignoreFirstFractions, inLiveMode);
    };
}
 
Example #23
Source File: ECGViewHandler.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
public void applyFilterAll(final FilterDialog f, final MainFrame attach) {
	final HashMap<Integer, Undoable> changes = new HashMap<Integer, Undoable>(model.size());
	for(int i = 0; i < model.size(); i++) {
		changes.put(i, (ECGDataSet)model.getDataset(i).clone());
	}
	model.pushChange(new Change<HashMap<Integer, Undoable>, String>(
					changes, 
					"Apply filter " + f.Id() + " to leads"));
	ProgressDialog.make(new SwingWorker<Void, Void>() {
		@Override
		public Void doInBackground() {
			setProgress(0);
			for(Iterator<Integer> i = attach.getSelectedLeads().iterator(); i.hasNext();) {
				int ind = i.next();
				model.applyFilter(ind, f.Id(), f.returnVals());
				setProgress((int)((double)ind/(double)model.size()*100));
				if(isCancelled()) {
					model.undo();
					model.resetFuture();
					break;
				}
			}
			return null;
		}

		@Override
		public void done() {
			attach.relink();
		}
	}, attach);
}
 
Example #24
Source File: SelfSamplerAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Invoked when an action occurs.
 */
@Override
public void actionPerformed(final ActionEvent e) {
    Sampler c = Sampler.createManualSampler("Self Sampler");  // NOI18N
    if (c != null) {
        if (RUNNING.compareAndSet(null, c)) {
            putValue(Action.NAME, ACTION_NAME_STOP);
            putValue(Action.SHORT_DESCRIPTION, ACTION_NAME_STOP);
            putValue ("iconBase", "org/netbeans/core/ui/sampler/selfSamplerRunning.png"); // NOI18N
            c.start();
        } else if ((c = RUNNING.getAndSet(null)) != null) {
            final Sampler controller = c;

            setEnabled(false);
            SwingWorker worker = new SwingWorker() {

                @Override
                protected Object doInBackground() throws Exception {
                    controller.stop();
                    return null;
                }

                @Override
                protected void done() {
                    putValue(Action.NAME, ACTION_NAME_START);
                    putValue(Action.SHORT_DESCRIPTION, ACTION_NAME_START);
                    putValue ("iconBase", "org/netbeans/core/ui/sampler/selfSampler.png"); // NOI18N
                    SelfSamplerAction.this.setEnabled(true);
                }
            };
            worker.execute();
        }
    } else {
        NotifyDescriptor d = new NotifyDescriptor.Message(NOT_SUPPORTED, NotifyDescriptor.INFORMATION_MESSAGE);
        DialogDisplayer.getDefault().notify(d);
    }
}
 
Example #25
Source File: PluginUpdateManager.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void setVisible(boolean visible) {
  if(visible) {
    MainFrame.getGuiRoots().add(this);
    // if the window is about to be made visible then do some quick setup
    //tabs.setSelectedIndex(0);
    if(defaultPluginsWorker != null && !defaultPluginsWorker.isDone()) {
      showProgressPanel(true);
      progressPanel.messageChanged("Downloading default plugins list");
      defaultPluginsWorker.addPropertyChangeListener((evt) -> {
        if("progress".equals(evt.getPropertyName())) {
          // progress property changes are notified on the EDT
          progressPanel.downloadProgressed("Default plugins", 100, (Integer)evt.getNewValue());
        } else if("state".equals(evt.getPropertyName())) {
          if(evt.getNewValue() == SwingWorker.StateValue.DONE) {
            // state property changes are notified on the background thread, not the EDT
            SwingUtilities.invokeLater(() -> {
              showProgressPanel(false);
              installed.reInit();
            });
          }
        }
      });
    } else {
      installed.reInit();
    }
  }

  // now actually show/hide the window
  super.setVisible(visible);

  dispose();
}
 
Example #26
Source File: LoadSaveScreen.java    From open-ig with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** Start the list population worker. */
void startWorker() {
	listWorker = new SwingWorker<Void, Void>() {
		final List<FileItem> flist = new ArrayList<>();
		@Override
		protected Void doInBackground() throws Exception {
			try {
				findSaves(flist);
			} catch (Throwable t) {
				Exceptions.add(t);
			}
			return null;
		}
		@Override
		protected void done() {
			listWorker = null;
			
			// create first entry

			if (maySave) {
				FileItem newSave = new FileItem(null);
				newSave.saveDate = new Date();
				newSave.level = world().level;
				newSave.difficulty = world().difficulty;
				newSave.money = player().money();
				newSave.skirmish = world().skirmishDefinition != null;
				newSave.gameDate = world().time.getTime();
				newSave.saveName = LoadSaveScreen.this.get("settings.new_save"); // FIXME labels
				
				flist.add(0, newSave);
				list.selected = newSave;
			}
			
			list.items.addAll(flist);
			askRepaint();
		}
       };
	listWorker.execute();
}
 
Example #27
Source File: XSheet.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Subscribe button action.
 */
private void registerListener() {
    new SwingWorker<Void, Void>() {
        @Override
        public Void doInBackground()
                throws InstanceNotFoundException, IOException {
            mbeanNotifications.registerListener(currentNode);
            return null;
        }
        @Override
        protected void done() {
            try {
                get();
                updateNotifications();
                validate();
            } catch (Exception e) {
                Throwable t = Utils.getActualException(e);
                if (JConsole.isDebug()) {
                    System.err.println("Problem adding listener");
                    t.printStackTrace();
                }
                showErrorDialog(t.getMessage(),
                        Messages.PROBLEM_ADDING_LISTENER);
            }
        }
    }.execute();
}
 
Example #28
Source File: ExceptionSafePlugin.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void executeSwingWorker(SwingWorker<?, ?> sw) {
    try {
        sw.execute();
    } catch (RuntimeException e) {
        handleException(e);
    }
}
 
Example #29
Source File: ExceptionSafePlugin.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SwingWorker<?, ?> newSwingWorker() {
    try {
        return plugin.newSwingWorker();
    } catch (RuntimeException e) {
        handleException(e);
    }
    return null;
}
 
Example #30
Source File: XSheet.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Subscribe button action.
 */
private void registerListener() {
    new SwingWorker<Void, Void>() {
        @Override
        public Void doInBackground()
                throws InstanceNotFoundException, IOException {
            mbeanNotifications.registerListener(currentNode);
            return null;
        }
        @Override
        protected void done() {
            try {
                get();
                updateNotifications();
                validate();
            } catch (Exception e) {
                Throwable t = Utils.getActualException(e);
                if (JConsole.isDebug()) {
                    System.err.println("Problem adding listener");
                    t.printStackTrace();
                }
                showErrorDialog(t.getMessage(),
                        Messages.PROBLEM_ADDING_LISTENER);
            }
        }
    }.execute();
}