com.mindfusion.diagramming
Class LinkLabel

java.lang.Object
  extended by com.mindfusion.diagramming.LinkLabel
All Implemented Interfaces:
InplaceEditable, java.io.Externalizable, java.io.Serializable

public class LinkLabel
extends java.lang.Object
implements java.io.Externalizable, InplaceEditable

Represents a label displayed by a DiagramLink. New labels can be added to a link by calling the DiagramLink.addLabel(String) method.

See Also:
Serialized Form

Constructor Summary
LinkLabel()
          Used during deserialization.
LinkLabel(DiagramLink link)
          Initializes a new instance of the LinkLabel class.
LinkLabel(DiagramLink link, java.lang.String text)
          Initializes a new instance of the LinkLabel class.
 
Method Summary
 LinkLabel clone()
          Creates a clone of this label.
protected  void draw(java.awt.Graphics2D graphics)
          Draws this label on the specified Graphics2D surface.
 boolean getAutoArrange()
          Gets a value indicating whether the label can be auto arranged.
 java.awt.geom.Rectangle2D getEditRect(java.awt.geom.Point2D mousePosition)
          Implements InplaceEditable.
 boolean getEnableWrap()
          Gets whether the text should wrap to multiple lines.
 java.awt.Font getFont()
          Gets the font of the link's label text.
 int getHorizontalAlign()
          Gets the horizontal alignment of the text within the label's layout rectangle.
 int getIndex()
          Gets the index of the segment or control point this label is relative to.
protected  java.awt.geom.Rectangle2D getLayoutRect()
          Gets the label's layout rectangle calculated from text length, font and alignment.
protected  DiagramLink getLink()
          Returns the DiagramLink that displays this label.
 float getMargin()
          Gets the text margins size.
 float getMaxWidth()
          Gets the maximal width that when reached should cause text to wrap to a new line.
 int getRelativeTo()
          Gets the label's relative positioning.
 java.lang.String getText()
          Gets the label's text.
 java.awt.Color getTextColor()
          Gets the color of the link's label text.
 java.lang.String getTextToEdit()
          Implements InplaceEditable.
 int getVerticalAlign()
          Gets the vertical alignment of the text relatively to the label's position.
protected  void loadFromXml(org.w3c.dom.Element xmlElement, XmlPersistContext context)
          Loads the label from the specified XML element.
protected  java.awt.geom.Point2D.Float pointAlongLength(float lengthFactor)
           
protected  java.awt.geom.Point2D.Float pointAlongLength(float lengthFactor, PointList segments)
          Returns a point lying on a polyline that is positioned at a relative position along the polyline's length.
 void readExternal(java.io.ObjectInput in)
          Loads the label from the specified binary stream.
protected  void saveToXml(org.w3c.dom.Element xmlElement, XmlPersistContext context)
          Saves the label into the specified XML element.
 void setAutoArrange(boolean value)
          Sets a value indicating whether the label can be auto arranged.
 void setControlPointPosition(int controlPoint, float dx, float dy)
          Positions this label relatively to the specified control point.
 void setEditedText(java.lang.String newText)
          Implements InplaceEditable.
 void setEnableWrap(boolean enableWrap)
          Sets whether the text should wrap to multiple lines.
 void setFont(java.awt.Font value)
          Sets the font of the link's label.
 void setHorizontalAlign(int align)
          Sets the horizontal alignment of the text within the label's layout rectangle.
 void setIndex(int value)
          Sets the index of the segment or control point this label is relative to.
 void setLinkLengthPosition(float lengthFactor)
          Positions this label relatively to the link length.
 void setMargin(float margin)
          Sets the text margins size.
 void setMaxWidth(float maxWidth)
          Sets the maximal width that when reached should cause text to wrap to a new line.
 void setRelativeTo(int value)
          Sets the label's relative positioning.
 void setSegmentPosition(int segment, float dx, float dy)
          Positions this label relatively to the specified link segment.
 void setText(java.lang.String text)
          Sets the label's text.
 void setTextColor(java.awt.Color value)
          Sets the color of the link's label.
 void setVerticalAlign(int align)
          Sets the vertical alignment of the text relatively to the label's position.
 void writeExternal(java.io.ObjectOutput out)
          Saves the label into the specified binary stream.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LinkLabel

public LinkLabel(DiagramLink link)
Initializes a new instance of the LinkLabel class.

Parameters:
link - The DiagramLink that displays the label.

LinkLabel

public LinkLabel()
Used during deserialization.


LinkLabel

public LinkLabel(DiagramLink link,
                 java.lang.String text)
Initializes a new instance of the LinkLabel class.

Parameters:
link - The DiagramLink that displays the label.
text - The label's text.
Method Detail

clone

public LinkLabel clone()
Creates a clone of this label.

Overrides:
clone in class java.lang.Object
Returns:
A new LinkLabel instance that is an exact copy of this label.

getAutoArrange

public boolean getAutoArrange()
Gets a value indicating whether the label can be auto arranged.

Returns:
A boolean indicating whether the label can be auto arranged.

setAutoArrange

public void setAutoArrange(boolean value)
Sets a value indicating whether the label can be auto arranged.

Parameters:
value - A boolean indicating whether the label can be auto arranged.

getIndex

public int getIndex()
Gets the index of the segment or control point this label is relative to.

Returns:
The integer index of a link's segment or control point.

setIndex

public void setIndex(int value)
Sets the index of the segment or control point this label is relative to.

Parameters:
value - The integer index of a link's segment or control point.

getRelativeTo

public int getRelativeTo()
Gets the label's relative positioning.

Returns:
One of the LinkLabel constants.

setRelativeTo

public void setRelativeTo(int value)
Sets the label's relative positioning.

Parameters:
value - One of the LinkLabel constants.

setText

public void setText(java.lang.String text)
Sets the label's text.

Parameters:
text - A String containing the label's text.

getText

public java.lang.String getText()
Gets the label's text.

Returns:
A String containing the label's text.

setTextColor

public void setTextColor(java.awt.Color value)
Sets the color of the link's label.

Parameters:
value - A Color object representing the text color.

getTextColor

public java.awt.Color getTextColor()
Gets the color of the link's label text.

Returns:
A Color object representing the text color.

setFont

public void setFont(java.awt.Font value)
Sets the font of the link's label.

Parameters:
value - A Font object representing the text font.

getFont

public java.awt.Font getFont()
Gets the font of the link's label text.

Returns:
A Font object representing the text font.

getLink

protected DiagramLink getLink()
Returns the DiagramLink that displays this label.

Returns:
A DiagramLink instance.

draw

protected void draw(java.awt.Graphics2D graphics)
Draws this label on the specified Graphics2D surface.

Parameters:
graphics - A Graphics2D instance.

setSegmentPosition

public void setSegmentPosition(int segment,
                               float dx,
                               float dy)
Positions this label relatively to the specified link segment.

Parameters:
segment - The segment index.
dx - Horizontal offset from the segment center.
dy - Vertical offset from the segment center.

setControlPointPosition

public void setControlPointPosition(int controlPoint,
                                    float dx,
                                    float dy)
Positions this label relatively to the specified control point.

Parameters:
controlPoint - The control point index.
dx - Horizontal offset from the point.
dy - Vertical offset from the point.

setLinkLengthPosition

public void setLinkLengthPosition(float lengthFactor)
Positions this label relatively to the link length.

Parameters:
lengthFactor - A value between 0 and 1 specifying the position of the label relatively to the link's length.

setMargin

public void setMargin(float margin)
Sets the text margins size.

Parameters:
margin - A float value specifying the size of text margins.

getMargin

public float getMargin()
Gets the text margins size.

Returns:
A float value specifying the size of text margins.

setEnableWrap

public void setEnableWrap(boolean enableWrap)
Sets whether the text should wrap to multiple lines.

Parameters:
enableWrap - true to enable text wrapping; otherwise, false.

getEnableWrap

public boolean getEnableWrap()
Gets whether the text should wrap to multiple lines.

Returns:
true if text wrapping is enabled; otherwise, false.

setMaxWidth

public void setMaxWidth(float maxWidth)
Sets the maximal width that when reached should cause text to wrap to a new line.

Parameters:
maxWidth - A float value specifying the maximal label width.

getMaxWidth

public float getMaxWidth()
Gets the maximal width that when reached should cause text to wrap to a new line.

Returns:
A float value specifying the maximal label width.

setHorizontalAlign

public void setHorizontalAlign(int align)
Sets the horizontal alignment of the text within the label's layout rectangle.

Parameters:
align - One of the Align constants.

getHorizontalAlign

public int getHorizontalAlign()
Gets the horizontal alignment of the text within the label's layout rectangle.

Returns:
One of the Align constants.

setVerticalAlign

public void setVerticalAlign(int align)
Sets the vertical alignment of the text relatively to the label's position.

Parameters:
align - One of the Align constants.

getVerticalAlign

public int getVerticalAlign()
Gets the vertical alignment of the text relatively to the label's position.

Returns:
One of the Align constants.

pointAlongLength

protected java.awt.geom.Point2D.Float pointAlongLength(float lengthFactor)

pointAlongLength

protected java.awt.geom.Point2D.Float pointAlongLength(float lengthFactor,
                                                       PointList segments)
Returns a point lying on a polyline that is positioned at a relative position along the polyline's length.

Parameters:
lengthFactor - A value from 0 to 1 specifying a portion of link's length.
segments - A list of points specifying the polyline segments.
Returns:
A Point2D.Float instance.

getLayoutRect

protected java.awt.geom.Rectangle2D getLayoutRect()
Gets the label's layout rectangle calculated from text length, font and alignment.

Returns:

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Saves the label into the specified binary stream.

Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Loads the label from the specified binary stream.

Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException

saveToXml

protected void saveToXml(org.w3c.dom.Element xmlElement,
                         XmlPersistContext context)
Saves the label into the specified XML element.

Parameters:
xmlElement - An Element instance.
context - An XmlPersistContext instance.

loadFromXml

protected void loadFromXml(org.w3c.dom.Element xmlElement,
                           XmlPersistContext context)
                    throws javax.xml.transform.TransformerException
Loads the label from the specified XML element.

Parameters:
xmlElement - An Element instance.
context - An XmlPersistContext instance.
Throws:
javax.xml.transform.TransformerException

getEditRect

public java.awt.geom.Rectangle2D getEditRect(java.awt.geom.Point2D mousePosition)
Implements InplaceEditable.

Specified by:
getEditRect in interface InplaceEditable

getTextToEdit

public java.lang.String getTextToEdit()
Implements InplaceEditable.

Specified by:
getTextToEdit in interface InplaceEditable

setEditedText

public void setEditedText(java.lang.String newText)
Implements InplaceEditable.

Specified by:
setEditedText in interface InplaceEditable