edu.rit.numeric.plot.impl
Class Label
- java.lang.Object
-
- edu.rit.numeric.plot.impl.Label
-
- All Implemented Interfaces:
- Drawable, java.io.Externalizable, java.io.Serializable
public class Label extends java.lang.Object implements Drawable, java.io.Externalizable
Class Label provides an object for drawing arbitrary text on a plot. A label has a location, a certain pair of coordinates (x,y) on the plot. A label can be drawn at any one of nine positions relative to its location: above left, above, above right, left, center, right, below left, below, or below right. A label can be offset a certain distance from its location. A label can be not rotated, rotated 90 degrees left, rotated 90 degrees right, or rotated 180 degrees. A label's location can be specified either in plot coordinates or in pixel coordinates.Class Label supports a subset of HTML for specifying attributes of characters. The following HTML tags may be embedded in a label's text:
- <B>Bold</B>
- <I>Italic</I>
- <SUP>Superscript</SUP>
- <SUB>Subscript</SUB>
To get literal less-than, greater-than, and ampersand characters in the text, use the following HTML character entities:
- < -- Less-than (<)
- > -- Greater-than (>)
- & -- Ampersand (&)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static intABOVEThe label is positioned above its location.static intABOVE_LEFTThe label is positioned above and to the left of its location.static intABOVE_RIGHTThe label is positioned above and to the right of its location.static intBELOWThe label is positioned below its location.static intBELOW_LEFTThe label is positioned below and to the left of its location.static intBELOW_RIGHTThe label is positioned below and to the right of its location.static intCENTERThe label is centered on its location.static java.awt.FontDEFAULT_FONTThe default label font (sanserif, plain, 12 point).static java.awt.ColorDEFAULT_PAINTThe default label color (black).static intLEFTThe label is positioned to the left of its location.static intPIXEL_COORDINATESThe label's location is specified in pixel coordinates relative to the lower left corner of the plot area, rather than in plot coordinates.static intRIGHTThe label is positioned to the right of its location.static intROTATE_AROUNDThe label is rotated 180 degrees around.static intROTATE_LEFTThe label is rotated 90 degrees left (counterclockwise).static intROTATE_RIGHTThe label is rotated 90 degrees right (clockwise).
-
Constructor Summary
Constructors Constructor and Description Label()Construct a new label.Label(java.lang.String text, double x, double y)Construct a new label with the given text and location.Label(java.lang.String text, double x, double y, int position)Construct a new label with the given text, location, and positioning.Label(java.lang.String text, double x, double y, int position, double offset)Construct a new label with the given text, location, positioning, and offset from its location.Label(java.lang.String text, double x, double y, int position, double offset, java.awt.Font font)Construct a new label with the given text, location, positioning, offset from its location, and font.Label(java.lang.String text, double x, double y, int position, double offset, java.awt.Font font, java.awt.Color color)Construct a new label with the given text, location, positioning, offset from its location, font, and color.Label(java.lang.String text, double x, double y, int position, double offset, java.awt.Font font, java.awt.Color color, java.awt.Color bg)Construct a new label with the given text, location, positioning, offset from its location, font, color, and background.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voiddraw(java.awt.Graphics2D g2d)Draw this drawable object in the given graphics context.java.awt.ColorgetBackground()Returns the color for drawing this label's background on the display.java.awt.ColorgetColor()Returns the color for drawing this label on the display.java.awt.FontgetFont()Returns this label's font.doublegetLocationX()Returns the X coordinate of this label's location.doublegetLocationY()Returns the Y coordinate of this label's location.doublegetOffset()Returns this label's offset from its location on the display (in display units).intgetPositioning()Returns this label's positioning.java.lang.StringgetText()Returns this label's text.voidreadExternal(java.io.ObjectInput in)Read this label from the given object input stream.voidwriteExternal(java.io.ObjectOutput out)Write this label to the given object output stream.
-
-
-
Field Detail
-
ABOVE_LEFT
public static final int ABOVE_LEFT
The label is positioned above and to the left of its location.- See Also:
- Constant Field Values
-
ABOVE
public static final int ABOVE
The label is positioned above its location.- See Also:
- Constant Field Values
-
ABOVE_RIGHT
public static final int ABOVE_RIGHT
The label is positioned above and to the right of its location.- See Also:
- Constant Field Values
-
LEFT
public static final int LEFT
The label is positioned to the left of its location.- See Also:
- Constant Field Values
-
CENTER
public static final int CENTER
The label is centered on its location.- See Also:
- Constant Field Values
-
RIGHT
public static final int RIGHT
The label is positioned to the right of its location.- See Also:
- Constant Field Values
-
BELOW_LEFT
public static final int BELOW_LEFT
The label is positioned below and to the left of its location.- See Also:
- Constant Field Values
-
BELOW
public static final int BELOW
The label is positioned below its location.- See Also:
- Constant Field Values
-
BELOW_RIGHT
public static final int BELOW_RIGHT
The label is positioned below and to the right of its location.- See Also:
- Constant Field Values
-
ROTATE_LEFT
public static final int ROTATE_LEFT
The label is rotated 90 degrees left (counterclockwise).- See Also:
- Constant Field Values
-
ROTATE_RIGHT
public static final int ROTATE_RIGHT
The label is rotated 90 degrees right (clockwise).- See Also:
- Constant Field Values
-
ROTATE_AROUND
public static final int ROTATE_AROUND
The label is rotated 180 degrees around.- See Also:
- Constant Field Values
-
PIXEL_COORDINATES
public static final int PIXEL_COORDINATES
The label's location is specified in pixel coordinates relative to the lower left corner of the plot area, rather than in plot coordinates.- See Also:
- Constant Field Values
-
DEFAULT_FONT
public static final java.awt.Font DEFAULT_FONT
The default label font (sanserif, plain, 12 point).
-
DEFAULT_PAINT
public static final java.awt.Color DEFAULT_PAINT
The default label color (black).
-
-
Constructor Detail
-
Label
public Label()
Construct a new label. This constructor is intended for use only by object deserialization.
-
Label
public Label(java.lang.String text, double x, double y)Construct a new label with the given text and location. The label is centered on its location and is not rotated. The default font and color are used. The label has no background.- Parameters:
text- Label text.x- X coordinate of this label's location.y- Y coordinate of this label's location.- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if text is null.
-
Label
public Label(java.lang.String text, double x, double y, int position)Construct a new label with the given text, location, and positioning. The default font and color are used. The label has no background.- Parameters:
text- Label text.x- X coordinate of this label's location.y- Y coordinate of this label's location.position- This label's positioning, ABOVE_LEFT through BELOW_RIGHT. Optionally, ROTATE_LEFT through ROTATE_AROUND may be added; e.g., LEFT+ROTATE_LEFT. Optionally, PIXEL_COORDINATES may be added.- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if text is null.java.lang.IllegalArgumentException- (unchecked exception) Thrown if position is invalid.
-
Label
public Label(java.lang.String text, double x, double y, int position, double offset)Construct a new label with the given text, location, positioning, and offset from its location. The default font and color are used. The label has no background. If the label's positioning is CENTER, the offset is not used.- Parameters:
text- Label text.x- X coordinate of this label's location.y- Y coordinate of this label's location.position- This label's positioning, ABOVE_LEFT through BELOW_RIGHT. Optionally, ROTATE_LEFT through ROTATE_AROUND may be added; e.g., LEFT+ROTATE_LEFT. Optionally, PIXEL_COORDINATES may be added.offset- Offset from this label's location on the display (in display units).- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if text is null.java.lang.IllegalArgumentException- (unchecked exception) Thrown if position is invalid. Thrown if offset is less than 0.
-
Label
public Label(java.lang.String text, double x, double y, int position, double offset, java.awt.Font font)Construct a new label with the given text, location, positioning, offset from its location, and font. The default color is used. The label has no background. If the label's positioning is CENTER, the offset is not used.- Parameters:
text- Label text.x- X coordinate of this label's location.y- Y coordinate of this label's location.position- This label's positioning, ABOVE_LEFT through BELOW_RIGHT. Optionally, ROTATE_LEFT through ROTATE_AROUND may be added; e.g., LEFT+ROTATE_LEFT. Optionally, PIXEL_COORDINATES may be added.offset- Offset from this label's location on the display (in display units).font- Font for drawing this label.- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if text is null or font is null.java.lang.IllegalArgumentException- (unchecked exception) Thrown if position is invalid. Thrown if offset is less than 0.
-
Label
public Label(java.lang.String text, double x, double y, int position, double offset, java.awt.Font font, java.awt.Color color)Construct a new label with the given text, location, positioning, offset from its location, font, and color. The label has no background. If the label's positioning is CENTER, the offset is not used.- Parameters:
text- Label text.x- X coordinate of this label's location.y- Y coordinate of this label's location.position- This label's positioning, ABOVE_LEFT through BELOW_RIGHT. Optionally, ROTATE_LEFT through ROTATE_AROUND may be added; e.g., LEFT+ROTATE_LEFT. Optionally, PIXEL_COORDINATES may be added.offset- Offset from this label's location on the display (in display units).font- Font for drawing this label.color- Color for drawing this label.- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if text is null, font is null, or color is null.java.lang.IllegalArgumentException- (unchecked exception) Thrown if position is invalid. Thrown if offset is less than 0.
-
Label
public Label(java.lang.String text, double x, double y, int position, double offset, java.awt.Font font, java.awt.Color color, java.awt.Color bg)Construct a new label with the given text, location, positioning, offset from its location, font, color, and background. If bg is null, the label has no background. If the label's positioning is CENTER, the offset is not used.- Parameters:
text- Label text.x- X coordinate of this label's location.y- Y coordinate of this label's location.position- This label's positioning, ABOVE_LEFT through BELOW_RIGHT. Optionally, ROTATE_LEFT through ROTATE_AROUND may be added; e.g., LEFT+ROTATE_LEFT. Optionally, PIXEL_COORDINATES may be added.offset- Offset from this label's location on the display (in display units).font- Font for drawing this label.color- Color for drawing this label.bg- Color for drawing this label's background.- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if text is null, font is null, or color is null.java.lang.IllegalArgumentException- (unchecked exception) Thrown if position is invalid. Thrown if offset is less than 0.
-
-
Method Detail
-
getText
public java.lang.String getText()
Returns this label's text.
-
getLocationX
public double getLocationX()
Returns the X coordinate of this label's location.
-
getLocationY
public double getLocationY()
Returns the Y coordinate of this label's location.
-
getPositioning
public int getPositioning()
Returns this label's positioning. The return value is ABOVE_LEFT through BELOW_RIGHT. If the label is rotated, one of the values ROTATE_LEFT through ROTATE_AROUND is added. If the pixel's location is specified in pixel coordinates rather than plot coordinates, PIXEL_COORDINATES is added.
-
getOffset
public double getOffset()
Returns this label's offset from its location on the display (in display units).
-
getFont
public java.awt.Font getFont()
Returns this label's font.
-
getColor
public java.awt.Color getColor()
Returns the color for drawing this label on the display.
-
getBackground
public java.awt.Color getBackground()
Returns the color for drawing this label's background on the display. If this label has no background, null is returned.
-
draw
public void draw(java.awt.Graphics2D g2d)
Draw this drawable object in the given graphics context. Upon return from this method, the given graphics context's state (color, font, transform, clip, and so on) is the same as it was upon entry to this method.The label is drawn at position (0,0). It is the caller's responsibility to transform the graphics context so the label ends up at the correct (x,y) coordinates.
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOExceptionWrite this label to the given object output stream.- Specified by:
writeExternalin interfacejava.io.Externalizable- Parameters:
out- Object output stream.- Throws:
java.io.IOException- Thrown if an I/O error occurred.
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionRead this label from the given object input stream.- Specified by:
readExternalin interfacejava.io.Externalizable- Parameters:
in- Object input stream.- Throws:
java.io.IOException- Thrown if an I/O error occurred.java.lang.ClassNotFoundException- Thrown if a class needed to deserialize this label could not be found.
-
-
DMelt 3.0 © DataMelt by jWork.ORG