com.mindfusion.diagramming
Class ShapeNode

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

public class ShapeNode
extends DiagramNode

ShapeNode objects represent nodes in graphs, tree, process diagrams, etc.

Use the setShape(com.mindfusion.diagramming.Shape) method to specify the shape of a node. There are many predefined shapes provided by the Shape class, which also lets you define your custom shapes.

ShapeNodes can be rotated, either interactively using the rotation handle above a node, or programmatically using the setRotationAngle(float) method.

Nodes can display images and text. Use the setImage(java.awt.Image) method to specify an image that should be painted inside a node. The position and alignment of an image within the node are set via the setImageAlign(int) method. To make a node as big as its image, call resizeToFitImage().

To set the node's text, call setText(java.lang.String). The text attributes can be changed through the setTextColor(java.awt.Color) and setTextFormat(com.mindfusion.diagramming.TextFormat) methods. To get even richer text formatting, call setEnableStyledText(boolean) to true and embed HTML-like formatting tags in the raw text. To make a node big enough to display its text without clipping, call resizeToFitText(com.mindfusion.diagramming.FitSize).

Call setTransparent(boolean) to make a node transparent, so that only its text and image will be drawn.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.mindfusion.diagramming.DiagramNode
allowIncomingLinks, allowOutgoingLinks, anchorPattern, AV_Cancel, AV_EndModIncoming, AV_EndModOutgoing, AV_StartModIncoming, AV_StartModOutgoing, AV_UpdateIncoming, AV_UpdateOutgoing, AV_UpdIntscIncoming, AV_UpdIntscOutgoing, AV_UpdPosIncoming, AV_UpdPosOutgoing, bounds, enabledHandles, handlesStyle, incomingLinks, masterGroup, obstacle, outgoingLinks, savedBounds
 
Fields inherited from class com.mindfusion.diagramming.DiagramItem
brush, cycleDetected, cycleProtect, font, hyperLink, ignoreLayout, locked, modifyDX, modifyDY, modifyHandle, modifying, pen, printable, ptEnd, ptMdfLast, ptOrg, ptSavedEnd, ptSavedOrg, selected, shadowColor, shadowOffsetX, shadowOffsetY, subordinateGroup, tag, toolTip, visible, zIndex
 
Constructor Summary
ShapeNode()
          Initializes a new instance of the ShapeNode class.
ShapeNode(Diagram parent)
          Initializes a new ShapeNode instance by setting its properties to the default values specified in the diagram.
ShapeNode(ShapeNode prototype)
          Initializes a new ShapeNode instance by copying the attribute values from the specified prototype node.
 
Method Summary
protected  boolean allowModify(java.awt.geom.Point2D current, InteractionState ist)
          Invoked during interactive modification of items to test whether the operation can be completed in the current context.
 void cancelModify(InteractionState ist)
           
protected  void completeModify(java.awt.geom.Point2D end, InteractionState ist)
          Invoked when the item modification has been completed.
 boolean containsPoint(java.awt.geom.Point2D point)
          ShapeNode.containsPoint override.
 boolean containsPoint(java.awt.geom.Point2D point, float threshold)
          DiagramNode.containsPoint override.
protected  com.mindfusion.diagramming.ConnectionPoint createConnectionPoint(DiagramLink link, java.awt.geom.Point2D pt, boolean incoming)
           
protected  DiagramItemProperties createProperties()
          DiagramItem.createProperties() override.
protected  DiagramItemState createState()
          DiagramItem.createState() override.
protected  void draw(java.awt.Graphics2D graphics, RenderOptions options)
           
protected  void drawShadow(java.awt.Graphics2D graphics, RenderOptions options)
           
 int getCustomDraw()
          Gets a value indicating what type of custom drawing to perform on a node.
 java.awt.geom.Rectangle2D getEditRect(java.awt.geom.Point2D mousePosition)
           
 boolean getEnableStyledText()
          Gets a value indicating whether the text of a node contains formatting tags which should be processed by JDiagram.
 java.awt.Font getFont()
          Gets the font used to draw the text label of a node.
 java.awt.Image getImage()
          Gets the image displayed inside this node.
 int getImageAlign()
          Gets the alignment of the node's image.
 java.lang.String getPlainText()
          Gets the plain text extracted from the formatted text by removing the formatting tags.
 boolean getRotateImage()
          Gets a value indicating whether the image displayed inside a node should rotate together with the node.
 boolean getRotateText()
          Gets a value indicating whether the text displayed inside a node should rotate together with the node.
 float getRotationAngle()
          Gets the rotation angle of a node.
 Shape getShape()
          Gets the shape of a node.
 float getShapeOrientation()
          Gets an orientation angle applied to the shape definition before the shape points are mapped to the node's bounding rectangle.
 java.lang.String getText()
          Gets the text displayed inside this node.
 java.awt.Color getTextColor()
          Gets the color used to paint the text of a node.
 TextFormat getTextFormat()
          Gets a TextFormat object specifying how to format and align the text of this node.
 java.lang.String getTextToEdit()
           
 boolean getTransparent()
          Gets a value indicating whether only the text and image of a node should be drawn on the screen.
protected  void loadFromXml(org.w3c.dom.Element xmlElement, XmlPersistContext context)
          Loads the item content from an XML element.
protected  void onUpdateBounds()
          Invoked when the bounding rectangle of the node has changed.
 void readExternal(java.io.ObjectInput in)
          Implements Externalizable.
 void renderText(java.lang.String text, java.awt.geom.Rectangle2D dest, com.mindfusion.diagramming.DrawTextHint hint)
           
 void resizeToFitImage()
          Resizes a node so that it will be as big as the image displayed in the node.
 boolean resizeToFitText(FitSize fit)
          Makes a node big enough to display its text without clipping.
protected  void restoreProperties(DiagramItemProperties props)
          DiagramItem.restoreProperties(com.mindfusion.diagramming.DiagramItemProperties) override.
protected  void restoreState(DiagramItemState state)
          DiagramItem.restoreState(com.mindfusion.diagramming.DiagramItemState) override.
protected  void saveProperties(DiagramItemProperties props)
          DiagramItem.saveProperties(com.mindfusion.diagramming.DiagramItemProperties) override.
protected  void saveState(DiagramItemState state)
          DiagramItem.saveState(com.mindfusion.diagramming.DiagramItemState) override.
protected  void saveToXml(org.w3c.dom.Element xmlElement, XmlPersistContext context)
          Saves the item content into an XML element.
 void setCustomDraw(int value)
          Sets a value indicating what type of custom drawing to perform on a node.
 void setEditedText(java.lang.String newText)
           
 void setEnableStyledText(boolean value)
          Sets a value indicating whether the text of a node contains formatting tags which should be processed by JDiagram.
 void setFont(java.awt.Font value)
          Sets the font used to draw the text label of a node.
 void setImage(java.awt.Image value)
          Sets the image that should be displayed inside the node.
 void setImageAlign(int value)
          Sets the alignment of the node's image.
 void setRotateImage(boolean value)
          Sets a value indicating whether the image displayed inside a node should rotate together with the node.
 void setRotateText(boolean value)
          Sets a value indicating whether the text displayed inside a node should rotate together with the node.
 void setRotationAngle(float value)
          Sets the rotation angle of a node.
 void setShape(Shape value)
          Sets the shape of a node to the specified Shape instance.
 void setShapeOrientation(float value)
          Sets an orientation angle applied to the shape definition before the shape points are mapped to the node's bounding rectangle.
 void setText(java.lang.String value)
          Sets the text label displayed inside this node.
 void setTextColor(java.awt.Color value)
          Sets the color used to paint the text of a node.
 void setTextFormat(TextFormat value)
          Sets a TextFormat object specifying how to format and align the text of this node.
 void setTransparent(boolean value)
          Sets a value indicating whether only the text and image of a node should be drawn on the screen.
protected  void startModify(java.awt.geom.Point2D org, int handle, InteractionState ist)
          Invoked when the user starts modifying this item interactively.
protected  void updateModify(java.awt.geom.Point2D current, InteractionState ist)
          Invoked during interactive modification of this item.
 void writeExternal(java.io.ObjectOutput out)
          Implements Externalizable.
 
Methods inherited from class com.mindfusion.diagramming.DiagramNode
allowCreate, attachTo, attachTo, attachTo, completeCreate, constraintsInfringed, detach, getAllowIncomingLinks, getAllowOutgoingLinks, getAnchorPattern, getBounds, getConstraints, getEnabledHandles, getExpandable, getExpanded, getHandlesStyle, getIncomingLinks, getMasterGroup, getObstacle, getOutgoingLinks, groupContains, move, moveTo, nodesIntersect, onDragOut, onDragOver, onDropOver, onRemove, putExpandable, rectFromPoints, resize, resizeToFitImage, setAllowIncomingLinks, setAllowOutgoingLinks, setAnchorPattern, setBounds, setBounds, setConstraints, setEnabledHandles, setExpandable, setExpanded, setExpandedFlag, setHandlesStyle, setObstacle, setReflexive, shouldRenderAnchors, startCreate, updateCreate, updateLinkPositions
 
Methods inherited from class com.mindfusion.diagramming.DiagramItem
clone, getBrush, getHyperLink, getIgnoreLayout, getLayoutTraits, getLocked, getMeasureUnit, getParent, getPen, getPrintable, getSelected, getShadowColor, getShadowOffsetX, getShadowOffsetY, getSubordinateGroup, getTag, getToolTip, getVisible, getWeight, getZIndex, hasSubordinates, onAdd, onChangeFont, onChildModified, onClick, onDoubleClick, onModify, putSelected, repaint, repaint, repaint, setBrush, setDiagramDirty, setHyperLink, setIgnoreLayout, setLocked, setPen, setPrintable, setSelected, setShadowColor, setShadowOffsetX, setShadowOffsetY, setTag, setToolTip, setVisible, setWeight, setZIndex, shouldRender, zBottom, zLevelDown, zLevelUp, zTop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShapeNode

public ShapeNode()
Initializes a new instance of the ShapeNode class.


ShapeNode

public ShapeNode(Diagram parent)
Initializes a new ShapeNode instance by setting its properties to the default values specified in the diagram.

Parameters:
parent - A Diagram instance whose default node attributes are copied to this node.

ShapeNode

public ShapeNode(ShapeNode prototype)
Initializes a new ShapeNode instance by copying the attribute values from the specified prototype node.

Parameters:
prototype - A ShapeNode instance whose attributes are copied to this node.
Method Detail

startModify

protected void startModify(java.awt.geom.Point2D org,
                           int handle,
                           InteractionState ist)
Description copied from class: DiagramItem
Invoked when the user starts modifying this item interactively.

Overrides:
startModify in class DiagramNode
Parameters:
org - Position of the mouse pointer.
handle - Index of the adjustment handle used to modify the item.
ist - An InteractionState object containing more information about the current state of the operation.

updateModify

protected void updateModify(java.awt.geom.Point2D current,
                            InteractionState ist)
Description copied from class: DiagramItem
Invoked during interactive modification of this item.

Overrides:
updateModify in class DiagramNode
Parameters:
current - Position of the mouse pointer.
ist - An InteractionState object containing more information about the current state of the operation.

allowModify

protected boolean allowModify(java.awt.geom.Point2D current,
                              InteractionState ist)
Description copied from class: DiagramItem
Invoked during interactive modification of items to test whether the operation can be completed in the current context.

Overrides:
allowModify in class DiagramNode
Parameters:
current - The current mouse pointer position.
ist - An InteractionState object containing more information about the current state of the operation.
Returns:
true to allow the modification of this item; otherwise, false.

completeModify

protected void completeModify(java.awt.geom.Point2D end,
                              InteractionState ist)
Description copied from class: DiagramItem
Invoked when the item modification has been completed.

Overrides:
completeModify in class DiagramNode
Parameters:
end - The mouse pointer position.
ist - An InteractionState object containing more information about the current state of the operation.

cancelModify

public void cancelModify(InteractionState ist)
Overrides:
cancelModify in class DiagramNode

onUpdateBounds

protected void onUpdateBounds()
Description copied from class: DiagramNode
Invoked when the bounding rectangle of the node has changed.

Overrides:
onUpdateBounds in class DiagramNode

draw

protected void draw(java.awt.Graphics2D graphics,
                    RenderOptions options)
Specified by:
draw in class DiagramItem

drawShadow

protected void drawShadow(java.awt.Graphics2D graphics,
                          RenderOptions options)
Specified by:
drawShadow in class DiagramItem

renderText

public void renderText(java.lang.String text,
                       java.awt.geom.Rectangle2D dest,
                       com.mindfusion.diagramming.DrawTextHint hint)

containsPoint

public boolean containsPoint(java.awt.geom.Point2D point,
                             float threshold)
DiagramNode.containsPoint override.

Overrides:
containsPoint in class DiagramNode
Parameters:
point - The point to check.
threshold - Specifies the size of the area around the node outlines where the point is still considered inside the node.
Returns:
true it this node contains the specified point; otherwise, false.

containsPoint

public boolean containsPoint(java.awt.geom.Point2D point)
ShapeNode.containsPoint override.

Overrides:
containsPoint in class DiagramNode
Parameters:
point - The point to check.
Returns:
true it this item contains the specified point; otherwise, false.

getImage

public java.awt.Image getImage()
Gets the image displayed inside this node.

Returns:
A java.awt.Image object.

setImage

public void setImage(java.awt.Image value)
Sets the image that should be displayed inside the node.

Parameters:
value - A java.awt.Image object.

getImageAlign

public int getImageAlign()
Gets the alignment of the node's image.

Returns:
One of the ImageAlign constants.

setImageAlign

public void setImageAlign(int value)
Sets the alignment of the node's image.

Parameters:
value - One of the ImageAlign constants.

getText

public java.lang.String getText()
Gets the text displayed inside this node.

Returns:
A String containing the label text.

setText

public void setText(java.lang.String value)
Sets the text label displayed inside this node.

Parameters:
value - A String containing the label text.

getPlainText

public java.lang.String getPlainText()
Gets the plain text extracted from the formatted text by removing the formatting tags.

Returns:
A String containing the label text stripped from formatting tags.

getTextColor

public java.awt.Color getTextColor()
Gets the color used to paint the text of a node.

Returns:
A Color object representing the text color.

setTextColor

public void setTextColor(java.awt.Color value)
Sets the color used to paint the text of a node.

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

getTextFormat

public TextFormat getTextFormat()
Gets a TextFormat object specifying how to format and align the text of this node.

Returns:
A TextFormat object specifying the text format and alignment.

setTextFormat

public void setTextFormat(TextFormat value)
Sets a TextFormat object specifying how to format and align the text of this node.

Parameters:
value - A TextFormat object specifying the text format and alignment.

getTransparent

public boolean getTransparent()
Gets a value indicating whether only the text and image of a node should be drawn on the screen.

Returns:
true to display only the node text and image, otherwise false.

setTransparent

public void setTransparent(boolean value)
Sets a value indicating whether only the text and image of a node should be drawn on the screen.

Parameters:
value - true to display only the node text and image, otherwise false.

resizeToFitImage

public void resizeToFitImage()
Resizes a node so that it will be as big as the image displayed in the node.


getCustomDraw

public int getCustomDraw()
Gets a value indicating what type of custom drawing to perform on a node.

Returns:
One of the CustomDraw constants.

setCustomDraw

public void setCustomDraw(int value)
Sets a value indicating what type of custom drawing to perform on a node.

Parameters:
value - One of the CustomDraw constants.

resizeToFitText

public boolean resizeToFitText(FitSize fit)
Makes a node big enough to display its text without clipping.

Parameters:
fit - A member of the FitSize enumeration specifying whether the width or height of the node should remain unchanged.
Returns:
true if the node is resized successfully; otherwise false.

getShape

public Shape getShape()
Gets the shape of a node.

Returns:
A Shape object representing the node's shape.

setShape

public void setShape(Shape value)
Sets the shape of a node to the specified Shape instance. The initial shape of a node is the one set via the Diagram.setDefaultShape(com.mindfusion.diagramming.Shape) method.

Parameters:
value - A Shape object representing the node's shape.

getShapeOrientation

public float getShapeOrientation()
Gets an orientation angle applied to the shape definition before the shape points are mapped to the node's bounding rectangle.

Returns:
A float value specifying the shape definition orientation.

setShapeOrientation

public void setShapeOrientation(float value)
Sets an orientation angle applied to the shape definition before the shape points are mapped to the node's bounding rectangle.

Parameters:
value - A float value specifying the shape definition orientation.

getRotationAngle

public float getRotationAngle()
Gets the rotation angle of a node.

Returns:
A float value specifying the node rotation angle.

setRotationAngle

public void setRotationAngle(float value)
Sets the rotation angle of a node.

Parameters:
value - A float value specifying the node rotation angle.

getRotateImage

public boolean getRotateImage()
Gets a value indicating whether the image displayed inside a node should rotate together with the node.

Returns:
true if the node image rotates when the node is rotated, otherwise false.

setRotateImage

public void setRotateImage(boolean value)
Sets a value indicating whether the image displayed inside a node should rotate together with the node.

Parameters:
value - true to rotate the node image when the node is rotated, otherwise false.

getRotateText

public boolean getRotateText()
Gets a value indicating whether the text displayed inside a node should rotate together with the node.

Returns:
true if the node text rotates when the node is rotated, otherwise false.

setRotateText

public void setRotateText(boolean value)
Sets a value indicating whether the text displayed inside a node should rotate together with the node.

Parameters:
value - true to rotate the node text when the node is rotated, otherwise false.

createConnectionPoint

protected com.mindfusion.diagramming.ConnectionPoint createConnectionPoint(DiagramLink link,
                                                                           java.awt.geom.Point2D pt,
                                                                           boolean incoming)
Overrides:
createConnectionPoint in class DiagramNode

getTextToEdit

public java.lang.String getTextToEdit()
Specified by:
getTextToEdit in interface InplaceEditable

setEditedText

public void setEditedText(java.lang.String newText)
Specified by:
setEditedText in interface InplaceEditable

getEditRect

public java.awt.geom.Rectangle2D getEditRect(java.awt.geom.Point2D mousePosition)
Specified by:
getEditRect in interface InplaceEditable

getFont

public java.awt.Font getFont()
Gets the font used to draw the text label of a node.

Overrides:
getFont in class DiagramItem
Returns:
A java.awt.Font object representing the label font.

setFont

public void setFont(java.awt.Font value)
Sets the font used to draw the text label of a node.

Overrides:
setFont in class DiagramItem
Parameters:
value - A java.awt.Font object representing the label font.

createState

protected DiagramItemState createState()
DiagramItem.createState() override.

Overrides:
createState in class DiagramNode

saveState

protected void saveState(DiagramItemState state)
DiagramItem.saveState(com.mindfusion.diagramming.DiagramItemState) override.

Overrides:
saveState in class DiagramNode

restoreState

protected void restoreState(DiagramItemState state)
DiagramItem.restoreState(com.mindfusion.diagramming.DiagramItemState) override.

Overrides:
restoreState in class DiagramNode

createProperties

protected DiagramItemProperties createProperties()
DiagramItem.createProperties() override.

Overrides:
createProperties in class DiagramNode
Returns:
A DiagramItemProperties-derived object containing a snapshot of the item's properties.

saveProperties

protected void saveProperties(DiagramItemProperties props)
DiagramItem.saveProperties(com.mindfusion.diagramming.DiagramItemProperties) override.

Overrides:
saveProperties in class DiagramNode
Parameters:
props - A DiagramItemProperties-derived object where the item's properties should be saved.

restoreProperties

protected void restoreProperties(DiagramItemProperties props)
DiagramItem.restoreProperties(com.mindfusion.diagramming.DiagramItemProperties) override.

Overrides:
restoreProperties in class DiagramNode
Parameters:
props - A DiagramItemProperties -derived object containing a snapshot of the item's properties.

getEnableStyledText

public boolean getEnableStyledText()
Gets a value indicating whether the text of a node contains formatting tags which should be processed by JDiagram.

Returns:
true if JDiagram should process formatting tags when rendering the node label, otherwise false.

setEnableStyledText

public void setEnableStyledText(boolean value)
Sets a value indicating whether the text of a node contains formatting tags which should be processed by JDiagram.

Parameters:
value - true if JDiagram should process formatting tags when rendering the node label, otherwise false.

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Implements Externalizable.

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

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Implements Externalizable.

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

saveToXml

protected void saveToXml(org.w3c.dom.Element xmlElement,
                         XmlPersistContext context)
Description copied from class: DiagramItem
Saves the item content into an XML element.

Overrides:
saveToXml in class DiagramNode
Parameters:
xmlElement - An Element the item's data should be stored into.
context - An XmlPersistContext object providing contextual information about the serialization process and some helper serialization methods.

loadFromXml

protected void loadFromXml(org.w3c.dom.Element xmlElement,
                           XmlPersistContext context)
                    throws javax.xml.transform.TransformerException,
                           XmlException
Description copied from class: DiagramItem
Loads the item content from an XML element.

Overrides:
loadFromXml in class DiagramNode
Parameters:
xmlElement - An XmlElement containing the item's data.
context - An XmlPersistContext object providing contextual information about the serialization process and some helper serialization methods
Throws:
javax.xml.transform.TransformerException
XmlException