Search this API

y.view
Class AbstractCustomLabelPainter

java.lang.Object
  extended by y.view.AbstractCustomLabelPainter
All Implemented Interfaces:
YLabel.Painter
Direct Known Subclasses:
HtmlLabelConfiguration

public abstract class AbstractCustomLabelPainter
extends java.lang.Object
implements YLabel.Painter

Abstract base class for YLabel.Painter implementations. This base class contains useful utility functions and supports non-paraxial label bounds. The default and the CroppingLabel node and edge label configurations extend this class.

 

Constructor Summary
AbstractCustomLabelPainter()
           
 
Method Summary
static YLabel.Painter asAutoFlippingPainter(YLabel.Painter painter)
          Decorates an existing YLabel.Painter instance to support automatic flipping of label content according to rotation angle.
protected  java.awt.Color getBackgroundColor(YLabel label, boolean selected)
          Determines the color for filling the specified label's background rectangle.
protected  java.awt.Paint getBackgroundPaint(YLabel label, boolean selected)
          Determines the paint for filling the specified label's background rectangle.
protected  java.awt.Color getLineColor(YLabel label, boolean selected)
          Determines the color for drawing the specified label's border.
protected  java.awt.Paint getLinePaint(YLabel label, boolean selected)
          Determines the paint for drawing the specified label's border.
protected  java.awt.Stroke getLineStroke(YLabel label, boolean selected)
          Determines the stroke for drawing the specified label's border.
protected  boolean initializeBackground(YLabel label, java.awt.Graphics2D graphics)
          This utility function can be called by subclasses to initialize the graphics context for the filling of the label's background.
protected  boolean initializeLine(YLabel label, java.awt.Graphics2D graphics)
          This utility function can be called by subclasses to initialize the graphics context for the drawing of the label's border.
 boolean isAutoFlippingEnabled()
          Determines whether or not this painter should automatically flip label content depending on the label's rotation angle.
 void paint(YLabel label, java.awt.Graphics2D graphics)
          Paints the specified label on the specified graphics context.
 void paintBox(YLabel label, java.awt.Graphics2D graphics, double x, double y, double width, double height)
          Paints the background of the specified label on the specified graphics context.
protected  void paintSelectionBox(YLabel label, java.awt.Graphics2D graphics, double x, double y, double width, double height)
          Paints a selection frame for the specified label if the label's selection state is true.
 void setAutoFlippingEnabled(boolean enabled)
          Specifies whether or not this painter should automatically flip label content depending on the label's rotation angle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface y.view.YLabel.Painter
getIconBox, getTextBox, paintContent
 

Constructor Detail

AbstractCustomLabelPainter

public AbstractCustomLabelPainter()
Method Detail

isAutoFlippingEnabled

public boolean isAutoFlippingEnabled()
Determines whether or not this painter should automatically flip label content depending on the label's rotation angle.

By default, this property is set to false.

Returns:
true if this painter automatically flips label content depending on the label's rotation angle and false otherwise.
See Also:
setAutoFlippingEnabled(boolean), asAutoFlippingPainter(y.view.YLabel.Painter)

setAutoFlippingEnabled

public void setAutoFlippingEnabled(boolean enabled)
Specifies whether or not this painter should automatically flip label content depending on the label's rotation angle.

By default, this property is set to false.

Parameters:
enabled - if true, this painter will automatically flip label content depending on the label's rotation angle.
See Also:
setAutoFlippingEnabled(boolean), asAutoFlippingPainter(y.view.YLabel.Painter)

paint

public void paint(YLabel label,
                  java.awt.Graphics2D graphics)
Paints the specified label on the specified graphics context. This implementation transforms the graphics context according to the orientation of the label's content and then delegates painting to YLabel.paintImpl(java.awt.Graphics2D, double, double, double, double).

Specified by:
paint in interface YLabel.Painter
Parameters:
label - the label to paint.
graphics - the graphics context to paint upon.

paintBox

public void paintBox(YLabel label,
                     java.awt.Graphics2D graphics,
                     double x,
                     double y,
                     double width,
                     double height)
Paints the background of the specified label on the specified graphics context. This implementation works in three steps:
  1. Prepare to fill the background rectangle by calling initializeBackground(YLabel, java.awt.Graphics2D). Then fill the rectangle.
  2. Prepare to draw the background rectangle border by calling initializeLine(YLabel, java.awt.Graphics2D). Then draw the rectangle.
  3. Call paintSelectionBox(YLabel, java.awt.Graphics2D, double, double, double, double) to paint selection decorations.

Specified by:
paintBox in interface YLabel.Painter
Parameters:
label - the label to paint.
graphics - the graphics context to paint upon.
x - the x-coordinate of the upper left corner of the label's background rectangle.
y - the y-coordinate of the upper left corner of the label's background rectangle.
width - the width of the label's background rectangle.
height - the height of the label's background rectangle.

paintSelectionBox

protected void paintSelectionBox(YLabel label,
                                 java.awt.Graphics2D graphics,
                                 double x,
                                 double y,
                                 double width,
                                 double height)
Paints a selection frame for the specified label if the label's selection state is true.

Parameters:
label - the label to paint.
graphics - the graphics context to paint upon.
x - the x-coordinate of the upper left corner of the label's background rectangle.
y - the y-coordinate of the upper left corner of the label's background rectangle.
width - the width of the label's background rectangle.
height - the height of the label's background rectangle.

initializeBackground

protected boolean initializeBackground(YLabel label,
                                       java.awt.Graphics2D graphics)
This utility function can be called by subclasses to initialize the graphics context for the filling of the label's background. If this method returns false the background should not be filled. Calls getBackgroundPaint(YLabel, boolean) to determine the paint for filling the background.

Parameters:
label - the label to paint.
graphics - the graphics context to configure.
Returns:
true if the label background should be filled and false otherwise.

getBackgroundPaint

protected java.awt.Paint getBackgroundPaint(YLabel label,
                                            boolean selected)
Determines the paint for filling the specified label's background rectangle. Called from initializeBackground(YLabel, java.awt.Graphics2D). The default implementation delegates to getBackgroundColor(YLabel, boolean).

Parameters:
label - the label to paint.
selected - the selection state of the label.
Returns:
the paint to use.

getBackgroundColor

protected java.awt.Color getBackgroundColor(YLabel label,
                                            boolean selected)
Determines the color for filling the specified label's background rectangle. Called from getBackgroundPaint(YLabel, boolean).

Parameters:
label - the label to paint.
selected - the selection state of the label.
Returns:
the color to use.

initializeLine

protected boolean initializeLine(YLabel label,
                                 java.awt.Graphics2D graphics)
This utility function can be called by subclasses to initialize the graphics context for the drawing of the label's border. If this method returns false no border should be drawn. Calls getLinePaint(YLabel, boolean) and getLineStroke(YLabel, boolean) to determine the paint and stroke for drawing the border.

Parameters:
label - the label to paint.
graphics - the graphics context to configure.
Returns:
true if the label border should be drawn and false otherwise.

getLineStroke

protected java.awt.Stroke getLineStroke(YLabel label,
                                        boolean selected)
Determines the stroke for drawing the specified label's border. Called from initializeLine(YLabel, java.awt.Graphics2D).

Parameters:
label - the label to paint.
selected - the selection state of the label.
Returns:
the stroke to use.

getLinePaint

protected java.awt.Paint getLinePaint(YLabel label,
                                      boolean selected)
Determines the paint for drawing the specified label's border. Called from initializeLine(YLabel, java.awt.Graphics2D). The default implementation delegates to getLineColor(YLabel, boolean).

Parameters:
label - the label to paint.
selected - the selection state of the label.
Returns:
the paint to use.

getLineColor

protected java.awt.Color getLineColor(YLabel label,
                                      boolean selected)
Determines the color for drawing the specified label's border. Called from getBackgroundColor(YLabel, boolean).

Parameters:
label - the label to paint.
selected - the selection state of the label.
Returns:
the color to use.

asAutoFlippingPainter

public static YLabel.Painter asAutoFlippingPainter(YLabel.Painter painter)
Decorates an existing YLabel.Painter instance to support automatic flipping of label content according to rotation angle.

Parameters:
painter - the YLabel.Painter instance to decorate.
Returns:
a YLabel.Painter instance that supports automatic flipping of label content according to rotation angle.
See Also:
isAutoFlippingEnabled(), setAutoFlippingEnabled(boolean)

© Copyright 2000-2019,
yWorks GmbH.
All rights reserved.