org.gicentre.utils.gui

## Class Tooltip

- java.lang.Object
- - org.gicentre.utils.gui.Tooltip

-     public class Tooltip
      extends java.lang.Object

  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.4, 5th February, 2016.
  Author:
    Jo Wood, giCentre, City University London.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `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

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `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` | `mouseEvent(processing.event.MouseEvent e)` Responds to mouse presses in the corner of the tooltip.
    `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.

    - #### mouseEvent

          public void mouseEvent(processing.event.MouseEvent e)

      Responds to mouse presses in the corner of the tooltip.
      Parameters:
        `e` - Mouse event.