us.zuercher.gpx2map.plotter.label
Class Label

java.lang.Object
  extended by us.zuercher.gpx2map.plotter.label.Label

public class Label
extends Object

Label represents a text label for a marker.

Author:
Stephan Zuercher

Field Summary
private  Rectangle area
          The location of the label's rectangle in its current position.
private  Color color
          The label's color.
private  int distance
          The distance from the marker's center to the text.
private  Font font
          The label's font.
private  int height
          Height of the rectangle containing the rendered label text.
private  String label
          The label's text.
private  Point marker
          The location of the center of the label's marker.
private  LabelPosition position
          The label's current position relative to the marker.
private  LabelPosition preferredPosition
          The label's preferred location relative to the marker.
private  byte[][] textAlphaRasters
          A byte[] containing the 8-bit alpha levels for a rectangle that contains the rendered label text.
private  int width
          Width of the rectangle containing the rendered label text.
 
Constructor Summary
Label(String label, Point marker, int distance, Font font, Color color, Rectangle imageBounds)
          Construct a new Label.
 
Method Summary
private  Rectangle computeLocation(LabelPosition position)
          Compute a rectangle that bounds the rendered label text when drawn at the given position.
private  LabelPosition computePreferredPosition(Rectangle imageBounds)
          Compute the preferred position of this label.
 List<Pixel> getPixels()
          Returns a list of Pixel objects representing the rendered label text in its final position.
 LabelPosition getPosition()
          Returns the label's current position.
 LabelPosition getPreferredPosition()
          Returns the label's preferred position.
 Rectangle getRectangle()
          Returns the label's bounding rectangle.
private  byte[][] renderText()
          Generate a two-dimensional byte array of alpha values for the label text.
 void setPosition(LabelPosition position)
          Set the label's current position.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

label

private final String label
The label's text.


font

private final Font font
The label's font.


color

private final Color color
The label's color.


marker

private final Point marker
The location of the center of the label's marker.


distance

private final int distance
The distance from the marker's center to the text.


textAlphaRasters

private final byte[][] textAlphaRasters
A byte[] containing the 8-bit alpha levels for a rectangle that contains the rendered label text.


width

private final int width
Width of the rectangle containing the rendered label text.


height

private final int height
Height of the rectangle containing the rendered label text.


preferredPosition

private final LabelPosition preferredPosition
The label's preferred location relative to the marker.


position

private LabelPosition position
The label's current position relative to the marker.


area

private Rectangle area
The location of the label's rectangle in its current position.

Constructor Detail

Label

public Label(String label,
             Point marker,
             int distance,
             Font font,
             Color color,
             Rectangle imageBounds)
Construct a new Label. Sets the label's preferred position based on the image bounds.

Parameters:
label - label text
marker - marker location
distance - text distance from marker
font - text font
color - text color
imageBounds - image size
See Also:
computePreferredPosition(Rectangle)
Method Detail

getPosition

public LabelPosition getPosition()
Returns the label's current position.

Returns:
the label's current position.

getPreferredPosition

public LabelPosition getPreferredPosition()
Returns the label's preferred position.

Returns:
the label's preferred position.

setPosition

public void setPosition(LabelPosition position)
Set the label's current position. Automatically invalidates the cached result of getRectangle().

Parameters:
position - label's new position.

getRectangle

public Rectangle getRectangle()
Returns the label's bounding rectangle. This value is not clipped to the image size.

Returns:
the label's bounding rectangle.

getPixels

public List<Pixel> getPixels()
Returns a list of Pixel objects representing the rendered label text in its final position.

Returns:
a list of Pixel objects representing the rendered label.

renderText

private byte[][] renderText()
Generate a two-dimensional byte array of alpha values for the label text.

Returns:
a two-dimensional byte array of alpha values

computePreferredPosition

private LabelPosition computePreferredPosition(Rectangle imageBounds)
Compute the preferred position of this label. The preferred position is as given by LabelPosition.getPreferredOrder(). The first position given in that array that does not cause the label to be clipped by the image bounds is returned.

Parameters:
imageBounds - the cropping rectangle that represents the final image
Returns:
this label's preferred position relative to its marker.

computeLocation

private Rectangle computeLocation(LabelPosition position)
Compute a rectangle that bounds the rendered label text when drawn at the given position.

Parameters:
position - a label position
Returns:
a rectangle that bounds the rendered label text.