tnt.metrics
Class KeyButton

java.lang.Object
  extended by java.awt.geom.RectangularShape
      extended by java.awt.geom.Rectangle2D
          extended by java.awt.geom.Rectangle2D.Double
              extended by tnt.metrics.KeyButton
All Implemented Interfaces:
java.awt.Shape, java.io.Serializable, java.lang.Cloneable

public class KeyButton
extends java.awt.geom.Rectangle2D.Double
implements java.io.Serializable

A class to define keys on a keypad/keyboard. Each key is defined by at least five arguments: a char used to identify this key when listing keystrokes, a String representing the character(s) on the key, the key's center x coordinate, the key's center y coordinate, and the key's target width (i.e., the minimum of its width or height). The unit of measurement does not matter, but for this implementation, pixels are assumed.

For example, the following represents the keypad on a Nokia 5110 mobile phone:

            S  S     13.25 27 6
            2  abc   13.25 0  6
            3  def   26.5  0  6
            4  ghi   0     9  6
            5  jkl   13.25 9  6
            6  mno   26.5  9  6
            7  pqrs  0     18 6
            8  tuv   13.25 18 6
            9  wxyz  26.5  18 6
            N  N     25.5  -9 6
        
Note: Typically, the SPACE and NEXT keys are identified by "S" and "N" respectively and other key identifiers are all lowercase.

This class also inherits from Rectangle2D.Double, so its objects can be illustrated in the TnToolkit GUI. Make sure to note the difference between the key's dimensions (i.e., cx, cy, and tw) and those of its outlining rectangle (i.e., x, y, width, and height).

Version:
1.0 - 2001 (Key.java, 2001),
1.1 - 10/2005 (Restructured and renamed KeyButton.java)
Author:
Scott MacKenzie,
Steven J. Castellucci
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.geom.Rectangle2D
java.awt.geom.Rectangle2D.Double, java.awt.geom.Rectangle2D.Float
 
Field Summary
static int BOTH_THUMBS
          Indicates that this key is to be pressed by either thumb equally.
 java.lang.String chars
          The characters associated with this key.
 char key
          This key's identifier.
static int LEFT_THUMB
          Indicates that this key is to be pressed by the left thumb only.
static int RIGHT_THUMB
          Indicates that this key is to be pressed by the right thumb only.
 int thumb
          This key's thumb assignment.
 
Fields inherited from class java.awt.geom.Rectangle2D.Double
height, width, x, y
 
Fields inherited from class java.awt.geom.Rectangle2D
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP
 
Constructor Summary
KeyButton(char c, java.lang.String s, double x, double y, double tw)
          Initializes a new object with minimal parameters.
KeyButton(char c, java.lang.String s, double x, double y, double w, double h, int a)
          Initializes a new object.
 
Method Summary
 double distanceTo(KeyButton k)
          Return the Pythagorean distance from this key to the specified key.
 double getTW()
          Returns this key's target width.
 java.lang.String toString()
          Returns a concise String representation of this object to be used in lists.
 java.lang.String toStringForExport()
          Returns a white-space-delimited String representation of this object for the purpose of exporting to an input file.
 
Methods inherited from class java.awt.geom.Rectangle2D.Double
createIntersection, createUnion, getBounds2D, getHeight, getWidth, getX, getY, isEmpty, outcode, setRect, setRect
 
Methods inherited from class java.awt.geom.Rectangle2D
add, add, add, contains, contains, equals, getPathIterator, getPathIterator, hashCode, intersect, intersects, intersectsLine, intersectsLine, outcode, setFrame, union
 
Methods inherited from class java.awt.geom.RectangularShape
clone, contains, contains, getBounds, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, intersects, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

key

public char key
This key's identifier.


chars

public java.lang.String chars
The characters associated with this key.


thumb

public int thumb
This key's thumb assignment.

See Also:
LEFT_THUMB, RIGHT_THUMB, BOTH_THUMBS

LEFT_THUMB

public static final int LEFT_THUMB
Indicates that this key is to be pressed by the left thumb only.

See Also:
Constant Field Values

RIGHT_THUMB

public static final int RIGHT_THUMB
Indicates that this key is to be pressed by the right thumb only.

See Also:
Constant Field Values

BOTH_THUMBS

public static final int BOTH_THUMBS
Indicates that this key is to be pressed by either thumb equally.

See Also:
Constant Field Values
Constructor Detail

KeyButton

public KeyButton(char c,
                 java.lang.String s,
                 double x,
                 double y,
                 double w,
                 double h,
                 int a)
Initializes a new object.

Parameters:
c - a char used to identify this key when listing keystrokes.
s - a String representing the character(s) on the key.
x - the x-coordinate of this key's rectangular outline.
y - the y-coordinate of this key's rectangular outline.
w - the width this key's rectangular outline.
h - the height coordinate of this key's rectangular outline.
a - the thumb assignment of this key.
See Also:
LEFT_THUMB, RIGHT_THUMB, BOTH_THUMBS

KeyButton

public KeyButton(char c,
                 java.lang.String s,
                 double x,
                 double y,
                 double tw)
Initializes a new object with minimal parameters. This constructor assumes a square key, with RIGHT_THUMB assignment. This is primarily used for backwards compatibility with previous versions.

Parameters:
c - a char used to identify this key when listing keystrokes.
s - a String representing the character(s) on the key.
x - the x-coordinate of this key's rectangular outline.
y - the y-coordinate of this key's rectangular outline.
tw - the target width of this key.
Method Detail

getTW

public double getTW()
Returns this key's target width.

Returns:
the target width.

distanceTo

public double distanceTo(KeyButton k)
Return the Pythagorean distance from this key to the specified key.

Parameters:
k - the specified KeyButton object to which to compute the distance.
Returns:
a double representing the distance between the two keys.

toString

public java.lang.String toString()
Returns a concise String representation of this object to be used in lists. For example: Key: 8 tuv

Overrides:
toString in class java.awt.geom.Rectangle2D.Double
Returns:
a consise String representation of this object.

toStringForExport

public java.lang.String toStringForExport()
Returns a white-space-delimited String representation of this object for the purpose of exporting to an input file. Specifically, it returns the following: return "" + key + "\t" + chars + "\t" + getCenterX() + "\t" + getCenterY() + "\t" + getTW();

Returns:
a String representation of this object.