lt.monarch.chart.text
Class TextPainter

java.lang.Object
  extended by lt.monarch.chart.text.TextPainter
All Implemented Interfaces:
java.io.Serializable, AbstractTextPainter
Direct Known Subclasses:
Rotated90TextPainter, RotatedLabelPainter, StackedTextPainter

public class TextPainter
extends java.lang.Object
implements java.io.Serializable, AbstractTextPainter

See Also:
Serialized Form

Field Summary
Modifier and Type Field and Description
protected  Rectangle2D boundingBox
           
protected  Alignment hAlignment
          Default horizontal alignment.
protected  java.lang.String[] text
          String to be painted.
protected  Alignment vAlignment
          Default vertical alignment.
protected  int xMargin
          Default horizontal margin.
protected  int yMargin
          Default vertical margin.
 
Constructor Summary
Constructor and Description
TextPainter()
          Creates text painter with empty text string.
TextPainter(java.lang.String s)
          Creates default text painter for specified text string.
TextPainter(java.lang.String[] s)
          Creates default text painter for specified string array.
TextPainter(java.lang.String s, Alignment hAlign, Alignment vAlign)
          Creates new text painter with specified text, horizontal and vertical alignments.
 
Method Summary
Modifier and Type Method and Description
 void dispose()
          Disposes the painter
 Rectangle2D findBounds(AbstractGraphics g, Rectangle2D r)
          Finds the bounding box of text painting area.
 Rectangle2D getBounds()
          Gets text painter bounds
 Alignment getHorizontalAlignment()
          Returns horizontal text alignment.
 int getHorizontalMargin()
          Returns value of horizontal text margin.
protected  int getMarginInPixels(java.awt.FontMetrics fm, int margin)
          Returns text margin in pixels.
 int getMinimumHeight(java.awt.FontMetrics fm, int width)
          Returns minimum height of text drawn using given font metrics into area of given width.
 java.awt.Dimension getMinimumSize(AbstractGraphics g)
          Returns the minimum font size of the specified graphics context's current font.
 java.awt.Dimension getMinimumSize(java.awt.FontMetrics fm)
          Returns the minimum font size of the specified font metrics.
 java.lang.String getText()
          Returns transformed text (with \n).
 Alignment getVerticalAlignment()
          Returns vertical text alignment.
 int getVerticalMargin()
          Returns value of vertical text margin.
 boolean getWrappingEnabled()
          Returns whether or not word wrapping is enabled.
 void paint(AbstractGraphics g, Rectangle2D r)
          Paints text into specified rectangle using provided graphics context.
 void setHorizontalAlignment(Alignment align)
          Sets horizontal text alignment.
 void setHorizontalMargin(int margin)
          Sets specified margin value for horizontal text margin.
 void setMargin(int margin)
          Sets equal specified margin value for horizontal and vertical text margin.
 void setText(java.lang.String s)
          Sets text for text painter.
 void setText(java.lang.String[] strings)
          Sets text array
 void setVerticalAlignment(Alignment align)
          Sets vertical text alignment.
 void setVerticalMargin(int margin)
          Sets specified margin value for vertical text margin.
 void setWrappingEnabled(boolean enable)
          Enables/disabled word wrapping when drawing the text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

boundingBox

protected Rectangle2D boundingBox

text

protected java.lang.String[] text
String to be painted.


hAlignment

protected Alignment hAlignment
Default horizontal alignment.


vAlignment

protected Alignment vAlignment
Default vertical alignment.


xMargin

protected int xMargin
Default horizontal margin.


yMargin

protected int yMargin
Default vertical margin.

Constructor Detail

TextPainter

public TextPainter(java.lang.String s,
                   Alignment hAlign,
                   Alignment vAlign)
Creates new text painter with specified text, horizontal and vertical alignments. Default text margin is 20.

Parameters:
s - string to be painted.
hAlign - horizontal alignment. Possible alignments: CENTER, LEFT, RIGHT.
vAlign - vertical alignment. Possible alignments: CENTER, TOP, BOTTOM.

TextPainter

public TextPainter(java.lang.String s)
Creates default text painter for specified text string. Horizontal alignment is LEFT and vertical alignment is TOP. Default text margin is 20.

Parameters:
s - text string.

TextPainter

public TextPainter(java.lang.String[] s)
Creates default text painter for specified string array.

Parameters:
s - string array.

TextPainter

public TextPainter()
Creates text painter with empty text string.

Method Detail

setHorizontalAlignment

public void setHorizontalAlignment(Alignment align)
Description copied from interface: AbstractTextPainter
Sets horizontal text alignment.

Specified by:
setHorizontalAlignment in interface AbstractTextPainter
Parameters:
align - value of horizontal alignment. Possible values are : CENTER, LEFT, RIGHT.

setVerticalAlignment

public void setVerticalAlignment(Alignment align)
Description copied from interface: AbstractTextPainter
Sets vertical text alignment.

Specified by:
setVerticalAlignment in interface AbstractTextPainter
Parameters:
align - value of vertical alignment. Possible values are: CENTER, TOP, BOTTOM.

getHorizontalAlignment

public Alignment getHorizontalAlignment()
Description copied from interface: AbstractTextPainter
Returns horizontal text alignment.

Specified by:
getHorizontalAlignment in interface AbstractTextPainter
Returns:
horizontal text alignment

getVerticalAlignment

public Alignment getVerticalAlignment()
Description copied from interface: AbstractTextPainter
Returns vertical text alignment.

Specified by:
getVerticalAlignment in interface AbstractTextPainter
Returns:
vertical text alignment

getHorizontalMargin

public int getHorizontalMargin()
Description copied from interface: AbstractTextPainter
Returns value of horizontal text margin.

Specified by:
getHorizontalMargin in interface AbstractTextPainter
Returns:
value of horizontal text margin.

getVerticalMargin

public int getVerticalMargin()
Description copied from interface: AbstractTextPainter
Returns value of vertical text margin.

Specified by:
getVerticalMargin in interface AbstractTextPainter
Returns:
value of vertical text margin.

setMargin

public void setMargin(int margin)
Description copied from interface: AbstractTextPainter
Sets equal specified margin value for horizontal and vertical text margin.

Specified by:
setMargin in interface AbstractTextPainter
Parameters:
margin - text margin value.

setHorizontalMargin

public void setHorizontalMargin(int margin)
Description copied from interface: AbstractTextPainter
Sets specified margin value for horizontal text margin.

Specified by:
setHorizontalMargin in interface AbstractTextPainter
Parameters:
margin - text margin value.

setVerticalMargin

public void setVerticalMargin(int margin)
Description copied from interface: AbstractTextPainter
Sets specified margin value for vertical text margin.

Specified by:
setVerticalMargin in interface AbstractTextPainter
Parameters:
margin - text margin value.

setWrappingEnabled

public void setWrappingEnabled(boolean enable)
Description copied from interface: AbstractTextPainter
Enables/disabled word wrapping when drawing the text.

Specified by:
setWrappingEnabled in interface AbstractTextPainter
Parameters:
enable - true for enabling, false for disabling.

getWrappingEnabled

public boolean getWrappingEnabled()
Description copied from interface: AbstractTextPainter
Returns whether or not word wrapping is enabled.

Specified by:
getWrappingEnabled in interface AbstractTextPainter
Returns:
true if enabled, false if disabled.

setText

public void setText(java.lang.String[] strings)
Sets text array

Parameters:
strings - text string array

setText

public void setText(java.lang.String s)
Description copied from interface: AbstractTextPainter
Sets text for text painter.

Specified by:
setText in interface AbstractTextPainter
Parameters:
s - text string.

getText

public java.lang.String getText()
Returns transformed text (with \n).

Returns:
s text

getMinimumSize

public final java.awt.Dimension getMinimumSize(AbstractGraphics g)
Description copied from interface: AbstractTextPainter
Returns the minimum font size of the specified graphics context's current font.

Specified by:
getMinimumSize in interface AbstractTextPainter
Parameters:
g - graphics context.
Returns:
dimension of font metrics placed in graphics context

getMinimumSize

public java.awt.Dimension getMinimumSize(java.awt.FontMetrics fm)
Description copied from interface: AbstractTextPainter
Returns the minimum font size of the specified font metrics.

Specified by:
getMinimumSize in interface AbstractTextPainter
Parameters:
fm - font metrics.
Returns:
dimension of font metrics placed in graphics context
See Also:
FontMetrics

getMinimumHeight

public int getMinimumHeight(java.awt.FontMetrics fm,
                            int width)
Description copied from interface: AbstractTextPainter
Returns minimum height of text drawn using given font metrics into area of given width. If word wrapping is enabled, returned height will fit entire wrapped text.

Specified by:
getMinimumHeight in interface AbstractTextPainter
Parameters:
fm - font metrics.
width - given width.
Returns:
text height for given width.

getMarginInPixels

protected int getMarginInPixels(java.awt.FontMetrics fm,
                                int margin)
Returns text margin in pixels.

Parameters:
fm - current font metrics.
margin - text margin value.

findBounds

public Rectangle2D findBounds(AbstractGraphics g,
                              Rectangle2D r)
Description copied from interface: AbstractTextPainter
Finds the bounding box of text painting area.

Specified by:
findBounds in interface AbstractTextPainter
Parameters:
g - current graphics context.
r - text string rectangle.
Returns:
bounding box

paint

public void paint(AbstractGraphics g,
                  Rectangle2D r)
Description copied from interface: AbstractTextPainter
Paints text into specified rectangle using provided graphics context.

Specified by:
paint in interface AbstractTextPainter
Parameters:
g - current graphics context.
r - area of text painting.

getBounds

public Rectangle2D getBounds()
Description copied from interface: AbstractTextPainter
Gets text painter bounds

Specified by:
getBounds in interface AbstractTextPainter
Returns:
bounds rectangle

dispose

public void dispose()
Description copied from interface: AbstractTextPainter
Disposes the painter

Specified by:
dispose in interface AbstractTextPainter