info.rolandkrueger.roklib.ui.swing
Class StatusBar

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 info.rolandkrueger.roklib.ui.swing.StatusBar
All Implemented Interfaces:
HoverListener, ImageObserver, MenuContainer, Serializable, Accessible

public class StatusBar
extends JPanel
implements HoverListener

This class represents a status bar that can be used to display status messages in a windowed application. The area of a status bar is divided into two parts. The bar's left half is used as display for general messages. Here, all types of messages can be displayed by the application. If desired, the right half of a status bar can be filled with specialized message fields. Such fields can be used to show the status of a some special part of the application. In a client-server application, it is conceivable to show the server address a client is connected to in such a field, for example. These specialized message fields are added to a status bar with addElement(String, String).

It is possible to display messages in the message area of a status bar that will be shown for a certain predefined period of time. This is done with setTimedMessage(String). If the delay of a timed message - which can be defined through the constructor StatusBar(long) or with setMessageDelay(long) - has elapsed, the timed message is replaced by the ready message as provided by setReadyMessage(String).

Example: The following code will create a status bar as sketched below:

 StatusBar bar = new StatusBar ();
 bar.setReadyMessage ("Ready.");
 bar.addElement      ("Msg. field 1",     "Help text for message field 1.");
 bar.addElement      ("Other msg. field", "Help text for the other message field.");
 
 +-------------------------------+--------------+------------------+
 | Ready.                        | Msg. field 1 | Other msg. field |
 +-------------------------------+--------------+------------------+
 

Author:
Roland Krueger
See Also:
Serialized Form

Nested Class Summary
private  class StatusBar.BarElement
          This class represents a single display area of a status bar.
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
private  String mCurrentMessage
           
private  long mDelay
           
private  ArrayList<StatusBar.BarElement> mElements
           
private  JPanel mElementsPanel
           
private  JLabel mInfoLabel
           
private  String mReadyText
           
private  Timer mTimer
           
private static long serialVersionUID
           
 
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
StatusBar()
          Default constructor.
StatusBar(long messageDelay)
          Constructs a StatusBar with the specified delay for timed messages.
 
Method Summary
 int addElement(String text, String helpText)
          Adds a specialized message field to the right half of the status bar.
 void hoverEnded(Hoverable source)
           
 void hoverStarted(Hoverable source)
           
 void setElementHelpText(int elementNr, String helpText)
          Sets the help text that belongs to the spezialized message area with the given identification number.
 void setElementText(int elementNr, String text)
          Sets the text displayed by the spezialized message area with the given identification number.
 void setMessageDelay(long delay)
          Sets the amount of time in milliseconds of how long a timed message will be displayed.
 void setReadyMessage(String msg)
          Sets the ready message for this status bar.
 void setTimedMessage(String msg)
          A timed message will be displayed in the message area for a certain amount of time.
 
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

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

mInfoLabel

private JLabel mInfoLabel

mElementsPanel

private JPanel mElementsPanel

mTimer

private Timer mTimer

mDelay

private long mDelay

mReadyText

private String mReadyText

mCurrentMessage

private String mCurrentMessage

mElements

private ArrayList<StatusBar.BarElement> mElements
Constructor Detail

StatusBar

public StatusBar()
Default constructor. The duration of displaying a timed message is set to 2 seconds.

See Also:
setTimedMessage(String)

StatusBar

public StatusBar(long messageDelay)
Constructs a StatusBar with the specified delay for timed messages.

Parameters:
messageDelay - delay in milliseconds for timed messages
See Also:
setTimedMessage(String)
Method Detail

hoverStarted

public void hoverStarted(Hoverable source)
Specified by:
hoverStarted in interface HoverListener

hoverEnded

public void hoverEnded(Hoverable source)
Specified by:
hoverEnded in interface HoverListener

setReadyMessage

public void setReadyMessage(String msg)
Sets the ready message for this status bar. This message will be displayed in the message area if no other message is currently being shown.

Parameters:
msg - the ready message for this status bar.

setTimedMessage

public void setTimedMessage(String msg)
A timed message will be displayed in the message area for a certain amount of time. This time can be configured either through the constructor StatusBar(long) or through method setMessageDelay(long). After the delay has elapsed, the status bar's ready message is displayed again.

Parameters:
msg - the message to be displayed for some time

setMessageDelay

public void setMessageDelay(long delay)
Sets the amount of time in milliseconds of how long a timed message will be displayed.

Parameters:
delay - the amount of time in milliseconds of how long a timed message will be displayed
See Also:
setTimedMessage(String)

addElement

public int addElement(String text,
                      String helpText)
Adds a specialized message field to the right half of the status bar. The specified text will be displayed in that field. The given helpText will be displayed in the general message area while the mouse cursor hovers over the specialized message field. Both of these text messages can be changed with setElementText(int, String) and setElementHelpText(int, String), respectively. The int value that is returned by this method is the identification number of the new specialized message field. This number is needed for the first parameter of the setElement* methods and indicates the field that is meant to be changed.

Parameters:
text - the text that will be displayed in the text area
helpText - help text for the text area that will be displayed in the general text area when the mouse hovers over the new text area
Returns:
an identification number that is needed to refer to the newly added text area
See Also:
setElementHelpText(int, String), setElementText(int, String)

setElementText

public void setElementText(int elementNr,
                           String text)
Sets the text displayed by the spezialized message area with the given identification number.

Parameters:
elementNr - identification number as provided by addElement(String, String) which refers to the message field that is to be changed by this method
text - the text to be displayed by the message field
Throws:
ArrayIndexOutOfBoundsException - if the message field denoted by elementNr does not exist

setElementHelpText

public void setElementHelpText(int elementNr,
                               String helpText)
Sets the help text that belongs to the spezialized message area with the given identification number.

Parameters:
elementNr - identification number as provided by addElement(String, String) which refers to the message field that is to be changed by this method
helpText - the text to be displayed by the message field
Throws:
ArrayIndexOutOfBoundsException - if the message field denoted by elementNr does not exist


Copyright © 2007-2011. All Rights Reserved.