buoy.widget
Class BToolTip

java.lang.Object
  extended by buoy.event.EventSource
      extended by buoy.widget.Widget
          extended by buoy.widget.BToolTip

public class BToolTip
extends Widget

A BToolTip is a small floating window that appears in front of another Widget. It contains a single line of text, and generally provides information about the function of the Widget it is displayed over.

The user triggers a tool tip by placing the mouse pointer over a Widget and leaving it there for a fixed amount of time. When this happens, the Widget sends out a ToolTipEvent. The program should respond to the event by calling either show() or processEvent() to display the tool tip.

The easiest way of doing this is to have the BToolTip listen for the event directly. For example, you can set a fixed String as the tool tip for a button by invoking:

 button.addEventLink(ToolTipEvent.class, new BToolTip("Do Not Press This Button"));
 

In some cases, you may want to do additional processing before the tool tip is displayed. For example, you might want to customize the tool tip text based on the mouse location, or exercise finer control over where the tool tip appears. In these cases, your program should listen for the event and handle it in the appropriate way.

As an example, the following code will display a tool tip over a BTable, showing the row and column the mouse is currently pointing to:

 table.addEventLink(ToolTipEvent.class, new Object()
 {
   void processEvent(ToolTipEvent ev)
   {
     Point pos = ev.getPoint();
     String text = "("+table.findRow(pos)+", "+table.findColumn(pos)+")";
     new BToolTip(text).processEvent(ev);
   }
 });
 

There can only be one tool tip showing at any time. It will automatically be hidden as soon as a new tool tip is shown, or the mouse is moved away from the Widget. You can call getShowingToolTip() to get the currently displayed tool tip, or hide() to hide it.

Author:
Peter Eastman

Constructor Summary
BToolTip()
          Create a new BToolTip with no text.
BToolTip(java.lang.String text)
          Create a new BToolTip.
 
Method Summary
 javax.swing.JToolTip getComponent()
          Get the java.awt.Component corresponding to this Widget.
static BToolTip getShowingToolTip()
          Get the currently showing tool tip, or null if none is showing.
 java.lang.String getText()
          Get the text to display on the tool tip.
static void hide()
          Hide the currently showing tool tip.
 void processEvent(ToolTipEvent event)
          Display the tool tip in response to a ToolTipEvent.
 void setText(java.lang.String text)
          Set the text to display on the tool tip.
 void show(Widget widget, java.awt.Point where)
          Display the tool tip.
 
Methods inherited from class buoy.widget.Widget
addEventLink, dispatchEvent, getBackground, getBounds, getCursor, getFont, getMaximumSize, getMinimumSize, getName, getParent, getPreferredSize, hasFocus, isEnabled, isFocusable, isVisible, repaint, requestFocus, setBackground, setCursor, setEnabled, setFocusable, setFont, setName, setVisible
 
Methods inherited from class buoy.event.EventSource
addEventLink, addEventLink, removeEventLink
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BToolTip

public BToolTip()
Create a new BToolTip with no text.


BToolTip

public BToolTip(java.lang.String text)
Create a new BToolTip.

Parameters:
text - the text to display in the tool tip
Method Detail

getComponent

public javax.swing.JToolTip getComponent()
Description copied from class: Widget
Get the java.awt.Component corresponding to this Widget.

Overrides:
getComponent in class Widget

getText

public java.lang.String getText()
Get the text to display on the tool tip.


setText

public void setText(java.lang.String text)
Set the text to display on the tool tip.


show

public void show(Widget widget,
                 java.awt.Point where)
Display the tool tip.

Parameters:
widget - the Widget over which to display the tool tip
where - the location at which to display the tool tip

processEvent

public void processEvent(ToolTipEvent event)
Display the tool tip in response to a ToolTipEvent.

Parameters:
event - the event from which to determine where to display the tool tip

getShowingToolTip

public static BToolTip getShowingToolTip()
Get the currently showing tool tip, or null if none is showing.


hide

public static void hide()
Hide the currently showing tool tip.



Written by Peter Eastman.