|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.davisor.graphics.LabelRenderer
LabelRenderer is a high-precision and high-quality label renderer that can render a rotated, scaled, and aligned labels into restricted rectangular areas. A dedicated label rendering tool is needed for this because naive affine scaling implementations often producing visually unpleasing results. This label renderer tool offers much better quality scaling results in all Java environment implementations, and offers also a number of other advanced label rendering functions.
LabelRenderer fits text in given restrictive rectangle by first selecting the largest possible font size with which the text fits completely inside a given area. This quarantees superior rendering quality when compared to corresponding plain affine scaling. This may also however still leave the text smaller than strictly neccessary. The label renderer will therefore apply an additional enlarging affine scaling, but now only with a small multiplier. Small enlarging affine text scaling does not detoriate text visual quality as much as other kind of affine text scaling, so the text visual quality is quaranteed to stay high while the text is made to fit the given space exactly.
Text scaling is applied only if given text will not fit into given area when rendered with given target font. Instead, if the text fits, it is rendered with given target font and font size, and not scaled up to fill up entirely the given area. Some area may therefore be left over, and this raises the question of text alignment withing the area.
Label renderer supports vertical and horizontal text alignment for
the whole text label, and row-spesific horizontal text aligment for
the individual rows of a multi-line text label. Please see RenderAttributes for available alignments and their codes.
Label size computation can be carried out it many different ways,
and the selected strategy affects text scaling and alignment
computation in suble ways. Label renderer supports the folliwing
label size computation methods. Please see getTextBounds(int) and
getRowBounds(java.lang.String, java.awt.Font, java.awt.font.FontRenderContext, int) for more information.
Font.getStringBounds
GlyphVector.getLogicalBounds
GlyphVector.getVisualBounds
Each label renderer instance is tuned to render only one label at a time, thanks to the complex high-precision text rendering issues involved.
draw(Graphics2D,Paint,Paint,float,float,int,int),
getRowBounds(String,Font,FontRenderContext,int),
getTextBounds(String,Font,FontRenderContext,int)| Field Summary | |
static int |
LOGICALBOUNDS
Logical bounds text bounding box resolvation mode. |
protected float |
M_ax
|
protected float |
M_ay
|
protected float |
M_derivedBloat
|
protected java.awt.Font |
M_derivedFont
|
protected java.awt.font.FontRenderContext |
M_frc
|
protected float |
M_height
|
protected int |
M_mode
|
protected java.awt.geom.Rectangle2D |
M_naturalBounds
|
protected java.awt.Font |
M_originalFont
|
protected java.awt.geom.Rectangle2D |
M_rotatedBounds
|
protected float |
M_rotation
|
protected java.lang.String |
M_text
|
protected float |
M_width
|
static int |
MAX
Maximum text bounding box resolvation mode. |
static int |
MEDIAN
Median text bounding box resolvation mode. |
static int |
MIN
Minimum text bounding box resolvation mode. |
static int |
STRINGBOUNDS
String bounds text bounding box resolvation mode (the default). |
static int |
VISUALBOUNDS
Visual bounds text bounding box resolvation mode. |
| Constructor Summary | |
LabelRenderer(java.awt.Font font,
java.awt.font.FontRenderContext frc,
float width,
float height,
float rotation,
float ax,
float ay,
int mode)
Creates a new label renderer instance. |
|
LabelRenderer(java.awt.Font font,
java.awt.font.FontRenderContext frc,
float width,
float height,
float rotation,
float ax,
float ay,
int mode,
java.lang.String text)
Creates a new label renderer instance. |
|
LabelRenderer(java.lang.String text,
java.awt.Font font,
java.awt.font.FontRenderContext frc,
float width,
float height,
float rotation,
float ax,
float ay,
int mode)
Deprecated. Please use LabelRenderer(Font,
FontRenderContext, float, float, float, float, float, int,
String) instead. |
|
| Method Summary | |
static java.awt.geom.Rectangle2D |
addBounds(java.awt.geom.Rectangle2D b1,
java.awt.geom.Rectangle2D b2)
Adds a text bounding box to another in null safe way. |
void |
draw(java.awt.Graphics2D g,
java.awt.Paint color,
java.awt.Paint paint,
float x,
float y,
int boundsAlignment,
int textAlignment)
Draws current label into the given graphics context in the given position. |
void |
draw(java.awt.Graphics2D g,
java.awt.Paint color,
java.awt.Paint paint,
float x,
float y,
int boundsAlignment,
int textAlignment,
java.lang.String text)
Draws given label into the given graphics context in the given position. |
java.awt.Font |
getFont()
Gets the font used to draw the label. |
float |
getHeight()
Gets the height of the box bounding the label. |
static java.awt.geom.Rectangle2D |
getRowBounds(java.lang.String text,
java.awt.Font font,
java.awt.font.FontRenderContext frc,
int mode)
Returns text row bounding box. |
static java.awt.geom.Rectangle2D |
getRowBounds(java.lang.String text,
java.awt.Font font,
java.awt.font.FontRenderContext frc,
int mode,
java.awt.geom.Rectangle2D bounds)
Adds text row bounding box to given bounds. |
java.lang.String |
getText()
Gets the current label text. |
java.awt.geom.Rectangle2D |
getTextBounds(int mode)
Wrapper for the static getTextBounds()method. |
static java.awt.geom.Rectangle2D |
getTextBounds(java.lang.String text,
java.awt.Font font,
java.awt.font.FontRenderContext frc,
int mode)
Returns multiline text bounding box. |
static java.awt.geom.Rectangle2D |
getTextBounds(java.lang.String text,
java.awt.Font font,
java.awt.font.FontRenderContext frc,
int mode,
java.awt.geom.Rectangle2D bounds)
Adds multiline text bounding box to given bounds. |
float |
getWidth()
Gets the width of the box bounding the label. |
protected void |
init()
Prepares label rendering based on current settings. |
void |
setFont(java.awt.Font font)
Sets label font. |
void |
setSize(float width,
float height)
Sets label size restrictions. |
void |
setText(java.lang.String text)
Sets current label text. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int STRINGBOUNDS
public static final int LOGICALBOUNDS
public static final int VISUALBOUNDS
public static final int MEDIAN
public static final int MIN
public static final int MAX
protected java.awt.Font M_derivedFont
protected java.awt.Font M_originalFont
protected java.awt.font.FontRenderContext M_frc
protected java.awt.geom.Rectangle2D M_naturalBounds
protected java.awt.geom.Rectangle2D M_rotatedBounds
protected java.lang.String M_text
protected float M_ax
protected float M_ay
protected float M_derivedBloat
protected float M_height
protected float M_rotation
protected float M_width
protected int M_mode
| Constructor Detail |
public LabelRenderer(java.awt.Font font,
java.awt.font.FontRenderContext frc,
float width,
float height,
float rotation,
float ax,
float ay,
int mode)
font - label fontfrc - the font render contextwidth - label maximum width in device coordinates (non-positive
values impose no width restrictions)height - label maximum height in device coordinates (non-positive
values impose no height restrictions)rotation - the rotation of labels of this axisax - X font scaling (-1 flips the font)ay - Y font scaling (-1 flips the font)mode - bounds computing method (see class description)
(invalid modes default to STRINGBOUNDS)
java.lang.IllegalArgumentException - if font or frc
is nullgetHeight(),
getTextBounds(int),
getWidth(),
RenderAttributes
public LabelRenderer(java.awt.Font font,
java.awt.font.FontRenderContext frc,
float width,
float height,
float rotation,
float ax,
float ay,
int mode,
java.lang.String text)
font - label fontfrc - the font render contextwidth - label maximum width in device coordinates (non-positive
values impose no width restrictions)height - label maximum height in device coordinates (non-positive
values impose no height restrictions)rotation - the rotation of labels of this axisax - X font scaling (-1 flips the font)ay - Y font scaling (-1 flips the font)mode - bounds computing method (see class description)
(invalid modes default to STRINGBOUNDS)text - label text
java.lang.IllegalArgumentException - if font or frc
is nullgetHeight(),
getTextBounds(int),
getWidth(),
RenderAttributes
public LabelRenderer(java.lang.String text,
java.awt.Font font,
java.awt.font.FontRenderContext frc,
float width,
float height,
float rotation,
float ax,
float ay,
int mode)
LabelRenderer(Font,
FontRenderContext, float, float, float, float, float, int,
String) instead.
font - label fontfrc - the font render contextwidth - label maximum width in device coordinates (non-positive
values impose no width restrictions)height - label maximum height in device coordinates (non-positive
values impose no height restrictions)rotation - the rotation of labels of this axisax - X font scaling (-1 flips the font)ay - Y font scaling (-1 flips the font)mode - bounds computing method (see class description)
(invalid modes default to STRINGBOUNDS)text - label text
java.lang.IllegalArgumentException - if font or frc
is nullgetHeight(),
getTextBounds(int),
getWidth(),
RenderAttributes| Method Detail |
protected void init()
draw(Graphics2D,Paint,Paint,float,float,int,int),
getFont()
public void draw(java.awt.Graphics2D g,
java.awt.Paint color,
java.awt.Paint paint,
float x,
float y,
int boundsAlignment,
int textAlignment)
If a label background paint is given, the label bounding box will be filled with that paint before the label itself is drawn.
g - the graphics contextcolor - label foreground color (may be null)paint - label background paint (may be null)x - label X-position in device coordinatesy - label Y-position in device coordinatesboundsAlignment - text bounding box alignment
(RenderAttributes alignment code)textAlignment - text alignment within text bounding box
(RenderAttributes alignment code)init()
public void draw(java.awt.Graphics2D g,
java.awt.Paint color,
java.awt.Paint paint,
float x,
float y,
int boundsAlignment,
int textAlignment,
java.lang.String text)
This method first sets current text to given text with setText(java.lang.String), and then calls the actual drawing method draw(Graphics2D,Paint,Paint,float,float,int,int).
g - the graphics contextcolor - label foreground color (may be null)paint - label background paint (may be null)x - label X-position in device coordinatesy - label Y-position in device coordinatesboundsAlignment - text bounding box alignment
(RenderAttributes alignment code)textAlignment - text alignment within text bounding box
(RenderAttributes alignment code)text - label textdraw(Graphics2D,Paint,Paint,float,float,int,int),
setText(java.lang.String)public java.awt.Font getFont()
init()public float getHeight()
init(),
setSize(float, float)public java.lang.String getText()
setText(java.lang.String)public float getWidth()
init(),
setSize(float, float)public void setFont(java.awt.Font font)
getFont()
public void setSize(float width,
float height)
width - label maximum width in device coordinates (non-positive
values impose no width restrictios)height - label maximum height in device coordinates (non-positive
values impose no height restrictios)public void setText(java.lang.String text)
text - label textgetText()
public static java.awt.geom.Rectangle2D addBounds(java.awt.geom.Rectangle2D b1,
java.awt.geom.Rectangle2D b2)
null safe way.
b1 - bounds to add the other bounds to (may be null)b2 - bounds to add into the other bounds (may be null)
b1 after addition, or a new
high-precision copy of b2 if b1 was
null, or null of both rectangles were
null
public static java.awt.geom.Rectangle2D getRowBounds(java.lang.String text,
java.awt.Font font,
java.awt.font.FontRenderContext frc,
int mode)
null text or font will give
null bounds.
text - the text to be measured (may be null)font - font to render text with (may be null)frc - the font render context (if null, the one in g is used)mode - bounds computing method (see class description)
(invalid modes default to STRINGBOUNDS)
getRowBounds(String,Font,FontRenderContext,int,Rectangle2D)
public static java.awt.geom.Rectangle2D getRowBounds(java.lang.String text,
java.awt.Font font,
java.awt.font.FontRenderContext frc,
int mode,
java.awt.geom.Rectangle2D bounds)
text - the text to be measured (may be null)font - font to render text with (may be null)frc - the font render context. If null, the one in g is used.mode - bounds computing method (see class description)
(invalid modes default to STRINGBOUNDS)bounds - old bounds to add text bounding box to (may be null)
addBounds(java.awt.geom.Rectangle2D, java.awt.geom.Rectangle2D),
getRowBounds(String,Font,FontRenderContext,int),
getTextBounds(String,Font,FontRenderContext,int,Rectangle2D)public java.awt.geom.Rectangle2D getTextBounds(int mode)
mode - bounds computing method (see class description)getTextBounds(String,Font,FontRenderContext,int)
public static java.awt.geom.Rectangle2D getTextBounds(java.lang.String text,
java.awt.Font font,
java.awt.font.FontRenderContext frc,
int mode)
getRowBounds(String,Font,FontRenderContext,int).
text - the text to be measured (may be null)font - font to render text with (may be null)frc - the font render context. If null, the one in g is used.mode - bounds computing method (see class description)
(invalid modes default to STRINGBOUNDS)
getRowBounds(String,Font,FontRenderContext,int),
getTextBounds(String,Font,FontRenderContext,int,Rectangle2D)
public static java.awt.geom.Rectangle2D getTextBounds(java.lang.String text,
java.awt.Font font,
java.awt.font.FontRenderContext frc,
int mode,
java.awt.geom.Rectangle2D bounds)
text - the text to be measured (may be null)font - font to render text with (may be null)frc - the font render context. If null, the one in g is used.mode - bounds computing method (see class description)
(invalid modes default to STRINGBOUNDS)bounds - old bounds to add text bounding box to (may be null)
addBounds(java.awt.geom.Rectangle2D, java.awt.geom.Rectangle2D),
getRowBounds(String,Font,FontRenderContext,int,Rectangle2D),
getTextBounds(String,Font,FontRenderContext,int)
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||