本文整理汇总了Java中javax.swing.SwingWorker类的典型用法代码示例。如果您正苦于以下问题:Java SwingWorker类的具体用法?Java SwingWorker怎么用?Java SwingWorker使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SwingWorker类属于javax.swing包,在下文中一共展示了SwingWorker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import javax.swing.SwingWorker; //导入依赖的package包/类
public static boolean run(SwingWorker<?,?> worker, Frame parent) throws Exception {
ProgressDialog dialog = new ProgressDialog(parent, worker);
worker.execute();
dialog.setVisible(true);
try {
worker.get();
}
catch (ExecutionException e) {
if (e.getCause() instanceof CancellationException) {
return false;
} else if (e.getCause() instanceof Exception) {
throw (Exception)e.getCause();
} else {
// ?!?
throw new AssertionError(e);
}
}
return !worker.isCancelled();
}
示例2: storeColors
import javax.swing.SwingWorker; //导入依赖的package包/类
private static void storeColors() {
final Properties properties = new Properties();
final List<ColoredFilter> colors = getRegisteredColors();
new SwingWorker() {
protected Object doInBackground() throws Exception {
for (int i = 0; i < colors.size(); i++) try {
colors.get(i).store(properties, Integer.toString(i) + "_"); // NOI18N
} catch (Throwable t) {
Logger.getLogger(PackageColorer.class.getName()).log(Level.INFO, null, t);
}
try {
ProfilerStorage.saveGlobalProperties(properties, FILTERS_FILE);
} catch (IOException e) {
Logger.getLogger(PackageColorer.class.getName()).log(Level.INFO, null, e);
}
return null;
}
}.execute();
}
示例3: authenticate
import javax.swing.SwingWorker; //导入依赖的package包/类
/**
* authenticates using existing credentials without triggering the auth
* workflow does nothing if offline
*/
public void authenticate() {
if (offline)
return;
SwingWorker<ConnectionStatus, Object> connectionWorker = AsyncWork.goUnderground(authFunction,
authContinuation);
Events.ui.post(RunState.AUTHENTICATION_STARTED);
try {
connectionWorker.execute();
logging.Info("attempting to authenticate");
String msgAuthFailed = "authentication failed: ";
try {
ConnectionStatus result = connectionWorker.get(clientSettings.authTimeout, TimeUnit.SECONDS);
if (result.status == HttpStatus.SC_OK)
logging.Info("authentication succeeded");
else
logging.Info(msgAuthFailed + result.message.or("unknown reason"));
} catch (InterruptedException | ExecutionException | TimeoutException e) {
connectionWorker.cancel(true);
logging.Info(String.format("%s %s %s", msgAuthFailed, e.getClass().getSimpleName(), e.getMessage()));
}
} finally {
Events.ui.post(RunState.AUTHENTICATION_FINISHED);
}
}
示例4: registerListener
import javax.swing.SwingWorker; //导入依赖的package包/类
private void registerListener() {
_configMaster.changeManager().addChangeListener(new ChangeListener() {
@Override
public void entityChanged(ChangeEvent event) {
SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
pullItems();
runFilter();
return null;
}
};
worker.execute();
}
});
}
示例5: createUpgradeWorker
import javax.swing.SwingWorker; //导入依赖的package包/类
/**
* Creates a new upgrade {@link SwingWorker}.
*
* @return
*/
private static SwingWorker<Void, Void> createUpgradeWorker() {
return new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
RMUrlHandler.handleUrl(URI_LICENSE_UPGRADE);
return null;
}
@Override
protected void done() {
try {
// see if anything failed
get();
} catch (ExecutionException | InterruptedException e) {
LogService.getRoot().log(Level.WARNING,
"com.rapidminer.license.gui.actions.UpgradeLicenseAction.failed_to_init_upgrade");
}
}
};
}
示例6: updateTimestampMasterStatus
import javax.swing.SwingWorker; //导入依赖的package包/类
protected void updateTimestampMasterStatus() {
final SwingWorker<Void, Void> masterUpdateWorker = new SwingWorker<Void, Void>() {
@Override
public Void doInBackground() {
try {
final int isMasterSPI = spiConfigReceive(CypressFX3.FPGA_SYSINFO, (short) 2);
isMaster.set(isMasterSPI != 0);
}
catch (HardwareInterfaceException e) {
// Ignore exceptions.
}
return (null);
}
};
masterUpdateWorker.execute();
}
示例7: unregisterListener
import javax.swing.SwingWorker; //导入依赖的package包/类
/**
* 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();
}
示例8: refreshAttributes
import javax.swing.SwingWorker; //导入依赖的package包/类
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);
}
示例9: main
import javax.swing.SwingWorker; //导入依赖的package包/类
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");
}
}
示例10: readSettings
import javax.swing.SwingWorker; //导入依赖的package包/类
@Override
public void readSettings(WizardDescriptor wizardDescriptor) {
this.wizardDescriptor = wizardDescriptor;
this.wizardDescriptor.setOptions( new Object[] { WizardDescriptor.FINISH_OPTION } );
importWorker.addPropertyChangeListener( (PropertyChangeEvent evt) -> {
if ( "state".equals( evt.getPropertyName() ) && evt.getNewValue() == SwingWorker.StateValue.DONE ) {
if ( importWorker.hasFailed() ) {
onImportFailed( importWorker.getException() );
} else {
onImportSuccess( importWorker.isMultiConfigBoard() );
}
}
});
importWorker.execute();
}
示例11: aniadirMangas
import javax.swing.SwingWorker; //导入依赖的package包/类
private void aniadirMangas() {
// // TODO Auto-generated method stub
final SwingWorker worker = new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
int inicio = Integer.parseInt(campoInicio.getText());
int fin = Integer.parseInt(campoFin.getText());
String url1 = campoUrl1.getText();
String url2 = campoUrl2.getText();
for (int i = inicio; i <= fin; i++) {
// ColaDescarga.addManga(url1 + i + url2);
textEnlaces.append(url1 + i + url2 + "\n");
}
return null;
}
};
worker.execute();
// dispose();
}
示例12: aniadirMangasMasivo
import javax.swing.SwingWorker; //导入依赖的package包/类
private void aniadirMangasMasivo() {
// TODO Auto-generated method stub
final SwingWorker worker = new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
String rawEnlaces = textEnlaces.getText();
String [] enlaces = rawEnlaces.split("\n");
for (int i = 0; i < enlaces.length; i++) {
ColaDescarga.addManga(enlaces[i]);
// System.out.println("+ "+enlaces[i]);
}
return null;
}
};
worker.execute();
// dispose();
}
示例13: aniadirMangas
import javax.swing.SwingWorker; //导入依赖的package包/类
protected void aniadirMangas() {
// // TODO Auto-generated method stub
final SwingWorker worker = new SwingWorker(){
@Override
protected Object doInBackground() throws Exception {
int inicio = Integer.parseInt(campoInicio.getText());
int fin = Integer.parseInt(campoFin.getText());
String url1=campoUrl1.getText();
String url2=campoUrl2.getText();
for (int i = inicio; i <= fin; i++) {
System.out.println("Aniadiendo: "+url1+i+url2);
ColaDescarga.addManga(url1+i+url2);
}
return null;
}
};
worker.execute();
dispose();
}
示例14: createNewSwingWorker
import javax.swing.SwingWorker; //导入依赖的package包/类
/**
* @return swing worker that starts the search() method and calls done() when that
* task finishes.
* @see SwingWorker
*/
private SwingWorker<M,U> createNewSwingWorker() {
return new SwingWorker<M,U>() {
@Override
protected M doInBackground() throws Exception {
return SearchTask.this.search();
}
@Override
protected void done() {
try {
M m = get(); // gets computed move
SearchTask.this.done(m);
} catch (InterruptedException | ExecutionException ex) {
System.err.println("Exception in search task: " + ex);
ex.printStackTrace();
}
}
};
}
示例15: open
import javax.swing.SwingWorker; //导入依赖的package包/类
public SwingWorker<?, ?> open(File file) {
if (file == null) {
JFileChooser chooser = new JFileChooser();
chooser.setFileFilter(new SupportFileFilter());
if (mCurrentFile != null && mCurrentFile.getParentFile().exists()) {
chooser.setCurrentDirectory(mCurrentFile.getParentFile());
}
int choice = chooser.showOpenDialog(this);
if (choice == JFileChooser.APPROVE_OPTION) {
return new OpenTask(chooser.getSelectedFile());
} else {
return null;
}
} else {
return new OpenTask(file);
}
}