com.nwoods.jgo
Class JGoBasicNode

java.lang.Object
  extended bycom.nwoods.jgo.JGoObject
      extended bycom.nwoods.jgo.JGoArea
          extended bycom.nwoods.jgo.JGoNode
              extended bycom.nwoods.jgo.JGoBasicNode
All Implemented Interfaces:
JGoIdentifiablePart, JGoLabeledPart, JGoObjectCollection, JGoObjectSimpleCollection, JGoXMLSaveRestore, java.io.Serializable

public class JGoBasicNode
extends JGoNode

A JGoBasicNode is an Area containing an Ellipse or Rectangle and one Port and an optional Text label.

See Also:
Serialized Form

Field Summary
static int ChangedAutoResize
          A JGoDocumentEvent.CHANGED subhint: modified the margin insets
static int ChangedDrawable
          A JGoDocumentEvent.CHANGED subhint: replaced the Drawable
static int ChangedInsets
          A JGoDocumentEvent.CHANGED subhint: changed the margins used around the text when the LabelSpot is Middle
static int ChangedLabel
          A JGoDocumentEvent.CHANGED subhint: replaced the Label
static int ChangedLabelSpot
          A JGoDocumentEvent.CHANGED subhint: changed the Label's spot
static int ChangedPort
          A JGoDocumentEvent.CHANGED subhint: replaced the Port
 
Fields inherited from class com.nwoods.jgo.JGoNode
ChangedPartID, ChangedToolTipText, ChangedUserObject, PartsLinks, PartsLinksIn, PartsLinksOut, PartsNodes, PartsNodesIn, PartsNodesOut, PartsNotSelf, PartsPorts
 
Fields inherited from class com.nwoods.jgo.JGoArea
ChangedPickableBackground
 
Fields inherited from class com.nwoods.jgo.JGoObject
Bottom, BottomCenter, BottomLeft, BottomMiddle, BottomRight, Center, CenterLeft, CenterRight, Changed4ResizeHandles, ChangedAutoRescale, ChangedBrush, ChangedDraggable, ChangedDragsNode, ChangedGeometry, ChangedGrabChildSelection, 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
JGoBasicNode()
          Create a JGoBasicNode with no parts.
JGoBasicNode(java.lang.String s)
          Create a JGoBasicNode with an elliptical shape, a port, and a label displaying the string S.
 
Method Summary
 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.
protected  void copyChildren(JGoArea newarea, JGoCopyEnvironment env)
          The default implementation for copying child objects is to just add a copy of each child to the new area.
 void copyNewValueForRedo(JGoDocumentChangedEdit e)
          This method is called when a JGoDocumentChangedEdit is created for a JGoDocumentEvent.CHANGED event, when a JGoObject has been changed.
 JGoDrawable createDrawable(JGoPort p)
          Create and initialize the drawable background object, normally an ellipse that is not Selectable or Resizable.
 JGoText createLabel(java.lang.String s)
          Create and initialize a text label displaying the given string.
 JGoPort createPort()
          Create and initialize the node's port, which is normally a black ellipse visible at the middle of the icon.
 JGoBrush getBrush()
          Return the JGoBrush used by the Drawable.
 JGoDrawable getDrawable()
          Return the JGoDrawable that serves as the background for this node.
 Insets getInsets()
          Return the desired margins around the Label, used by layoutChildren to size the Drawable when getLabelSpot() == JGoObject.Center.
 JGoText getLabel()
          Return the JGoText object that displays the text string.
 int getLabelSpot()
          Return the spot where the Label is placed relative to the Drawable ellipse/rectangle.
 org.eclipse.swt.graphics.Point getLocation(org.eclipse.swt.graphics.Point result)
          Return the location of this object.
 JGoPen getPen()
          Return the JGoPen used by the Drawable.
 JGoPort getPort()
          Return the JGoPort object for this node.
 java.lang.String getText()
          Return the text string associated with this object.
 boolean isAutoResize()
          Return whether text's bounding rectangle is recomputed whenever the text string or any of the other visual attributes is changed.
 void labelSpotChanged(int old)
          This is called by setLabelSpot to handle reconfiguring this node accordingly.
 void layoutChildren(JGoObject childchanged)
          Keep the parts of a JGoBasicNode positioned relative to each other by setting their locations using some of the standard spots of a JGoObject.
 void onAutoResizeChanged(boolean old)
          When the AutoResize property changes, make sure the label's Multiline, Wrapping and Clipping properties are true when isAutoResize() is false, and vice-versa.
 JGoObject removeObjectAtPos(JGoListPosition pos)
          When an object is removed, make sure there are no more references from fields.
 void setAutoResize(boolean bFlag)
          Control whether the bounding rectangle is changed whenever the text string or other visual attributes are changed.
 void setBrush(JGoBrush b)
          Change the Drawable's JGoBrush.
 void setDrawable(JGoDrawable shape)
          Change the background JGoDrawable object for this node.
 void setInsets(Insets x)
          Change the margins used around the text when getLabelSpot() == JGoObject.Center.
 void setLabel(JGoText lab)
          Change the label for this node.
 void setLabelSpot(int s)
          Change the spot specifying where layoutChildren will position the label relative to the Drawable object.
 void setLocation(int x, int y)
          Sets the location of this object to the given point.
 void setPen(JGoPen p)
          Change the Drawable's JGoPen.
 void setPort(JGoPort p)
          Change the port for this node.
 void setText(java.lang.String s)
          Change the Label's text string.
 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.
 
Methods inherited from class com.nwoods.jgo.JGoNode
copyObject, findAll, getPartID, getToolTipText, getUserObject, setPartID, setToolTipText, setUserObject
 
Methods inherited from class com.nwoods.jgo.JGoArea
addCollection, addCollection, addObjectAtHead, addObjectAtTail, bringObjectToFront, computeBoundingRect, expandRectByPenWidth, findObject, geometryChange, geometryChangeChild, getFirstObjectPos, getLastObjectPos, getNearestIntersectionPoint, getNextObjectPos, getNextObjectPosAtTop, getNumObjects, getObjectAtPos, getPrevObjectPos, insertObjectAfter, insertObjectBefore, isEmpty, isPickableBackground, moveChildren, paint, pick, pickObject, pickObjects, removeObject, rescaleChildren, sendObjectToBack, setPickableBackground
 
Methods inherited from class com.nwoods.jgo.JGoObject
canView, computeMove, computeResize, copy, copyObjectDelayed, copyOldValueForUndo, copyRect, doMouseClick, doMouseDblClick, doUncapturedMouseMove, findCommonParent, foredate, gainedSelection, getBoundingRect, getDocument, getDraggingObject, getFlags, getHeight, getLayer, getLeft, getLocation, getParent, getParentJGoNode, getParentNode, getPartner, getRectangleSpotLocation, getSize, getSize, getSpotLocation, getSpotLocation, getTop, getTopLeft, getTopLeft, getTopLevelObject, getView, getWidth, growRect, handleMove, handleResize, hideSelectionHandles, is4ResizeHandles, isAutoRescale, isBoundingRectInvalid, isChildOf, isDraggable, isDragsNode, isInitializing, isPointInObj, isResizable, isSelectable, isSkipsUndoManager, isSuspendUpdates, isTopLevel, isUpdatePartner, isVisible, lostSelection, ownerChange, partnerUpdate, redirectSelection, remove, set4ResizeHandles, setAutoRescale, setBoundingRect, setBoundingRect, setBoundingRect, setBoundingRectInvalid, setBoundsRect, setDraggable, setDragsNode, setFlags, setHeight, setInitializing, setLeft, 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, SVGReadAttributes, SVGWriteAttributes, update, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ChangedLabelSpot

public static final int ChangedLabelSpot
A JGoDocumentEvent.CHANGED subhint: changed the Label's spot

See Also:
Constant Field Values

ChangedDrawable

public static final int ChangedDrawable
A JGoDocumentEvent.CHANGED subhint: replaced the Drawable

See Also:
Constant Field Values

ChangedLabel

public static final int ChangedLabel
A JGoDocumentEvent.CHANGED subhint: replaced the Label

See Also:
Constant Field Values

ChangedPort

public static final int ChangedPort
A JGoDocumentEvent.CHANGED subhint: replaced the Port

See Also:
Constant Field Values

ChangedInsets

public static final int ChangedInsets
A JGoDocumentEvent.CHANGED subhint: changed the margins used around the text when the LabelSpot is Middle

See Also:
Constant Field Values

ChangedAutoResize

public static final int ChangedAutoResize
A JGoDocumentEvent.CHANGED subhint: modified the margin insets

See Also:
Constant Field Values
Constructor Detail

JGoBasicNode

public JGoBasicNode()
Create a JGoBasicNode with no parts.

You will need to initialize this object manually, for example by: bn.setPort(bn.createPort()); bn.setDrawable(bn.createDrawable(bn.getPort()));


JGoBasicNode

public JGoBasicNode(java.lang.String s)
Create a JGoBasicNode with an elliptical shape, a port, and a label displaying the string S.

Method Detail

createPort

public JGoPort createPort()
Create and initialize the node's port, which is normally a black ellipse visible at the middle of the icon.

The port has no FromSpot or ToSpot and its PortObject is set to the Drawable.


createDrawable

public JGoDrawable createDrawable(JGoPort p)
Create and initialize the drawable background object, normally an ellipse that is not Selectable or Resizable.

You may want to override this method to create the appropriate shape automatically given the argument port, and thereby avoid having to call setDrawable later.

Parameters:
p - the JGoPort returned by createPort

createLabel

public JGoText createLabel(java.lang.String s)
Create and initialize a text label displaying the given string.

By default the JGoText object is not Selectable or Editable.

Parameters:
s - the initial string to display; if null, no JGoText Label is created

copyChildren

protected void copyChildren(JGoArea newarea,
                            JGoCopyEnvironment env)
Description copied from class: JGoArea
The default implementation for copying child objects is to just add a copy of each child to the new area.

You may wish to override this in order to keep track of the children or do other bookkeeping. Remember that JGoObject.copyObject will return null if the object has already been copied. We suggest using JGoCopyEnvironment.copy instead: newobj.myObjRef = env.copy(myObjRef);

Or call super.copyChildren first and just refer to the copied objects that are remembered in the copy environment: newobj.myObjRef = (JGoObject)env.get(myObjRef);

Overrides:
copyChildren in class JGoArea
Parameters:
newarea - the area newly created by copyObject() to which we need to add copies of the children of this area
env - the environment for the copy operation - keeps track of copied objects.

removeObjectAtPos

public JGoObject removeObjectAtPos(JGoListPosition pos)
When an object is removed, make sure there are no more references from fields.

Specified by:
removeObjectAtPos in interface JGoObjectCollection
Overrides:
removeObjectAtPos in class JGoArea

getLocation

public org.eclipse.swt.graphics.Point getLocation(org.eclipse.swt.graphics.Point result)
Description copied from class: JGoObject
Return the location of this object.

Defaults to the value of getTopLeft(), but may be overridden by various objects that have a different natural notion of what their location is, with respect to the top-left corner. If you override this method, you should also override setLocation().

Overrides:
getLocation in class JGoObject
Parameters:
result - a Point that will be modified to have the object's natural location in document coordinates; if result is null a Point will be allocated
Returns:
the location of the object, in document coordinates; this is the modified argument result or else a newly allocated Point

setLocation

public void setLocation(int x,
                        int y)
Description copied from class: JGoObject
Sets the location of this object to the given point.

By default the location is the top-left corner. Override this method to change the default behavior, to match any override of getLocation().

Overrides:
setLocation in class JGoObject
Parameters:
x - the new X position for the object's location
y - the new Y position for the object's location

layoutChildren

public void layoutChildren(JGoObject childchanged)
Keep the parts of a JGoBasicNode positioned relative to each other by setting their locations using some of the standard spots of a JGoObject.

By default the label will be positioned at the top of the node, above the drawable object. To change this to be below the object, at the bottom of the node, call setLabelSpot with a new spot relative to the object.

Overrides:
layoutChildren in class JGoArea
Parameters:
childchanged - the child JGoObject that was moved or changed size; this may be null, indicating that everything should be reconsidered
See Also:
JGoArea.geometryChange(org.eclipse.swt.graphics.Rectangle), JGoArea.geometryChangeChild(com.nwoods.jgo.JGoObject, org.eclipse.swt.graphics.Rectangle)

getLabelSpot

public int getLabelSpot()
Return the spot where the Label is placed relative to the Drawable ellipse/rectangle.

By default the spot is JGoObject.TopCenter.


setLabelSpot

public void setLabelSpot(int s)
Change the spot specifying where layoutChildren will position the label relative to the Drawable object.

If the value is modified, we call labelSpotChanged with the original label spot value.


labelSpotChanged

public void labelSpotChanged(int old)
This is called by setLabelSpot to handle reconfiguring this node accordingly.

If the new label spot is Center, we change the port's style to be JGoPort.StyleHidden. If the old label spot was Center, then we make the Drawable and Port small again instead of being sized to fit around the text. Afterwards, this calls layoutChildren.


getInsets

public Insets getInsets()
Return the desired margins around the Label, used by layoutChildren to size the Drawable when getLabelSpot() == JGoObject.Center.

The default values are top: 5, left: 10, bottom: 5, right: 10.


setInsets

public void setInsets(Insets x)
Change the margins used around the text when getLabelSpot() == JGoObject.Center.


setAutoResize

public void setAutoResize(boolean bFlag)
Control whether the bounding rectangle is changed whenever the text string or other visual attributes are changed.

If the value is modified, we call onAutoResizeChanged with the original AutoResize value.

Parameters:
bFlag - true if this should resize itself when the text changes

isAutoResize

public boolean isAutoResize()
Return whether text's bounding rectangle is recomputed whenever the text string or any of the other visual attributes is changed.

By default, this is true.


onAutoResizeChanged

public void onAutoResizeChanged(boolean old)
When the AutoResize property changes, make sure the label's Multiline, Wrapping and Clipping properties are true when isAutoResize() is false, and vice-versa.

Parameters:
old - the old value of isAutoResize(), before it was changed

getPen

public JGoPen getPen()
Return the JGoPen used by the Drawable.


setPen

public void setPen(JGoPen p)
Change the Drawable's JGoPen.


getBrush

public JGoBrush getBrush()
Return the JGoBrush used by the Drawable.


setBrush

public void setBrush(JGoBrush b)
Change the Drawable's JGoBrush.


getText

public java.lang.String getText()
Description copied from interface: JGoLabeledPart
Return the text string associated with this object.

This property is normally implemented to return the Label's Text string. This would return null if there is no Label. You may wish to implement this differently if there is no Label but there is a string naturally associated with the object, or if the desired string might be different than the label's text string.

Specified by:
getText in interface JGoLabeledPart
Overrides:
getText in class JGoNode

setText

public void setText(java.lang.String s)
Description copied from class: JGoNode
Change the Label's text string.

This does nothing if getLabel() returns null.

Overrides:
setText in class JGoNode

getDrawable

public JGoDrawable getDrawable()
Return the JGoDrawable that serves as the background for this node.


setDrawable

public void setDrawable(JGoDrawable shape)
Change the background JGoDrawable object for this node.

You might want to override the createDrawable method if you want to create a different kind of JGoDrawable when constructing this kind of node.


getLabel

public JGoText getLabel()
Return the JGoText object that displays the text string.

Specified by:
getLabel in interface JGoLabeledPart
Overrides:
getLabel in class JGoNode

setLabel

public void setLabel(JGoText lab)
Change the label for this node.

You might want to override the createLabel method if you want to create a different kind of JGoText when constructing this kind of node.

Overrides:
setLabel in class JGoNode

getPort

public JGoPort getPort()
Return the JGoPort object for this node.


setPort

public void setPort(JGoPort p)
Change the port for this node.

You might want to override the createPort method if you want to create a different kind of JGoPort when constructing this kind of node.


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 JGoNode

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 JGoNode

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 JGoNode

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 JGoNode

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 JGoNode