com.isti.util.gui
Class HintManager

java.lang.Object
  extended by com.isti.util.gui.HintManager
All Implemented Interfaces:
java.awt.event.FocusListener, java.awt.event.MouseListener, java.util.EventListener

public class HintManager
extends java.lang.Object
implements java.awt.event.FocusListener, java.awt.event.MouseListener

HintManager is a reusable class that provides an implementation for status-bar hints. Using it is straightforward. Just construct an instance of HintManager passing a hint component (JLabel or JTextField) instance that will be used to display the hints; call the method addHintFor to set a hint for each component you want; and call the method enableHints for the user interface top container (window, frame, dialog box, etc.) after adding all the components.


Field Summary
static int FOCUS_EVENT_TYPE
          Focus event type.
protected static java.lang.String hintClearText
          The hint clear text.
static int MOUSE_EVENT_TYPE
          Mouse event type.
 
Constructor Summary
HintManager(java.lang.Object hintComponent)
          Creates the hint manager.
 
Method Summary
protected  java.lang.String addComponentHintText(java.lang.String hint, java.awt.Component comp)
          Adds help text for the specific component if needed.
 void addHintFor(java.awt.Component comp, java.lang.String hintText)
          Adds a hint for the component.
 void disableHints(java.awt.Component comp)
          Disables hints for the component and all children.
 void enableHints(java.awt.Component comp, int type)
          Enable hints for the component and all children.
 void focusGained(java.awt.event.FocusEvent e)
           
 void focusLost(java.awt.event.FocusEvent e)
           
protected  java.lang.String getFullHintText(java.lang.String hint, java.lang.String additionalHintText)
          Gets the full hint text.
protected  java.lang.String getHintClearText()
          Gets the hint clear text.
protected  java.lang.String getHintText(java.lang.String hint, java.lang.String additionalHintText)
          Gets the hint text.
protected  java.lang.String getHintText(java.lang.String hint, java.lang.String additionalHintText, boolean htmlFlag)
          Gets the hint text.
 boolean isUseToolTipText()
          Determines if tool tip text is used if no hints were found.
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 void setAddtionalHintTextColor(java.awt.Color color, boolean boldFlag)
          Sets the additional hint text color attributes.
protected  void setHint(java.lang.String hint)
          Sets the hint on the hint component.
 void setUseToolTipText(boolean b)
          Sets if tool tip text is used if no hints were found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MOUSE_EVENT_TYPE

public static final int MOUSE_EVENT_TYPE
Mouse event type.

See Also:
Constant Field Values

FOCUS_EVENT_TYPE

public static final int FOCUS_EVENT_TYPE
Focus event type.

See Also:
Constant Field Values

hintClearText

protected static final java.lang.String hintClearText
The hint clear text.

See Also:
Constant Field Values
Constructor Detail

HintManager

public HintManager(java.lang.Object hintComponent)
            throws java.lang.Exception
Creates the hint manager.

Parameters:
hintComponent - the hint component (JLabel or JTextField), which must have a 'setText(String)' method.
Throws:
java.lang.Exception - if error.
Method Detail

addHintFor

public void addHintFor(java.awt.Component comp,
                       java.lang.String hintText)
Adds a hint for the component.

Parameters:
comp - the component.
hintText - the hint text.

disableHints

public void disableHints(java.awt.Component comp)
Disables hints for the component and all children.

Parameters:
comp - the component.

enableHints

public void enableHints(java.awt.Component comp,
                        int type)
Enable hints for the component and all children. The default is for tool tip text to be used if no hint can be found but this may be disabled by calling 'setUseToolTipText(false)' prior to calling this method.

Parameters:
comp - the component.
type - the type of event to listen to, MOUSE_EVENT_TYPE for mouse events and FOCUS_EVENT_TYPE for focus events.
See Also:
setUseToolTipText

isUseToolTipText

public boolean isUseToolTipText()
Determines if tool tip text is used if no hints were found.

Returns:
true if tool tip text is used, false otherwise.

setAddtionalHintTextColor

public void setAddtionalHintTextColor(java.awt.Color color,
                                      boolean boldFlag)
Sets the additional hint text color attributes.

Parameters:
color - the color or null if none.
boldFlag - true for bold, false otherwise.

setUseToolTipText

public void setUseToolTipText(boolean b)
Sets if tool tip text is used if no hints were found. This should be set before enabling hints.

Parameters:
b - true if tool tip text is used, false otherwise.
See Also:
enableHints

addComponentHintText

protected java.lang.String addComponentHintText(java.lang.String hint,
                                                java.awt.Component comp)
Adds help text for the specific component if needed.

Parameters:
hint - the hint text or null if none.
comp - the component.
Returns:
the hint text or null if none.

getFullHintText

protected java.lang.String getFullHintText(java.lang.String hint,
                                           java.lang.String additionalHintText)
Gets the full hint text.

Parameters:
hint - the hint text.
additionalHintText - the additional hint text.
Returns:
the hint text or null if none.

getHintText

protected java.lang.String getHintText(java.lang.String hint,
                                       java.lang.String additionalHintText)
Gets the hint text.

Parameters:
hint - the hint text.
additionalHintText - the additional hint text or null if none.
Returns:
the hint text or null if none.

getHintText

protected java.lang.String getHintText(java.lang.String hint,
                                       java.lang.String additionalHintText,
                                       boolean htmlFlag)
Gets the hint text.

Parameters:
hint - the hint text.
additionalHintText - the additional hint text.
htmlFlag - true to use HTML text, false otherwise.
Returns:
the hint text or null if none.

getHintClearText

protected java.lang.String getHintClearText()
Gets the hint clear text.

Returns:
the hint clear text.

setHint

protected void setHint(java.lang.String hint)
Sets the hint on the hint component.

Parameters:
hint - the hint text or null if none.

focusGained

public void focusGained(java.awt.event.FocusEvent e)
Specified by:
focusGained in interface java.awt.event.FocusListener

focusLost

public void focusLost(java.awt.event.FocusEvent e)
Specified by:
focusLost in interface java.awt.event.FocusListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener