Java Code Examples for javax.swing.ProgressMonitor#setProgress()

The following examples show how to use javax.swing.ProgressMonitor#setProgress() . 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
Source File: JPEGMovWriter.java    From pumpernickel with MIT License 6 votes vote down vote up
/**
 * 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++;
	}
}
 
Example 2
Source File: RanksResult.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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();

	}
 
Example 3
Source File: DownloadServerLogDialog.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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();
}
 
Example 4
Source File: Main.java    From Face-Recognition with GNU General Public License v3.0 6 votes vote down vote up
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();

}
 
Example 5
Source File: ImageViewer.java    From scifio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 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);
}
 
Example 6
Source File: MenuBarView.java    From rest-client with Apache License 2.0 4 votes vote down vote up
/**
* 
* @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);
    }

}
 
Example 7
Source File: FontPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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();
   }
 
Example 8
Source File: ExportImage.java    From Logisim with GNU General Public License v3.0 4 votes vote down vote up
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();

}
 
Example 9
Source File: LoginDialog.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
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();

}
 
Example 10
Source File: ProgressDialog.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
private void run(Component attach) {
	pm = new ProgressMonitor(attach, "", "Working...", 0, 100);
	pm.setProgress(0);
	t.addPropertyChangeListener(this);
	t.execute();
}
 
Example 11
Source File: HMProgressMonitorDialog.java    From hortonmachine with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 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);
}