Class ViewJProgressBar

All Implemented Interfaces:
ProgressBarInterface, ProgressChangeListener, ActionListener, WindowListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants
Direct Known Subclasses:
ViewJProgressBarMulti, ViewJSimpleProgressBar

public class ViewJProgressBar extends JFrame implements ActionListener, ProgressBarInterface, ProgressChangeListener, WindowListener
Progress bar used everywhere for displaying to the user how long the current process is going to take. The progress bar looks like this:
        +-Title------------------------+
        | Message                      |
        | |--------Bar--------| percent|
        |           Cancel             |
        +------------------------------+

 

The cancel button is not always present; that option is set in the constructor.

Version:
0.1 Oct 19, 1998
Author:
Matthew J. McAuliffe, Ph.D.
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Use serialVersionUID for interoperability.
      See Also:
    • PROGRESS_VALUE_UNCHANGED

      public static final int PROGRESS_VALUE_UNCHANGED
      DOCUMENT ME!
      See Also:
    • PROGRESS_WINDOW_CLOSING

      public static final int PROGRESS_WINDOW_CLOSING
      DOCUMENT ME!
      See Also:
    • LOCK_PROGRESS_MESSAGE

      public static final String LOCK_PROGRESS_MESSAGE
      Constant indicating whether to lock the message string so that other algorithms will not change this (sub-algorithms)
      See Also:
    • UNLOCK_PROGRESS_MESSAGE

      public static final String UNLOCK_PROGRESS_MESSAGE
      With the above variable, unlocks the message updating
      See Also:
    • cancelButton

      private JButton cancelButton
      Cancel button, if applicable.
    • messagePBar

      private JLabel messagePBar
      Label directly above the bar that is updated during operation if necessary.
    • pBar

      private JProgressBar pBar
      Actual bar which fills with color as the percentage of completion increases.
    • percentage

      private JLabel percentage
      Percentage label, puts a number next to the bar with the actual percent completed.
    • readyToDispose

      private boolean readyToDispose
      For users wanting to override the automatic closing option when progress reaches 100.
    • separateThread

      private boolean separateThread
      DOCUMENT ME!
    • title

      private String title
      Title of the frame for the progress bar.
    • messageLocked

      private boolean messageLocked
      indicates if the message string (in the progress bar) is locked so that it wont be updated
  • Constructor Details

    • ViewJProgressBar

      public ViewJProgressBar(String _title, String msg, int min, int max, boolean cancelFlag)
      Creates a new ViewJProgressBar object.
      Parameters:
      _title - DOCUMENT ME!
      msg - DOCUMENT ME!
      min - DOCUMENT ME!
      max - DOCUMENT ME!
      cancelFlag - DOCUMENT ME!
    • ViewJProgressBar

      public ViewJProgressBar(String _title, String msg, int min, int max, boolean cancelFlag, ActionListener actionListener, WindowListener windowListener)
      Creates a new progress bar with the given title, message, and min and max. The percentage is initially set to "0%". The cancelFlag indicates if there should be a cancel button - usually this is used for algorithms, which can be stopped, but not loading images.
      Parameters:
      _title - Title for the frame of the progress bar.
      msg - Message directly above the actual progress bar.
      min - Minimum value progress bar takes.
      max - Maximum value progress bar takes.
      cancelFlag - true indicates that the user can stop the process by clicking on the cancel button, and so the button should be added to the frame.
      actionListener - Listener to tie to cancel button.
      windowListener - Listener to tie to this frame.
    • ViewJProgressBar

      public ViewJProgressBar(String _title, String msg, int min, int max, boolean cancelFlag, ActionListener actionListener, WindowListener windowListener, boolean isVisible)
      Creates a new progress bar with the given title, message, and min and max. The percentage is initially set to "0%". The cancelFlag indicates if there should be a cancel button - usually this is used for algorithms, which can be stopped, but not loading images.
      Parameters:
      _title - Title for the frame of the progress bar.
      msg - Message directly above the actual progress bar.
      min - Minimum value progress bar takes.
      max - Maximum value progress bar takes.
      cancelFlag - true indicates that the user can stop the process by clicking on the cancel button, and so the button should be added to the frame.
      actionListener - Listener to tie to cancel button.
      windowListener - Listener to tie to this frame.
      isVisible - Whether to display the progress bar after it is first constructed. Note that the progress bar is never displayed if the -hide option was chosen by the user.
  • Method Details

    • getProgressFromFloat

      public static int getProgressFromFloat(int minProgressValue, int maxProgressValue, float percentage)
      DOCUMENT ME!
      Parameters:
      minProgressValue - DOCUMENT ME!
      maxProgressValue - DOCUMENT ME!
      percentage - DOCUMENT ME!
      Returns:
      DOCUMENT ME!
    • getProgressFromInt

      public static int getProgressFromInt(int minProgressValue, int maxProgressValue, int percentage)
      DOCUMENT ME!
      Parameters:
      minProgressValue - DOCUMENT ME!
      maxProgressValue - DOCUMENT ME!
      percentage - DOCUMENT ME!
      Returns:
      DOCUMENT ME!
    • actionPerformed

      public void actionPerformed(ActionEvent e)
      Closes this progress bar when the cancel button is clicked. This doesn't actually get called when the progress bar is running in the same thread.
      Specified by:
      actionPerformed in interface ActionListener
      Parameters:
      e - Event that triggered this method.
    • addActionListener

      public void addActionListener(ActionListener l)
      DOCUMENT ME!
      Parameters:
      l - DOCUMENT ME!
    • appendMessage

      public void appendMessage(String msg)
      Concatenates a message to the message area of the progress bar. Be sure to provide appropriate leading spacing.
      Specified by:
      appendMessage in interface ProgressBarInterface
      Parameters:
      msg - Message to be displayed.
    • getCancelButton

      public JButton getCancelButton()
      Get the cancel button
      Returns:
      canelButton cancel button
    • getMessageBar

      public JLabel getMessageBar()
      Get the message label.
      Returns:
      messagePBar message label.
    • getPercentageLabel

      public JLabel getPercentageLabel()
      Get the percentage label.
      Returns:
      percentage percentage label.
    • getProgressBar

      public JProgressBar getProgressBar()
      Get the progress bar.
      Specified by:
      getProgressBar in interface ProgressBarInterface
      Returns:
      pBar the progress bar.
    • getValue

      public int getValue()
      Used to get the present value of the progress bar.
      Specified by:
      getValue in interface ProgressBarInterface
      Returns:
      Value of progress bar.
    • isComplete

      public boolean isComplete()
      Used to determine if the progress bar is at 100%.
      Specified by:
      isComplete in interface ProgressBarInterface
      Returns:
      true if progress bar is at 100%, false if not.
    • progressStateChanged

      public void progressStateChanged(ProgressChangeEvent e)
      Implementation of the ProgressChangeListener interface.
      Specified by:
      progressStateChanged in interface ProgressChangeListener
      Parameters:
      e - DOCUMENT ME!
    • removeActionListener

      public void removeActionListener(ActionListener l)
      DOCUMENT ME!
      Parameters:
      l - DOCUMENT ME!
    • setIndeterminate

      public void setIndeterminate(boolean flag)
      Enable or disable the progress bar indeterminate mode.
      Parameters:
      flag - boolean
    • setMessage

      public void setMessage(String msg)
      Sets the message area of the progress bar.
      Specified by:
      setMessage in interface ProgressBarInterface
      Parameters:
      msg - Message to be displayed.
    • setReadyToDispose

      public void setReadyToDispose(boolean isReady)
      accessor to allow user to override the automatic closing (until they set this flag to true);
      Parameters:
      isReady - DOCUMENT ME!
    • setSeparateThread

      public void setSeparateThread(boolean flag)
      Changes whether the algorithm which is using this progress bar is running in its own thread.
      Parameters:
      flag - whether the progress bar's algorithm is running is a separate thread
    • setTitle

      public void setTitle(String _title)
      Sets the title of the frame of the progress bar.
      Specified by:
      setTitle in interface ProgressBarInterface
      Overrides:
      setTitle in class Frame
      Parameters:
      _title - Title of the frame.
    • setVisible

      public void setVisible(boolean visible)
      DOCUMENT ME!
      Specified by:
      setVisible in interface ProgressBarInterface
      Overrides:
      setVisible in class Window
      Parameters:
      visible - DOCUMENT ME!
    • updateValue

      public void updateValue(int value)
      Use this method if you are not running in a separate thread, or, you have already set the value of separateThread through the setSeparateThread method. Otherwise, use updateValue(int, boolean);
      Parameters:
      value - new progress bar value
    • updateValue

      public void updateValue(int value, boolean sepThread)
      Used to set the present value of the progress bar. Changes the percentage label and title of the frame as well.
      Specified by:
      updateValue in interface ProgressBarInterface
      Parameters:
      value - Set the progress bar to the given value.
      sepThread - Whether the calling algorithm is running in a separate thread
    • updateValueImmed

      public void updateValueImmed(int value)
      Used to set the present value of the progress bar. Changes the percentage label and title of the frame as well. It also forces an immediate update of the frame. Typically used when using IO functions.
      Parameters:
      value - Set the progress bar to the given value.
    • windowActivated

      public void windowActivated(WindowEvent event)
      Do nothing.
      Specified by:
      windowActivated in interface WindowListener
      Parameters:
      event - the window activated event
    • windowClosed

      public void windowClosed(WindowEvent event)
      Do nothing.
      Specified by:
      windowClosed in interface WindowListener
      Parameters:
      event - the window closed event
    • windowClosing

      public void windowClosing(WindowEvent event)
      Dispose the progress window.
      Specified by:
      windowClosing in interface WindowListener
      Parameters:
      event - event that triggered function
    • windowDeactivated

      public void windowDeactivated(WindowEvent event)
      Do nothing.
      Specified by:
      windowDeactivated in interface WindowListener
      Parameters:
      event - the window deactivated event
    • windowDeiconified

      public void windowDeiconified(WindowEvent event)
      Do nothing.
      Specified by:
      windowDeiconified in interface WindowListener
      Parameters:
      event - the window deiconified event
    • windowIconified

      public void windowIconified(WindowEvent event)
      Do nothing.
      Specified by:
      windowIconified in interface WindowListener
      Parameters:
      event - the window iconified event
    • windowOpened

      public void windowOpened(WindowEvent event)
      Do nothing.
      Specified by:
      windowOpened in interface WindowListener
      Parameters:
      event - the window opened event