javax.swing

Class ProgressMonitor


public class ProgressMonitor
extends Object

Using this class you can easily monitor tasks where you cannot estimate the duration exactly.

A ProgressMonitor instance waits until the first time setProgress is called. When millisToDecideToPopup time elapsed the instance estimates the duration until the whole operation is completed. If this duration exceeds millisToPopup a non-modal dialog with a message and a progress bar is shown.

The value of millisToDecideToPopup defaults to 500 and millisToPopup to 2000.

Since:
1.2

Field Summary

protected AccessibleContext
accessibleContext
The accessible content for this component

Constructor Summary

ProgressMonitor(Component component, Object message, String note, int minimum, int maximum)
Creates a new ProgressMonitor instance.

Method Summary

void
close()
Hides the dialog and stops any measurements.

Has no effect when setProgress is not at least called once.

AccessibleContext
getAccessibleContext()
Gets the accessible context.
int
getMaximum()
Return the maximum or end value of your operation.
int
getMillisToDecideToPopup()
Returns the amount of milliseconds to wait until the ProgressMonitor should decide whether a progress dialog is to be shown or not.
int
getMillisToPopup()
Returns the number of milliseconds to wait before displaying the progress dialog.
int
getMinimum()
Returns the minimum or start value of the operation.
String
getNote()
Returns a message which is shown in the progress dialog.
boolean
isCanceled()
Returns whether the user canceled the operation.
void
setMaximum(int maximum)
Sets the maximum or end value of the operation to the given integer.
void
setMillisToDecideToPopup(int time)
Sets the amount of milliseconds to wait until the ProgressMonitor should decide whether a progress dialog is to be shown or not.
void
setMillisToPopup(int time)
Sets the number of milliseconds to wait before displaying the progress dialog.
void
setMinimum(int minimum)
Use this method to set the minimum or start value of your operation.

For typical application like copy operation this will be zero.

Keep in mind that changing this value after the progress dialog is made visible has no effect upon the progress bar.

void
setNote(String note)
Set the message shown in the progess dialog.

Changing the note while the progress dialog is visible is possible.

void
setProgress(int progress)
Updates the progress value.

When called for the first time this initializes a timer which decides after millisToDecideToPopup time whether to show a progress dialog or not.

If the progress value equals or exceeds the maximum value the progress dialog is closed automatically.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

accessibleContext

protected AccessibleContext accessibleContext
The accessible content for this component

Constructor Details

ProgressMonitor

public ProgressMonitor(Component component,
                       Object message,
                       String note,
                       int minimum,
                       int maximum)
Creates a new ProgressMonitor instance. This is used to monitor a task and pops up a dialog if the task is taking a long time to run.
Parameters:
component - The parent component of the progress dialog or null.
message - A constant message object which works in the way it does in JOptionPane.
note - A string message which can be changed while the operation goes on.
minimum - The minimum value for the operation (start value).
maximum - The maximum value for the operation (end value).

Method Details

close

public void close()
Hides the dialog and stops any measurements.

Has no effect when setProgress is not at least called once.


getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the accessible context.
Returns:
the accessible context.

getMaximum

public int getMaximum()
Return the maximum or end value of your operation.
Returns:
Maximum or end value.

getMillisToDecideToPopup

public int getMillisToDecideToPopup()
Returns the amount of milliseconds to wait until the ProgressMonitor should decide whether a progress dialog is to be shown or not.
Returns:
The duration in milliseconds.

getMillisToPopup

public int getMillisToPopup()
Returns the number of milliseconds to wait before displaying the progress dialog. The default value is 2000.
Returns:
The number of milliseconds.

getMinimum

public int getMinimum()
Returns the minimum or start value of the operation.
Returns:
Minimum or start value of the operation.

getNote

public String getNote()
Returns a message which is shown in the progress dialog.
Returns:
The changeable message visible in the progress dialog.

isCanceled

public boolean isCanceled()
Returns whether the user canceled the operation.
Returns:
Whether the operation was canceled.

setMaximum

public void setMaximum(int maximum)
Sets the maximum or end value of the operation to the given integer.
Parameters:
maximum -

setMillisToDecideToPopup

public void setMillisToDecideToPopup(int time)
Sets the amount of milliseconds to wait until the ProgressMonitor should decide whether a progress dialog is to be shown or not.

This method has no effect when the progress dialog is already visible.

Parameters:
time - The duration in milliseconds.

setMillisToPopup

public void setMillisToPopup(int time)
Sets the number of milliseconds to wait before displaying the progress dialog.
Parameters:
time - the number of milliseconds.

setMinimum

public void setMinimum(int minimum)
Use this method to set the minimum or start value of your operation.

For typical application like copy operation this will be zero.

Keep in mind that changing this value after the progress dialog is made visible has no effect upon the progress bar.

Parameters:
minimum - The new minimum value.

setNote

public void setNote(String note)
Set the message shown in the progess dialog.

Changing the note while the progress dialog is visible is possible.

Parameters:
note - A message shown in the progress dialog.

setProgress

public void setProgress(int progress)
Updates the progress value.

When called for the first time this initializes a timer which decides after millisToDecideToPopup time whether to show a progress dialog or not.

If the progress value equals or exceeds the maximum value the progress dialog is closed automatically.

Parameters:
progress - New progress value.

ProgressMonitor.java -- Copyright (C) 2002, 2004, 2005, 2006, Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.