InputTipsManager V1.3
by Matthew Ford
2005/12/08

au.com.forward.inputTipsManager
Class InputTipsManager

java.lang.Object
  extended by au.com.forward.inputTipsManager.InputTipsManager
All Implemented Interfaces:
java.awt.event.FocusListener, java.util.EventListener

public class InputTipsManager
extends java.lang.Object
implements java.awt.event.FocusListener

Manages all the InputTips in the application.

use
InputTipsManager.sharedInstance().showInputTip(jcomponent,tip);
to show the tip and
InputTipsManager.sharedInstance().hideInputTip();
to hide it.

The InputTip will also be removed when the jcomponent looses focus, or on next keystroke.

For more control use
InputTipsManager.sharedInstance().showInputTip(jcomponent,tipText,attachFocusListener, cellRect);
which lets you control if a focus and keyboard listener is attached and specify the cell rectangle in a JTable to show the tip next to.

For example
Rectangle cellRect = table.getCellRect(selectedRow,selectedColumn, true);
String tip = "" + "Row "+selectedRow+" has been selected.";
InputTipsManager.sharedInstance().showInputTip(table,tip, false, cellRect);


Nested Class Summary
protected  class InputTipsManager.InputTipsKeyHandler
          This class hides the inputtip on each keystroke press
 
Constructor Summary
protected InputTipsManager()
          Constructor for the InputTipsManager object
 
Method Summary
 void focusGained(java.awt.event.FocusEvent e)
          To satisfy FocusListener Interface does nothing
 void focusLost(java.awt.event.FocusEvent e)
          Hide InputTip when focus lost
protected static java.awt.Frame frameForComponent(java.awt.Component component)
          Get the Frame containing this component
static java.lang.String getKeyText(char c)
          Gets a display text for this char
Has special handling for Backspace, Tab, Enter, Cancel, Escape, Delete and SYN (code 0x16)
static java.lang.String getKeyText(int keyCode)
          Gets a display text for this keycode e.g.
static java.lang.String getKeyText(java.awt.event.KeyEvent e)
          Gets a display text for the key in a KeyEvent
 void hideInputTip()
          Hides the InputTip
 boolean isBeepEnabled()
          Returns true if beeps are enabled.
 boolean isEnabled()
          Returns true if InputTips are enabled.
 void setBeepEnabled(boolean flag)
          Globally enables or disables the Beep on showInputTips (default enabled).
 void setEnabled(boolean flag)
          Globally enables or disables the InputTips.
static InputTipsManager sharedInstance()
          Returns a shared InputTipsManager instance.
 void showInputTip(javax.swing.JComponent component, java.lang.String tipText)
          Shows an InputTip for this component.
 void showInputTip(javax.swing.JComponent component, java.lang.String tipText, boolean attachFocusListener, java.awt.Rectangle cellRect)
          Shows an InputTip for this component.
 void showInputTip(java.lang.String tipText)
          Shows an InputTip for the component which currently has focus.
If you know which component has focus use showInputTip(JComponent,String) instead
Tip is removed when component looses focus or a key is pressed or when the hideInputTip() is called.
This method runs an internal method on the SwingThread using invokeLater
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InputTipsManager

protected InputTipsManager()
Constructor for the InputTipsManager object

Method Detail

focusGained

public void focusGained(java.awt.event.FocusEvent e)
To satisfy FocusListener Interface does nothing

Specified by:
focusGained in interface java.awt.event.FocusListener
Parameters:
e - focus event

focusLost

public void focusLost(java.awt.event.FocusEvent e)
Hide InputTip when focus lost

Specified by:
focusLost in interface java.awt.event.FocusListener
Parameters:
e - focus event

setBeepEnabled

public void setBeepEnabled(boolean flag)
Globally enables or disables the Beep on showInputTips (default enabled). When set to true Toolkit.getDefaultToolkit().beep(); will be called each time an InputTip is displayed.

Parameters:
flag - true to enable beep on input tip display, false otherwise

isBeepEnabled

public boolean isBeepEnabled()
Returns true if beeps are enabled.

Returns:
true if InputTipManger will beep when displaying an tip

setEnabled

public void setEnabled(boolean flag)
Globally enables or disables the InputTips. When set to false any existing input tip is hidden and showInputTip() calls are ignored.

Parameters:
flag - true to enable the inputtip, false otherwise

isEnabled

public boolean isEnabled()
Returns true if InputTips are enabled.

Returns:
true if showInputTip() will display an tip

showInputTip

public void showInputTip(javax.swing.JComponent component,
                         java.lang.String tipText,
                         boolean attachFocusListener,
                         java.awt.Rectangle cellRect)
Shows an InputTip for this component. If attachFocusListener is true, tip is removed when component looses focus or a key is pressed or when the hideInputTip() is called.
If the cellRect is non-null it is used to locate the tip within the component.
If the component is a JTable, it is scrolled to make the cell rectangle visible.
This method runs an internal method on the SwingThread using invokeLater

Parameters:
component - The JComponent to display the tip next to
tipText - The tip to display, can be <HTML> text
attachFocusListener - true if should attach focus listener and key listener to hide tip on change in focus false if listeners should not be attached
cellRect - The rectangle representing the information the tip is to be displayed against. If the component is a JTable scroll to make this rectangle visible. Null if not needed.

showInputTip

public void showInputTip(javax.swing.JComponent component,
                         java.lang.String tipText)
Shows an InputTip for this component. Tip is removed when component looses focus or a key is pressed or when the hideInputTip() is called.
This method runs an internal method on the SwingThread using invokeLater

Parameters:
component - The JComponent to display the tip next to
tipText - The tip to display, can be <HTML> text

showInputTip

public void showInputTip(java.lang.String tipText)
Shows an InputTip for the component which currently has focus.
If you know which component has focus use showInputTip(JComponent,String) instead
Tip is removed when component looses focus or a key is pressed or when the hideInputTip() is called.
This method runs an internal method on the SwingThread using invokeLater

Parameters:
tipText - The tip to display, can be <HTML> text

hideInputTip

public void hideInputTip()
Hides the InputTip


sharedInstance

public static InputTipsManager sharedInstance()
Returns a shared InputTipsManager instance.

Returns:
a shared InputTipsManager object

getKeyText

public static java.lang.String getKeyText(java.awt.event.KeyEvent e)
Gets a display text for the key in a KeyEvent

Parameters:
e - the KeyEvent
Returns:
The display text for the key in this event

getKeyText

public static java.lang.String getKeyText(char c)
Gets a display text for this char
Has special handling for Backspace, Tab, Enter, Cancel, Escape, Delete and SYN (code 0x16)

Parameters:
c - the char to display
Returns:
The display text for this char

getKeyText

public static java.lang.String getKeyText(int keyCode)
Gets a display text for this keycode e.g. "HOME", "F1" or "A". These strings can be localized by changing the awt.properties file.

Parameters:
keyCode - the keycode to translate
Returns:
The display text for this key code

frameForComponent

protected static java.awt.Frame frameForComponent(java.awt.Component component)
Get the Frame containing this component

Parameters:
component - the component
Returns:
the Frame containing it

©2005, Forward Computing and Control Pty. Ltd
ACN 003 669 994   NSW Australia
All Rights Reserved.