下面列出了javax.swing.ProgressMonitor#setProgress ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Add all the frames from an AnimationReader.
*
* @param r
* the animation to read.
* @param monitor
* an optional ProgressMonitor to update
* @throws IOException
* if an error occurs copying frames.
*/
public void addFrames(AnimationReader r, ProgressMonitor monitor)
throws IOException {
if (monitor != null)
monitor.setMaximum(r.getFrameCount());
BufferedImage bi = r.getNextFrame(false);
int ctr = 1;
while (bi != null) {
if (monitor != null) {
if (monitor.isCanceled()) {
throw new UserCancelledException();
}
monitor.setProgress(ctr);
}
float d;
try {
d = (float) r.getFrameDuration();
} catch (Exception e) {
e.printStackTrace();
d = 1;
}
addFrame(d, bi, .98f);
bi = r.getNextFrame(false);
ctr++;
}
}
public RanksResult(JFrame parent,Ranks ranks,int bestNRanks,boolean ascendant){
super(parent,true);
//this.parent=parent;
this.bestNRanks=bestNRanks;
this.ranks=ranks;
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.factorCompare=ascendant?-1:1;
this.maxJump=ranks.getMaxJump();
this.stackWidth=ranks.getStackWidth();
progressMonitor=new ProgressMonitor(parent,AIRanksTool.getUIText("Result_Progress_Message"),"",0,100);
progressMonitor.setProgress(0);
task = new Task();
task.addPropertyChangeListener(this);
task.execute();
}
@Override
public void actionPerformed(ActionEvent event) {
String path = pathField.getText();
if (path.trim().isEmpty()) {
JOptionPane.showMessageDialog(this, "A file path must be selected.", "Empty File Path", JOptionPane.ERROR_MESSAGE);
return;
}
File selectedFile = new File(path);
if (selectedFile.exists()) {
this.setVisible(false);
int option = JOptionPane.showConfirmDialog(cliGuiCtx.getMainWindow(), "Overwrite " + path, "Overwrite?", JOptionPane.YES_NO_OPTION);
if (option == JOptionPane.NO_OPTION) {
this.setVisible(true);
return;
}
}
this.dispose();
progressMonitor = new ProgressMonitor(cliGuiCtx.getMainWindow(), "Downloading " + fileName, "", 0, 100);
progressMonitor.setProgress(0);
downloadTask = new DownloadLogTask(selectedFile);
downloadTask.addPropertyChangeListener(this);
downloadTask.execute();
}
public void run(JComponent parent, final Runnable calc, String title) {
bFinished = false;
progressMonitor = new ProgressMonitor(parent,
title, "", 0, 100);
progressMonitor.setProgress(0);
progressMonitor.setMillisToDecideToPopup(0);
timer = new Timer(100, new TimerListener());
final SwingWorker worker = new SwingWorker() {
public Object construct() {
thread = new Thread(calc);
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
return null;
}
};
worker.start();
timer.start();
}
/**
* Saves the current images to the given destination using the current format
* writer.
*/
public void save(final Location id) {
if (images == null) return;
wait(true);
try {
myWriter.setDest(id);
final boolean stack = myWriter.canDoStacks();
final ProgressMonitor progress = new ProgressMonitor(this, "Saving " + id,
null, 0, stack ? images.length : 1);
if (stack) {
// save entire stack
for (int i = 0; i < images.length; i++) {
progress.setProgress(i);
final boolean canceled = progress.isCanceled();
myWriter.savePlane(0, i, getPlane(images[i]));
if (canceled) break;
}
progress.setProgress(images.length);
}
else {
// save current image only
myWriter.savePlane(0, 0, getPlane(getImage()));
progress.setProgress(1);
}
myWriter.close();
}
catch (FormatException | IOException exc) {
logService.info("", exc);
}
wait(false);
}
/**
*
* @Title: testPerformed
* @Description: Test Menu Item Performed
* @param @param item
* @return void
* @throws
*/
private void testPerformed(JMenuItem item)
{
if (RESTConst.START_TEST.equals(item.getText()))
{
if (MapUtils.isEmpty(RESTCache.getHists()))
{
return;
}
miStart.setEnabled(false);
miStop.setEnabled(true);
HttpHists hists = new HttpHists(RESTCache.getHists().values());
pm = new ProgressMonitor(RESTView.getView(), RESTConst.TEST_CASE, "", 0, hists.getTotal());
pm.setProgress(0);
task = new HistTask(hists);
task.addPropertyChangeListener(this);
task.execute();
testThrd = new TestThd(hists);
testThrd.setName(RESTConst.TEST_THREAD);
RESTThdPool.getInstance().getPool().submit(testThrd);
}
if (RESTConst.STOP_TEST.equals(item.getText()))
{
if (null == testThrd)
{
return;
}
try
{
miStop.setEnabled(false);
pm.close();
task.cancel(true);
testThrd.getHists().setStop(true);
testThrd.interrupt();
miStart.setEnabled(true);
}
catch(Exception ex)
{
log.error("Failed to interrupt test thread.", ex);
}
}
if (RESTConst.TEST_REPORT.equals(item.getText()))
{
TestUtil.open(RESTConst.REPORT_HTML,
RESTConst.MSG_REPORT,
RESTConst.TEST_REPORT);
}
}
private void updateFontList() {
Runnable whenDone = new Runnable() {
@Override
public void run() {
fontListUpdated();
}
};
this.continuation = whenDone;
setModal(true);
final GetFontsWorker worker = new GetFontsWorker(this, showFixed, size, style);
progressMonitor = new ProgressMonitor(this,
Catalog.get("MSG_TakingInventory"),// NOI18N
" ", // NOI18N
0, 2);
// TMP progressMonitor.setMillisToDecideToPopup(0);
// TMP progressMonitor.setMillisToPopup(0);
// kick-start it so the progress dialog becomes visible.
progressMonitor.setProgress(1);
// Track notifications from worker and update pogressMonitor
worker.addPropertyChangeListener(new PropertyChangeListener() {
private boolean ckCancel() {
// SwingWorker queues up "progress" notificatons so
// it's possible that we receive some after SwingWorker.done()
// is called! If we then call setProgress() it "resurrects"
// a closed ProgresMonitor.
if (worker.isCancelled()) {
return true;
} else if (progressMonitor == null || progressMonitor.isCanceled()) {
boolean withInterrupts = true;
worker.cancel(withInterrupts);
return true;
} else {
return false;
}
}
@Override
public void propertyChange(PropertyChangeEvent evt) {
switch (evt.getPropertyName()) {
case "progress":// NOI18N
if (ckCancel())
return;
progressMonitor.setProgress((Integer) evt.getNewValue());
break;
case GetFontsWorker.PROP_NFONTS:
if (ckCancel())
return;
progressMonitor.setNote(Catalog.get("MSG_CheckingFixedWidth")); // NOI18N
progressMonitor.setMaximum((Integer) evt.getNewValue());
break;
}
}
});
worker.execute();
}
static void doExport(Project proj) {
// First display circuit/parameter selection dialog
Frame frame = proj.getFrame();
CircuitJList list = new CircuitJList(proj, true);
if (list.getModel().getSize() == 0) {
JOptionPane.showMessageDialog(proj.getFrame(), Strings.get("exportEmptyCircuitsMessage"),
Strings.get("exportEmptyCircuitsTitle"), JOptionPane.YES_NO_OPTION);
return;
}
OptionsPanel options = new OptionsPanel(list);
int action = JOptionPane.showConfirmDialog(frame, options, Strings.get("exportImageSelect"),
JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (action != JOptionPane.OK_OPTION)
return;
List<Circuit> circuits = list.getSelectedCircuits();
double scale = options.getScale();
boolean printerView = options.getPrinterView();
if (circuits.isEmpty())
return;
ImageFileFilter filter;
int fmt = options.getImageFormat();
switch (options.getImageFormat()) {
case FORMAT_GIF:
filter = new ImageFileFilter(fmt, Strings.getter("exportGifFilter"), new String[] { "gif" });
break;
case FORMAT_PNG:
filter = new ImageFileFilter(fmt, Strings.getter("exportPngFilter"), new String[] { "png" });
break;
case FORMAT_JPG:
filter = new ImageFileFilter(fmt, Strings.getter("exportJpgFilter"),
new String[] { "jpg", "jpeg", "jpe", "jfi", "jfif", "jfi" });
break;
default:
System.err.println("unexpected format; aborted"); // OK
return;
}
// Then display file chooser
Loader loader = proj.getLogisimFile().getLoader();
JFileChooser chooser = loader.createChooser();
if (circuits.size() > 1) {
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setDialogTitle(Strings.get("exportImageDirectorySelect"));
} else {
chooser.setFileFilter(filter);
chooser.setDialogTitle(Strings.get("exportImageFileSelect"));
}
int returnVal = chooser.showDialog(frame, Strings.get("exportImageButton"));
if (returnVal != JFileChooser.APPROVE_OPTION)
return;
// Determine whether destination is valid
File dest = chooser.getSelectedFile();
chooser.setCurrentDirectory(dest.isDirectory() ? dest : dest.getParentFile());
if (dest.exists()) {
if (!dest.isDirectory()) {
int confirm = JOptionPane.showConfirmDialog(proj.getFrame(), Strings.get("confirmOverwriteMessage"),
Strings.get("confirmOverwriteTitle"), JOptionPane.YES_NO_OPTION);
if (confirm != JOptionPane.YES_OPTION)
return;
}
} else {
if (circuits.size() > 1) {
boolean created = dest.mkdir();
if (!created) {
JOptionPane.showMessageDialog(proj.getFrame(), Strings.get("exportNewDirectoryErrorMessage"),
Strings.get("exportNewDirectoryErrorTitle"), JOptionPane.YES_NO_OPTION);
return;
}
}
}
// Create the progress monitor
ProgressMonitor monitor = new ProgressMonitor(frame, Strings.get("exportImageProgress"), null, 0, 10000);
monitor.setMillisToDecideToPopup(100);
monitor.setMillisToPopup(200);
monitor.setProgress(0);
// And start a thread to actually perform the operation
// (This is run in a thread so that Swing will update the
// monitor.)
new ExportThread(frame, frame.getCanvas(), dest, filter, circuits, scale, printerView, monitor).start();
}
private void loginButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loginButtonActionPerformed
signup.setEnabled(false);
loginButton.setEnabled(false);
user.setEnabled(false);
password.setEnabled(false);
final ProgressMonitor mon = new ProgressMonitor(this, "Logging In", "Connecting To Server", 0, 100);
mon.setMillisToDecideToPopup(0);
mon.setProgress(1);
new Thread() {
public void run() {
try {
mon.setProgress(40);
URL u = new URL("https://codename-one.appspot.com/getData?m=login&u=" + URLEncoder.encode(user.getText(), "UTF-8") +
"&p=" + URLEncoder.encode(password.getText(), "UTF-8"));
InputStream i = u.openStream();
byte[] b = new byte[4];
i.read(b);
i.close();
mon.setProgress(90);
// success
if(b[0] == 'O') {
Preferences p = Preferences.userNodeForPackage(getClass());
if(remember.isSelected()) {
p.put("user", user.getText());
p.put("pass", password.getText());
} else {
p.remove("user");
p.remove("pass");
}
globalPassword = password.getText();
globalUser = user.getText();
dispose();
} else {
signup.setEnabled(true);
loginButton.setEnabled(true);
user.setEnabled(true);
password.setEnabled(true);
// fail
if(b[0] == 'F') {
signup.setText("Login Failed, check user/password");
} else {
// unknown error maybe proxy
JOptionPane.showMessageDialog(LoginDialog.this, "Login Failed", "Unable to connect, check proxy settings", JOptionPane.ERROR_MESSAGE);
}
}
mon.close();
} catch (Exception ex) {
ex.printStackTrace();
signup.setEnabled(true);
loginButton.setEnabled(true);
user.setEnabled(true);
password.setEnabled(true);
JOptionPane.showMessageDialog(LoginDialog.this, "Login Failed", "Internal Error:\n" + ex, JOptionPane.ERROR_MESSAGE);
}
}
}.start();
}
private void run(Component attach) {
pm = new ProgressMonitor(attach, "", "Working...", 0, 100);
pm.setProgress(0);
t.addPropertyChangeListener(this);
t.execute();
}
/**
* Create the monitor dialog.
*
* @param parent the parent component.
* @param title the title of the monitor dialog.
* @param workLoad the maximum work to do.
*/
public HMProgressMonitorDialog( Component parent, String title, int workLoad ) {
this.parent = parent;
progressMonitor = new ProgressMonitor(parent, title, "", 0, workLoad);
progressMonitor.setProgress(0);
}