Java Code Examples for javax.swing.SwingWorker

The following examples show how to use javax.swing.SwingWorker. These examples are extracted from open source projects. 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
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 Project: ghidra   Source File: CachingSwingWorkerTest.java    License: 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 3
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 4
Source Project: hottub   Source File: XSheet.java    License: 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 Project: PyramidShader   Source File: MainWindow.java    License: 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 6
Source Project: jdk8u-jdk   Source File: bug6432565.java    License: 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 7
Source Project: jdk8u-jdk   Source File: XMBeanAttributes.java    License: 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 8
Source Project: openjdk-8-source   Source File: XSheet.java    License: 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 9
Source Project: android-classyshark   Source File: ClassySharkPanel.java    License: 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 10
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 Project: openjdk-8   Source File: XSheet.java    License: 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 12
Source Project: blog   Source File: SwingWorkerPropertyChangeAdapter.java    License: 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 13
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 14
Source Project: hottub   Source File: XMBeanAttributes.java    License: 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 15
Source Project: jdk8u-jdk   Source File: bug6432565.java    License: 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 16
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 17
Source Project: hottub   Source File: bug6432565.java    License: 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 18
Source Project: openjdk-jdk9   Source File: XSheet.java    License: 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 19
VMPanel(Application application, JConsolePluginWrapper wrapper, ProxyClient proxyClient) {
    this.application = application;
    this.proxyClient = proxyClient;
    plugins = new LinkedHashMap<JConsolePlugin, SwingWorker<?, ?>>();
    for (JConsolePlugin p : wrapper.getPlugins()) {
        p.setContext(proxyClient);
        plugins.put(p, null);
    }
    // Start listening to connection state events
    //
    proxyClient.addPropertyChangeListener(this);
}
 
Example 20
/**
 *
 * @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 21
@Override
public SwingWorker<?, ?> newSwingWorker() {
    try {
        return plugin.newSwingWorker();
    } catch (RuntimeException e) {
        handleException(e);
    }
    return null;
}
 
Example 22
Source Project: importer-exporter   Source File: MapWindow.java    License: Apache License 2.0 5 votes vote down vote up
public void setBoundingBox(final BoundingBox bbox) {
	new SwingWorker<ValidationResult, Void>() {
		protected ValidationResult doInBackground() throws Exception {
			return validator.validate(bbox);
		}

		protected void done() {
			try {
				switch (get()) {
				case CANCEL:
					dispose();
					break;
				case SKIP:
				case OUT_OF_RANGE:
				case NO_AREA:
					clearBoundingBox();
					break;
				case INVISIBLE:
					clearBoundingBox();
					indicateInvisibleBoundingBox(bbox);
					break;
				default:
					minX.setValue(bbox.getLowerCorner().getX());
					minY.setValue(bbox.getLowerCorner().getY());
					maxX.setValue(bbox.getUpperCorner().getX());
					maxY.setValue(bbox.getUpperCorner().getY());
					showBoundingBox();
				}
			} catch (InterruptedException | ExecutionException e) {
				//
			}
		}
	}.execute();
}
 
Example 23
Source Project: ghidra   Source File: CachingSwingWorker.java    License: Apache License 2.0 5 votes vote down vote up
private void blockSwingWithProgressDialog(final SwingWorker<T, Object> localWorker) {
	if (!localWorker.isDone()) {

		TaskDialog dialog = new SwingWorkerTaskDialog(name, hasProgress, localWorker);
		taskMonitor.setBlockingMonitor(dialog);
		localWorker.addPropertyChangeListener(new SwingWorkerCompletionWaiter(dialog));
		dialog.show(taskDialogDelay);
	}
}
 
Example 24
Source Project: ghidra   Source File: CachingSwingWorker.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent event) {
	if ("state".equals(event.getPropertyName()) &&
		SwingWorker.StateValue.DONE == event.getNewValue()) {
		dialog.close();
	}
}
 
Example 25
public void executeSwingWorker(SwingWorker<?, ?> sw) {
    try {
        sw.execute();
    } catch (RuntimeException e) {
        handleException(e);
    }
}
 
Example 26
private void loadTreeFile(final File file, final int row) {

		frame.setBusy();
		SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {

			// Executed in background thread
			public Void doInBackground() {

				try {

					Tree tree = Utils.importTreeFromFile(file);
					tree.setId(file.getName());

					setRow(row, new TreesTableRecord(tree.getId(), tree));

				} catch (Exception e) {
					Utils.handleException(e);
				}// END: try-catch block

				return null;
			}// END: doInBackground()

			// Executed in event dispatch thread
			public void done() {
				frame.setIdle();
				frame.fireTaxaChanged();
			}// END: done
		};

		worker.execute();

	}
 
Example 27
Source Project: TencentKona-8   Source File: XSheet.java    License: 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
/**
 *
 * @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 29
private void loadDoc()
{
	
	if(isVisible())
		ThreadManager.getInstance().runInEdt(new SwingWorker<Document,Void>() {
			@Override
			protected void done() {
				try {
					
					Document d= get();
					int width = (int)getSize().getWidth();
					
					if(width<=0)
						width=450;
					
					d.select("img").attr("width", String.valueOf(width));
					pane.setText(d.html().replace("$USER_HOME", SystemUtils.USER_HOME));
				} catch (Exception e) {
					logger.error("error loading help",e);
					pane.setText(e.getLocalizedMessage());
				} 
			}
			
			@Override
			protected Document doInBackground() throws Exception {
				if(plug.getDocumentation().getContentType().equals(FORMAT_NOTIFICATION.MARKDOWN))
					return URLTools.extractMarkDownAsDocument(plug.getDocumentation().getUrl());
				else
					return URLTools.extractHtml(plug.getDocumentation().getUrl());
			}
		}, "Loading doc for "+ plug);
}
 
Example 30
Source Project: jdk8u60   Source File: ExceptionSafePlugin.java    License: 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;
}