org.gicentre.utils.gui
Class Tooltip

java.lang.Object
  extended by org.gicentre.utils.gui.Tooltip
All Implemented Interfaces:
java.awt.event.MouseListener, java.util.EventListener

public class Tooltip
extends java.lang.Object
implements java.awt.event.MouseListener

Class to allow a simple 'tooltip' type pop-up panel to display text at a given location. Can be used for mouse-based tooltips or info-boxes.

Version:
3.3, 1st August, 2011.
Author:
Jo Wood, giCentre, City University London.

Constructor Summary
Tooltip(processing.core.PApplet parent, processing.core.PFont font, float textSize, float width)
          Creates a tool tip with given parent sketch and font for displaying text.
 
Method Summary
 void draw(float ttX, float ttY)
          Draws the tooltip at the given location.
 float getHeight()
          Reports the height of the tooltip.
 float getWidth()
          Reports the width of the tooltip.
 boolean isActive()
          Reports whether or not this tooltip is active.
 boolean isFixedWidth()
          Reports whether or not this tooltip has a fixed width.
 void mouseClicked(java.awt.event.MouseEvent e)
          Would respond to a mouse being clicked in this tooltip, but does nothing in this case.
 void mouseEntered(java.awt.event.MouseEvent e)
          Would respond to a mouse entering this tooltip, but does nothing in this case.
 void mouseExited(java.awt.event.MouseEvent e)
          Would respond to a mouse leaving this tooltip, but does nothing in this case.
 void mousePressed(java.awt.event.MouseEvent e)
          Checks to see if the user has clicked on the close icon of this tooltip if present.
 void mouseReleased(java.awt.event.MouseEvent e)
          Would respond to a mouse being released over this tooltip, but does nothing in this case.
 void setAnchor(Direction anchorPosition)
          Sets the anchor position of the tooltip.
 void setBackgroundColour(int backgroundColour)
          Changes the colour of background of the tooltip.
 void setBorderColour(int borderColour)
          Changes the colour of border drawn around the tooltip.
 void setBorderWidth(float borderWidth)
          Changes the width of border drawn around the tooltip.
 void setIsActive(boolean isActive)
          Determines whether or not this tooltip should be active or not.
 void setIsCurved(boolean curve)
          Determines if tip is drawn with slightly curved boundaries.
 void setIsFixedWidth(boolean isFixedWidth)
          Determines whether or not this tooltip should have a fixed width.
 void setPointerSize(float size)
          Determines the size of the pointer when the tip is drawn with showPointer(true).
 void setText(java.lang.String text)
          Sets the text to be displayed in the tooltip.
 void setTextColour(int textColour)
          Changes the colour of text to be displayed in the tooltip.
 void showCloseIcon(boolean show)
          Determines if a 'close' icon should be drawn in the tooltip.
 void showPointer(boolean show)
          Determines whether or not a pointer drawn as part of the tip pointing towards the anchor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Tooltip

public Tooltip(processing.core.PApplet parent,
               processing.core.PFont font,
               float textSize,
               float width)
Creates a tool tip with given parent sketch and font for displaying text.

Parameters:
parent - Sketch in which this tooltip will be displayed.
font - Font used to display text.
textSize - Size of text in pixels.
width - Width of tooltip in pixels. Height is determined by the content of the tip.
Method Detail

draw

public void draw(float ttX,
                 float ttY)
Draws the tooltip at the given location.

Parameters:
ttX - x coordinate of location to display tooltip.
ttY - y coordinate of location to display tooltip.

setText

public void setText(java.lang.String text)
Sets the text to be displayed in the tooltip.

Parameters:
text - Text to be displayed.

setBorderColour

public void setBorderColour(int borderColour)
Changes the colour of border drawn around the tooltip.

Parameters:
borderColour - New border colour to be drawn around the tooltip.

setTextColour

public void setTextColour(int textColour)
Changes the colour of text to be displayed in the tooltip.

Parameters:
textColour - New text colour to be used by the tooltip.

setBackgroundColour

public void setBackgroundColour(int backgroundColour)
Changes the colour of background of the tooltip.

Parameters:
backgroundColour - New background colour to be used by the tooltip.

setBorderWidth

public void setBorderWidth(float borderWidth)
Changes the width of border drawn around the tooltip.

Parameters:
borderWidth - Width of the border to be drawn around the tooltip in pixels. Can be a fraction of a pixel.

setIsCurved

public void setIsCurved(boolean curve)
Determines if tip is drawn with slightly curved boundaries.

Parameters:
curve - Lines drawn as curves if true.

setPointerSize

public void setPointerSize(float size)
Determines the size of the pointer when the tip is drawn with showPointer(true).

Parameters:
size - Size of pointer in pixels.

setAnchor

public void setAnchor(Direction anchorPosition)
Sets the anchor position of the tooltip. This determines where, in or around the tooltip, the rectangle of text is drawn. For example, setting the anchor to Direction.WEST will draw the tip to the right of the (x,y) coordinates provided to draw().

Parameters:
anchorPosition - Position of the tip's anchor.

showPointer

public void showPointer(boolean show)
Determines whether or not a pointer drawn as part of the tip pointing towards the anchor.

Parameters:
show - Pointer is drawn if true.

showCloseIcon

public void showCloseIcon(boolean show)
Determines if a 'close' icon should be drawn in the tooltip. If present, clicking on the icon will set the state of the tip to be inactive (isActive() will return false).

Parameters:
show - True if a close icon is to be drawn.

setIsActive

public void setIsActive(boolean isActive)
Determines whether or not this tooltip should be active or not. When inactive it is not drawn.

Parameters:
isActive - True if the tooltip is to be active, false if invisible.

isActive

public boolean isActive()
Reports whether or not this tooltip is active. The active status can be controlled programmatically through setIsActive() or it can be made inactive by the user if the close icon is shown and the user has clicked on it. While the tooltip is inactive, it cannot be drawn.

Returns:
True if the tooltip is currently active.

setIsFixedWidth

public void setIsFixedWidth(boolean isFixedWidth)
Determines whether or not this tooltip should have a fixed width. While fixed, the tooltip will never change its width. If false and the text sent to the tip is one line long and takes up less than the width of the tip, the width is shrunk. This has no effect if the text to be displayed occupies more than one line of the tip.

Parameters:
isFixedWidth - True if the tip width is to be fixed.

isFixedWidth

public boolean isFixedWidth()
Reports whether or not this tooltip has a fixed width. While fixed, the tooltip will never change its width. If false and the text sent to the tip is one line long and takes up less than the width of the tip, the width is shrunk.

Returns:
True if the tip width is fixed.

getWidth

public float getWidth()
Reports the width of the tooltip. If isFixedWidth() is true or the tooltip contains more than one line, this will be the same as the maximum width specified in the constructor. Otherwise the width will depend on the width of the text displayed in the tooltip.

Returns:
Width do the tooltip in pixel units.

getHeight

public float getHeight()
Reports the height of the tooltip.

Returns:
Height of the tooltip in pixel units.

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Checks to see if the user has clicked on the close icon of this tooltip if present. If clicked, the tooltip state is set to closed.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - Mouse event storing the mouse pressed action.

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Would respond to a mouse being clicked in this tooltip, but does nothing in this case.

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - Mouse event (ignored).
See Also:
MouseListener.mouseClicked(java.awt.event.MouseEvent)

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Would respond to a mouse entering this tooltip, but does nothing in this case.

Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
e - Mouse event (ignored).
See Also:
MouseListener.mouseEntered(java.awt.event.MouseEvent)

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Would respond to a mouse leaving this tooltip, but does nothing in this case.

Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
e - Mouse event (ignored).
See Also:
MouseListener.mouseExited(java.awt.event.MouseEvent)

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Would respond to a mouse being released over this tooltip, but does nothing in this case.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - Mouse event (ignored).
See Also:
MouseListener.mouseReleased(java.awt.event.MouseEvent)


giCentre Utilities V.3.3, API documentation generated 6th April, 2013