|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.nwoods.jgo.JGoObject
com.nwoods.jgo.JGoArea
JGoArea implements the concept of a "group" of objects that can be manipulated together. An area, like a document, contains a list of JGoObjects. These objects must not also be contained directly by the document, or by other areas.
Most "nodes" of a graph are implemented by extending from the JGoNode class, or one of the predefined nodes classes such as JGoBasicNode, JGoIconicNode, or JGoTextNode.
JGoArea is a subclass of JGoObject, which means that areas can contain other areas. This is the Composite pattern. Using this mechanism, an object hierarchy can be created.
An area does not really have its own independent bounding rectangle. Instead the bounding rectangle is really the bounding rectangle for all of the children. In fact getBoundingRect() is not meaningful when there are no objects in an area.
JGoDocument and JGoView treat areas specially--they search in them when you use pickObject() or getNextObject().
A selectable area will get selected when the user clicks on a child that is not selectable. Clicking on a part of the area where there is no child will not select this area unless you first call setPickableBackground(true).
JGoNode
,
JGoDocument
,
JGoView
,
JGoObjectCollection
,
Serialized FormField Summary | |
static int |
ChangedPickableBackground
a CHANGED JGoDocumentEvent subhint: changed whether the user can pick this subgraph not at a child |
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 | |
JGoArea()
Construct a new empty JGoArea. |
Method Summary | |
java.util.ArrayList |
addCollection(java.util.ArrayList coll,
boolean reparentLinks,
JGoLayer linksLayer)
Move some objects into this area, as immediate children of this group, even if they are part of other areas in this same layer. |
java.util.ArrayList |
addCollection(JGoObjectSimpleCollection coll,
boolean reparentLinks,
JGoLayer linksLayer)
Move some objects into this area, as immediate children of this group, even if they are part of other areas in this same layer. |
JGoListPosition |
addObjectAtHead(JGoObject obj)
Adds a child to the beginning of this area's list of children, appearing underneath other objects in this area. |
JGoListPosition |
addObjectAtTail(JGoObject obj)
Adds a child to the end of this area's list of children, appearing on top of other objects in this area. |
void |
bringObjectToFront(JGoObject obj)
Moves a child object of this area to the "front" of the z-order. |
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 org.eclipse.swt.graphics.Rectangle |
computeBoundingRect()
Recalculate the correct bounding box for this area by going through all of its children. |
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. |
JGoObject |
copyObject(JGoCopyEnvironment env)
Create a new instance of this object with the same field values. |
void |
expandRectByPenWidth(org.eclipse.swt.graphics.Rectangle rect)
Account for the pen widths of the area's children. |
JGoListPosition |
findObject(JGoObject obj)
Return the position of a specific object in the collection. |
protected void |
geometryChange(org.eclipse.swt.graphics.Rectangle prevRect)
Called when the geometry (size or position) of this area is changed. |
protected boolean |
geometryChangeChild(JGoObject child,
org.eclipse.swt.graphics.Rectangle prevRect)
Call layoutChildren because one of the children of this JGoArea has been moved or resized. |
JGoListPosition |
getFirstObjectPos()
Return the position of the first object in the collection. |
JGoListPosition |
getLastObjectPos()
Return the position of the last object in the collection. |
boolean |
getNearestIntersectionPoint(int px,
int py,
int cx,
int cy,
org.eclipse.swt.graphics.Point result)
A group's closest intersection point with a line is the closest such point among all of the children. |
JGoListPosition |
getNextObjectPos(JGoListPosition pos)
Return the position for the next object in the collection. |
JGoListPosition |
getNextObjectPosAtTop(JGoListPosition pos)
Return the position for the next top-level object in the collection. |
int |
getNumObjects()
Return the number of top-level objects in the collection. |
JGoObject |
getObjectAtPos(JGoListPosition pos)
Return the object for the given position. |
JGoListPosition |
getPrevObjectPos(JGoListPosition pos)
Return the position of the previous object in the collection. |
JGoListPosition |
insertObjectAfter(JGoListPosition pos,
JGoObject obj)
Adds a child to this area after the given position. |
JGoListPosition |
insertObjectBefore(JGoListPosition pos,
JGoObject obj)
Adds a child to this area before the given position. |
boolean |
isEmpty()
Return true if there are no objects in the collection. |
boolean |
isPickableBackground()
Return whether the user can also select this area (if isSelectable() is true) by clicking somewhere within the area but not on any child object. |
void |
layoutChildren(JGoObject childchanged)
This method is responsible for repositioning and resizing all of the children. |
protected void |
moveChildren(org.eclipse.swt.graphics.Rectangle prevRect)
This method is called by geometryChange when this area's position but not its size has been changed by a call to setBoundingRect. |
void |
paint(Graphics2D g,
JGoView view)
Draw the area and all its children. |
JGoObject |
pick(org.eclipse.swt.graphics.Point p,
boolean selectableOnly)
Picking in an area first tries to pick a child object, starting with the last one, which is most in front. |
JGoObject |
pickObject(org.eclipse.swt.graphics.Point pointToCheck,
boolean selectableOnly)
Returns the topmost object that is under the given point. |
java.util.ArrayList |
pickObjects(org.eclipse.swt.graphics.Point p,
boolean selectableOnly,
java.util.ArrayList coll,
int max)
Return a list of all the JGoObjects that contain a given point. |
void |
removeObject(JGoObject obj)
Removes a child object from this area. |
JGoObject |
removeObjectAtPos(JGoListPosition pos)
Remove an object at specified position from the collection. |
protected void |
rescaleChildren(org.eclipse.swt.graphics.Rectangle prevRect)
This method is called by geometryChange when this area's size has been changed by a call to setBoundingRect. |
void |
sendObjectToBack(JGoObject obj)
Moves a child object of this area to the "back" of the z-order. |
void |
setPickableBackground(boolean bFlag)
Change whether the user can select this selectable area by clicking somewhere within the subgraph but not on any child object. |
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 |
SVGWriteObject(DomDoc svgDoc,
DomElement jGoElementGroup)
Write this object out to a DomDoc representing a Scalable Vector Graphics (SVG) XML document. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int ChangedPickableBackground
Constructor Detail |
public JGoArea()
Method Detail |
public JGoObject copyObject(JGoCopyEnvironment env)
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);
If you override copyChildren for your area class, you may find it more convenient to copy the fields first in that method, rather than also overriding this method. Sometimes the new field values are needed while you are copying child objects, but your override of copyObject will be called after your override of copyChildren.
copyObject
in class JGoObject
env
- the environment for the copy operation - keeps track of copied objects.
protected void copyChildren(JGoArea newarea, JGoCopyEnvironment env)
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);
newarea
- the area newly created by copyObject() to which we need to
add copies of the children of this areaenv
- the environment for the copy operation - keeps track of copied objects.public void setPickableBackground(boolean bFlag)
Note that clicking on an unselectable child object will cause this area to be selected, if this area isSelectable().
public boolean isPickableBackground()
The default value is false, which causes parts of areas where there are no child to act "transparently" with respect to picking.
public JGoObject pick(org.eclipse.swt.graphics.Point p, boolean selectableOnly)
If isVisible() is false for this area, this method returns null. This method calls pickObject to recursively search for a child object that can be picked. If pickObject does not return an object, then this will return null, unless isPickableBackground() is true. If isPickableBackground() is true and no child pick succeeded, then the point is in the background of this area, so this area is returned if selectableOnly is false, or if isSelectable() is true. If neither case holds for this area, then this will search up the Parent chain to find a parent area that isSelectable().
pick
in class JGoObject
p
- a Point in document coordinatesselectableOnly
- whether the return value must be selectable by the user.
public JGoObject pickObject(org.eclipse.swt.graphics.Point pointToCheck, boolean selectableOnly)
pickObject
in interface JGoObjectCollection
pointToCheck
- the point under which to find an object.selectableOnly
- if true, only include selectable objects in the search.
public java.util.ArrayList pickObjects(org.eclipse.swt.graphics.Point p, boolean selectableOnly, java.util.ArrayList coll, int max)
For an area, this is implemented to add the object found by a call to pickObject, if any object is found. Thus for a typical node that happens to have several objects underneath each other, only the top-most (front-most) object is added. Since most child objects are not selectable, if "selectableOnly" is true, this method will typically add the area itself to the result ArrayList collection.
However, this method is overridden on JGoSubGraphBase to have a different behavior.
p
- a Point in document coordinatesselectableOnly
- if true, only consider selectable objectscoll
- an ArrayList to which any objects found are added; if null, this method allocates a new ArrayList and returns itmax
- a limit on the number of objects that may be returned in the ArrayList
public boolean getNearestIntersectionPoint(int px, int py, int cx, int cy, org.eclipse.swt.graphics.Point result)
Currently, this means that a point on a child object that does not intersect the line from (px,py) to (cx,cy) may be closer than a point on some other child that actually does intersect the line.
getNearestIntersectionPoint
in class JGoObject
px
- the X coordinate of a point that starts a linepy
- the Y coordinate of a point that starts a linecx
- the X coordinate of a point that specifies the other end of the linecy
- the Y coordinate of a point that specifies the other end of the lineresult
- a Point that is modified (must not be null)
public void SVGWriteObject(DomDoc svgDoc, DomElement jGoElementGroup)
JGoXMLSaveRestore
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.
SVGWriteObject
in interface JGoXMLSaveRestore
SVGWriteObject
in class JGoObject
public DomNode SVGReadObject(DomDoc svgDoc, JGoDocument jGoDoc, DomElement svgElement, DomElement jGoChildElement)
JGoXMLSaveRestore
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.
SVGReadObject
in interface JGoXMLSaveRestore
SVGReadObject
in class JGoObject
public void paint(Graphics2D g, JGoView view)
paint
in class JGoObject
g
- the graphics context on which to draw this area.view
- the view we're drawing inpublic void expandRectByPenWidth(org.eclipse.swt.graphics.Rectangle rect)
expandRectByPenWidth
in class JGoObject
rect
- a rectangle to be modifiedprotected org.eclipse.swt.graphics.Rectangle computeBoundingRect()
computeBoundingRect
in class JGoObject
protected void geometryChange(org.eclipse.swt.graphics.Rectangle prevRect)
By default this method handles both moving the area (and all its children) and/or scaling all the children proportional to any changes in the width and height of the new bounding rectangle.
When the size of the area changes, the default rescaling behavior is often inadequate, so this method also calls layoutChildren with a null argument. Override layoutChildren to reposition and resize the children objects in the desired manner.
geometryChange
in class JGoObject
prevRect
- the previous bounding rectangle of this area.moveChildren(org.eclipse.swt.graphics.Rectangle)
,
rescaleChildren(org.eclipse.swt.graphics.Rectangle)
,
layoutChildren(com.nwoods.jgo.JGoObject)
protected boolean geometryChangeChild(JGoObject child, org.eclipse.swt.graphics.Rectangle prevRect)
geometryChangeChild
in class JGoObject
child
- the child that has changedprevRect
- the child's previous bounding rectangle
layoutChildren(com.nwoods.jgo.JGoObject)
protected void moveChildren(org.eclipse.swt.graphics.Rectangle prevRect)
By default, this just moves all this area's child objects by the same offset as the whole area was. All links are moved before any other kind of child. This method is rarely overridden.
prevRect
- the original bounds of this areageometryChange(org.eclipse.swt.graphics.Rectangle)
protected void rescaleChildren(org.eclipse.swt.graphics.Rectangle prevRect)
By default, this just resizes all of this area's child objects by the proportion each child object takes of the whole area. Children whose JGoObject.isAutoRescale() method returns false are not resized or repositioned. All links are moved and resized before any other kind of child. This method is rarely overridden.
prevRect
- the original bounds of this areageometryChange(org.eclipse.swt.graphics.Rectangle)
public void layoutChildren(JGoObject childchanged)
Each node subclass should override this method to position and size each child so that the node has the desired arrangement and appearance. This method is normally called by geometryChange after calling rescaleChildren, by geometryChangeChild when a child's bounding rectangle has changed, and when a child is added to the area, but may be called at other times for any reason. By default this does nothing.
childchanged
- the child JGoObject that was moved or changed
size; this may be null, indicating that everything should
be reconsideredgeometryChange(org.eclipse.swt.graphics.Rectangle)
,
geometryChangeChild(com.nwoods.jgo.JGoObject, org.eclipse.swt.graphics.Rectangle)
public int getNumObjects()
JGoObjectSimpleCollection
getNumObjects
in interface JGoObjectSimpleCollection
public boolean isEmpty()
JGoObjectSimpleCollection
isEmpty
in interface JGoObjectSimpleCollection
public JGoListPosition addObjectAtHead(JGoObject obj)
If this area is already part of a document, the object will become part of the document.
The object should not already have been a part of the document, unless it is already part of this same area.
addObjectAtHead
in interface JGoObjectCollection
obj
- the child object to add.
public JGoListPosition addObjectAtTail(JGoObject obj)
If this area is already part of a document, the object will become part of the document.
The object should not already have been a part of the document, unless it is already part of this same area.
addObjectAtTail
in interface JGoObjectCollection
obj
- the child object to add.
public JGoListPosition insertObjectBefore(JGoListPosition pos, JGoObject obj)
If this area is already part of a document, the object will become part of the document.
If the object is already a part of this area, the object is moved in the drawing order. The CHANGED event will have a ChangedZOrder hint/flag and a previous value that is the JGoObject that used to follow the given object in the area.
The object should not otherwise already have been a part of the document.
insertObjectBefore
in interface JGoObjectCollection
pos
- the position before which to add the child.obj
- the child object to add.
public JGoListPosition insertObjectAfter(JGoListPosition pos, JGoObject obj)
If this area is already part of a document, the object will become part of the document.
If the object is already a part of this area, the object is moved in the drawing order. The CHANGED event will have a ChangedZOrder hint/flag and a previous value that is the JGoObject that used to follow the given object in the area.
The object should not otherwise already have been a part of the document.
insertObjectAfter
in interface JGoObjectCollection
pos
- the position after which to add the child.obj
- the child object to add.
public void bringObjectToFront(JGoObject obj)
The CHANGED event will have a ChangedZOrder hint/flag and a previous value that is the JGoObject that used to follow the given object in the area
The object should already be a part of this area.
bringObjectToFront
in interface JGoObjectCollection
obj
- the object to put on top.public void sendObjectToBack(JGoObject obj)
The CHANGED event will have a ChangedZOrder hint/flag and a previous value that is the JGoObject that used to follow the given object in the area.
The object should already be a part of this area.
sendObjectToBack
in interface JGoObjectCollection
obj
- the object to put on top.public void removeObject(JGoObject obj)
removeObject
in interface JGoObjectCollection
obj
- the child object to remove.public JGoObject removeObjectAtPos(JGoListPosition pos)
JGoObjectCollection
removeObjectAtPos
in interface JGoObjectCollection
pos
- the position of the object to remove.
public JGoListPosition getFirstObjectPos()
JGoObjectSimpleCollection
getFirstObjectPos
in interface JGoObjectSimpleCollection
public JGoListPosition getLastObjectPos()
JGoObjectCollection
getLastObjectPos
in interface JGoObjectCollection
public JGoListPosition getNextObjectPos(JGoListPosition pos)
JGoObjectSimpleCollection
getNextObjectPos
in interface JGoObjectSimpleCollection
pos
- the position previous to that which will be returned.
public JGoListPosition getNextObjectPosAtTop(JGoListPosition pos)
JGoObjectSimpleCollection
getNextObjectPosAtTop
in interface JGoObjectSimpleCollection
pos
- the position from which to start searching for the next
top-level object.
public JGoListPosition getPrevObjectPos(JGoListPosition pos)
JGoObjectCollection
getPrevObjectPos
in interface JGoObjectCollection
pos
- the position of the object that follows the object position
to be returned.
public JGoObject getObjectAtPos(JGoListPosition pos)
JGoObjectSimpleCollection
getObjectAtPos
in interface JGoObjectSimpleCollection
pos
- the position of an object in the collection.
public JGoListPosition findObject(JGoObject obj)
JGoObjectCollection
findObject
in interface JGoObjectCollection
obj
- the object whose position in the collection is to be returned.
to be returned.
public final java.util.ArrayList addCollection(JGoObjectSimpleCollection coll, boolean reparentLinks, JGoLayer linksLayer)
This just calls addCollection(ArrayList) with an ArrayList composed of the JGoObjects provided in the argument collection. Making a separate list of the JGoObjects is useful in case there are any changes made to the original JGoObjectSimpleCollection, such as a JGoArea.
coll
- the collection of JGoObjects to make children of this areareparentLinks
- whether to call JGoSubGraphBase.reparentAllLinksToSubGraphs
to make sure each link belongs to the proper subgraph or layerlinksLayer
- the JGoLayer of the document that should hold any top-level links
public java.util.ArrayList addCollection(java.util.ArrayList coll, boolean reparentLinks, JGoLayer linksLayer)
This method tries to preserve the links connecting any ports of the objects being moved into this group. Of course, none of the objects to be added to this group may be the group itself nor a parent of this group. The objects must also either belong to no layer or to the same layer as this JGoArea. Just as with the addObjectAtTail method, you may find that you will want to set the Selectable property to false for each of the objects being added to this group. The need for this depends on the behavior you want in your application.
coll
- an ArrayList of JGoObjects to make children of this areareparentLinks
- whether to call JGoSubGraphBase.reparentAllLinksToSubGraphs
to make sure each link belongs to the proper subgraph or layerlinksLayer
- the JGoLayer of the document that should hold any top-level links
public void copyNewValueForRedo(JGoDocumentChangedEdit e)
JGoObject
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.
copyNewValueForRedo
in class JGoObject
e
- the UndoableEdit that also remembers the kind of change and any
appropriate new state that should be copied inpublic void changeValue(JGoDocumentChangedEdit e, boolean undo)
JGoObject
You will want to override this method to handle changing the additional state of your object subclasses.
changeValue
in class JGoObject
e
- the UndoableEdit that also remembers the kind of change and any
appropriate old and new state for performing an undo or redoundo
- if true, this method should restore the old state/value, otherwise
this method should restore the new state/value
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |