edu.northwestern.at.utils.swing
Class ProgressPanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by edu.northwestern.at.utils.swing.ProgressPanel
All Implemented Interfaces:
ProgressReporter, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class ProgressPanel
extends javax.swing.JPanel
implements ProgressReporter

Displays progress in a panel.

The progress panel an updateable label field for explaining the current progress of the task and a progress bar for visually displaying the current progress of the task. This is essentially the same as a ProgressDialog but the ProgressPanel can be embedded in another panel or window.

A progress panel supports but does not provide a cancel button. You may create a cancel button externally and invoke the progress panel's "doCancel" method as the button press action. Override the "doCancel" method to add any processing you need for a cancel action.

The progress panel is updated twice a second using a timer. This ensures correct behavior regardless of the originating thread.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
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 panel 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  javax.swing.JLabel label
          Label for explanatory message.
protected  java.awt.Color labelColor
          The label color.
protected  java.lang.String labelText
          The current value of the 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  boolean nowIndeterminate
          True if the progress display is indeterminate.
protected  boolean nowVisible
          True if the progress display is visible.
static int ONE_SECOND
          One second in thousandths of a second.
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.
protected  javax.swing.Timer timer
          The timer used to update the display a one second intervals.
protected  javax.swing.JLabel titleLabel
          Title.
protected  java.lang.String titleText
          The current value of the title.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ProgressPanel(java.lang.String title, java.lang.String initLabel)
          Create progress panel with specified title and initial label.
ProgressPanel(java.lang.String title, java.lang.String initLabel, int minBar, int maxBar, long startupDelay)
          Create progress panel.
 
Method Summary
 void close()
          Close.
protected  void doCancel()
          Action to take when cancel button pressed.
protected  void doClose()
          Action to take when panel closed.
 java.awt.event.ActionListener getCancelPressedAction()
          Return cancel action listener.
 int getCurrentBarValue()
          Get the current bar value.
 int getMaximumBarValue()
          Get the maximum bar value.
 boolean isCancelled()
          See if progress panel 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 newBarValue)
          Update progress display.
 void updateProgress(int newBarValue, java.lang.String newLabelText)
          Update progress display.
 void updateProgress(java.lang.String newLabelText)
          Update progress display.
protected  void updateProgressDisplay()
          Updates the progress display.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, 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.


titleLabel

protected javax.swing.JLabel titleLabel
Title.


titleText

protected java.lang.String titleText
The current value of the title.


label

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


labelText

protected java.lang.String labelText
The current value of the explanatory message.


labelColor

protected java.awt.Color labelColor
The label color.


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 panel 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.


labelWidth

protected int labelWidth
Nice wide label size.


nowVisible

protected boolean nowVisible
True if the progress display is visible.


nowIndeterminate

protected boolean nowIndeterminate
True if the progress display is indeterminate.


timer

protected javax.swing.Timer timer
The timer used to update the display a one second intervals.


ONE_SECOND

public static final int ONE_SECOND
One second in thousandths of a second.

See Also:
Constant Field Values

cancelPressed

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

Constructor Detail

ProgressPanel

public ProgressPanel(java.lang.String title,
                     java.lang.String initLabel,
                     int minBar,
                     int maxBar,
                     long startupDelay)
Create progress panel.

Parameters:
title - Title for progress display.
initLabel - Initial text of label.
minBar - Minimum value for progress bar.
maxBar - Maximum value for progress bar.
startupDelay - Startup delay. Dialog will not appear until this many milliseconds have passed since creation of dialog.

ProgressPanel

public ProgressPanel(java.lang.String title,
                     java.lang.String initLabel)
Create progress panel with specified title and initial label.

Parameters:
title - Title for progress display.
initLabel - Initial text of label.
Method Detail

setTitle

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

Specified by:
setTitle in interface ProgressReporter
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.


getCancelPressedAction

public java.awt.event.ActionListener getCancelPressedAction()
Return cancel action listener.

Returns:
Action listener for cancel button.

Use to create a cancel button externally.


doClose

protected void doClose()
Action to take when panel closed.

Override this in derived subclasses to take a specified action when the panel is closed.


isCancelled

public boolean isCancelled()
See if progress panel 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 newBarValue,
                           java.lang.String newLabelText)
Update progress display.

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

updateProgress

public void updateProgress(int newBarValue)
Update progress display.

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

updateProgress

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

Specified by:
updateProgress in interface ProgressReporter
Parameters:
newLabelText - 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.

Specified by:
close in interface ProgressReporter

updateProgressDisplay

protected void updateProgressDisplay()
Updates the progress display.

UpdateProgress is guaranteed to run on the AWT event thread since it is called from the timer's actionPerformed handler method.