Class KTooltip

java.lang.Object
com.iizix.prop.ui.KTooltip
All Implemented Interfaces:
Cloneable

public class KTooltip extends Object implements Cloneable
KTooltip is the invariant data holder for a TooltipProp.

Locations. A tooltip location is an IIZI direction, named after the numeric keypad as used by AbsoluteLayout and AbsoluteData: 8 is top, 2 is bottom, 4 is left, 6 is right, 5 is middle, 0 is nowhere or don't care, and 7, 9, 1 and 3 are the corners top-left, top-right, bottom-left and bottom-right. A tooltip may only be placed on an edge, so the sole permitted location values are 8, 2, 4 and 6, given as a list in order of preference.

The list holds at most four entries, and that limit is imposed by the storage rather than by convention: the locations are packed into a single integer, three bits per entry as location/2, so four entries fill twelve bits. That packed integer is what is serialized and what getLocations() unpacks.

Author:
Christopher Mindus
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The location: ABOVE (=8).
    static final int
    The location: AFTER (=6).
    static final int
    The location: BEFORE (=4).
    static final int
    The location: BELOW (=2).
    final int
    The message category if this applies, -1 for none, 0=informational, 1=warning, 2=error.
    static final int[]
    The "none" locations.
    final int
    The locations as an integer that needs packing up using getLocations(), zero for none.
    final int
    The show delay in milliseconds, 400 as default, values 0-9999 are allowed.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a tooltip with a default location, category "none" and showDelay 400 ms.
    KTooltip(KString text, int category)
    Creates a tooltip for a message with a default location and showDelay 400 ms.
    KTooltip(KString text, int showDelay, int... locations)
    Creates a tooltip with category "none".
    KTooltip(KString text, int showDelay, int category, int... locations)
    Creates a tooltip for a message.
    KTooltip(KString text, KTooltip prev)
    Creates a tooltip with specified text and settings from another tooltip instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    Clones the tooltip.
    void
    Disposes of the tooltip when no longer needed.
    boolean
    Checks if two tooltips are equal.
    boolean
    Checks for pure equality between two KTooltip's, excluding KString reference refresh counter checking but including potential original source string.
    protected void
    Called when the tooltip is being garbage collected.
    int[]
    Gets the locations.
    Gets the text.
    int
    Gets the hash code of this instance, consistent with equals: category, locations, show delay and text.
    Creates a string representation for textual output.

    Methods inherited from class Object

    getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • ABOVE

      public static final int ABOVE
      The location: ABOVE (=8).
      See Also:
    • BELOW

      public static final int BELOW
      The location: BELOW (=2).
      See Also:
    • BEFORE

      public static final int BEFORE
      The location: BEFORE (=4).
      See Also:
    • AFTER

      public static final int AFTER
      The location: AFTER (=6).
      See Also:
    • EMPTY

      public static final int[] EMPTY
      The "none" locations.
    • category

      public final int category
      The message category if this applies, -1 for none, 0=informational, 1=warning, 2=error.
    • showDelay

      public final int showDelay
      The show delay in milliseconds, 400 as default, values 0-9999 are allowed.
    • locations

      public final int locations
      The locations as an integer that needs packing up using getLocations(), zero for none.
  • Constructor Details

    • KTooltip

      public KTooltip(KString text)
      Creates a tooltip with a default location, category "none" and showDelay 400 ms.
      Parameters:
      text - The KString text for the tooltip.
      Throws:
      NullPointerException - if text is null.
    • KTooltip

      public KTooltip(KString text, KTooltip prev)
      Creates a tooltip with specified text and settings from another tooltip instance.
      Parameters:
      text - The KString text for the tooltip.
      prev - The previous instance for settings.
      Throws:
      NullPointerException - if text or prev is null.
    • KTooltip

      public KTooltip(KString text, int showDelay, int... locations)
      Creates a tooltip with category "none".
      Parameters:
      text - The KString text for the tooltip.
      showDelay - The show delay in milliseconds (0-9999, -1 for default 400 ms).
      locations - List of locations in order of preference, at most 4, each being ABOVE (8), BELOW (2), BEFORE (4) or AFTER (6). An invalid value or a longer list is logged as a warning and treated as no locations.
      Throws:
      NullPointerException - if text is null.
      IllegalArgumentException - if showDelay is not -1 to 9999.
    • KTooltip

      public KTooltip(KString text, int category)
      Creates a tooltip for a message with a default location and showDelay 400 ms.
      Parameters:
      text - The KString text for the tooltip.
      category - The message category if this applies, -1 for none, 0=informational, 1=warning, 2=error.
      Throws:
      NullPointerException - if text is null.
      IllegalArgumentException - if category is not -1 to 2.
    • KTooltip

      public KTooltip(KString text, int showDelay, int category, int... locations)
      Creates a tooltip for a message.
      Parameters:
      text - The KString text for the tooltip.
      showDelay - The show delay in milliseconds (0-9999, -1 for default 400 ms).
      category - The message category if this applies, -1 for none, 0=informational, 1=warning, 2=error.
      locations - List of locations in priority order, max 4.
      Throws:
      NullPointerException - if text is null.
      IllegalArgumentException - if showDelay is not -1 to 9999 or category is not -1 to 2.
  • Method Details

    • getText

      public KString getText()
      Gets the text.
      Returns:
      The KString text.
    • clone

      public KTooltip clone()
      Clones the tooltip.
      Overrides:
      clone in class Object
      Returns:
      A cloned tooltip.
    • dispose

      public void dispose()
      Disposes of the tooltip when no longer needed. This method is required for KString text.
    • finalize

      protected void finalize() throws Throwable
      Called when the tooltip is being garbage collected.

      The KString will be disposed if not previously disposed of.

      Overrides:
      finalize in class Object
      Throws:
      Throwable
    • getLocations

      public int[] getLocations()
      Gets the locations.
      Returns:
      A location list of integers, at most 4, each being ABOVE (8), BELOW (2), BEFORE (4) or AFTER (6), in order of preference. Empty for none.
    • equals

      public boolean equals(Object o)
      Checks if two tooltips are equal.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Gets the hash code of this instance, consistent with equals: category, locations, show delay and text.
      Overrides:
      hashCode in class Object
      Returns:
      The hash code.
    • equalsOmitReferenceRefreshCheck

      public boolean equalsOmitReferenceRefreshCheck(KTooltip tooltip)
      Checks for pure equality between two KTooltip's, excluding KString reference refresh counter checking but including potential original source string.

      This method is used when comparing values for e.g. save file.

      Parameters:
      tooltip - Another KTooltip, perhaps null.
      Returns:
      true if equal, false otherwise.
    • toString

      public String toString()
      Creates a string representation for textual output.
      Overrides:
      toString in class Object
      Returns:
      A string formatted for debug output or logging.