public class IlvLabelRenderer extends Object implements Serializable, SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
Constructor and Description |
---|
IlvLabelRenderer()
Creates a new
IlvLabelRenderer object with a null rotation. |
IlvLabelRenderer(Color bg,
Color fg)
Creates a new filled and outlined
IlvLabelRenderer . |
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(PropertyChangeListener listener)
Adds a property change listener to this object.
|
void |
firePropertyChange(String propertyName,
Object oldValue,
Object newValue,
int effects)
Notifies the listeners when a property change occurred.
|
int |
getAlignment()
Returns the label alignment.
|
Color |
getBackground()
Returns the background color.
|
Paint |
getBackgroundPaint()
Returns the background paint.
|
Shape |
getBackgroundShape(JComponent comp,
double x,
double y,
String label)
Returns the combined background shapes of the text lines, according to the
given position.
|
Border |
getBorder()
Returns the border of this label.
|
Rectangle2D |
getBounds(JComponent comp,
double x,
double y,
String label,
Rectangle2D bounds)
Returns the label bounds, according to the given position.
|
Color |
getColor()
Returns the label color.
|
Font |
getFont()
Returns the label font.
|
double |
getRotation()
Returns the rotation applied to the label.
|
Dimension |
getSize(JComponent comp,
String label,
boolean useBorder,
boolean useRotation)
Returns the size of the specified label, when displayed by this renderer.
|
Dimension2D |
getSize2D(JComponent comp,
String label,
boolean useBorder,
boolean useRotation)
Returns the size of the specified label, when displayed by this renderer.
|
float |
getWrappingWidth()
Returns the wrapping width.
|
boolean |
isAutoWrapping()
Indicates whether automatic wrapping is used.
|
boolean |
isCaching()
Returns
true if this label renderer caches previous text
layouts and bounds, for speed. |
boolean |
isOpaque()
Indicates whether the background of the label is filled.
|
boolean |
isOutline()
Indicates whether the label is drawn in outline mode.
|
boolean |
isScalingFont()
Returns whether this label renderer enables the font scaling.
|
void |
paintLabel(JComponent comp,
Color foreground,
Graphics g,
String label,
double x,
double y)
Paints the label at the given position.
|
void |
paintLabel(JComponent comp,
Graphics g,
String label,
double x,
double y)
Paints the label at the given position.
|
void |
removePropertyChangeListener(PropertyChangeListener listener)
Removes a property change listener from this object.
|
void |
setAlignment(int alignment)
Specifies the label alignment.
|
void |
setAutoWrapping(boolean autoWrapping)
Toggles automatic wrapping.
|
void |
setBackground(Color color)
Sets the label background.
|
void |
setBackgroundPaint(Paint paint)
Sets the background paint.
|
void |
setBorder(Border border)
Sets a border for this label.
|
void |
setCaching(boolean caching)
Determines whether this label renderer caches previous text layouts and
bounds, for speed.
|
void |
setColor(Color color)
Sets the label color.
|
void |
setFont(Font font)
Sets the label font.
|
void |
setOpaque(boolean opaque)
Specifies whether the background of the label is filled.
|
void |
setOutline(boolean outline)
Specifies whether the label is drawn in outline mode.
|
void |
setRotation(double rotation)
Sets the rotation applied to the label.
|
void |
setScalingFont(boolean scalingFont)
Sets whether this label renderer enables the font scaling.
|
void |
setWrappingWidth(float wrappingWidth)
Sets the wrapping width.
|
protected void |
stateChanged()
Called when a change occurred.
|
public IlvLabelRenderer()
IlvLabelRenderer
object with a null rotation.public final Font getFont()
public void setFont(Font font)
public final boolean isScalingFont()
public void setScalingFont(boolean scalingFont)
scalingFont
property is only used if a font has been
specified for this renderer.setFont(java.awt.Font)
,
IlvChart.setScalingFont(boolean)
public final Color getColor()
Color
or an IlvContrastingColor
.public void setColor(Color color)
color
- A normal Color
or an IlvContrastingColor
.public final Color getBackground()
null
if no background
has been specified, or if the background paint is not an instance
of java.awt.Color
.setBackgroundPaint(java.awt.Paint)
public final Paint getBackgroundPaint()
setBackgroundPaint(java.awt.Paint)
public void setBackground(Color color)
setOpaque(boolean)
public void setBackgroundPaint(Paint paint)
setOpaque(boolean)
public final double getRotation()
public void setRotation(double rotation)
rotation
- The angle of the rotation in degrees.public final boolean isOpaque()
setOpaque(boolean)
public void setOpaque(boolean opaque)
isOpaque()
public final boolean isOutline()
setOutline(boolean)
public void setOutline(boolean outline)
true
, the label is surrounded by a thin shadow border,
increasing the contrast to the background.isOutline()
public final int getAlignment()
setAlignment(int)
public void setAlignment(int alignment)
The alignment is only used for multiline labels. It can take the following values:
SwingConstants.LEFT
: left alignment.SwingConstants.CENTER
(default): centered alignment.SwingConstants.RIGHT
: right alignment.IllegalArgumentException
- The alignment constant is incorrect.setAutoWrapping(boolean)
,
getAlignment()
public final boolean isAutoWrapping()
public void setAutoWrapping(boolean autoWrapping)
setWrappingWidth(float)
public final float getWrappingWidth()
public void setWrappingWidth(float wrappingWidth)
wrappingWidth
- The maximum width of a line, in pixels, before a line
break is forced (when isAutoWrapping()
returns true
).setAutoWrapping(boolean)
public final Border getBorder()
setBorder(javax.swing.border.Border)
public void setBorder(Border border)
getBorder()
public final boolean isCaching()
true
if this label renderer caches previous text
layouts and bounds, for speed.setCaching(boolean)
public void setCaching(boolean caching)
When set to true
, this label renderer will memoize the line
breaking, text layouts and bounds of all previous settings, as far as
memory permits. This is useful when a label renderer is used to draw
or measure many labels.
When set to false
, this label renderer will memoize the line
breaking, text layouts and bounds of the last setting. This is useful when
a label renderer is used for a single label only.
The default value is true
.
isCaching()
public void paintLabel(JComponent comp, Graphics g, String label, double x, double y)
comp
- The component rendering the label. This argument is used to
get properties such as background and foreground colors if they are not
specified by the label renderer.g
- The Graphics
context to draw in.label
- The string to draw.x
- The x-coordinate of the label center.y
- The y-coordinate of the label center.public void paintLabel(JComponent comp, Color foreground, Graphics g, String label, double x, double y)
comp
- The component rendering the label. This argument is used to
get properties such as background and foreground colors if they are not
specified foregreound
argument or by the label renderer.foreground
- The foreground color to use, or null
.g
- The Graphics
context to draw in.label
- The string to draw.x
- The x-coordinate of the label center.y
- The y-coordinate of the label center.public Rectangle2D getBounds(JComponent comp, double x, double y, String label, Rectangle2D bounds)
comp
- The component rendering the label. This argument is used to
get properties such as background and foreground colors if they are not
specified by the label renderer.x
- The x-coordinate of the label center.y
- The y-coordinate of the label center.label
- The string to draw.bounds
- A rectangle used to store the result.public Dimension2D getSize2D(JComponent comp, String label, boolean useBorder, boolean useRotation)
comp
- The component rendering the label. This argument is used to
get properties such as background and foreground colors if they are not
specified by the label renderer.label
- The considered label.useBorder
- Whether to take into account the border insets.useRotation
- Whether to take into account the rotation.setBorder(javax.swing.border.Border)
,
setRotation(double)
public Dimension getSize(JComponent comp, String label, boolean useBorder, boolean useRotation)
comp
- The component rendering the label. This argument is used to
get properties such as background and foreground colors if they are not
specified by the label renderer.label
- The considered label.useBorder
- Whether to take into account the border insets.useRotation
- Whether to take into account the rotation.getSize2D(javax.swing.JComponent, java.lang.String, boolean, boolean)
public Shape getBackgroundShape(JComponent comp, double x, double y, String label)
comp
- The component rendering the label. This argument is used to
get properties such as background and foreground colors if they are not
specified by the label renderer.x
- The x-coordinate of the label center.y
- The y-coordinate of the label center.label
- The string to draw.null
if empty.public void addPropertyChangeListener(PropertyChangeListener listener)
Note: No events for the property "background" are sent. Instead, events are sent for the property "backgroundPaint".
public void removePropertyChangeListener(PropertyChangeListener listener)
public void firePropertyChange(String propertyName, Object oldValue, Object newValue, int effects)
This method is meant to be invoked by subclasses that define additional bean properties.
propertyName
- The name of the bean property whose value has changed.oldValue
- The previous value of the bean property.newValue
- The new value of the bean property.effects
- A bit mask consisting possibly of
LabelRendererPropertyEvent.AFFECTS_DRAWING
and LabelRendererPropertyEvent.AFFECTS_BOUNDS
.protected void stateChanged()
© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.