|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectprefuse.render.AbstractShapeRenderer
prefuse.render.LabelRenderer
public class LabelRenderer
Renderer that draws a label, which consists of a text string, an image, or both.
When created using the default constructor, the renderer attempts
to use text from the "label" field. To use a different field, use the
appropriate constructor or use the setTextField(String)
method.
To perform custom String selection, subclass this Renderer and override the
getText(VisualItem)
method. When the text field is
null
, no text label will be shown. Labels can span multiple
lines of text, determined by the presence of newline characters ('\n')
within the text string.
By default, no image is shown. To show an image, the image field needs
to be set, either using the appropriate constructor or the
setImageField(String)
method. The value of the image field should
be a text string indicating the location of the image file to use. The
string should be either a URL, a file located on the current classpath,
or a file on the local filesystem. If found, the image will be managed
internally by an ImageFactory
instance, which maintains a
cache of loaded images.
The position of the image relative to text can be set using the
setImagePosition(Alignment)
method. Images can be placed to the
left, right, above, or below the text. The horizontal and vertical
alignments of either the text or the image can be set explicitly
using the appropriate methods of this class (e.g.,
setHorizontalTextAlignment(Alignment)
). By default, both the
text and images are centered along both the horizontal and
vertical directions.
Field Summary | |
---|---|
protected int |
m_arcHeight
|
protected int |
m_arcWidth
|
protected java.awt.geom.RectangularShape |
m_bbox
The holder for the currently computed bounding box |
protected java.lang.String |
m_delim
|
protected java.awt.Font |
m_font
|
protected Alignment |
m_hImageAlign
|
protected int |
m_horizBorder
|
protected Alignment |
m_hTextAlign
|
protected int |
m_imageMargin
|
protected java.lang.String |
m_imageName
|
protected Alignment |
m_imagePos
|
protected ImageFactory |
m_images
|
protected java.lang.String |
m_labelName
|
protected int |
m_maxTextWidth
|
protected java.awt.geom.Point2D |
m_pt
|
protected java.lang.String |
m_text
|
protected java.awt.Dimension |
m_textDim
|
protected int |
m_vertBorder
|
protected Alignment |
m_vImageAlign
|
protected Alignment |
m_vTextAlign
|
protected Alignment |
m_xAlign
|
protected Alignment |
m_yAlign
|
protected java.lang.Integer |
maxLineLength
|
Fields inherited from class prefuse.render.AbstractShapeRenderer |
---|
m_manageBounds |
Fields inherited from interface prefuse.render.Renderer |
---|
DEFAULT_GRAPHICS |
Constructor Summary | |
---|---|
LabelRenderer()
Create a new LabelRenderer. |
|
LabelRenderer(java.lang.String textField)
Create a new LabelRenderer. |
|
LabelRenderer(java.lang.String textField,
java.lang.String imageField)
Create a new LabelRenderer. |
Method Summary | |
---|---|
protected static void |
getAlignedPoint(java.awt.geom.Point2D p,
VisualItem<?> item,
double w,
double h,
Alignment xAlign,
Alignment yAlign)
Helper method, which calculates the top-left co-ordinate of an item given the item's alignment. |
Alignment |
getHorizontalAlignment()
Get the horizontal alignment of this node with respect to its x, y coordinates. |
Alignment |
getHorizontalImageAlignment()
Get the horizontal image alignment within the layout. |
int |
getHorizontalPadding()
Returns the amount of padding in pixels between the content and the border of this item along the horizontal dimension. |
Alignment |
getHorizontalTextAlignment()
Get the horizontal text alignment within the layout. |
protected java.awt.Image |
getImage(VisualItem<?> item)
Get the image to include in the label for the given VisualItem. |
ImageFactory |
getImageFactory()
Returns the image factory used by this renderer. |
java.lang.String |
getImageField()
Get the data field for image locations. |
protected java.lang.String |
getImageLocation(VisualItem<?> item)
Returns a location string for the image to draw. |
Alignment |
getImagePosition()
Get the image position, determining where the image is placed with respect to the text. |
int |
getImageTextPadding()
Get the padding, in pixels, between an image and text. |
java.lang.Integer |
getMaxLineLength()
|
protected java.awt.Shape |
getRawShape(VisualItem<?> item)
Return a non-transformed shape for the visual representation of the item. |
protected java.lang.String |
getText(VisualItem<?> item)
Returns the text to draw. |
protected java.awt.Color |
getTextColor(VisualItem<?> item)
|
java.lang.String |
getTextField()
Get the field name to use for text labels. |
Alignment |
getVerticalAlignment()
Get the vertical alignment of this node with respect to its x, y coordinates. |
Alignment |
getVerticalImageAlignment()
Get the vertical image alignment within the layout. |
int |
getVerticalPadding()
Returns the amount of padding in pixels between the content and the border of this item along the vertical dimension. |
Alignment |
getVerticalTextAlignment()
Get the vertical text alignment within the layout. |
void |
render(java.awt.Graphics2D g,
VisualItem<?> item)
Render item into a Graphics2D context. |
void |
setHorizontalAlignment(Alignment align)
Set the horizontal alignment of this node with respect to its x, y coordinates. |
void |
setHorizontalImageAlignment(Alignment halign)
Set the horizontal image alignment within the layout. |
void |
setHorizontalPadding(int xpad)
Sets the amount of padding in pixels between the content and the border of this item along the horizontal dimension. |
void |
setHorizontalTextAlignment(Alignment halign)
Set the horizontal text alignment within the layout. |
void |
setImageFactory(ImageFactory ifact)
Sets the image factory used by this renderer. |
void |
setImageField(java.lang.String imageField)
Set the data field for image locations. |
void |
setImagePosition(Alignment pos)
Set the image position, determining where the image is placed with respect to the text. |
void |
setImageTextPadding(int pad)
Set the padding, in pixels, between an image and text. |
void |
setMaxImageDimensions(int width,
int height)
Sets the maximum image dimensions, used to control scaling of loaded images. |
void |
setMaxLineLength(java.lang.Integer maxLineLength)
|
void |
setMaxTextWidth(int maxWidth)
Sets the maximum width that should be allowed of the text label. |
void |
setRoundedCorner(int arcWidth,
int arcHeight)
Rounds the corners of the bounding rectangle in which the text string is rendered. |
void |
setTextField(java.lang.String textField)
Set the field name to use for text labels. |
void |
setVerticalAlignment(Alignment align)
Set the vertical alignment of this node with respect to its x, y coordinates. |
void |
setVerticalImageAlignment(Alignment valign)
Set the vertical image alignment within the layout. |
void |
setVerticalPadding(int ypad)
Sets the amount of padding in pixels between the content and the border of this item along the vertical dimension. |
void |
setVerticalTextAlignment(Alignment valign)
Set the vertical text alignment within the layout. |
Methods inherited from class prefuse.render.AbstractShapeRenderer |
---|
calculateBounds, drawShape, getFillColor, getRenderType, getShape, getStroke, getStrokeColor, getTransform, locatePoint, managesBounds, setManageBounds, setRenderType |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected ImageFactory m_images
protected java.lang.String m_delim
protected java.lang.String m_labelName
protected java.lang.String m_imageName
protected Alignment m_xAlign
protected Alignment m_yAlign
protected Alignment m_hTextAlign
protected Alignment m_vTextAlign
protected Alignment m_hImageAlign
protected Alignment m_vImageAlign
protected Alignment m_imagePos
protected int m_horizBorder
protected int m_vertBorder
protected int m_imageMargin
protected int m_arcWidth
protected int m_arcHeight
protected int m_maxTextWidth
protected java.lang.Integer maxLineLength
protected java.awt.geom.RectangularShape m_bbox
protected java.awt.geom.Point2D m_pt
protected java.awt.Font m_font
protected java.lang.String m_text
protected java.awt.Dimension m_textDim
Constructor Detail |
---|
public LabelRenderer()
public LabelRenderer(java.lang.String textField)
textField
- the data field for the text label.public LabelRenderer(java.lang.String textField, java.lang.String imageField)
textField
- the data field for the text labelimageField
- the data field for the image location. This value
in the data field should be a URL, a file within the current classpath,
a file on the filesystem, or null for no image. If the
imageField
parameter is null, no images at all will be
drawn.Method Detail |
---|
public void setRoundedCorner(int arcWidth, int arcHeight)
arcWidth
- the width of the curved cornerarcHeight
- the height of the curved cornerpublic java.lang.String getTextField()
public void setTextField(java.lang.String textField)
textField
- the data field for text labels, or null for no textpublic void setMaxTextWidth(int maxWidth)
maxWidth
- the maximum width of the text or -1 for no limitprotected java.lang.String getText(VisualItem<?> item)
item
- the item to represent as a String
String
to drawpublic java.lang.String getImageField()
public void setImageField(java.lang.String imageField)
imageField
parameter is null, no images at all will be
drawn.
imageField
- the data field for image locations, or null for
no imagespublic void setMaxImageDimensions(int width, int height)
width
- the maximum width of images (-1 for no limit)height
- the maximum height of images (-1 for no limit)protected java.lang.String getImageLocation(VisualItem<?> item)
item
- the item for which to select an image to draw
protected java.awt.Image getImage(VisualItem<?> item)
item
- the item to get an image for
protected java.awt.Shape getRawShape(VisualItem<?> item)
AbstractShapeRenderer
getRawShape
in class AbstractShapeRenderer
item
- the VisualItem being drawn
AbstractShapeRenderer.getRawShape(prefuse.visual.VisualItem)
protected static void getAlignedPoint(java.awt.geom.Point2D p, VisualItem<?> item, double w, double h, Alignment xAlign, Alignment yAlign)
protected java.awt.Color getTextColor(VisualItem<?> item)
public void render(java.awt.Graphics2D g, VisualItem<?> item)
Renderer
render
in interface Renderer
render
in class AbstractShapeRenderer
g
- the Graphics2D contextitem
- the visual item to drawRenderer.render(java.awt.Graphics2D, prefuse.visual.VisualItem)
public ImageFactory getImageFactory()
public void setImageFactory(ImageFactory ifact)
ifact
- the image factorypublic Alignment getHorizontalTextAlignment()
public void setHorizontalTextAlignment(Alignment halign)
Alignment.LEFT
, Alignment.RIGHT
, or
Alignment.CENTER
. The default is centered text.
halign
- the desired horizontal text alignmentpublic Alignment getVerticalTextAlignment()
Alignment.TOP
, Alignment.BOTTOM
, or
Alignment.CENTER
. The default is centered text.
public void setVerticalTextAlignment(Alignment valign)
Alignment.TOP
, Alignment.BOTTOM
, or
Alignment.CENTER
. The default is centered text.
valign
- the desired vertical text alignmentpublic Alignment getHorizontalImageAlignment()
Alignment.LEFT
, Alignment.RIGHT
, or
Alignment.CENTER
. The default is a centered image.
public void setHorizontalImageAlignment(Alignment halign)
Alignment.LEFT
, Alignment.RIGHT
, or
Alignment.CENTER
. The default is a centered image.
halign
- the desired horizontal image alignmentpublic Alignment getVerticalImageAlignment()
Alignment.TOP
, Alignment.BOTTOM
, or
Alignment.CENTER
. The default is a centered image.
public void setVerticalImageAlignment(Alignment valign)
Alignment.TOP
, Alignment.BOTTOM
, or
Alignment.CENTER
. The default is a centered image.
valign
- the desired vertical image alignmentpublic Alignment getImagePosition()
public void setImagePosition(Alignment pos)
pos
- the desired image positionpublic Alignment getHorizontalAlignment()
Alignment.LEFT
, Alignment.RIGHT
, or
Alignment.CENTER
.public Alignment getVerticalAlignment()
Alignment.TOP
, Alignment.BOTTOM
, or
Alignment.CENTER
.public void setHorizontalAlignment(Alignment align)
align
- the horizontal alignment, one of
Alignment.LEFT
, Alignment.RIGHT
, or
Alignment.CENTER
.public void setVerticalAlignment(Alignment align)
align
- the vertical alignment, one of
Alignment.TOP
, Alignment.BOTTOM
, or
Alignment.CENTER
.public int getHorizontalPadding()
public void setHorizontalPadding(int xpad)
xpad
- the horizontal padding to setpublic int getVerticalPadding()
public void setVerticalPadding(int ypad)
ypad
- the vertical paddingpublic int getImageTextPadding()
public void setImageTextPadding(int pad)
pad
- the padding to use between an image and textpublic java.lang.Integer getMaxLineLength()
public void setMaxLineLength(java.lang.Integer maxLineLength)
maxLineLength
- the maximum line length
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |