当前位置: 首页>>代码示例>>Java>>正文


Java SwingWorker类代码示例

本文整理汇总了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();
}
 
开发者ID:josmas,项目名称:openwonderland,代码行数:18,代码来源:HUDFrameHeader2D.java

示例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) {
    }
}
 
开发者ID:josmas,项目名称:openwonderland,代码行数:34,代码来源:HUDFrameHeader2D.java

示例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();
}
 
开发者ID:josmas,项目名称:openwonderland,代码行数:38,代码来源:HUDFrameHeader2D.java

示例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();
    }
}
 
开发者ID:josmas,项目名称:openwonderland,代码行数:17,代码来源:AsynchronousJTree.java

示例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();

}
 
开发者ID:premiummarkets,项目名称:pm,代码行数:30,代码来源:ProgressPanelDescriptor.java

示例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();
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:82,代码来源:ServerStatusView.java

示例7: submit

import org.jdesktop.swingworker.SwingWorker; //导入依赖的package包/类
public <V> Future<V> submit(SwingWorker<V,?> req) {
  execute(req);
  return req;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:5,代码来源:ThreadManager.java

示例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);
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:66,代码来源:WizardSupport.java

示例9: isPending

import org.jdesktop.swingworker.SwingWorker; //导入依赖的package包/类
public final boolean isPending()
/*  288:     */   {
/*  289: 716 */     return getState() == SwingWorker.StateValue.PENDING;
/*  290:     */   }
 
开发者ID:xiwc,项目名称:confluence.keygen,代码行数:5,代码来源:Task.java

示例10: isStarted

import org.jdesktop.swingworker.SwingWorker; //导入依赖的package包/类
public final boolean isStarted()
/*  293:     */   {
/*  294: 728 */     return getState() == SwingWorker.StateValue.STARTED;
/*  295:     */   }
 
开发者ID:xiwc,项目名称:confluence.keygen,代码行数:5,代码来源:Task.java

示例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));
}
 
开发者ID:josmas,项目名称:openwonderland,代码行数:56,代码来源:AsynchronousJTable.java

示例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));
    }
}
 
开发者ID:sing-group,项目名称:aibench-project,代码行数:74,代码来源:LoginService.java

示例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);
}
 
开发者ID:PistoiaHELM,项目名称:HELMEditor,代码行数:61,代码来源:ConvertNotationDialog.java


注:本文中的org.jdesktop.swingworker.SwingWorker类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。