Class ViewJProgressBar

  • All Implemented Interfaces:
    ProgressBarInterface, ProgressChangeListener, java.awt.event.ActionListener, java.awt.event.WindowListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.RootPaneContainer, javax.swing.WindowConstants
    Direct Known Subclasses:
    ViewJProgressBarMulti, ViewJSimpleProgressBar

    public class ViewJProgressBar
    extends javax.swing.JFrame
    implements java.awt.event.ActionListener, ProgressBarInterface, ProgressChangeListener, java.awt.event.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:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class javax.swing.JFrame

        javax.swing.JFrame.AccessibleJFrame
      • Nested classes/interfaces inherited from class java.awt.Frame

        java.awt.Frame.AccessibleAWTFrame
      • Nested classes/interfaces inherited from class java.awt.Window

        java.awt.Window.AccessibleAWTWindow, java.awt.Window.Type
      • 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

      Fields 
      Modifier and Type Field Description
      private javax.swing.JButton cancelButton
      Cancel button, if applicable.
      static java.lang.String LOCK_PROGRESS_MESSAGE
      Constant indicating whether to lock the message string so that other algorithms will not change this (sub-algorithms)
      private boolean messageLocked
      indicates if the message string (in the progress bar) is locked so that it wont be updated
      private javax.swing.JLabel messagePBar
      Label directly above the bar that is updated during operation if necessary.
      private javax.swing.JProgressBar pBar
      Actual bar which fills with color as the percentage of completion increases.
      private javax.swing.JLabel percentage
      Percentage label, puts a number next to the bar with the actual percent completed.
      static int PROGRESS_VALUE_UNCHANGED
      DOCUMENT ME!
      static int PROGRESS_WINDOW_CLOSING
      DOCUMENT ME!
      private boolean readyToDispose
      For users wanting to override the automatic closing option when progress reaches 100.
      private boolean separateThread
      DOCUMENT ME!
      private static long serialVersionUID
      Use serialVersionUID for interoperability.
      private java.lang.String title
      Title of the frame for the progress bar.
      static java.lang.String UNLOCK_PROGRESS_MESSAGE
      With the above variable, unlocks the message updating
      • Fields inherited from class javax.swing.JFrame

        accessibleContext, rootPane, rootPaneCheckingEnabled
      • Fields inherited from class java.awt.Frame

        CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
      • 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
      • Fields inherited from interface javax.swing.WindowConstants

        DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE
    • Constructor Summary

      Constructors 
      Constructor Description
      ViewJProgressBar​(java.lang.String _title, java.lang.String msg, int min, int max, boolean cancelFlag)
      Creates a new ViewJProgressBar object.
      ViewJProgressBar​(java.lang.String _title, java.lang.String msg, int min, int max, boolean cancelFlag, java.awt.event.ActionListener actionListener, java.awt.event.WindowListener windowListener)
      Creates a new progress bar with the given title, message, and min and max.
      ViewJProgressBar​(java.lang.String _title, java.lang.String msg, int min, int max, boolean cancelFlag, java.awt.event.ActionListener actionListener, java.awt.event.WindowListener windowListener, boolean isVisible)
      Creates a new progress bar with the given title, message, and min and max.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void actionPerformed​(java.awt.event.ActionEvent e)
      Closes this progress bar when the cancel button is clicked.
      void addActionListener​(java.awt.event.ActionListener l)
      DOCUMENT ME!
      void appendMessage​(java.lang.String msg)
      Concatenates a message to the message area of the progress bar.
      javax.swing.JButton getCancelButton()
      Get the cancel button
      javax.swing.JLabel getMessageBar()
      Get the message label.
      javax.swing.JLabel getPercentageLabel()
      Get the percentage label.
      javax.swing.JProgressBar getProgressBar()
      Get the progress bar.
      static int getProgressFromFloat​(int minProgressValue, int maxProgressValue, float percentage)
      DOCUMENT ME!
      static int getProgressFromInt​(int minProgressValue, int maxProgressValue, int percentage)
      DOCUMENT ME!
      int getValue()
      Used to get the present value of the progress bar.
      boolean isComplete()
      Used to determine if the progress bar is at 100%.
      void progressStateChanged​(ProgressChangeEvent e)
      Implementation of the ProgressChangeListener interface.
      void removeActionListener​(java.awt.event.ActionListener l)
      DOCUMENT ME!
      void setIndeterminate​(boolean flag)
      Enable or disable the progress bar indeterminate mode.
      void setMessage​(java.lang.String msg)
      Sets the message area of the progress bar.
      void setReadyToDispose​(boolean isReady)
      accessor to allow user to override the automatic closing (until they set this flag to true);
      void setSeparateThread​(boolean flag)
      Changes whether the algorithm which is using this progress bar is running in its own thread.
      void setTitle​(java.lang.String _title)
      Sets the title of the frame of the progress bar.
      void setVisible​(boolean visible)
      DOCUMENT ME!
      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.
      void updateValue​(int value, boolean sepThread)
      Used to set the present value of the progress bar.
      void updateValueImmed​(int value)
      Used to set the present value of the progress bar.
      void windowActivated​(java.awt.event.WindowEvent event)
      Do nothing.
      void windowClosed​(java.awt.event.WindowEvent event)
      Do nothing.
      void windowClosing​(java.awt.event.WindowEvent event)
      Dispose the progress window.
      void windowDeactivated​(java.awt.event.WindowEvent event)
      Do nothing.
      void windowDeiconified​(java.awt.event.WindowEvent event)
      Do nothing.
      void windowIconified​(java.awt.event.WindowEvent event)
      Do nothing.
      void windowOpened​(java.awt.event.WindowEvent event)
      Do nothing.
      • Methods inherited from class javax.swing.JFrame

        addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
      • Methods inherited from class java.awt.Frame

        addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setBackground, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setOpacity, setResizable, setShape, setState, setUndecorated
      • Methods inherited from class java.awt.Window

        addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, show, toBack, 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, 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, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, 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, 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, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setMixingCutoutShape, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.awt.MenuContainer

        getFont, postEvent
    • Field Detail

      • serialVersionUID

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

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

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

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

        public static final java.lang.String UNLOCK_PROGRESS_MESSAGE
        With the above variable, unlocks the message updating
        See Also:
        Constant Field Values
      • cancelButton

        private javax.swing.JButton cancelButton
        Cancel button, if applicable.
      • messagePBar

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

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

        private javax.swing.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 java.lang.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 Detail

      • ViewJProgressBar

        public ViewJProgressBar​(java.lang.String _title,
                                java.lang.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​(java.lang.String _title,
                                java.lang.String msg,
                                int min,
                                int max,
                                boolean cancelFlag,
                                java.awt.event.ActionListener actionListener,
                                java.awt.event.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​(java.lang.String _title,
                                java.lang.String msg,
                                int min,
                                int max,
                                boolean cancelFlag,
                                java.awt.event.ActionListener actionListener,
                                java.awt.event.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 Detail

      • 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​(java.awt.event.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 java.awt.event.ActionListener
        Parameters:
        e - Event that triggered this method.
      • addActionListener

        public void addActionListener​(java.awt.event.ActionListener l)
        DOCUMENT ME!
        Parameters:
        l - DOCUMENT ME!
      • appendMessage

        public void appendMessage​(java.lang.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 javax.swing.JButton getCancelButton()
        Get the cancel button
        Returns:
        canelButton cancel button
      • getMessageBar

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

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

        public javax.swing.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.
      • removeActionListener

        public void removeActionListener​(java.awt.event.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​(java.lang.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​(java.lang.String _title)
        Sets the title of the frame of the progress bar.
        Specified by:
        setTitle in interface ProgressBarInterface
        Overrides:
        setTitle in class java.awt.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 java.awt.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​(java.awt.event.WindowEvent event)
        Do nothing.
        Specified by:
        windowActivated in interface java.awt.event.WindowListener
        Parameters:
        event - the window activated event
      • windowClosed

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

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

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

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

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

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