Search this API

y.view
Class YLabel

java.lang.Object
  extended by y.view.YLabel
Direct Known Subclasses:
EdgeLabel, NodeLabel

public abstract class YLabel
extends java.lang.Object

This class encapsulates a multi-line text label. There are specialized classes handling labels for nodes and edges.

 

Nested Class Summary
static interface YLabel.BoundsProvider
          The interface that is used by a specific label configuration that calculates the union bounds of a label and a given rectangle.
static class YLabel.Factory
          This class is used for managing the different configurations for YLabel instances.
static interface YLabel.Layout
          The interface that is used by a specific label configuration that calculates the layout size and determines whether a given point is contained in a label's geometry.
static interface YLabel.Painter
          The interface that is used by a specific label configuration that performs the painting.
static interface YLabel.SelectionChangeHandler
          This interface is used by YLabel to notify interested parties of selection state changes.
static interface YLabel.UserDataHandler
          This interface is used during YGF serialization to delegate the copying and serialization/deserialization of any user-defined data to.
 
Field Summary
static byte ALIGN_CENTER
          Vertical text alignment constant.
static byte ALIGN_LEFT
          Vertical text alignment constant.
static byte ALIGN_RIGHT
          Vertical text alignment constant.
static byte AUTOSIZE_CONTENT
          Automatic size calculation policy specifier.
static byte AUTOSIZE_NONE
          Automatic size calculation policy specifier.
static byte BOTTOM_TEXT_POSITION
          Vertical text position specifier that places text below the icon.
static byte CENTER_TEXT_POSITION
          Vertical and horizontal text position specifier that aligns the center of text and icon either vertically or horizontally.
protected  double contentHeight
          (including icons, text, etc, rotation not included!)
protected  double contentWidth
          (including icons, text, etc, rotation not included!)
static java.awt.Insets defaultInsets
          Default insets that define the distance between the bounding box of the label and its content.
protected  double height
          The height of this label (including icons, text, etc, rotation considered)
static byte LEFT_ALIGNED_TEXT_POSITION
          Horizontal text position specifier that aligns the left border of the icon and the text.
static byte LEFT_TEXT_POSITION
          Horizontal text position specifier that places text to the left of the icon.
protected  byte model
          The model constant for the label model.
protected  boolean offsetDirty
          Whether the offset of the label is up to date or not.
protected  OrientedRectangle offsetRectangle
          The relative, oriented label bounds.
protected  byte placement
          The placement constant for the label model.
static byte RIGHT_ALIGNED_TEXT_POSITION
          Horizontal text position specifier that aligns the right border of the icon and the text.
static byte RIGHT_TEXT_POSITION
          Horizontal text position specifier that places text to the right of the icon.
protected  boolean sizeDirty
          Whether the size of the label is up to date or not.
static byte TOP_TEXT_POSITION
          Vertical text position specifier that places text above the icon.
protected  double width
          the width of this label.
 
Constructor Summary
protected YLabel()
          Instantiates a new YLabel.
 
Method Summary
 void adoptValues(YLabel label)
          Adopts the values from the given label.
abstract  void calculateOffset()
          Calculates the offset of this label.
 void calculateSize()
          Calculates the size of this label
 void calculateSize(java.awt.font.FontRenderContext frc)
          Calculates the size of this label with the help of the given FontRenderContext.
 void calcUnionRect(java.awt.geom.Rectangle2D r)
          Enlarges the given rectangle such that it will contain the bounding box of this label.
 boolean contains(double x, double y)
          Determines whether the given point in world coordinates is contained within the label's graphics.
 byte getAlignment()
          Returns the currently set alignment style for multiple lines of label text.
 byte getAutoSizePolicy()
          Returns the currently set automatic size calculation policy for this label.
 java.awt.Color getBackgroundColor()
          Returns the background color to be used for painting this label.
abstract  java.lang.Object getBestModelParameterForBounds(OrientedRectangle bounds)
          Returns the best model parameter for this label such that the label's oriented bounds will match the specified bounds as closely as possible within the label's current label model.
 YRectangle getBox()
          Returns the bounding box of this label.
 java.lang.String getConfiguration()
          Returns the string identifier of the current configuration this label is in.
 OrientedRectangle getContentBox()
          Returns the label's content box.
 double getContentHeight()
          Gets the height of the content area.
 double getContentWidth()
          Gets the width of the content area.
 java.awt.Font getFont()
          Returns the font used for this label.
 java.lang.String getFontName()
          Returns the name of the label's font.
 int getFontSize()
          Returns the point size of the label's font
 int getFontStyle()
          Returns the font style for this label.
 double getHeight()
          Returns the height of the bounding box of this label.
 byte getHorizontalTextPosition()
          Returns the horizontal position of text relative to the icon.
 javax.swing.Icon getIcon()
          Returns the icon that is displayed by this label and If no icon is associated with this label null is returned.
 OrientedRectangle getIconBox()
          Returns the oriented bounds of the label's icon in the coordinate space of the label's content box.
 YPoint getIconLocation()
          Returns the absolute coordinate of the upper left corner of the label icon's paraxial bounding box.
 byte getIconTextGap()
          Returns the gap between text and icon
 java.awt.Insets getInsets()
          Returns the insets for this label.
 java.awt.Color getLineColor()
          Returns the color used to draw a border around the bounding box of this label.
 YPoint getLocation()
          Returns the absolute coordinate of the upper left corner of this label's paraxial bounding box.
 byte getModel()
          Returns the model specifier for this label.
 OrientedRectangle getOffset()
          Determines the oriented offset rectangle of this label.
 double getOffsetX()
          Returns the x-coordinate of the offset of the label's paraxial bounding box.
 double getOffsetY()
          Returns the y-coordinate of the offset of the label's paraxial bounding box.
abstract  OrientedRectangle getOrientedBox()
          Returns the label's oriented bounding box as determined by its label model before applying the label's inherent rotation.
 byte getPosition()
          Returns the position specifier for this label.
 double getRotationAngle()
          Returns the rotation angle for this label.
 java.lang.String getText()
          Returns the text of this label
 OrientedRectangle getTextBox()
          Returns the oriented bounds of the label's text in the coordinate space of the label's content box.
 java.awt.Color getTextColor()
          Returns the text color of this label.
 YPoint getTextLocation()
          Returns the absolute coordinate of the upper left corner of the label text's paraxial bounding box.
 java.lang.Object getUserData()
          Retrieves the user data object that can be used by the configurations.
 byte getVerticalTextPosition()
          Returns the vertical position of text relative ot the icon.
 double getWidth()
          Returns the width of the bounding box of this label.
 void internalSetAutoSizePolicy(byte autoSize)
          This method is for internal use only and shall not be used by developers.
 void internalSetOffsetDirty(boolean dirty)
          This method is for internal use only and shall not be used by developers.
 void internalSetSizeDirty(boolean dirty)
          This method is for internal use only and shall not be used by developers.
 boolean intersects(double x, double y, double width, double height)
          Returns true iff the bounding box of this label intersects with the given box.
static boolean isFractionMetricsForSizeCalculationEnabled()
          Returns whether or not fractional font metrics shall be used to calculate the size of the label text.
 boolean isOffsetDirty()
          Returns true if the label offset is not valid yet.
 boolean isSelected()
          Whether or not this label is in a selected state.
 boolean isSizeDirty()
          Returns true if the label size is not valid yet.
 boolean isUnderlinedTextEnabled()
          Returns whether or not the text of the label should be underlined.
 boolean isVisible()
          Whether of not this label is visible.
 void paint(java.awt.Graphics2D gfx)
          Paints the YLabel on the given graphics object.
protected  void paintBox(java.awt.Graphics2D gfx, double x, double y, double width, double height)
          Paints the background of the label into the graphics context.
protected  void paintContent(java.awt.Graphics2D gfx, double x, double y, double width, double height)
          Paints the contents of the label into the graphics context.
protected  void paintImpl(java.awt.Graphics2D gfx, double x, double y, double width, double height)
          Called by paint(java.awt.Graphics2D) Calls paintBox(java.awt.Graphics2D, double, double, double, double) and paintContent(java.awt.Graphics2D, double, double, double, double) in order.
 void read(java.io.ObjectInputStream in)
          Deprecated. Use the GraphML format instead.
abstract  void repaint()
          Triggers a repaint of the bounds in the views for this label.
 void setAlignment(byte a)
          Sets the vertical alignment style for label text that spreads over multiple lines.
 void setAutoSizePolicy(byte autoSize)
          Sets the automatic size calculation policy for this label.
 void setBackgroundColor(java.awt.Color bgColor)
          Sets the background color to be used.
abstract  void setConfiguration(java.lang.String name)
          Configures this instance to use the configuration specified by the given name.
 void setContentHeight(double contentHeight)
          Sets the height of the content area.
 void setContentSize(double width, double height)
          Sets the size of the content area of this label and updates the width and height properties according to the current rotation angle.
 void setContentWidth(double contentWidth)
          Sets the width of the content area.
 void setFont(java.awt.Font f)
          Sets the font in which the text of this label gets displayed.
 void setFontName(java.lang.String name)
          Sets a new font with the specified name for the label.
 void setFontSize(int s)
          Sets the point size for the label's font.
 void setFontStyle(int s)
          Sets the font style for this label.
static void setFractionMetricsForSizeCalculationEnabled(boolean fractionalFontMetricsEnabled)
          Sets whether or not fractional font metrics shall be used to calculate the size of the label text.
 void setHorizontalTextPosition(byte pos)
          Sets the horizontal position of text relative to the icon.
static void setHTMLRenderingEnabled(boolean enabled)
          Whether or not to enable HTML rendering for labels whose text starts with the html tag <html>.
 void setIcon(javax.swing.Icon icon)
          Sets the icon that is displayed by this label.
 void setIconTextGap(byte gap)
          Sets the size of the gap between text and icon
 void setInsets(java.awt.Insets insets)
          Sets the insets for this label.
 void setLineColor(java.awt.Color lineColor)
          Sets the color used to draw a border around the bounding box of this label.
 void setModel(byte m)
          Sets a model specifier for this label.
abstract  void setModelParameter(java.lang.Object value)
          Sets the current parameters for the label model implementation.
 void setOffset(double x, double y)
          Deprecated. Client code should not set a label's offset directly, but rather use getBestModelParameterForBounds(y.geom.OrientedRectangle) and setModelParameter(Object) to create and specify a parameter that represents the desired label position in the label's model.
 void setOffset(OrientedRectangle offsetRectangle)
          Sets the oriented offset rectangle for this label.
 void setOffsetDirty()
          Marks the label offsets as dirty.
 void setOffsetX(double x)
          Deprecated. Client code should not set a label's offset directly, but rather use getBestModelParameterForBounds(y.geom.OrientedRectangle) and setModelParameter(Object) to create and specify a parameter that represents the desired label position in the label's model.
 void setOffsetY(double y)
          Deprecated. Client code should not set a label's offset directly, but rather use getBestModelParameterForBounds(y.geom.OrientedRectangle) and setModelParameter(Object) to create and specify a parameter that represents the desired label position in the label's model.
 void setPosition(byte b)
          Sets a position specifier for this label.
 void setRotationAngle(double angle)
          Sets the rotation angle for this label.
 void setSelected(boolean s)
          Sets the selected state of this label.
 void setSizeDirty()
          Marks the size of the label as dirty
 void setText(java.lang.String text)
          Sets the text being displayed by this label.
 void setTextColor(java.awt.Color c)
          Sets the text color of this label.
 void setUnderlinedTextEnabled(boolean u)
          Sets whether or not to underline the text of the label
 void setUserData(java.lang.Object userData)
          Sets the user data object that can be used by the configurations.
 void setVerticalTextPosition(byte pos)
          Sets the vertical position of text relative to the icon.
 void setVisible(boolean vis)
          Sets the visibility state of this label.
 java.lang.String toString()
          Returns a string representation of this label.
 OrientedRectangle transformCTW(OrientedRectangle box)
          Transforms the specified rectangle from the coordinate space of this label's content box into world/graph coordinates.
 void write(java.io.ObjectOutputStream out)
          Deprecated. Use the GraphML format instead.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ALIGN_LEFT

public static final byte ALIGN_LEFT
Vertical text alignment constant. This alignment type left aligns multiple lines of label text.

See Also:
Constant Field Values

ALIGN_CENTER

public static final byte ALIGN_CENTER
Vertical text alignment constant. This alignment type center aligns multiple lines of label text.

See Also:
Constant Field Values

ALIGN_RIGHT

public static final byte ALIGN_RIGHT
Vertical text alignment constant. This alignment type right aligns multiple lines of label text.

See Also:
Constant Field Values

TOP_TEXT_POSITION

public static final byte TOP_TEXT_POSITION
Vertical text position specifier that places text above the icon.

See Also:
setVerticalTextPosition(byte), Constant Field Values

CENTER_TEXT_POSITION

public static final byte CENTER_TEXT_POSITION
Vertical and horizontal text position specifier that aligns the center of text and icon either vertically or horizontally.

See Also:
setVerticalTextPosition(byte), setHorizontalTextPosition(byte), Constant Field Values

BOTTOM_TEXT_POSITION

public static final byte BOTTOM_TEXT_POSITION
Vertical text position specifier that places text below the icon.

See Also:
setVerticalTextPosition(byte), Constant Field Values

LEFT_TEXT_POSITION

public static final byte LEFT_TEXT_POSITION
Horizontal text position specifier that places text to the left of the icon.

See Also:
setHorizontalTextPosition(byte), Constant Field Values

RIGHT_TEXT_POSITION

public static final byte RIGHT_TEXT_POSITION
Horizontal text position specifier that places text to the right of the icon.

See Also:
setHorizontalTextPosition(byte), Constant Field Values

LEFT_ALIGNED_TEXT_POSITION

public static final byte LEFT_ALIGNED_TEXT_POSITION
Horizontal text position specifier that aligns the left border of the icon and the text.

See Also:
setHorizontalTextPosition(byte), Constant Field Values

RIGHT_ALIGNED_TEXT_POSITION

public static final byte RIGHT_ALIGNED_TEXT_POSITION
Horizontal text position specifier that aligns the right border of the icon and the text.

See Also:
setHorizontalTextPosition(byte), Constant Field Values

offsetRectangle

protected OrientedRectangle offsetRectangle
The relative, oriented label bounds.


width

protected double width
the width of this label. (including icons, text, etc, rotation considered)


height

protected double height
The height of this label (including icons, text, etc, rotation considered)


contentWidth

protected double contentWidth
(including icons, text, etc, rotation not included!)


contentHeight

protected double contentHeight
(including icons, text, etc, rotation not included!)


model

protected byte model
The model constant for the label model.


placement

protected byte placement
The placement constant for the label model.


sizeDirty

protected boolean sizeDirty
Whether the size of the label is up to date or not.


offsetDirty

protected boolean offsetDirty
Whether the offset of the label is up to date or not.


AUTOSIZE_CONTENT

public static final byte AUTOSIZE_CONTENT
Automatic size calculation policy specifier. Indicates that the size of the label should be determined by the size of its text and icon. In that case the YLabel.Layout implementation should use its own logic to determine the content size.

See Also:
getAutoSizePolicy(), setAutoSizePolicy(byte), Constant Field Values

AUTOSIZE_NONE

public static final byte AUTOSIZE_NONE
Automatic size calculation policy specifier. Indicates that the size of the label should be determined by the user. The user may use the setContentSize(double, double) method to specify the desired size of the content of the label. In that case the YLabel.Layout implementation should use the getContentWidth() and getContentHeight() to determine the size.

See Also:
getAutoSizePolicy(), setAutoSizePolicy(byte), Constant Field Values

defaultInsets

public static final java.awt.Insets defaultInsets
Default insets that define the distance between the bounding box of the label and its content.

Constructor Detail

YLabel

protected YLabel()
Instantiates a new YLabel.

Method Detail

getUserData

public java.lang.Object getUserData()
Retrieves the user data object that can be used by the configurations.

Returns:
the user data object
See Also:
YLabel.UserDataHandler

setUserData

public void setUserData(java.lang.Object userData)
Sets the user data object that can be used by the configurations.

Parameters:
userData - the new user data object
See Also:
YLabel.UserDataHandler

getContentWidth

public double getContentWidth()
Gets the width of the content area. The content area is the area where the label paints its contents, not taking into account possible rotation.

Returns:
the width of the content
See Also:
getWidth()

setContentWidth

public void setContentWidth(double contentWidth)
Sets the width of the content area. This will only be used by the YLabel.Layout implementation for this label if auto size policy is set to AUTOSIZE_NONE.

Parameters:
contentWidth - the new width of the content

getContentBox

public OrientedRectangle getContentBox()
Returns the label's content box. The content box is the oriented rectangle that is centered on the label's oriented box, whose width and height equal the label's contentWidth and contentHeight, and whose orientation is calculated by rotating the label's oriented box orientation according to the label's rotation angle.

Returns:
the oriented rectangle holding the label's content, i.e. its text and icon.
See Also:
getOrientedBox(), getRotationAngle(), getContentWidth(), getContentHeight()

isSelected

public boolean isSelected()
Whether or not this label is in a selected state. The default is false.


setSelected

public void setSelected(boolean s)
Sets the selected state of this label. The default is false.

See Also:
isSelected()

getContentHeight

public double getContentHeight()
Gets the height of the content area. The content area is the area where the label paints its contents, not taking into account possible rotation.

Returns:
the height of the content
See Also:
getHeight()

setContentHeight

public void setContentHeight(double contentHeight)
Sets the height of the content area. This will only be used by the YLabel.Layout implementation for this label if auto size policy is set to AUTOSIZE_NONE.

Parameters:
contentHeight - the new height of the content

setContentSize

public void setContentSize(double width,
                           double height)
Sets the size of the content area of this label and updates the width and height properties according to the current rotation angle. Calling this method without specifying the AUTOSIZE_NONE value for the auto size policy will not result in the desired effect. This method will be called by implementations of the YLabel.Layout interface as a response to the YLabel.Layout.calculateContentSize(YLabel, java.awt.font.FontRenderContext) method.

Parameters:
width - the width of the content area
height - the height of the content area
See Also:
AUTOSIZE_NONE

paint

public void paint(java.awt.Graphics2D gfx)
Paints the YLabel on the given graphics object. This implementation delegates to the configuration to perform the actual painting in YLabel.Painter.paint(YLabel, java.awt.Graphics2D). The default implementation will then configure the graphics context to consider rotation and call paintImpl(java.awt.Graphics2D, double, double, double, double).

Parameters:
gfx - the context to paint into

paintBox

protected void paintBox(java.awt.Graphics2D gfx,
                        double x,
                        double y,
                        double width,
                        double height)
Paints the background of the label into the graphics context. Called by paintImpl(java.awt.Graphics2D, double, double, double, double), which itself gets called by paint(java.awt.Graphics2D) This implementation delegates to the configuration to perform the actual painting in YLabel.Painter.paintBox(YLabel, java.awt.Graphics2D, double, double, double, double).

Parameters:
gfx - the graphics context (pre-configured to consider rotation
x - the top left x-coordinate of the drawing area
y - the top left y-coordinate of the drawing area
width - the width of the drawing area
height - the height of the drawing area

contains

public boolean contains(double x,
                        double y)
Determines whether the given point in world coordinates is contained within the label's graphics. This implementation checks whether the coordinates are contained within getBox(). This implementation delegates to the configuration to perform the check in YLabel.Layout.contains(YLabel, double, double).

Parameters:
x - the x world coordinate to check
y - the x world coordinate to check
Returns:
whether the given coordinate pair is deemed inside this label

paintContent

protected void paintContent(java.awt.Graphics2D gfx,
                            double x,
                            double y,
                            double width,
                            double height)
Paints the contents of the label into the graphics context. Called by paintImpl(java.awt.Graphics2D, double, double, double, double), which itself gets called by paint(java.awt.Graphics2D) This implementation delegates to the configuration to perform the actual painting in YLabel.Painter.paintContent(YLabel, java.awt.Graphics2D, double, double, double, double).

Parameters:
gfx - the graphics context (pre-configured to consider rotation
x - the top left x-coordinate of the drawing area
y - the top left y-coordinate of the drawing area
width - the width of the drawing area
height - the height of the drawing area

paintImpl

protected void paintImpl(java.awt.Graphics2D gfx,
                         double x,
                         double y,
                         double width,
                         double height)
Called by paint(java.awt.Graphics2D) Calls paintBox(java.awt.Graphics2D, double, double, double, double) and paintContent(java.awt.Graphics2D, double, double, double, double) in order.

Parameters:
gfx - the graphics context (pre-configured to consider rotation)
x - the top left x-coordinate of the drawing area
y - the top left y-coordinate of the drawing area
width - the width of the drawing area
height - the height of the drawing area

setHTMLRenderingEnabled

public static void setHTMLRenderingEnabled(boolean enabled)
Whether or not to enable HTML rendering for labels whose text starts with the html tag <html>. By default this feature is enabled.


isSizeDirty

public boolean isSizeDirty()
Returns true if the label size is not valid yet.


isOffsetDirty

public boolean isOffsetDirty()
Returns true if the label offset is not valid yet.


setSizeDirty

public void setSizeDirty()
Marks the size of the label as dirty


internalSetSizeDirty

public final void internalSetSizeDirty(boolean dirty)
This method is for internal use only and shall not be used by developers. Please use setSizeDirty() instead.


setOffsetDirty

public void setOffsetDirty()
Marks the label offsets as dirty.


internalSetOffsetDirty

public final void internalSetOffsetDirty(boolean dirty)
This method is for internal use only and shall not be used by developers. Please use setOffsetDirty() instead.


calculateOffset

public abstract void calculateOffset()
Calculates the offset of this label.


calculateSize

public void calculateSize()
Calculates the size of this label


calculateSize

public void calculateSize(java.awt.font.FontRenderContext frc)
Calculates the size of this label with the help of the given FontRenderContext.


getBox

public final YRectangle getBox()
Returns the bounding box of this label.


getOrientedBox

public abstract OrientedRectangle getOrientedBox()
Returns the label's oriented bounding box as determined by its label model before applying the label's inherent rotation. The oriented box is given in absolute world coordinates.

Returns:
label's oriented bounding box as determined by its label model.
See Also:
getContentBox()

repaint

public abstract void repaint()
Triggers a repaint of the bounds in the views for this label.

See Also:
getBox(), View.updateView(double, double, double, double)

setVerticalTextPosition

public void setVerticalTextPosition(byte pos)
Sets the vertical position of text relative to the icon.

Parameters:
pos - one of TOP_TEXT_POSITION, CENTER_TEXT_POSITION and BOTTOM_TEXT_POSITION.

getVerticalTextPosition

public byte getVerticalTextPosition()
Returns the vertical position of text relative ot the icon.

See Also:
setVerticalTextPosition(byte)

setHorizontalTextPosition

public void setHorizontalTextPosition(byte pos)
Sets the horizontal position of text relative to the icon.

Parameters:
pos - one of LEFT_TEXT_POSITION, CENTER_TEXT_POSITION and RIGHT_TEXT_POSITION.

getHorizontalTextPosition

public byte getHorizontalTextPosition()
Returns the horizontal position of text relative to the icon.

See Also:
setHorizontalTextPosition(byte)

setIconTextGap

public void setIconTextGap(byte gap)
Sets the size of the gap between text and icon


getIconTextGap

public byte getIconTextGap()
Returns the gap between text and icon


setUnderlinedTextEnabled

public void setUnderlinedTextEnabled(boolean u)
Sets whether or not to underline the text of the label


isUnderlinedTextEnabled

public boolean isUnderlinedTextEnabled()
Returns whether or not the text of the label should be underlined.


setRotationAngle

public void setRotationAngle(double angle)
Sets the rotation angle for this label. The label will be rotated by the given angle (in degrees) in clockwise direction.


getRotationAngle

public double getRotationAngle()
Returns the rotation angle for this label.

See Also:
setRotationAngle(double)

setInsets

public void setInsets(java.awt.Insets insets)
Sets the insets for this label. The insets define the distance between the label border and the label content.


getInsets

public java.awt.Insets getInsets()
Returns the insets for this label. If no insets are set null will be returned. In this case the default insets defaultInsets will be used.


setIcon

public void setIcon(javax.swing.Icon icon)
Sets the icon that is displayed by this label.


getIcon

public javax.swing.Icon getIcon()
Returns the icon that is displayed by this label and If no icon is associated with this label null is returned.


setTextColor

public void setTextColor(java.awt.Color c)
Sets the text color of this label.


getTextColor

public java.awt.Color getTextColor()
Returns the text color of this label.


isVisible

public boolean isVisible()
Whether of not this label is visible.


setVisible

public void setVisible(boolean vis)
Sets the visibility state of this label.


getPosition

public byte getPosition()
Returns the position specifier for this label.


setPosition

public void setPosition(byte b)
Sets a position specifier for this label.


getModel

public byte getModel()
Returns the model specifier for this label.


setModel

public void setModel(byte m)
Sets a model specifier for this label.


setBackgroundColor

public void setBackgroundColor(java.awt.Color bgColor)
Sets the background color to be used.


getBackgroundColor

public java.awt.Color getBackgroundColor()
Returns the background color to be used for painting this label.


setLineColor

public void setLineColor(java.awt.Color lineColor)
Sets the color used to draw a border around the bounding box of this label. No border will be painted if null is given as an argument. By default no border will be drawn.


getLineColor

public java.awt.Color getLineColor()
Returns the color used to draw a border around the bounding box of this label.

See Also:
setLineColor(Color)

setText

public void setText(java.lang.String text)
Sets the text being displayed by this label.


getText

public java.lang.String getText()
Returns the text of this label


setOffset

public void setOffset(OrientedRectangle offsetRectangle)
Sets the oriented offset rectangle for this label.

Note: Client code should not set a label's offset directly, but rather use getBestModelParameterForBounds(y.geom.OrientedRectangle) and setModelParameter(Object) to create and specify a parameter that represents the desired label position in the label's model.

Parameters:
offsetRectangle - the new relative, oriented bounds of the rectangle. Must not be null!
See Also:
getOffset()

getOffset

public OrientedRectangle getOffset()
Determines the oriented offset rectangle of this label.

See Also:
setOffset(y.geom.OrientedRectangle)

getOffsetX

public double getOffsetX()
Returns the x-coordinate of the offset of the label's paraxial bounding box.

Returns:
the x-coordinate of the offset of the label's paraxial bounding box.

getOffsetY

public double getOffsetY()
Returns the y-coordinate of the offset of the label's paraxial bounding box.

Returns:
the y-coordinate of the offset of the label's paraxial bounding box.

setOffsetX

public void setOffsetX(double x)
Deprecated. Client code should not set a label's offset directly, but rather use getBestModelParameterForBounds(y.geom.OrientedRectangle) and setModelParameter(Object) to create and specify a parameter that represents the desired label position in the label's model.

Sets the x-coordinate of the offset of the label's paraxial bounding box.

Parameters:
x - the x-coordinate of the paraxial offset box.

setOffsetY

public void setOffsetY(double y)
Deprecated. Client code should not set a label's offset directly, but rather use getBestModelParameterForBounds(y.geom.OrientedRectangle) and setModelParameter(Object) to create and specify a parameter that represents the desired label position in the label's model.

Sets the y-coordinate of the offset of the label's paraxial bounding box.

Parameters:
y - the y-coordinate of the paraxial offset box.

setOffset

public void setOffset(double x,
                      double y)
Deprecated. Client code should not set a label's offset directly, but rather use getBestModelParameterForBounds(y.geom.OrientedRectangle) and setModelParameter(Object) to create and specify a parameter that represents the desired label position in the label's model.

Sets the positional offset for this label. Invoking this method is equivalent to calling
setOffset(new OrientedRectangle(x, y + height, width, height));

Parameters:
x - the x-offset of the upper left corner of a paraxial rectangle.
y - the y-offset of the upper left corner of a paraxial rectangle.

getLocation

public YPoint getLocation()
Returns the absolute coordinate of the upper left corner of this label's paraxial bounding box.

Returns:
the absolute coordinate of the upper left corner of this label's paraxial bounding box.

setAlignment

public void setAlignment(byte a)
Sets the vertical alignment style for label text that spreads over multiple lines. By default ALIGN_CENTER is set.

See Also:
ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT

getAlignment

public byte getAlignment()
Returns the currently set alignment style for multiple lines of label text.

See Also:
setAlignment(byte)

getTextLocation

public YPoint getTextLocation()
Returns the absolute coordinate of the upper left corner of the label text's paraxial bounding box. This will take into account insets, alignment and other text placement settings. The default implementation is equivalent to:
return transformCTW(getTextBox()).getBoundingBox().getLocation();

Returns:
the absolute position of the text's paraxial bounding box.

getTextBox

public OrientedRectangle getTextBox()
Returns the oriented bounds of the label's text in the coordinate space of the label's content box. The origin of said coordinate space is the content box's anchor point, the x-direction is (-uy, ux) and the y-direction is -(ux, uy) with the content box's up vector (ux, uy). Use transformCTW(y.geom.OrientedRectangle) to determine the text bounds in (absolute) world coordinates.

Note: This method is not used to calculate the text placement in the label, but rather provides a means to query the label for text position and orientation.

Returns:
the oriented text bounds relative to the content box.
See Also:
getContentBox(), transformCTW(y.geom.OrientedRectangle)

getIconLocation

public YPoint getIconLocation()
Returns the absolute coordinate of the upper left corner of the label icon's paraxial bounding box. This will take into account insets and placement settings. The default implementation is equivalent to:
return transformCTW(getIconBox()).getBoundingBox().getLocation();

Returns:
the absolute position of the icon's paraxial bounding box.

getIconBox

public OrientedRectangle getIconBox()
Returns the oriented bounds of the label's icon in the coordinate space of the label's content box. The origin of said coordinate space is the content box's anchor point, the x-direction is (-uy, ux) and the y-direction is -(ux, uy) with the content box's up vector (ux, uy). Use transformCTW(y.geom.OrientedRectangle) to determine the icon bounds in (absolute) world coordinates.

Note: This method is not used to calculate the icon placement in the label, but rather provides a means to query the label for icon position and orientation.

Returns:
the oriented icon bounds relative to the content box.
See Also:
getContentBox(), transformCTW(y.geom.OrientedRectangle)

transformCTW

public OrientedRectangle transformCTW(OrientedRectangle box)
Transforms the specified rectangle from the coordinate space of this label's content box into world/graph coordinates.

Parameters:
box - an oriented rectangle whose anchor point and up vector are interpreted in the coordinate space of this label's content box. I.e. the origin of said coordinate space is the content box's anchor point, the x-direction is (-uy, ux) and the y-direction is (-ux, -uy) with the content box's up vector (ux, uy).
Returns:
the corresponding oriented rectangle in world coordinates.

intersects

public boolean intersects(double x,
                          double y,
                          double width,
                          double height)
Returns true iff the bounding box of this label intersects with the given box.


calcUnionRect

public void calcUnionRect(java.awt.geom.Rectangle2D r)
Enlarges the given rectangle such that it will contain the bounding box of this label. This implementation delegates to the YLabel.BoundsProvider instance registered with this instance's configuration.


setModelParameter

public abstract void setModelParameter(java.lang.Object value)
Sets the current parameters for the label model implementation.


getBestModelParameterForBounds

public abstract java.lang.Object getBestModelParameterForBounds(OrientedRectangle bounds)
Returns the best model parameter for this label such that the label's oriented bounds will match the specified bounds as closely as possible within the label's current label model. This method will return null if no suitable parameter can be determined.

Parameters:
bounds - the desired label bounds in absolute world coordinates.
Returns:
the model parameter that encodes the best match for the specified absolute bounds or null if no suitable model parameter could be determined.

getWidth

public double getWidth()
Returns the width of the bounding box of this label. getContentWidth() yields the width of the content area of the label.


getHeight

public double getHeight()
Returns the height of the bounding box of this label. getContentHeight() yields the height of the content area of the label.


toString

public java.lang.String toString()
Returns a string representation of this label.

Overrides:
toString in class java.lang.Object

getFont

public java.awt.Font getFont()
Returns the font used for this label.


setFont

public void setFont(java.awt.Font f)
Sets the font in which the text of this label gets displayed.


getFontName

public java.lang.String getFontName()
Returns the name of the label's font. This can be a logical font name or a font face name.

Returns:
the name of the label's font.

setFontName

public void setFontName(java.lang.String name)
Sets a new font with the specified name for the label. The style and size of the label's font will stay unchanged if possible.

Parameters:
name - the name of the label's new font. This can be a logical font name or a font face name.
See Also:
Font.Font(String, int, int)

getFontSize

public int getFontSize()
Returns the point size of the label's font

Returns:
the point size of the label's font.

setFontSize

public void setFontSize(int s)
Sets the point size for the label's font.

Parameters:
s - the point size of the label's font.
See Also:
Font.Font(String, int, int)

getFontStyle

public int getFontStyle()
Returns the font style for this label. The font style is an integer bit mask that may be Font.PLAIN, or a bitwise union of Font.BOLD and/or Font.ITALIC.

Returns:
the font style for this label.
See Also:
Font.Font(String, int, int)

setFontStyle

public void setFontStyle(int s)
Sets the font style for this label.

Parameters:
s - the style mask for the label's font. The style argument is an integer bit mask that may be Font.PLAIN, or a bitwise union of Font.BOLD and/or Font.ITALIC.
See Also:
Font.Font(String, int, int)

adoptValues

public void adoptValues(YLabel label)
Adopts the values from the given label.


write

public void write(java.io.ObjectOutputStream out)
           throws java.io.IOException
Deprecated. Use the GraphML format instead.

Writes out this label in a serialized form.

Throws:
java.io.IOException

read

public void read(java.io.ObjectInputStream in)
          throws java.io.IOException,
                 java.lang.ClassNotFoundException
Deprecated. Use the GraphML format instead.

Reads in the serialized form of this label. The label must have been written out before by it's write(ObjectOutputStream) method.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

setConfiguration

public abstract void setConfiguration(java.lang.String name)
Configures this instance to use the configuration specified by the given name. A configuration must have been registered with the factory previously in order to work. This can be done by using the factory instances provided by NodeLabel.getFactory() and EdgeLabel.getFactory() respectively.

Parameters:
name - the name of the configuration as it has been specified in YLabel.Factory.addConfiguration(String, java.util.Map)
See Also:
YLabel.Factory, YLabel.Factory.addConfiguration(String, java.util.Map)

getConfiguration

public java.lang.String getConfiguration()
Returns the string identifier of the current configuration this label is in. The configuration can be used to plug specific functionality into a label at runtime.

Returns:
The string identifier or null if no specific configuration is used.
See Also:
setConfiguration(String), YLabel.Factory

setAutoSizePolicy

public void setAutoSizePolicy(byte autoSize)
Sets the automatic size calculation policy for this label. By default AUTOSIZE_CONTENT is set.

Parameters:
autoSize - one of the specifiers AUTOSIZE_CONTENT or AUTOSIZE_NONE.

internalSetAutoSizePolicy

public void internalSetAutoSizePolicy(byte autoSize)
This method is for internal use only and shall not be used by developers. Please use setAutoSizePolicy(byte) instead.


getAutoSizePolicy

public byte getAutoSizePolicy()
Returns the currently set automatic size calculation policy for this label.

See Also:
setAutoSizePolicy(byte).

setFractionMetricsForSizeCalculationEnabled

public static void setFractionMetricsForSizeCalculationEnabled(boolean fractionalFontMetricsEnabled)
Sets whether or not fractional font metrics shall be used to calculate the size of the label text. For consistent results, this setting should be kept in sync with the fraction font metrics rendering hints that can be set on Graph2DView. By default, this feature is turned off.

See Also:
Graph2DView.getRenderingHints(), RenderingHints.KEY_FRACTIONALMETRICS

isFractionMetricsForSizeCalculationEnabled

public static boolean isFractionMetricsForSizeCalculationEnabled()
Returns whether or not fractional font metrics shall be used to calculate the size of the label text. For consistent results, this setting should be kept in sync with the fraction font metrics rendering hints that can be set on Graph2DView. By default, this feature is turned off.

See Also:
Graph2DView.getRenderingHints(), RenderingHints.KEY_FRACTIONALMETRICS

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