Class TLcdTTFIcon

java.lang.Object
com.luciad.gui.TLcdTTFIcon
All Implemented Interfaces:
ILcdIcon, ILcdCloneable, Serializable, Cloneable

public class TLcdTTFIcon extends Object implements ILcdIcon
Icon that displays a single text character based on a char.

Some fonts (usually symbol fonts) display their characters in a range not starting from \u0000. Mapping the font to a range starting from \u0000 is hidden from the user by most applications, so that they can still display the symbols while using the standard keyboard keys. TLcdTTFIcon uses a heuristic to calculate a font offset to hide this mapping from the user, the first time the font is used. This heuristic may fail and return an incorrect offset and then the user will have to set the offset manually with setFontOffset(char). This will set the font the offset only for the TLcdTTFIcon it is applied to, not to all icons that use that font.

The heuristic traverses the whole unicode range per 0x100 characters pages and returns as offset the page from which it can display the highest number of characters using Font.canDisplay(char).

Remarks:

  • The heuristic returns \u0100 for the dialog font
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct a default True Type Font icon: the character A in black Arial font, size 10.
    TLcdTTFIcon(char aCharacter, Font aFont, Color aColor)
    Constructs a True Type Font icon displaying the given character in the given font and color.
    TLcdTTFIcon(char aCharacter, Font aFont, Color aColor, double aRotation)
    Constructs a rotated True Type Font icon displaying the given character in the given font and color, with the given rotation angle.
    Copy constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    Makes Object.clone() public.
    boolean
    equals(Object aObject)
    Compares this object to aObject, by checking the font, the character, the color, the rotation and the offset.
    protected char
    This method finds the best offset for this icon's font.
    char
    Gets the character to display.
    Gets the color of the character.
    Gets the icon's font.
    char
    Gets the font offset.
    int
    Returns the font size as an approximation for the icon height.
    int
    Returns the font size as an approximation for the icon width.
    double
    Gets the rotation.
    boolean
    Shows if offset is used.
    void
    paintIcon(Component c, Graphics g, int aX, int aY)
    Draw the ILcdIcon at the specified location.
    void
    setCharacter(char aCharacter)
    Sets the character to display.
    void
    setColor(Color aColor)
    Sets the color of the character.
    void
    setFont(Font aFont)
    Set the icon's font.
    void
    setFontOffset(char aOffset)
    Sets the font offset.
    void
    setRotation(double aRotation)
    Sets the rotation of the icon.
    void
    setUseFontOffset(boolean aUseFontOffset)
    Use the offset or not.
     

    Methods inherited from class java.lang.Object

    finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • TLcdTTFIcon

      public TLcdTTFIcon()
      Construct a default True Type Font icon: the character A in black Arial font, size 10.
    • TLcdTTFIcon

      public TLcdTTFIcon(TLcdTTFIcon aIcon)
      Copy constructor.
      Parameters:
      aIcon - the icon to copy.
    • TLcdTTFIcon

      public TLcdTTFIcon(char aCharacter, Font aFont, Color aColor)
      Constructs a True Type Font icon displaying the given character in the given font and color.
      Parameters:
      aCharacter - the character to display.
      aFont - the Font to display the character in.
      aColor - the Color to display the character in.
    • TLcdTTFIcon

      public TLcdTTFIcon(char aCharacter, Font aFont, Color aColor, double aRotation)
      Constructs a rotated True Type Font icon displaying the given character in the given font and color, with the given rotation angle.
      Parameters:
      aCharacter - the character to display.
      aFont - the Font to display the character in.
      aColor - the Color to display the character in.
      aRotation - the rotation given in radials.
  • Method Details

    • paintIcon

      public void paintIcon(Component c, Graphics g, int aX, int aY)
      Description copied from interface: ILcdIcon
      Draw the ILcdIcon at the specified location. ILcdIcon implementations may use the Component argument to get properties useful for painting, e.g. the foreground or background color.
      Specified by:
      paintIcon in interface ILcdIcon
      Parameters:
      c - a Component to retrieve properties from.
      g - the Graphics on which the icon will be painted.
      aX - the x position where the icon will be painted. x is the first coordinate of the top left corner point of the icon.
      aY - the y position where the icon will be painted. y is the second coordinate of the top left corner point of the icon.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • clone

      public Object clone()
      Description copied from interface: ILcdCloneable

      Makes Object.clone() public.

      When for example extending from java.lang.Object, it can be implemented like this:
      
       public Object clone() {
         try {
           return super.clone();
         } catch ( CloneNotSupportedException e ) {
           // Cannot happen: extends from Object and implements Cloneable (see also Object.clone)
           throw new RuntimeException( e );
         }
       }
       
      Specified by:
      clone in interface ILcdCloneable
      Overrides:
      clone in class Object
      See Also:
    • getIconWidth

      public int getIconWidth()
      Returns the font size as an approximation for the icon width.
      Specified by:
      getIconWidth in interface ILcdIcon
      Returns:
      the font size as an approximation for the icon width.
    • getIconHeight

      public int getIconHeight()
      Returns the font size as an approximation for the icon height.
      Specified by:
      getIconHeight in interface ILcdIcon
      Returns:
      the font size as an approximation for the icon height.
    • equals

      public boolean equals(Object aObject)
      Compares this object to aObject, by checking the font, the character, the color, the rotation and the offset.
      Overrides:
      equals in class Object
      Parameters:
      aObject - the object to compare to.
      Returns:
      true if the character and font are the same.
    • setFont

      public void setFont(Font aFont)
      Set the icon's font. If needed the best offset is calculated.
      Parameters:
      aFont - the font to set.
      See Also:
    • getFont

      public Font getFont()
      Gets the icon's font.
      Returns:
      the icon's font.
      See Also:
    • setCharacter

      public void setCharacter(char aCharacter)
      Sets the character to display.
      Parameters:
      aCharacter - the character to display.
      See Also:
    • getCharacter

      public char getCharacter()
      Gets the character to display.
      Returns:
      the character to display.
      See Also:
    • setColor

      public void setColor(Color aColor)
      Sets the color of the character.
      Parameters:
      aColor - the color of the character.
      See Also:
    • getColor

      public Color getColor()
      Gets the color of the character.
      Returns:
      the color of the character.
      See Also:
    • setFontOffset

      public void setFontOffset(char aOffset)
      Sets the font offset. Manually setting the offset overrides the calculated offset. The font offset is a translation of the unicode, which can be useful for symbol fonts.
      Parameters:
      aOffset - the offset to use to calculate the character to display.
      See Also:
    • getFontOffset

      public char getFontOffset()
      Gets the font offset.
      Returns:
      the font offset.
      See Also:
    • isUseFontOffset

      public boolean isUseFontOffset()
      Shows if offset is used.
      Returns:
      true if an offset for the font has to be used.
      See Also:
    • setUseFontOffset

      public void setUseFontOffset(boolean aUseFontOffset)
      Use the offset or not.
      Parameters:
      aUseFontOffset - true to use the font offset.
      See Also:
    • setRotation

      public void setRotation(double aRotation)
      Sets the rotation of the icon. Has no effect in Java 1.1.
      Parameters:
      aRotation - the rotation of the character.
      See Also:
    • getRotation

      public double getRotation()
      Gets the rotation.
      Returns:
      the rotation of the character.
      See Also:
    • findFontOffset

      protected char findFontOffset(Font aFont)
      This method finds the best offset for this icon's font. The heuristic used to determine the best offset is the number of characters that can be displayed in a range of characters.
      Parameters:
      aFont - the font to find the offset for.
      Returns:
      best offset based on a heuristic