本文整理汇总了Java中org.jdesktop.swingworker.SwingWorker类的典型用法代码示例。如果您正苦于以下问题:Java SwingWorker类的具体用法?Java SwingWorker怎么用?Java SwingWorker使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SwingWorker类属于org.jdesktop.swingworker包,在下文中一共展示了SwingWorker类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: notifyActionListeners
import org.jdesktop.swingworker.SwingWorker; //导入依赖的package包/类
public void notifyActionListeners(final ActionEvent e) {
(new SwingWorker<String, Object>() {
@Override
public String doInBackground() {
if (actionListeners != null) {
ListIterator<ActionListener> iter = actionListeners.listIterator();
while (iter.hasNext()) {
ActionListener listener = iter.next();
listener.actionPerformed(e);
}
iter = null;
}
return null;
}
}).execute();
}
示例2: notifyMouseMotionListeners
import org.jdesktop.swingworker.SwingWorker; //导入依赖的package包/类
public void notifyMouseMotionListeners(final MouseEvent e) {
SwingWorker worker = new SwingWorker<String, Object>() {
@Override
public String doInBackground() {
if (mouseMotionListeners != null) {
e.setSource(this);
ListIterator<MouseMotionListener> iter = mouseMotionListeners.listIterator();
while (iter.hasNext()) {
MouseMotionListener listener = iter.next();
switch (e.getID()) {
case MouseEvent.MOUSE_MOVED:
listener.mouseMoved(e);
break;
case MouseEvent.MOUSE_DRAGGED:
listener.mouseDragged(e);
break;
default:
break;
}
}
iter = null;
}
return null;
}
};
worker.execute();
try {
worker.get();
} catch (Exception ie) {
}
}
示例3: notifyMouseListeners
import org.jdesktop.swingworker.SwingWorker; //导入依赖的package包/类
public void notifyMouseListeners(final MouseEvent e) {
(new SwingWorker<String, Object>() {
@Override
public String doInBackground() {
if (mouseListeners != null) {
e.setSource(this);
ListIterator<MouseListener> iter = mouseListeners.listIterator();
while (iter.hasNext()) {
MouseListener listener = iter.next();
switch (e.getID()) {
case MouseEvent.MOUSE_ENTERED:
listener.mouseEntered(e);
break;
case MouseEvent.MOUSE_EXITED:
listener.mouseExited(e);
break;
case MouseEvent.MOUSE_PRESSED:
listener.mousePressed(e);
break;
case MouseEvent.MOUSE_RELEASED:
listener.mouseReleased(e);
break;
case MouseEvent.MOUSE_CLICKED:
listener.mouseReleased(e);
break;
default:
break;
}
}
iter = null;
}
return null;
}
}).execute();
}
示例4: stopWorker
import org.jdesktop.swingworker.SwingWorker; //导入依赖的package包/类
/**
* Stops the active worker, if any. This is always called on the AWT Event
* Thread.
*/
private void stopWorker(AsyncTreeNode node) {
// Check to see if there is an active worker for the give node. Since
// this is always called on the AWT Event Thread, we do not need to
// separately synchronize around the Map of workers.
SwingWorker worker = workerMap.get(node);
if (worker != null) {
worker.cancel(true);
workerMap.remove(node);
updateCursor();
}
}
示例5: displayingPanel
import org.jdesktop.swingworker.SwingWorker; //导入依赖的package包/类
@Override
public void displayingPanel() {
task = new Task(InstallFolderPanel.getInstallFolder(), this, panel3);
task.execute();
SwingWorker<Void, Void> deltaPrg = new SwingWorker<Void,Void>() {
@Override
protected Void doInBackground() throws Exception {
synchronized (this) {
while (!done) {
try {
this.wait(5000);
task.comeOn(PROGRESSBAR_FAKEINC, "backgroundInc");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
return null;
}
};
deltaPrg.execute();
}
示例6: refresh
import org.jdesktop.swingworker.SwingWorker; //导入依赖的package包/类
private void refresh(final int page) {
if (page == 0) {
if (cur_request != null && !cur_request.isDone()) return;
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
cur_request = new SwingWorker<ServerStatus.ModuleSummary[],Void>() {
@Override
public ServerStatus.ModuleSummary[] doInBackground() {
return status.getStatus();
}
@Override
protected void done() {
try {
if (getSelectedIndex() == 0) {
refresh(model, get());
fireSelectionChanged();
}
}
catch (InterruptedException ex) {
ErrorDialog.bug(ex);
}
// FIXME: review error message
catch (ExecutionException ex) {
ex.printStackTrace();
}
if (hist_request == null || hist_request.isDone())
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
cur_request = null;
}
};
cur_request.execute();
}
else {
if (hist_request != null && !hist_request.isDone()) return;
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
hist_request = new SwingWorker<ServerStatus.ModuleSummary[],Void>() {
@Override
public ServerStatus.ModuleSummary[] doInBackground() {
return status.getHistory(getTitleAt(page));
}
@Override
protected void done() {
final int sel = getSelectedIndex();
if (sel == page) {
// page didn't change, refresh with what we computed
try {
refresh(historicalModels[sel-1], get());
}
// FIXME: review error message
catch (InterruptedException ex) {
ex.printStackTrace();
}
// FIXME: review error message
catch (ExecutionException ex) {
ex.printStackTrace();
}
fireSelectionChanged();
}
else if (sel != 0) {
// page changed, refresh that page instead
hist_request = null;
refresh(sel);
}
if (cur_request == null || cur_request.isDone())
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
};
hist_request.execute();
}
}
示例7: submit
import org.jdesktop.swingworker.SwingWorker; //导入依赖的package包/类
public <V> Future<V> submit(SwingWorker<V,?> req) {
execute(req);
return req;
}
示例8: showWelcomeWizard
import org.jdesktop.swingworker.SwingWorker; //导入依赖的package包/类
/**
* Show the "Welcome" wizard, shown when loading a module in play mode
*
*/
public void showWelcomeWizard() {
final GameModule g = GameModule.getGameModule();
final Boolean showWizard = (Boolean) Prefs.getGlobalPrefs().getValue(WELCOME_WIZARD_KEY);
if (! Boolean.TRUE.equals(showWizard)) {
g.getFrame().setVisible(true);
// prompt for username and password if wizard is off
// but no username is set
// FIXME: this belongs outside of the wizard, not here
final String name = (String) g.getPrefs().getValue(GameModule.REAL_NAME);
if (name == null || name.equals("newbie")) {
new UsernameAndPasswordDialog(g.getFrame()).setVisible(true);
}
return;
}
final WizardBranchController c = createWelcomeWizard();
final Wizard welcomeWizard = c.createWizard();
final HashMap<String, Wizard> props = new HashMap<String, Wizard>();
props.put(WELCOME_WIZARD_KEY, welcomeWizard);
Action help = null;
try {
help = new ShowHelpAction(new URL("http://www.vassalengine.org/wiki/doku.php?id=getting_started:getting_started"), null);
}
catch (MalformedURLException e) {
ErrorDialog.bug(e);
}
final Object result =
WizardDisplayer.showWizard(welcomeWizard, null, help, props);
if (result instanceof Map) {
final Map m = (Map) result;
final Object action = m.get(ACTION_KEY);
if (PLAY_ONLINE_ACTION.equals(action)) {
final ChatServerControls controls =
((BasicModule) g).getServerControls();
g.getFrame().setVisible(true);
controls.toggleVisible();
new SwingWorker<Void,Void>() {
@Override
protected Void doInBackground() {
controls.getClient().setConnected(true);
return null;
}
}.execute();
}
else {
g.getGameState().setup(true);
g.getFrame().setVisible(true);
}
}
else {
g.getFrame().setVisible(true);
}
}
示例9: isPending
import org.jdesktop.swingworker.SwingWorker; //导入依赖的package包/类
public final boolean isPending()
/* 288: */ {
/* 289: 716 */ return getState() == SwingWorker.StateValue.PENDING;
/* 290: */ }
示例10: isStarted
import org.jdesktop.swingworker.SwingWorker; //导入依赖的package包/类
public final boolean isStarted()
/* 293: */ {
/* 294: 728 */ return getState() == SwingWorker.StateValue.STARTED;
/* 295: */ }
示例11: startWorker
import org.jdesktop.swingworker.SwingWorker; //导入依赖的package包/类
/**
* Asynchronously loads the chidren of the given content collection and
* updates the table model.
*/
private void startWorker(final ContentCollection collection) {
// Create a new SwingWorker to find the children for the given directory
// and when done, update the list model.
worker = new SwingWorker<List<ContentNode>, Void>() {
@Override
protected void done() {
// Set the worker to null and stop the animation, but only if we
// are the active worker.
if (worker == this) {
worker = null;
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
// Fetch the children from the asynchronous worker. Upon an
// exception, log an error and return
List<ContentNode> children = null;
try {
children = get();
tableModel.setNodeList(children);
} catch (java.util.concurrent.CancellationException excp) {
// Just ignore this exception. This happens when a node is
// closed before it has time to finish loading. It is a normal
// condition, not exceptional at all.
return;
} catch (java.lang.InterruptedException excp) {
// event-dispatch thread won't be interrupted
logger.log(Level.WARNING, "Failed to get children for " +
collection.toString(), excp);
throw new IllegalStateException(excp + "");
} catch (java.lang.Exception excp) {
logger.log(Level.WARNING, "Failed to get children for " +
collection.toString(), excp);
return;
}
}
@Override
protected List<ContentNode> doInBackground() throws Exception {
if (collection == null) {
return new LinkedList();
}
return collection.getChildren();
}
};
// Start worker, update status line, and start animation.
worker.execute();
setCursor(new Cursor(Cursor.WAIT_CURSOR));
}
示例12: startAuthentication
import org.jdesktop.swingworker.SwingWorker; //导入依赖的package包/类
/**
* This method starts the authentication process and is either synchronous
* or asynchronous based on the synchronous property
*
* @param user
* user
* @param password
* password
* @param server
* server
* @throws Exception
*/
public void startAuthentication(final String user, final char[] password,
final String server) throws Exception {
if (getSynchronous()) {
try {
if (authenticate(user, password, server)) {
fireLoginSucceeded(new LoginEvent(this));
} else {
fireLoginFailed(new LoginEvent(this));
}
} catch (Throwable e) {
fireLoginFailed(new LoginEvent(this, e));
}
} else {
loginWorker = new SwingWorker<Boolean, Void>() {
protected Boolean doInBackground() throws Exception {
try {
final boolean result = authenticate(user, password,
server);
if (isCancelled()) {
EventQueue.invokeLater(new Runnable() {
public void run() {
fireLoginCanceled(new LoginEvent(this));
}
});
return false;
}
EventQueue.invokeLater(new Runnable() {
public void run() {
if (result) {
fireLoginSucceeded(new LoginEvent(
LoginService.this));
} else {
fireLoginFailed(new LoginEvent(
LoginService.this));
}
}
});
return result;
} catch (final Throwable failed) {
if (!isCancelled()) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
fireLoginFailed(new LoginEvent(
LoginService.this, failed));
}
});
} else {
EventQueue.invokeLater(new Runnable() {
public void run() {
fireLoginCanceled(new LoginEvent(this));
}
});
}
return false;
}
}
};
loginWorker.execute();
fireLoginStarted(new LoginEvent(this));
}
}
示例13: configComponents
import org.jdesktop.swingworker.SwingWorker; //导入依赖的package包/类
private void configComponents() {
setTitle("HELM Notation Converter");
setIconImage(IconGenerator
.getImage(IconGenerator.HELM_APP_ICON_RESOURCE_URL));
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
setLocationRelativeTo(_editor.getFrame());
_convertNotation.setIcon(IconGenerator
.getIcon(IconGenerator.FORWARD_ARROW_ICON_RESOURCE_URL));
_convertNotation.setVerticalTextPosition(SwingConstants.CENTER);
_convertNotation.setHorizontalTextPosition(SwingConstants.LEFT);
_toNotationArea.setEditable(false);
_toNotationArea.setLineWrap(true);
_fromNotationArea.setEditable(true);
_fromNotationArea.setLineWrap(true);
_convertNotation.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SwingWorker<Void, String> worker = new SwingWorker<Void, String>() {
private String _convertingResult;
@Override
protected void done() {
_toNotationArea.setText(_convertingResult);
(ConvertNotationDialog.this).setCursor(Cursor
.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
(ConvertNotationDialog.this)
.setControlsState(CONTROLS_ENABLED);
}
protected Void doInBackground() throws Exception {
(ConvertNotationDialog.this)
.setControlsState(CONTROLS_BLOCKED);
(ConvertNotationDialog.this).setCursor(Cursor
.getPredefinedCursor(Cursor.WAIT_CURSOR));
_convertingResult = convertinNotationProcess();
return null;
}
};
worker.execute();
}
});
_closeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
dispose();
}
});
_selectToNotation.setSelectedIndex(DEFAULT_SELECTED_INDEX);
}