soc.client
Class AWTToolTip

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Canvas
          extended by soc.client.AWTToolTip
All Implemented Interfaces:
java.awt.event.ComponentListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class AWTToolTip
extends java.awt.Canvas
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.ComponentListener

A short tooltip for a component. Does not handle component resize or moving, but will respond to hide/un-hide.

To change the tooltip text, call setTip(String).

The tooltip adds itself as a listener to the parent component. If you need to remove this tooltip from the parent, call destroy().

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
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
private  boolean autoPopup
          Does the tooltip automatically appear when mouse enters parentComp?
(package private) static java.awt.Color bgcol
          The background color of the window
private  int boxH
          Our size
private  int boxW
          Our size
private  int boxX
          Our location within parentComp
private  int boxY
          Our location within parentComp
 int closeAfterMoveX
          The tip is hidden after the mouse has been moved closeAfterMoveX poinntes horizontally or closeAfterMoveY points vertically away from the point where it has been clicked (or it has left its parent component's area)
 int closeAfterMoveY
           
(package private) static java.awt.Color fgcol
          The foreground color of the window
private  boolean isShown
          Currently showing? Also indicated by mainParentComp != null.
protected  java.lang.Object l_mainParentComp
          thread-lock on changes/accesses of mainParentComp
protected  java.awt.Container mainParentComp
          parentComp's top-level parent, set at mouseEntered; null if not currently visible
protected  java.awt.LayoutManager mainParentLayout
          true layout manager of mainParentComp; temporarily changed to add the tooltip
private  int mousePosAtWinShowX
          Mouse location within parentComp
private  int mousePosAtWinShowY
          Mouse location within parentComp
static int OFFSET_X
          X-offset (from mouse location) of tooltip upper-left corner
static int OFFSET_Y
          Y-offset (from mouse location) of tooltip upper-left corner
protected  java.awt.Component parentComp
          Component to which tooltip is notionally added, set in constructor.
protected  int parentX
          Position of parentComp within painParentComp
protected  int parentY
          Position of parentComp within painParentComp
protected  java.awt.Font tfont
          tfont is parentComp.getFont, set at mouseEntered
private  java.lang.String tip
           
private  boolean wantsShown
          Want shown? If true, must dynamically add us to parentComp when become visible.
 
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
AWTToolTip(java.lang.String _tip, java.awt.Component _comp)
          Constructs a Tooltip which is displayed when the mouse enters the given component.
 
Method Summary
protected  void addToParent(int x, int y)
          Add and show tooltip, with mouse at this location.
 void componentHidden(java.awt.event.ComponentEvent e)
          when parentComp becomes hidden, hide this tooltip if shown.
 void componentMoved(java.awt.event.ComponentEvent e)
          stub, required for ComponentListener
 void componentResized(java.awt.event.ComponentEvent e)
          stub, required for ComponentListener
 void componentShown(java.awt.event.ComponentEvent e)
          When parentComp becomes un-hidden, flag this tooltip to be shown when mouse moves in.
 void destroy()
          destroys the tooltip.
static java.awt.Container getParentContainer(java.awt.Component c)
          Gets the top-level container of c.
 java.lang.String getTip()
           
private  void hideTip()
          hides the tooltip.
 void mouseClicked(java.awt.event.MouseEvent e)
          MouseListener-Methods
 void mouseDragged(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mouseMoved(java.awt.event.MouseEvent e)
          Must keep out of the way of the mouse pointer.
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 void paint(java.awt.Graphics g)
           
protected  void removeFromParent()
          Hide and remove from a main parent, until addToParent is called (typically from mouseEntered).
 void setTip(java.lang.String newTip)
          Change the tooltip text.
protected  void showAtMouse(int x, int y)
          Show tip at appropriate location when mouse is at (x,y) within mainparent (NOT within parentComp).
 void update(java.awt.Graphics g)
           
 
Methods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

closeAfterMoveX

public int closeAfterMoveX
The tip is hidden after the mouse has been moved closeAfterMoveX poinntes horizontally or closeAfterMoveY points vertically away from the point where it has been clicked (or it has left its parent component's area)


closeAfterMoveY

public int closeAfterMoveY

tip

private java.lang.String tip

tfont

protected java.awt.Font tfont
tfont is parentComp.getFont, set at mouseEntered


parentComp

protected java.awt.Component parentComp
Component to which tooltip is notionally added, set in constructor. Actually tip is added directly to mainParentComp when needed. Tooltip is a mouseListener, mouseMotionListener of parentComp.


mainParentComp

protected java.awt.Container mainParentComp
parentComp's top-level parent, set at mouseEntered; null if not currently visible


l_mainParentComp

protected java.lang.Object l_mainParentComp
thread-lock on changes/accesses of mainParentComp


mainParentLayout

protected java.awt.LayoutManager mainParentLayout
true layout manager of mainParentComp; temporarily changed to add the tooltip


parentX

protected int parentX
Position of parentComp within painParentComp


parentY

protected int parentY
Position of parentComp within painParentComp


mousePosAtWinShowX

private int mousePosAtWinShowX
Mouse location within parentComp


mousePosAtWinShowY

private int mousePosAtWinShowY
Mouse location within parentComp


autoPopup

private boolean autoPopup
Does the tooltip automatically appear when mouse enters parentComp?


OFFSET_X

public static int OFFSET_X
X-offset (from mouse location) of tooltip upper-left corner

See Also:
showAtMouse(int, int)

OFFSET_Y

public static int OFFSET_Y
Y-offset (from mouse location) of tooltip upper-left corner

See Also:
showAtMouse(int, int)

wantsShown

private boolean wantsShown
Want shown? If true, must dynamically add us to parentComp when become visible.


isShown

private boolean isShown
Currently showing? Also indicated by mainParentComp != null.


boxX

private int boxX
Our location within parentComp


boxY

private int boxY
Our location within parentComp


boxW

private int boxW
Our size


boxH

private int boxH
Our size


bgcol

static java.awt.Color bgcol
The background color of the window


fgcol

static java.awt.Color fgcol
The foreground color of the window

Constructor Detail

AWTToolTip

public AWTToolTip(java.lang.String _tip,
                  java.awt.Component _comp)
Constructs a Tooltip which is displayed when the mouse enters the given component. The tooltip's font is the same as the component's font.

Parameters:
_comp - the Component which this Tooltip describes.
_tip - Text to show; single line.
Method Detail

getTip

public java.lang.String getTip()
Returns:
the tooltip text.

setTip

public void setTip(java.lang.String newTip)
            throws java.lang.IllegalArgumentException
Change the tooltip text. Handles repaint and (if needed) reposition

Parameters:
newTip - New tip text
Throws:
java.lang.IllegalArgumentException - if newTip is null

showAtMouse

protected void showAtMouse(int x,
                           int y)
Show tip at appropriate location when mouse is at (x,y) within mainparent (NOT within parentComp). If not currently visible, nothing happens.


update

public void update(java.awt.Graphics g)
Overrides:
update in class java.awt.Canvas

paint

public void paint(java.awt.Graphics g)
Overrides:
paint in class java.awt.Canvas

removeFromParent

protected void removeFromParent()
Hide and remove from a main parent, until addToParent is called (typically from mouseEntered). Does not remove from the immediate parent passed to the constructor.

See Also:
addToParent(int, int)

addToParent

protected void addToParent(int x,
                           int y)
Add and show tooltip, with mouse at this location. mainParentComp will be set to the "top-level" container of the parent passed to the constructor. If already added to a (main) parent, nothing happens. If the parent is currently not visible, nothing happens.

Parameters:
x - Mouse position within parentComp when adding (NOT within mainparent)
y - Mouse position within parentComp when adding (NOT within mainparent)
See Also:
removeFromParent()

getParentContainer

public static java.awt.Container getParentContainer(java.awt.Component c)
Gets the top-level container of c.

Parameters:
c - The Component.
Returns:
The parent-frame, dialog, or applet, or null.

hideTip

private void hideTip()
hides the tooltip. (Removes from parent container)


destroy

public void destroy()
destroys the tooltip. Hide it first if visible.


mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
MouseListener-Methods

Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseExited

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

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered 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

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Must keep out of the way of the mouse pointer. On some Win32, flickers if (x,y) of mouse is in our bounding box. showAtMouse is called here to move the box if needed.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
See Also:
showAtMouse(int, int)

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

componentHidden

public void componentHidden(java.awt.event.ComponentEvent e)
when parentComp becomes hidden, hide this tooltip if shown.

Specified by:
componentHidden in interface java.awt.event.ComponentListener

componentMoved

public void componentMoved(java.awt.event.ComponentEvent e)
stub, required for ComponentListener

Specified by:
componentMoved in interface java.awt.event.ComponentListener

componentResized

public void componentResized(java.awt.event.ComponentEvent e)
stub, required for ComponentListener

Specified by:
componentResized in interface java.awt.event.ComponentListener

componentShown

public void componentShown(java.awt.event.ComponentEvent e)
When parentComp becomes un-hidden, flag this tooltip to be shown when mouse moves in. If the mouse was already in the parent's bounding box, tip will not know that until it receives a mouseEntered event.

Specified by:
componentShown in interface java.awt.event.ComponentListener