com.nwoods.jgo
Class JGoLabeledLink

java.lang.Object
  extended bycom.nwoods.jgo.JGoObject
      extended bycom.nwoods.jgo.JGoDrawable
          extended bycom.nwoods.jgo.JGoStroke
              extended bycom.nwoods.jgo.JGoLink
                  extended bycom.nwoods.jgo.JGoLabeledLink
All Implemented Interfaces:
JGoIdentifiablePart, JGoXMLSaveRestore, java.io.Serializable

public class JGoLabeledLink
extends JGoLink

JGoLabeledLink is a JGoLink that has optional JGoObject "labels" near the ports and the middle of the link.

By default there are no labels; create and set them. Frequently JGoLinkLabel is used for textual labels, but other JGoObjects can be used as well. You may find you will need to override the label positioning methods, if the default label positions are not to your liking.

See Also:
Serialized Form

Field Summary
static int ChangedFromLabel
          a CHANGED JGoDocumentEvent or JGoViewEvent hint: a text label has changed
static int ChangedGrabChildSelection
          a CHANGED JGoDocumentEvent or JGoViewEvent hint: changed whether trying to select a label selects this link instead
static int ChangedMidLabel
          a CHANGED JGoDocumentEvent or JGoViewEvent hint: a text label has changed
static int ChangedToLabel
          a CHANGED JGoDocumentEvent or JGoViewEvent hint: a text label has changed
 
Fields inherited from class com.nwoods.jgo.JGoLink
AdjustingStyleCalculate, AdjustingStyleEnd, AdjustingStyleScale, AdjustingStyleStretch, ChangedAdjustingStyle, ChangedAvoidsNodes, ChangedCurviness, ChangedFromPort, ChangedJumpsOver, ChangedOrthogonal, ChangedPartID, ChangedRelinkable, ChangedRoundedCorners, ChangedToPort, ChangedUserObject, RelinkableFromHandle, RelinkableToHandle
 
Fields inherited from class com.nwoods.jgo.JGoStroke
ChangedAddPoint, ChangedAllPoints, ChangedArrowHeads, ChangedArrowLength, ChangedArrowShaftLength, ChangedArrowWidth, ChangedCubic, ChangedHighlight, ChangedModifiedPoint, ChangedRemovePoint, myPoints
 
Fields inherited from class com.nwoods.jgo.JGoObject
Bottom, BottomCenter, BottomLeft, BottomMiddle, BottomRight, Center, CenterLeft, CenterRight, Changed4ResizeHandles, ChangedAutoRescale, ChangedBrush, ChangedDraggable, ChangedDragsNode, ChangedGeometry, ChangedInitializing, ChangedPen, ChangedResizable, ChangedSelectable, ChangedUpdatePartner, ChangedVisible, ChangedZOrder, LastChangedHint, Left, LeftCenter, NoHandle, NoSpot, NumReservedHandles, RepaintAll, Right, RightCenter, SideLeft, SideRight, Top, TopCenter, TopLeft, TopMiddle, TopRight
 
Constructor Summary
JGoLabeledLink()
          Create an unconnected link.
JGoLabeledLink(JGoPort from, JGoPort to)
          Create a link from one port to another.
 
Method Summary
 void calculateStroke()
          When a link is recalculated, we need to reposition any labels.
 void changeValue(JGoDocumentChangedEdit e, boolean undo)
          This method is called by the JGoDocumentChangedEdit.undo and redo methods to actually perform the property value change for a JGoObject.
 void copyNewValueForRedo(JGoDocumentChangedEdit e)
          This method is called when a JGoDocumentChangedEdit is created for a JGoDocumentEvent.CHANGED event, when a JGoObject has been changed.
 JGoObject copyObject(JGoCopyEnvironment env)
          Create a copy of the JGoLink, but do not copy or share the links ports.
 JGoObject getFromLabel()
          Return the label near the source end of the link.
 JGoObject getMidLabel()
          Return the label near the middle of the link.
 JGoObject getToLabel()
          Return the label near the destination end of the link.
 boolean isGrabChildSelection()
           
 void layoutMidLabel()
          Decide which segment should get the middle label, and call positionMidLabel to perform that positioning.
protected  void ownerChange(JGoObjectCollection oldOwner, JGoObjectCollection newOwner, JGoObject mainObject)
          When a link is "inserted", we need to add any labels to the document (or view).
protected  void positionEndLabel(JGoObject lab, int ax, int ay, int bx, int by, int cx, int cy)
          Given the two end segment's points, move the label object to an appropriate location near the port.
 void positionLabels()
          Reposition any existing labels according to the stroke points of this link.
protected  void positionMidLabel(JGoObject lab, int ax, int ay, int bx, int by)
          Given the middle line segment's points, move the Mid label object to an appropriate location near the middle of the link.
 void setFromLabel(JGoObject lab)
          Set the label near the source, the "from" end of the link.
 void setGrabChildSelection(boolean bFlag)
           
 void setMidLabel(JGoObject lab)
          Set the label near the middle of the link.
 void setToLabel(JGoObject lab)
          Set the label near the destination, the "to" end of the link.
 DomNode SVGReadObject(DomDoc svgDoc, JGoDocument jGoDoc, DomElement svgElement, DomElement jGoChildElement)
          Read this object in from a DomDoc representing a Scalable Vector Graphics (SVG) XML document.
 void SVGUpdateReference(java.lang.String attr, java.lang.Object referencedObject)
          This method will be called to fill in object references.
 void SVGWriteObject(DomDoc svgDoc, DomElement jGoElementGroup)
          Write this object out to a DomDoc representing a Scalable Vector Graphics (SVG) XML document.
 void update(int hint, int prevInt, java.lang.Object prevVal)
          If this object has changed its relative order in the document or area, change the labels to come right afterwards, i.e., just above it.
 
Methods inherited from class com.nwoods.jgo.JGoLink
addOrthoPoints, adjustPoints, copyObjectDelayed, gainedSelection, getAdjustingStyle, getCurviness, getFirstPickPoint, getFromPort, getLastPickPoint, getMidOrthoPosition, getOtherPort, getPartID, getToPort, getUserObject, handleResize, isAvoidsNodes, isCubic, isDefaultResizingRelinks, isJumpsOver, isOrthogonal, isRelinkable, isRoundedCorners, isSelfLoop, modifyEndPoints, paint, portChange, rescalePoints, setAdjustingStyle, setAvoidsNodes, setCurviness, setDefaultResizingRelinks, setFromPort, setJumpsOver, setOrthogonal, setPartID, setRelinkable, setRoundedCorners, setToPort, setUserObject, stretchPoints, unlink
 
Methods inherited from class com.nwoods.jgo.JGoStroke
addPoint, addPoint, calculateFilledArrowhead, computeBoundingRect, copyOldValueForUndo, copyPoints, copyPointsArray, drawArrowhead, drawArrowHeads, expandRectByPenWidth, geometryChange, getArrowFromAnchorPoint, getArrowFromEndPoint, getArrowLength, getArrowShaftLength, getArrowToAnchorPoint, getArrowToEndPoint, getArrowWidth, getEndPoint, getHighlight, getNearestIntersectionOnLine, getNearestIntersectionPoint, getNearestPointOnLine, getNearestPointOnLine, getNumPoints, getPoint, getPointX, getPointY, getSegmentNearPoint, getStartPoint, hasArrowAtEnd, hasArrowAtStart, insertPoint, insertPoint, isPointInObj, removeAllPoints, removePoint, setArrowHeads, setArrowLength, setArrowShaftLength, setArrowWidth, setCubic, setHighlight, setPoint, setPoint, setPoints, setPoints
 
Methods inherited from class com.nwoods.jgo.JGoDrawable
draw3DRect, draw3DRect, drawEllipse, drawEllipse, drawEllipse, drawLine, drawLine, drawPath, drawPolygon, drawPolygon, drawRect, drawRect, drawRect, drawRoundRect, drawRoundRect, getBrush, getPen, setBrush, setPen, SVGAddPathArgs, SVGReadAttributes, SVGWriteAttributes
 
Methods inherited from class com.nwoods.jgo.JGoObject
canView, computeMove, computeResize, copy, copyRect, doMouseClick, doMouseDblClick, doUncapturedMouseMove, findCommonParent, foredate, geometryChangeChild, getBoundingRect, getDocument, getDraggingObject, getFlags, getHeight, getLayer, getLeft, getLocation, getLocation, getParent, getParentJGoNode, getParentNode, getPartner, getRectangleSpotLocation, getSize, getSize, getSpotLocation, getSpotLocation, getToolTipText, getTop, getTopLeft, getTopLeft, getTopLevelObject, getView, getWidth, growRect, handleMove, hideSelectionHandles, is4ResizeHandles, isAutoRescale, isBoundingRectInvalid, isChildOf, isDraggable, isDragsNode, isInitializing, isResizable, isSelectable, isSkipsUndoManager, isSuspendUpdates, isTopLevel, isUpdatePartner, isVisible, lostSelection, partnerUpdate, pick, redirectSelection, remove, set4ResizeHandles, setAutoRescale, setBoundingRect, setBoundingRect, setBoundingRect, setBoundingRectInvalid, setBoundsRect, setDraggable, setDragsNode, setFlags, setHeight, setInitializing, setLeft, setLocation, setLocation, setLocationOffset, setLocationOffset, setParent, setPartner, setRectangleSpotLocation, setResizable, setSelectable, setSize, setSize, setSizeKeepingLocation, setSkipsUndoManager, setSpotLocation, setSpotLocation, setSpotLocation, setSpotLocationOffset, setSuspendUpdates, setTop, setTopLeft, setTopLeft, setUpdatePartner, setVisible, setWidth, showSelectionHandles, spotOpposite, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ChangedFromLabel

public static final int ChangedFromLabel
a CHANGED JGoDocumentEvent or JGoViewEvent hint: a text label has changed

See Also:
Constant Field Values

ChangedMidLabel

public static final int ChangedMidLabel
a CHANGED JGoDocumentEvent or JGoViewEvent hint: a text label has changed

See Also:
Constant Field Values

ChangedToLabel

public static final int ChangedToLabel
a CHANGED JGoDocumentEvent or JGoViewEvent hint: a text label has changed

See Also:
Constant Field Values

ChangedGrabChildSelection

public static final int ChangedGrabChildSelection
a CHANGED JGoDocumentEvent or JGoViewEvent hint: changed whether trying to select a label selects this link instead

See Also:
Constant Field Values
Constructor Detail

JGoLabeledLink

public JGoLabeledLink()
Create an unconnected link.


JGoLabeledLink

public JGoLabeledLink(JGoPort from,
                      JGoPort to)
Create a link from one port to another.

Parameters:
from - the starting port.
to - the ending port.
Method Detail

copyObject

public JGoObject copyObject(JGoCopyEnvironment env)
Create a copy of the JGoLink, but do not copy or share the links ports.

Overrides:
copyObject in class JGoLink
Parameters:
env - the environment for the copy operation - keeps track of copied objects.

setGrabChildSelection

public void setGrabChildSelection(boolean bFlag)

isGrabChildSelection

public boolean isGrabChildSelection()

ownerChange

protected void ownerChange(JGoObjectCollection oldOwner,
                           JGoObjectCollection newOwner,
                           JGoObject mainObject)
When a link is "inserted", we need to add any labels to the document (or view). When a link is "deleted", we need to remove any labels

Overrides:
ownerChange in class JGoLink

calculateStroke

public void calculateStroke()
When a link is recalculated, we need to reposition any labels. This performs the normal link recalculating of the stroke's points, and then calls positionLabels() to move any labels.

Overrides:
calculateStroke in class JGoLink

positionLabels

public void positionLabels()
Reposition any existing labels according to the stroke points of this link. This calls positionEndLabel for the "from" and "end" labels, and calls layoutMidLabel which calls positionMidLabel for the "mid" label.


positionEndLabel

protected void positionEndLabel(JGoObject lab,
                                int ax,
                                int ay,
                                int bx,
                                int by,
                                int cx,
                                int cy)
Given the two end segment's points, move the label object to an appropriate location near the port. The label could be either the From label or the To label.

If there is only one segment in the link, ax==bx and ay==by.

Parameters:
lab - the label object
ax - the port link point
ay - the port link point
bx - the inner point of the end segment
by - the inner point of the end segment
cx - the end point of the second line segment
cy - the end point of the second line segment

layoutMidLabel

public void layoutMidLabel()
Decide which segment should get the middle label, and call positionMidLabel to perform that positioning.

If there are an odd number of segments in the link's stroke, this calls positionMidLabel with the endpoints of the middle segment. Otherwise with an even number of segments, it uses the longer of the two middle segments.


positionMidLabel

protected void positionMidLabel(JGoObject lab,
                                int ax,
                                int ay,
                                int bx,
                                int by)
Given the middle line segment's points, move the Mid label object to an appropriate location near the middle of the link.

By default this centers the label object in the middle of the middle segment of the link. However for labels that are subclass of JGoText, it places the label a little higher up so that in the case of horizontal links the text does not intersect with the link.

Parameters:
lab - the Mid label object
ax - the start point of the middle line segment
ay - the start point of the middle line segment
bx - the end point of the middle line segment
by - the end point of the middle line segment

SVGWriteObject

public void SVGWriteObject(DomDoc svgDoc,
                           DomElement jGoElementGroup)
Description copied from interface: JGoXMLSaveRestore
Write this object out to a DomDoc representing a Scalable Vector Graphics (SVG) XML document.

This method will be called by com.nwoods.jgo.svg.DefaultDocument.SVGWriteDoc() for every JGoObject contained within a JGoDocument. The following example uses a JGoRectangle to illustrate the format of a generated SVG JGoObject:

<g>
<JGoClass class="com.nwoods.jgo.JGoRectangle"\>
<rect height="75" style="stroke:black;stroke-width:1;fill:rgb(255,0,0);" width="75" x="65" y="71"/>
<JGoClass class="com.nwoods.jgo.JGoDrawable" drawablebrush="jgoid1" drawablepen="jgoid2" embeddedpenbrush="false"/>
<JGoClass class="com.nwoods.jgo.JGoObject" obj_flags="1054"/>
</g>

Note that the entire JGoObject is enclosed in a group (<g>). Each subclass of the JGoObject is described by a <JGoClass> element, starting with the most specific class and moving to the more general. Each <JGoClass> element has a "class" attribute which defines the class name. Each <JGoClass> element may also have several other attributes which uniquely describe that state of that class. Following the <JGoClass> element, each class may also genereate any other elements that are required, including representations of contained objects and standard SVG elements such as the <rect> element shown in the above example. The generation of SVG elements in the output makes it possible for the output to be read by SVG viewers and other SVG aware applications. The information contained in the <JGoClass> elements allows us to accurately save and restore all the information in a particular JGoObject subclass.

If this class contains a reference to another object, call DomDoc.registerReferencingNode() to register that reference. This will cause the element representing the referenced object to be identified with a unique id attribute, and cause the element representing the referring object to have a user defined attribute containing a reference to that id. See DomDoc.registerReferencingNode() for more information.

Typically, an implementation of this method will generate a <JGoClass> element using the DomDoc.createJGoClassElement() method, adding whatever attributes are necessary to describe the class. It will then call its superclass so that the superclass can add its own <JGoClass> element and other information to jGoElementGroup within the DomDoc.

Refer to com.nwoods.jgo.examples.flower.ActivityNode.SVGWriteObject() and com.nwoods.jgo.examples.SimpleNode.SVGWriteObject() for examples using this method.

Refer to the file com.nwoods.jgo.svg\xsvg.dtd for a formal description of JGo extensions to the SVG document type.

Specified by:
SVGWriteObject in interface JGoXMLSaveRestore
Overrides:
SVGWriteObject in class JGoLink

SVGReadObject

public DomNode SVGReadObject(DomDoc svgDoc,
                             JGoDocument jGoDoc,
                             DomElement svgElement,
                             DomElement jGoChildElement)
Description copied from interface: JGoXMLSaveRestore
Read this object in from a DomDoc representing a Scalable Vector Graphics (SVG) XML document.

This method will be called by com.nwoods.jgo.svg.DefaultDocument.SVGReadDoc() for every <JGoClass> element encountered in a DomDoc. First, an object of the type specified by the class attribute will be created and then the SVGReadObject() method will be called on that newly created object. Refer to SVGWriteObject() for a description of the expected format of the SVG document.

This method may also be called by com.nwoods.jgo.svg.DefaultDocument.SVGReadDoc() when reading any SVG document, including those not generated by JGo and therefore not containing any <JGoClass> elements. In such cases, the DefaultDocument.SVGReadElement() method may be subclassed to examine the SVG element and cause the appropriate JGoObject to be created to represent that element and call SVGReadObject() on that newly created object. By default, standard JGoObjects such as JGoRectangles, JGoStrokes, etc will be created to represent these objects.

If this class contains a reference to another object, call DomDoc.registerReferencingObject() to register that reference. This will cause the JGoObject.SVGUpdateReference() to be called on the referencing object after all the objects have been created, passing in the object befing referenced. See DomDoc.registerReferencingObject() for more information.

Typically, an implementation of this method starts by verifying that the element being read is a <JGoClass> element (which will be true if jGoChildElement is not null). This will always be true unless you have subclassed the DefaultDocument.SVGReadElement() method as described above. It will then read the expected attributes of the <JGoClass> element (as written by SVGReadObject()), call SVGReadObject() on its superclass, and finally return the next element by calling svgElement.getNextSibling().

Refer to com.nwoods.jgo.examples.flower.ActivityNode.SVGReadObject() and com.nwoods.jgo.examples.SimpleNode.SVGReadObject() for examples using this method.

Specified by:
SVGReadObject in interface JGoXMLSaveRestore
Overrides:
SVGReadObject in class JGoLink

SVGUpdateReference

public void SVGUpdateReference(java.lang.String attr,
                               java.lang.Object referencedObject)
Description copied from class: JGoObject
This method will be called to fill in object references.

This is called by com.nwoods.jgo.svg.DefaultDocument.SVGReadDoc() after all the objects have been created and if DomDoc.registerReferencingObject() has been previously called by SVGReadObject().

Typically, an implementation of this method will first call the superclass and then fill in the appropriate object reference based on the attr argument.

Refer to com.nwoods.jgo.examples.SimpleNode.SVGWriteObject() for an example using this method.

Overrides:
SVGUpdateReference in class JGoLink

getFromLabel

public JGoObject getFromLabel()
Return the label near the source end of the link.


setFromLabel

public void setFromLabel(JGoObject lab)
Set the label near the source, the "from" end of the link. If the new value is null, the label is removed from the link.

Setting the label will result in a call to positionLabels().

Parameters:
lab - the new label

getMidLabel

public JGoObject getMidLabel()
Return the label near the middle of the link.


setMidLabel

public void setMidLabel(JGoObject lab)
Set the label near the middle of the link. If the new value is null, the label is removed from the link.

Setting the label will result in a call to positionLabels().

Parameters:
lab - the new label

getToLabel

public JGoObject getToLabel()
Return the label near the destination end of the link.


setToLabel

public void setToLabel(JGoObject lab)
Set the label near the destination, the "to" end of the link. If the new value is null, the label is removed from the link.

Setting the label will result in a call to positionLabels().

Parameters:
lab - the new label

update

public void update(int hint,
                   int prevInt,
                   java.lang.Object prevVal)
If this object has changed its relative order in the document or area, change the labels to come right afterwards, i.e., just above it.

Overrides:
update in class JGoObject
Parameters:
hint - the flags to be passed through the event to the listener as the flags to help distinguish the kind of change.
prevInt - a previous value for a changed property
prevVal - a previous value for a changed property

copyNewValueForRedo

public void copyNewValueForRedo(JGoDocumentChangedEdit e)
Description copied from class: JGoObject
This method is called when a JGoDocumentChangedEdit is created for a JGoDocumentEvent.CHANGED event, when a JGoObject has been changed. In order for the JGoDocumentChangedEdit to be able to perform a redo, it needs to remember the new property value or state. However, the JGoObject.update method does not provide such a new value. The value must be taken from this object and copied into the JGoDocumentChangedEdit by calling setNewValue and/or setNewValueInt.

Just as the previous/old value/state information is stored as one or both of an integer and an Object, the new value/state information may be stored as either or both of an integer or an Object.

The responsibility for copying rests with the document event listener rather than the code calling JGoObject.update for efficiency when there is no undo/redo manager.

Overrides:
copyNewValueForRedo in class JGoLink

changeValue

public void changeValue(JGoDocumentChangedEdit e,
                        boolean undo)
Description copied from class: JGoObject
This method is called by the JGoDocumentChangedEdit.undo and redo methods to actually perform the property value change for a JGoObject.

You will want to override this method to handle changing the additional state of your object subclasses.

Overrides:
changeValue in class JGoLink