edu.northwestern.at.utils.swing
Class ProgressDialog

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Dialog
                  extended by javax.swing.JDialog
                      extended by edu.northwestern.at.utils.swing.ModalDialog
                          extended by edu.northwestern.at.utils.swing.ProgressDialog
All Implemented Interfaces:
ProgressReporter, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.RootPaneContainer, javax.swing.WindowConstants
Direct Known Subclasses:
PrintProgressDialog, ProgressMonitorDialog, RepaginationProgressDialog

public class ProgressDialog
extends ModalDialog
implements ProgressReporter

Displays a progress dialog.

The progress dialog has a title, an updateable label field for explaining the current progress of the task, a progress bar for visually displaying the current progress of the task, and an optional cancel button for cancelling the task.

By default the cancel button does nothing except to close the status dialog. Override the "doCancel" method to add any processing you need for a cancel action.

The progress dialog should always be attached to a process running in a separate thread. The progress dialog will not be updated correctly by Swing unless it is executing in a separate thread.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JDialog
javax.swing.JDialog.AccessibleJDialog
 
Nested classes/interfaces inherited from class java.awt.Dialog
java.awt.Dialog.AccessibleAWTDialog, java.awt.Dialog.ModalExclusionType, java.awt.Dialog.ModalityType
 
Nested classes/interfaces inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  boolean cancelled
          True if progress dialog cancelled.
protected  java.awt.event.ActionListener cancelPressed
          Handle Cancel button pressed.
protected  int currentBarValue
          Current progress bar value.
protected static long defaultStartupDelay
          Default startup delay = 1.5 seconds.
protected  java.lang.String initLabel
          The initial value of the explanatory message.
protected  javax.swing.JLabel label
          Label for explanatory message.
protected  int labelWidth
          Nice wide label size.
protected  int maxBar
          Maximum value for progress bar.
protected  int minBar
          Minimum value for progress bar.
protected  java.awt.Window parentWindow
          Parent window for progress dialog.
protected  javax.swing.JProgressBar progressBar
          Progress bar indicating how far work has progressed.
protected  long startupDelay
          How many milliseconds to wait before displaying dialog.
protected  long startupTime
          Startup time for dialog.
 
Fields inherited from class edu.northwestern.at.utils.swing.ModalDialog
usePlatformPositionForDefaultButton
 
Fields inherited from class javax.swing.JDialog
accessibleContext, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Dialog
DEFAULT_MODALITY_TYPE
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ProgressDialog(java.lang.String title, java.lang.String initLabel, int minBar, int maxBar, boolean allowCancel)
          Create progress dialog.
ProgressDialog(java.lang.String title, java.lang.String initLabel, int minBar, int maxBar, boolean allowCancel, long startupDelay)
          Create progress dialog.
ProgressDialog(java.awt.Window parentWindow, java.lang.String title, java.lang.String initLabel, int minBar, int maxBar, boolean allowCancel)
          Create progress dialog.
ProgressDialog(java.awt.Window parentWindow, java.lang.String title, java.lang.String initLabel, int minBar, int maxBar, boolean allowCancel, long startupDelay)
          Create progress dialog.
 
Method Summary
 void close()
          Close the progress dialog.
protected  void doCancel()
          Action to take when cancel button pressed.
 int getCurrentBarValue()
          Get the current bar value.
 int getMaximumBarValue()
          Get the maximum bar value.
 boolean isCancelled()
          See if progress dialog cancelled.
 void makeVisible(boolean visible)
          Make the dialog visible or invisble.
 void setIndeterminate(boolean isIndeterminate)
          Set tbe progress bar determinate/indeterminate state.
 void setLabelColor(java.awt.Color color)
          Set the progress label text color.
 void setMaximumBarValue(int maxBar)
          Set maximum bar value.
 void setStartupTime(long startupTime)
          Set the startup time.
 void setTitle(java.lang.String title)
          Set the title.
 void updateProgress(int barValue)
          Update progress display.
 void updateProgress(int barValue, java.lang.String newLabel)
          Update progress display.
 void updateProgress(java.lang.String newLabel)
          Update progress display.
 
Methods inherited from class edu.northwestern.at.utils.swing.ModalDialog
add, add, add, add, add, addButton, addDefaultButton, fixDefaultButtonPosition, getUsePlatformPositionForDefaultButton, paintImmediately, setInitialFocus, setUsePlatformPositionForDefaultButton, setVisible, show, showUnpacked, showUnpacked
 
Methods inherited from class javax.swing.JDialog
addImpl, createRootPane, dialogInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
 
Methods inherited from class java.awt.Dialog
addNotify, getModalityType, getTitle, hide, isModal, isResizable, isUndecorated, setModal, setModalityType, setResizable, setUndecorated, show, toBack
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeNotify, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImage, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

minBar

protected int minBar
Minimum value for progress bar.


maxBar

protected int maxBar
Maximum value for progress bar.


label

protected javax.swing.JLabel label
Label for explanatory message.


initLabel

protected java.lang.String initLabel
The initial value of the explanatory message.


progressBar

protected javax.swing.JProgressBar progressBar
Progress bar indicating how far work has progressed.


currentBarValue

protected int currentBarValue
Current progress bar value.


cancelled

protected boolean cancelled
True if progress dialog cancelled.


defaultStartupDelay

protected static long defaultStartupDelay
Default startup delay = 1.5 seconds.


startupDelay

protected long startupDelay
How many milliseconds to wait before displaying dialog.


startupTime

protected long startupTime
Startup time for dialog.


parentWindow

protected java.awt.Window parentWindow
Parent window for progress dialog.


labelWidth

protected int labelWidth
Nice wide label size.


cancelPressed

protected java.awt.event.ActionListener cancelPressed
Handle Cancel button pressed.

Constructor Detail

ProgressDialog

public ProgressDialog(java.awt.Window parentWindow,
                      java.lang.String title,
                      java.lang.String initLabel,
                      int minBar,
                      int maxBar,
                      boolean allowCancel,
                      long startupDelay)
Create progress dialog.

Parameters:
parentWindow - The parent window.
title - Title for progress dialog.
initLabel - Initial text of label.
minBar - Minimum value for progress bar.
maxBar - Maximum value for progress bar.
allowCancel - Display a cancel button.
startupDelay - Startup delay. Dialog will not appear until this many milliseconds have passed since creation of dialog.

ProgressDialog

public ProgressDialog(java.lang.String title,
                      java.lang.String initLabel,
                      int minBar,
                      int maxBar,
                      boolean allowCancel,
                      long startupDelay)
Create progress dialog.

Parameters:
title - Title for progress dialog.
initLabel - Initial text of label.
minBar - Minimum value for progress bar.
maxBar - Maximum value for progress bar.
allowCancel - Display a cancel button.

ProgressDialog

public ProgressDialog(java.lang.String title,
                      java.lang.String initLabel,
                      int minBar,
                      int maxBar,
                      boolean allowCancel)
Create progress dialog.

Parameters:
title - Title for progress dialog.
initLabel - Initial text of label.
minBar - Minimum value for progress bar.
maxBar - Maximum value for progress bar.
allowCancel - Display a cancel button.

ProgressDialog

public ProgressDialog(java.awt.Window parentWindow,
                      java.lang.String title,
                      java.lang.String initLabel,
                      int minBar,
                      int maxBar,
                      boolean allowCancel)
Create progress dialog.

Parameters:
parentWindow - The parent window.
title - Title for progress dialog.
initLabel - Initial text of label.
minBar - Minimum value for progress bar.
maxBar - Maximum value for progress bar.
allowCancel - Display a cancel button.
Method Detail

setTitle

public void setTitle(java.lang.String title)
Set the title.

Specified by:
setTitle in interface ProgressReporter
Overrides:
setTitle in class java.awt.Dialog
Parameters:
title - The title.

doCancel

protected void doCancel()
Action to take when cancel button pressed.

Override this in derived subclasses to take a specified action when the cancel button is pressed. The only required action is to set the class variable "cancelled" to true.


isCancelled

public boolean isCancelled()
See if progress dialog cancelled.

Specified by:
isCancelled in interface ProgressReporter
Returns:
True if cancelled, false otherwise.

setStartupTime

public void setStartupTime(long startupTime)
Set the startup time.

Specified by:
setStartupTime in interface ProgressReporter
Parameters:
startupTime - The startup time in milliseconds.

updateProgress

public void updateProgress(int barValue,
                           java.lang.String newLabel)
Update progress display.

Specified by:
updateProgress in interface ProgressReporter
Parameters:
barValue - New value for progress bar. If negative, the current value remains unchanged.
newLabel - New label text. If null, the current label text is unchanged.

updateProgress

public void updateProgress(int barValue)
Update progress display.

Specified by:
updateProgress in interface ProgressReporter
Parameters:
barValue - New value for progress bar.

updateProgress

public void updateProgress(java.lang.String newLabel)
Update progress display.

Specified by:
updateProgress in interface ProgressReporter
Parameters:
newLabel - New label text. If null, the current label text is unchanged.

setLabelColor

public void setLabelColor(java.awt.Color color)
Set the progress label text color.

Specified by:
setLabelColor in interface ProgressReporter
Parameters:
color - Text color for progress label.

setMaximumBarValue

public void setMaximumBarValue(int maxBar)
Set maximum bar value.

Specified by:
setMaximumBarValue in interface ProgressReporter
Parameters:
maxBar - The new maximum bar value.

getCurrentBarValue

public int getCurrentBarValue()
Get the current bar value.

Specified by:
getCurrentBarValue in interface ProgressReporter
Returns:
The current bar value.

getMaximumBarValue

public int getMaximumBarValue()
Get the maximum bar value.

Specified by:
getMaximumBarValue in interface ProgressReporter
Returns:
The maximum value.

setIndeterminate

public void setIndeterminate(boolean isIndeterminate)
Set tbe progress bar determinate/indeterminate state.

Specified by:
setIndeterminate in interface ProgressReporter
Parameters:
isIndeterminate - true if indeterminate, false otherwise.

makeVisible

public void makeVisible(boolean visible)
Make the dialog visible or invisble.

Specified by:
makeVisible in interface ProgressReporter
Parameters:
visible - true to show dialog, false to hide.

close

public void close()
Close the progress dialog.

Specified by:
close in interface ProgressReporter