|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.nwoods.jgo.JGoObject
JGoObject is the superclass of all objects that can be contained in a JGoDocument or a JGoView and that can be displayed in a view.
JGoObjects are fairly efficient; if most SWT controls are considered heavyweight, JGoObjects are flyweight.
Each object has a size and a position, in document coordinates. There are many methods for getting and setting the bounding rectangle for the object, or for just the Left, Top, Width, or Height properties. All ultimately go through the basic getBoundingRect() and setBoundingRect() methods.
Although normally one can think of the location of an object being the same as the TopLeft corner, that may not be natural for some objects. Thus each object has its own notion of Location; by default this is the same as the TopLeft.
There are a number of convenience methods for dealing with the standard nine spots of an object (corners, sides, and center), and for repositioning two objects so that their particular user-specified spots coincide. (The old Spot... values have been replaced by and merged with the handle identifiers; for example, SpotTopLeft is now TopLeft.)
Most JGoObjects should either belong directly to a JGoDocument (a top-level document object) or to a JGoArea that belongs to a JGoDocument. In either case getDocument() returns this document; for children of areas, getParent() will return that JGoArea instead of null.
Occasionally some objects will properly belong to a JGoView instead of to a JGoDocument, because they really represent part of the "view" of the document and not of the document itself. Predefined cases include selection handles and the in-place text editor.
As you define your own subclasses, you can define customized default behaviors for responding to various events. JGoObjects do not have their own listeners and events because it is assumed that most of the objects of a certain class in a graph want to behave the same way. This is unlike the situation where one expects to add controls to a dialog without subclassing and yet have radically different behaviors for each one.
The standard "event" handling methods are:
Furthermore each CHANGED document event should also have a previous value associated with it, representing the original value, before the modification, of the corresponding object's property. For convenience and efficiency, this previous value may be passed in either as an Object or as an integer. By convention, boolean values are also passed in as integers, rather than allocating new Boolean objects.
If there is no efficient way of passing in the previous value, you need to call the foredate method before making any modifications to this object. Then on the call to the update method, you can pass in zero and null as the "previous value" arguments. This circumstance can occur when there are multiple state changes made. A typical case of this is removing some objects from a collection in this object.
A standardized way of creating copies of objects is provided by copy(). Override copyObject() when you add fields to a subclass of JGoObject.
Serialized objects will not be compatible with future JGo releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of JGo.
JGoObject participates in the standard undo/redo mechanism by supporting the copyOldValueForUndo, copyNewValueForRedo, and changeValue methods. The update method has been changed to include an integer and an Object argument specifying the previous or old value.
When defining your own extensions to JGoObject, be sure to define your own unique change hints for any new properties. Mutating methods should first check to be sure a change is really needed--setting a property to its current value should be a no-op. If the new value is indeed different, remember the original value, set the field with the new value, and then call update passing the original value as one or both of the last arguments.
The update method calls the document's fireUpdate method, passing any old value along. If one of the document listeners is responsible for undo and redo, typically an instance of JGoUndoManager, it will remember enough information to be able to perform an undo and later redo, typically using an instance of JGoDocumentChangedEdit. This step is accomplished by calling copyOldValueForUndo and copyNewValueForRedo. These JGoDocument methods call the corresponding JGoObject methods when the event type is JGoDocumentEvent.CHANGED. Finally when the JGoDocumentChangedEdit's undo or redo methods are called, they just call JGoDocument.changeValue. Likewise, that JGoDocument method calls the corresponding JGoObject method when the event type is JGoDocumentEvent.CHANGED.
Note that the built-in undo and redo mechanism only works for document objects, not for unowned objects or for objects in views.
JGoDocument
,
JGoDocumentEvent
,
JGoDocumentChangedEdit
,
JGoUndoManager
,
JGoSelection
,
JGoView
,
Serialized FormField Summary | |
static int |
Bottom
a spot location or handle placement, the same as BottomCenter |
static int |
BottomCenter
a spot location or handle placement |
static int |
BottomLeft
a spot location or handle placement |
static int |
BottomMiddle
a spot location or handle placement, the same as BottomCenter |
static int |
BottomRight
a spot location or handle placement |
static int |
Center
a spot location or handle placement |
static int |
CenterLeft
a spot location or handle placement, the same as LeftCenter |
static int |
CenterRight
a spot location or handle placement, the same as RightCenter |
static int |
Changed4ResizeHandles
a CHANGED JGoDocumentEvent or JGoViewEvent hint: the 4ResizeHandles property has changed |
static int |
ChangedAutoRescale
a CHANGED JGoDocumentEvent or JGoViewEvent hint: the AutoRescale property has changed |
static int |
ChangedBrush
a CHANGED JGoDocumentEvent or JGoViewEvent hint: the JGoBrush has changed |
static int |
ChangedDraggable
a CHANGED JGoDocumentEvent or JGoViewEvent hint: the draggable property has changed |
static int |
ChangedDragsNode
a CHANGED JGoDocumentEvent or JGoViewEvent hint: the dragsNode property has changed |
static int |
ChangedGeometry
a CHANGED JGoDocumentEvent or JGoViewEvent hint: the size and/or position have changed |
static int |
ChangedGrabChildSelection
Deprecated. |
static int |
ChangedInitializing
|
static int |
ChangedPen
a CHANGED JGoDocumentEvent or JGoViewEvent hint: the JGoPen has changed |
static int |
ChangedResizable
a CHANGED JGoDocumentEvent or JGoViewEvent hint: the resizable property has changed |
static int |
ChangedSelectable
a CHANGED JGoDocumentEvent or JGoViewEvent hint: the selectable property has changed |
static int |
ChangedUpdatePartner
a CHANGED JGoDocumentEvent or JGoViewEvent hint: the UpdatePartner property has changed |
static int |
ChangedVisible
a CHANGED JGoDocumentEvent or JGoViewEvent hint: the visible property has changed |
static int |
ChangedZOrder
a CHANGED JGoDocumentEvent or JGoViewEvent hint: the object's drawing order has changed relative to other objects in the same document, area, or view. |
static int |
LastChangedHint
users can define their own CHANGED event hint values greater than this value |
static int |
Left
a spot location or handle placement, the same as LeftCenter |
static int |
LeftCenter
a spot location or handle placement |
static int |
NoHandle
no handle or no particular handle placement |
static int |
NoSpot
no particular spot location |
static int |
NumReservedHandles
user-defined handles should have identifiers greater than this value |
static int |
RepaintAll
a CHANGED JGoDocumentEvent or JGoViewEvent hint: no object state has really changed, but views should be repainted |
static int |
Right
a spot location or handle placement, the same as RightCenter |
static int |
RightCenter
a spot location or handle placement |
static int |
SideLeft
a spot location or handle placement, the same as LeftCenter |
static int |
SideRight
a spot location or handle placement, the same as RightCenter |
static int |
Top
a spot location or handle placement, the same as TopCenter |
static int |
TopCenter
a spot location or handle placement |
static int |
TopLeft
a spot location or handle placement |
static int |
TopMiddle
a spot location or handle placement, the same as TopCenter |
static int |
TopRight
a spot location or handle placement |
Constructor Summary | |
JGoObject()
Construct a new object with no dimensions |
|
JGoObject(org.eclipse.swt.graphics.Point location,
Dimension size)
Construct a JGoObject with a location and a size. |
|
JGoObject(org.eclipse.swt.graphics.Rectangle rect)
Construct a JGoObject with a bounding rectangle. |
Method Summary | |
boolean |
canView()
Return whether this object and all of its Parent areas and its Layer are visible. |
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 object. |
org.eclipse.swt.graphics.Point |
computeMove(int origX,
int origY,
int newX,
int newY,
org.eclipse.swt.graphics.Point result)
Calculate a new location for this object. |
protected org.eclipse.swt.graphics.Rectangle |
computeResize(org.eclipse.swt.graphics.Rectangle origRect,
org.eclipse.swt.graphics.Point newPoint,
int whichHandle,
int minWidth,
int minHeight)
Calculate a new bounding rectangle for this object. |
JGoObject |
copy()
This convenience method just makes a copy of the object itself, using a generic JGoCopyMap, without adding it to a document. |
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)
Called during the first phase of the copy process to produce a copy of this object within the given copy dictionary. |
void |
copyObjectDelayed(JGoCopyEnvironment env,
JGoObject newobj)
For objects that require a second pass to complete the copying, this method is called after the first pass of copying all of the objects in JGoDocument.copyFromCollection. |
void |
copyOldValueForUndo(JGoDocumentChangedEdit e)
This method is called when a JGoDocumentChangedEdit is created for a JGoDocumentEvent.CHANGED event, when a JGoObject has been changed. |
static org.eclipse.swt.graphics.Rectangle |
copyRect(org.eclipse.swt.graphics.Rectangle b)
This method implements new Rectangle(Rectangle) for convenient compatibility with SWT. |
boolean |
doMouseClick(int modifiers,
org.eclipse.swt.graphics.Point dc,
org.eclipse.swt.graphics.Point vc,
JGoView view)
Called when the user clicks on this object. |
boolean |
doMouseDblClick(int modifiers,
org.eclipse.swt.graphics.Point dc,
org.eclipse.swt.graphics.Point vc,
JGoView view)
Called when the user double clicks on this object. |
boolean |
doUncapturedMouseMove(int flags,
org.eclipse.swt.graphics.Point dc,
org.eclipse.swt.graphics.Point vc,
JGoView view)
Called when the mouse moves over this object without any mouse button down, not during a drag or resize or similar mouse action. |
void |
expandRectByPenWidth(org.eclipse.swt.graphics.Rectangle rect)
Modify the given rectangle to account for any likely drawing beyond the bounds of the rectangle caused by wide pens. |
static JGoObject |
findCommonParent(JGoObject a,
JGoObject b)
Find the JGoArea that is closest parent area for this object and another. |
void |
foredate(int hint)
The foredate method should be called by state changing methods before actually making any changes, when the following update method call is unable to provide the previous property value(s) in a convenient manner. |
protected void |
gainedSelection(JGoSelection selection)
Called after this object has gained the selection in some view. |
protected void |
geometryChange(org.eclipse.swt.graphics.Rectangle prevRect)
Called just after the bounding rectangle for this object has been changed. |
protected boolean |
geometryChangeChild(JGoObject child,
org.eclipse.swt.graphics.Rectangle prevRect)
Called if any child of this object has their bounding box changed. |
org.eclipse.swt.graphics.Rectangle |
getBoundingRect()
Return the bounding box for this object, in document coordinates. |
JGoDocument |
getDocument()
Gets the document for this object. |
JGoObject |
getDraggingObject()
This is called by JGoView.moveSelection to decide which object should be moved for a given object in the selection. |
int |
getFlags()
Return the current state of this object's flags. |
int |
getHeight()
Return the height of this object's bounding box. |
JGoLayer |
getLayer()
Return the JGoLayer that owns this object. |
int |
getLeft()
Return this object's bounding box's X position |
org.eclipse.swt.graphics.Point |
getLocation()
Return the location of this object. |
org.eclipse.swt.graphics.Point |
getLocation(org.eclipse.swt.graphics.Point result)
Return the location of this object. |
boolean |
getNearestIntersectionPoint(int px,
int py,
int cx,
int cy,
org.eclipse.swt.graphics.Point result)
Compute the point along the sides of this object's bounding rectangle that is closest to a given point on a straight line from that point to another given point. |
JGoArea |
getParent()
Gets the parent area for this object. |
JGoNode |
getParentJGoNode()
Return the first object in the parent chain that is a JGoNode. |
JGoObject |
getParentNode()
Return the highest-level object in the parent chain that is not a JGoSubGraphBase. |
JGoObject |
getPartner()
Sometimes it is convenient to be able to associate an object with another object, without any predetermined knowledge about the class. |
org.eclipse.swt.graphics.Point |
getRectangleSpotLocation(org.eclipse.swt.graphics.Rectangle r,
int spot,
org.eclipse.swt.graphics.Point result)
|
Dimension |
getSize()
Return the height and the width of this object's bounding box, in document coordinates. |
Dimension |
getSize(Dimension result)
Return the height and the width of this object's bounding box, in document coordinates. |
org.eclipse.swt.graphics.Point |
getSpotLocation(int nSpot)
Return the location of the given spot. |
org.eclipse.swt.graphics.Point |
getSpotLocation(int nSpot,
org.eclipse.swt.graphics.Point result)
Return the location of the given spot. |
java.lang.String |
getToolTipText()
Called to produce a string to be used for a tooltip for this object. |
int |
getTop()
Return this object's bounding box's Y position |
org.eclipse.swt.graphics.Point |
getTopLeft()
Return the position of the top left corner of the bounding box. |
org.eclipse.swt.graphics.Point |
getTopLeft(org.eclipse.swt.graphics.Point result)
Return the position of the top left corner of the bounding box. |
JGoObject |
getTopLevelObject()
If this object has no parent area, return this object itself. |
JGoView |
getView()
Returns the view that owns this object if it is a view object, or else null if it is not a view object. |
int |
getWidth()
Return the width of this object's bounding box. |
static void |
growRect(org.eclipse.swt.graphics.Rectangle b,
int w,
int h)
This method implements Rectangle.grow(int, int) for convenient compatibility with SWT. |
void |
handleMove(JGoView view,
int modifiers,
int event,
int spotNumber,
int origX,
int origY,
int newX,
int newY)
Called by JGoView.moveSelection when the user moves this object. |
protected org.eclipse.swt.graphics.Rectangle |
handleResize(Graphics2D g,
JGoView view,
org.eclipse.swt.graphics.Rectangle origRect,
org.eclipse.swt.graphics.Point newPoint,
int whichHandle,
int event,
int minWidth,
int minHeight)
Called when dragging a resize handle. |
void |
hideSelectionHandles(JGoSelection selection)
Hide the selection handles. |
boolean |
is4ResizeHandles()
Return whether this object displays only four resize handles instead of the default eight when selected and resizable. |
boolean |
isAutoRescale()
Return whether this object automatically rescales its appearance when its size changes. |
protected boolean |
isBoundingRectInvalid()
Return whether the bounding rectangle is out-of-date and getBoundingRect() needs to compute it. |
boolean |
isChildOf(JGoObject obj)
Determines if this object is a child, perhaps indirectly, of the given object. |
boolean |
isDraggable()
Return whether this object is draggable by the user. |
boolean |
isDragsNode()
Return whether this object, when moved, drags the first parent area whose DragsNode property is false, or the top-level object if no such parent is found. |
boolean |
isInitializing()
Return whether the Initializing flag is set. |
boolean |
isPointInObj(org.eclipse.swt.graphics.Point pnt)
Returns true if the given point is inside this object. |
boolean |
isResizable()
Return whether this object is resizable by the user. |
boolean |
isSelectable()
Return whether this object is selectable by the user. |
boolean |
isSkipsUndoManager()
Return whether this object's document's undo manager (if any) should avoid remembering any changes to this object. |
boolean |
isSuspendUpdates()
Return whether this object is not automatically updated when it is changed. |
boolean |
isTopLevel()
This predicate returns true if this object is not part of an area. |
boolean |
isUpdatePartner()
Return whether this object will notify a partner or parent object about any updates. |
boolean |
isVisible()
Return whether this object is visible in the view. |
protected void |
lostSelection(JGoSelection selection)
Called after this object has lost the selection in some view. |
protected void |
ownerChange(JGoObjectCollection oldOwner,
JGoObjectCollection newOwner,
JGoObject mainObject)
Called whenever this object's owner (JGoDocument or JGoView) changes. |
void |
paint(Graphics2D g,
JGoView view)
Draws the object on the given graphics context. |
protected void |
partnerUpdate(JGoObject partner,
int hint,
int prevInt,
java.lang.Object prevVal)
This method is called when a partner or child object is updated, if its isUpdatePartner() is true. |
JGoObject |
pick(org.eclipse.swt.graphics.Point p,
boolean selectableOnly)
Return an object at a point, perhaps only a selectable one. |
JGoObject |
redirectSelection()
Called before this object is selected in some view. |
void |
remove()
This convenience method just removes this object from its container, if there is any. |
void |
set4ResizeHandles(boolean bFlag)
Change whether the object has four standard resize handles instead of eight. |
void |
setAutoRescale(boolean bFlag)
Change whether this object automatically rescales its appearance when its size changes. |
void |
setBoundingRect(int left,
int top,
int width,
int height)
Given four integers, set the bounding box for this object. |
void |
setBoundingRect(org.eclipse.swt.graphics.Point loc,
Dimension size)
Given a location and a size, set the bounding box for this object. |
void |
setBoundingRect(org.eclipse.swt.graphics.Rectangle rect)
Given a Rectangle, set the bounding box for this object. |
protected void |
setBoundingRectInvalid(boolean bFlag)
Set whether or not the bounding rectangle for this object needs to be recomputed before getBoundingRect() returns. |
static void |
setBoundsRect(org.eclipse.swt.graphics.Rectangle r,
org.eclipse.swt.graphics.Rectangle b)
This method implements Rectangle.setBounds(Rectangle) for convenient compatibility with SWT. |
void |
setDraggable(boolean bFlag)
Change whether the object can be dragged by the user. |
void |
setDragsNode(boolean bFlag)
Change whether this object, when moved, drags the top-level object instead. |
void |
setFlags(int f)
Each JGoObject keeps a set of flags that you can use for any purpose; the JGo system itself does not make use of this property. |
void |
setHeight(int h)
Set this object's bounding box's height. |
void |
setInitializing(boolean bFlag)
Set or clear a flag indicating that this object is being initialized. |
void |
setLeft(int l)
Set this object's bounding box's X position. |
void |
setLocation(int x,
int y)
Sets the location of this object to the given point. |
void |
setLocation(org.eclipse.swt.graphics.Point loc)
Sets the location of this object to the given (x,y) position. |
void |
setLocationOffset(int x,
int y,
int dx,
int dy)
Sets the location of this object from a point and an offset from that point. |
void |
setLocationOffset(org.eclipse.swt.graphics.Point location,
org.eclipse.swt.graphics.Point offset)
Sets the location of this object from a point and an offset from that point. |
protected void |
setParent(JGoArea parent)
Called by the area's methods to add and remove objects from the area, to set the parent area back-pointer for this object. |
void |
setPartner(JGoObject obj)
Sometimes it is convenient to be able to associate an object with another object, without any predetermined knowledge about the class. |
org.eclipse.swt.graphics.Rectangle |
setRectangleSpotLocation(org.eclipse.swt.graphics.Rectangle rect,
int spot,
int x,
int y,
org.eclipse.swt.graphics.Rectangle result)
|
void |
setResizable(boolean bFlag)
Change whether the object can be resized by the user. |
void |
setSelectable(boolean bFlag)
Change whether the object can be selected by the user's clicking or drag-box-selecting the object. |
void |
setSize(Dimension size)
Set the height and the width of this object, given a Dimension. |
void |
setSize(int width,
int height)
Set the height and the width of this object, in document coordinates. |
void |
setSizeKeepingLocation(int width,
int height)
Sets a new size for this object while maintaining the same Location. |
void |
setSkipsUndoManager(boolean bFlag)
Change whether the JGoUndoManager for this object's JGoDocument (if any) should record any change to this object. |
void |
setSpotLocation(int nSpot,
int x,
int y)
Set the location of a particular spot to the given (x,y) location. |
void |
setSpotLocation(int nSpot,
JGoObject obj,
int otherSpot)
Set the location of a particular spot to be the same as a given spot on another object. |
void |
setSpotLocation(int nSpot,
org.eclipse.swt.graphics.Point pnt)
Set the location of a particular spot to the given point. |
void |
setSpotLocationOffset(int nSpot,
int x,
int y,
int dx,
int dy)
Set the location of this object by a particular spot to the given point offset by (dx,dy). |
void |
setSuspendUpdates(boolean bFlag)
Change whether the screen is updated and document listeners are notified in response to a change to this object. |
void |
setTop(int t)
Set this object's bounding box's Y position. |
void |
setTopLeft(int x,
int y)
Change the location of this object so that the top-left corner of the bounding rectangle is at the given point. |
void |
setTopLeft(org.eclipse.swt.graphics.Point p)
Change the location of this object so that the top-left corner of the bounding rectangle is at the given point. |
void |
setUpdatePartner(boolean bFlag)
Change whether any partner of this object should be notified of any updates to this object by calling its partnerUpdate method. |
void |
setVisible(boolean bFlag)
Change whether the object can be seen by the user. |
void |
setWidth(int w)
Set this object's bounding box's width. |
void |
showSelectionHandles(JGoSelection selection)
Show the selection handles. |
static int |
spotOpposite(int nSpot)
For the predefined spots, return the spot corresponding to the one on the opposite side of the object. |
void |
SVGReadAttributes(DomElement svgElement)
This method will read attributes from standard SVG elements. |
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 |
SVGWriteAttributes(DomElement svgElement)
This method will add attributes to standard SVG elements. |
void |
SVGWriteObject(DomDoc svgDoc,
DomElement jGoElementGroup)
Write this object out to a DomDoc representing a Scalable Vector Graphics (SVG) XML document. |
void |
update()
Cause this object to be repainted sometime in the near future. |
void |
update(int hint,
int prevInt,
java.lang.Object prevVal)
Cause this object to be repainted sometime in the near future. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int NoSpot
public static final int NoHandle
public static final int Center
public static final int TopLeft
public static final int TopCenter
public static final int TopMiddle
public static final int Top
public static final int TopRight
public static final int RightCenter
public static final int CenterRight
public static final int SideRight
public static final int Right
public static final int BottomRight
public static final int BottomCenter
public static final int BottomMiddle
public static final int Bottom
public static final int BottomLeft
public static final int LeftCenter
public static final int CenterLeft
public static final int SideLeft
public static final int Left
public static final int NumReservedHandles
public static final int RepaintAll
public static final int ChangedGeometry
public static final int ChangedVisible
public static final int ChangedSelectable
public static final int ChangedDraggable
public static final int ChangedResizable
public static final int Changed4ResizeHandles
public static final int ChangedGrabChildSelection
public static final int ChangedZOrder
public static final int ChangedPen
public static final int ChangedBrush
public static final int ChangedDragsNode
public static final int ChangedUpdatePartner
public static final int ChangedAutoRescale
public static final int ChangedInitializing
public static final int LastChangedHint
Constructor Detail |
public JGoObject()
public JGoObject(org.eclipse.swt.graphics.Rectangle rect)
By default an object is Visible, Selectable, Draggable and Resizable (with 8 resize handles).
rect
- the bounding rectanglepublic JGoObject(org.eclipse.swt.graphics.Point location, Dimension size)
By default an object is Visible, Selectable, Draggable and Resizable (with 8 resize handles).
location
- the location of the objectsize
- the size of the objectMethod Detail |
public JGoObject copyObject(JGoCopyEnvironment env)
You should override this method in your derived classes when it has some fields that have reference objects that need to be copied. Your override method should first call super.copyObject(env) to get the newly copied object. The standard implementation of this method for JGoObject is to do a shallow copy, by Object.getClass().newInstance(). This depends on the existence of a zero-argument constructor. The result should be the object you return, after performing any other deeper copying of referenced objects that you deem necessary, and after removing references that should not be shared (such as to cached data structures). If super.copyObject(env) returns null, it's either already copied, or mapped to an existing object in this document, or shouldn't be copied at all.
The copied object does not belong to any layer or any group, nor does it have any observers; the ultimate caller (i.e. JGoDocument.copyFromCollection) is responsible for adding it to the appropriate collection and copyObjectDelayed is responsible for adding the appropriate observers.
You probably should not be calling this method for any reason but the initial super.copyObject(env) call in an override of this method; normally only JGoCopyEnvironment.copy is the caller. Within an override of this method, if you need to make a copy of another object, call JGoCopyEnvironment.copy instead.
env
- the environment for the copy operation -
keeps track of copied objects.
public void copyObjectDelayed(JGoCopyEnvironment env, JGoObject newobj)
This method need only be overridden by objects that refer to other independent objects. The problem usually is that during the call to copyObject, some of the objects that this object refers to might not yet have been copied. So it's best to add this object to the JGoCopyEnvironment's Delayeds collection in the call to copyObject, and then fix things up during the second pass in the call to this method, copyObjectDelayed.
For most objects, this method does nothing. For JGoLinks, however, it also makes sure both ports refer to the copied ports, and if the ports were not copied, it removes the link.
env
- a JGoCopyEnvironment that remembers the mapping of original
objects to copied onesnewobj
- the newly copied instance of this objectpublic JGoObject copy()
The easiest way to add a copy of an object to a document is to call JGoDocument.addCopy.
You should not override this method, which is implemented as:
JGoCopyMap env = new JGoCopyMap(); return env.copyComplete(this);JGoCopyMap.copyComplete calls JGoObject.copyObject to allow the object to decide how to copy itself. Although the use of a copy environment isn't really needed for the simplest objects, more complex objects (such as JGoAreas) may contain references that need to be resolved with a second pass.
If you want to copy many objects together, it will be more efficient to allocate your own JGoCopyMap, call JGoCopyMap.copy (not copyComplete!) on each object, and then finally call JGoCopyMap.finishDelayedCopies. But if you are just going to be adding those copied objects into a JGoDocument, just call JGoDocument.copyFromCollection, which performs both copy passes using a single JGoCopyMap.
If you want to make many copies of one object without adding them immediately to any JGoDocument, it will be more efficient to allocate your own JGoCopyMap, and then for each copy you want to make, call JGoCopyMap.copyComplete on the object followed by a call to clear() the map. Clearing the copy environment will make sure each JGoCopyMap.copyComplete call does not share any references with any other copy.
public org.eclipse.swt.graphics.Rectangle getBoundingRect()
The bounding rectangle represents the maximum drawing extent of the object. The object need not appear rectangular, of course, but the updating routines of JGoDocument and JGoView depend on a bounding rectangle that is large enough to cover the object and that is not significantly larger than needed, for efficiency.
To simplify this notion, the expandRectByPenWidth() method is also used by the updating routines so that most object manipulations need not worry about pen widths greater than 1.
A subclass that finds that the bounding rectangle is expensive to compute may wish to use the BoundingRectInvalid property to only carry out such computations upon demand. Such a class must override computeBoundingRect() to return the correct bounding bounding rectangle.
public void setBoundingRect(int left, int top, int width, int height)
This method also calls the geometryChange() method and fires a CHANGED event with a ChangedGeometry flag/hint. If the object is part of a JGoArea, it also calls the area's geometryChangeChild() method, so that the area is notified of the change in the child.
You may want to override this method in order to enforce certain constraints, such as a minimum width or height. Just call super.setBoundingRect() with the desired values. You will need to override the constructors to make sure a newly created instance of your subclass doesn't start out with invalid geometry.
left
- the left side of the new bounding boxtop
- the top side of the new bounding boxwidth
- the width of the new bounding boxheight
- the height of the new bounding boxpublic final void setBoundingRect(org.eclipse.swt.graphics.Point loc, Dimension size)
This method is final so that you will not accidentally override it instead of setBoundingRect(int, int, int, int).
loc
- the new locationsize
- the new dimensionspublic final void setBoundingRect(org.eclipse.swt.graphics.Rectangle rect)
This method is final so that you will not accidentally override it instead of setBoundingRect(int, int, int, int).
rect
- the new bounding rectangleprotected org.eclipse.swt.graphics.Rectangle computeBoundingRect()
public final Dimension getSize()
This returns a newly allocated Dimension; you may find it more efficient to call getSize(Dimension).
public final Dimension getSize(Dimension result)
result
- a Dimension that will be modified to have the width/height
sizes; if result is null a Dimension will be allocated
public final void setSize(Dimension size)
size
- the new dimensions for this object's bounding rectanglepublic final void setSize(int width, int height)
width
- the new width for this object's bounding rectangleheight
- the new height for this object's bounding rectanglepublic final int getWidth()
public final void setWidth(int w)
w
- the new width, in document coordinatespublic final int getHeight()
public final void setHeight(int h)
h
- the new height, in document coordinatespublic final int getLeft()
public final void setLeft(int l)
l
- the new left position, in document coordinatespublic final int getTop()
public final void setTop(int t)
t
- the new top position, in document coordinatespublic final org.eclipse.swt.graphics.Point getTopLeft()
This method similar to getLocation(), except that the Location for some kinds of JGoObjects might not be the top-left corner of the bounding rectangle.
This returns a newly allocated Point; you may find it more efficient to call getTopLeft(Point).
public final org.eclipse.swt.graphics.Point getTopLeft(org.eclipse.swt.graphics.Point result)
This method similar to getLocation(), except that the Location for some kinds of JGoObjects might not be the top-left corner of the bounding rectangle.
result
- a Point that will be modified to have the top-left
coordinates; if result is null a Point will be allocated
public final void setTopLeft(org.eclipse.swt.graphics.Point p)
This method similar to setLocation(), except that the Location for some kinds of JGoObjects might not be the top-left corner of the bounding rectangle.
p
- the new location, in document coordinatespublic final void setTopLeft(int x, int y)
This method similar to setLocation(), except that the Location for some kinds of JGoObjects might not be the top-left corner of the bounding rectangle.
x
- the new left position, in document coordinatesy
- the new top position, in document coordinatespublic org.eclipse.swt.graphics.Point getLocation(org.eclipse.swt.graphics.Point result)
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().
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
public final org.eclipse.swt.graphics.Point getLocation()
This returns a newly allocated Point; you may find it more efficient to call getLocation(Point).
public void setLocation(int x, int y)
By default the location is the top-left corner. Override this method to change the default behavior, to match any override of getLocation().
x
- the new X position for the object's locationy
- the new Y position for the object's locationpublic final void setLocation(org.eclipse.swt.graphics.Point loc)
loc
- the location to set to, in document coordinatespublic void setSizeKeepingLocation(int width, int height)
By default this is just the same as setSize(int, int).
width
- the new width for this object's bounding rectangleheight
- the new height for this object's bounding rectanglepublic final void setLocationOffset(int x, int y, int dx, int dy)
x
- the x-coordinatey
- the y-coordinatedx
- the x-offsetdy
- the y-offsetpublic final void setLocationOffset(org.eclipse.swt.graphics.Point location, org.eclipse.swt.graphics.Point offset)
location
- the basic Point to which this object should be movedoffset
- a relative-to-the-location positionpublic static int spotOpposite(int nSpot)
This returns Center for the opposite of Center.
public org.eclipse.swt.graphics.Point getRectangleSpotLocation(org.eclipse.swt.graphics.Rectangle r, int spot, org.eclipse.swt.graphics.Point result)
public org.eclipse.swt.graphics.Rectangle setRectangleSpotLocation(org.eclipse.swt.graphics.Rectangle rect, int spot, int x, int y, org.eclipse.swt.graphics.Rectangle result)
public org.eclipse.swt.graphics.Point getSpotLocation(int nSpot, org.eclipse.swt.graphics.Point result)
If you override this method, perhaps because you want to support additional spots that make sense for your particular class, don't forget to override setSpotLocation too.
nSpot
- the spot to return the location ofresult
- 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
public final org.eclipse.swt.graphics.Point getSpotLocation(int nSpot)
This returns a newly allocated Point; you may find it more efficient to call getSpotLocation(int, Point).
nSpot
- the spot to return the location of
public void setSpotLocation(int nSpot, int x, int y)
If you override this method, override the function getSpotLocation() too.
nSpot
- the number of the spotx
- the x-coordinate of the new pointy
- the y-coordinate of the new pointpublic final void setSpotLocation(int nSpot, org.eclipse.swt.graphics.Point pnt)
nSpot
- the number of the spot to movepnt
- the new pointpublic final void setSpotLocation(int nSpot, JGoObject obj, int otherSpot)
nSpot
- the number of the spot to moveobj
- another objectotherSpot
- the spot on the other objectpublic final void setSpotLocationOffset(int nSpot, int x, int y, int dx, int dy)
nSpot
- the number of the spotx
- the x-coordinatey
- the y-coordinatedx
- the x-offsetdy
- the y-offsetpublic final void update()
Listeners will receive a JGoDocumentEvent.CHANGED or a JGoViewEvent.CHANGED, depending on whether the object is a document object or a view object. The flag/sub-hint value will be RepaintAll, to indicate that views should repaint this object, but that no specific object state has been changed
This method observes the SuspendUpdates properties of both this object and its document.
public void update(int hint, int prevInt, java.lang.Object prevVal)
Listeners will receive a JGoDocumentEvent.CHANGED or a JGoViewEvent.CHANGED, depending on whether the object is a document object or a view object.
A number of subhint values are predefined for the different kinds of changes that can happen:
This method observes the SuspendUpdates properties of this object. The object's document's fireUpdate() method observes the SuspendUpdates property of that document.
When isUpdatePartner() is true, this method also calls the partner's partnerUpdate method. If getPartner() returns null, this method will call partnerUpdate on the parent area, if getParent() returns an object.
When you add state to objects in your subclasses, be sure to remember to override copyOldValueForUndo, copyNewValueForRedo, and changeValue so that the JGoDocumentChangedEdit remembers and restores the before and after states of the object for each new object CHANGED hint.
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 propertyprevVal
- a previous value for a changed propertypublic void foredate(int hint)
When an object's mutating method uses foredate/update instead of just update with a previous value, it is moving the responsibility of keeping track of the object's original state to any Undo/Redo document listeners.
Note that this method is effective only for document objects. If this object is part of a view or not part of a document, this method is a no-op.
Be sure that the copyOldValueForUndo method does copy the appropriate state.
hint
- the flags to be passed through the event to the
listener to help distinguish the kind of change.public void paint(Graphics2D g, JGoView view)
This method is commonly overridden. It is not called if the object is not Visible.
The view argument can be used to customize the drawing behavior.
g
- the graphics context on which to drawview
- the view we're drawing inpublic boolean isPointInObj(org.eclipse.swt.graphics.Point pnt)
By default, this just checks to see if the point is in the bounding rectangle. Some classes will override this when the representation is not rectangular.
pnt
- the point to check
public void expandRectByPenWidth(org.eclipse.swt.graphics.Rectangle rect)
JGoDrawable has a JGoPen, so it overrides this.
rect
- a rectangle to be modifiedpublic boolean getNearestIntersectionPoint(int px, int py, int cx, int cy, org.eclipse.swt.graphics.Point result)
We modify the given result Point to hold the point that is closest to (px,py).
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 JGoObject pick(org.eclipse.swt.graphics.Point p, boolean selectableOnly)
This will return null if this object is not visible or if the point is not in this object (isPointInObj). If the selectableOnly argument is false, it will return this object; if selectableOnly is true, it will return this object only if isSelectable() is true. Finally, if isSelectable() is false, and this object is part of a JGoArea, it proceeds up the chain of parent objects until it finds one that isSelectable(), and returns that. Failing all of those tests, this method will return null.
This method is called by JGoLayer.pickObject, JGoLayer.pickObjects, JGoView.pickObject, and JGoArea.pickObject.
p
- a Point in document coordinatesselectableOnly
- whether the return value must be selectable by the user
public boolean doMouseClick(int modifiers, org.eclipse.swt.graphics.Point dc, org.eclipse.swt.graphics.Point vc, JGoView view)
The default implementation is to do nothing. Derived classes can override to provide various behaviors such as bringing up a properties editing dialog appropriate for this class, or by performing some action on this object. JGoText overrides this to start user-editing of the text string, if that behavior was enabled on that instance of the JGoText.
If this method returns false, the view will try this object's parent, and so on up the chain of parents, until either a call returns true, or until there are no more parents. In the latter case the view will have some default behavior.
Another way to get notified of an object being clicked on is to add a JGoViewListener and watch for CLICKED events.
modifiers
- which keys are depressed (see Event documentation)dc
- the point of the click in document coordinatesvc
- the point of the click in view coordinatesview
- the view in which this event occured
JGoView.doMouseDblClick(int, org.eclipse.swt.graphics.Point, org.eclipse.swt.graphics.Point)
public boolean doMouseDblClick(int modifiers, org.eclipse.swt.graphics.Point dc, org.eclipse.swt.graphics.Point vc, JGoView view)
The default implementation is to do nothing. Derived classes can override to provide various behaviors such as bringing up a properties editing dialog appropriate for this class, or by bringing up another window.
If this method returns false, the view will try this object's parent, and so on up the chain of parents, until either a call returns true, or until there are no more parents. In the latter case the view will have some default behavior.
Another way to get notified of an object being clicked on is to add a JGoViewListener and watch for DOUBLE_CLICKED events.
modifiers
- which keys are depressed (see Event documentation)dc
- the point of the click in document coordinatesvc
- the point of the click in view coordinatesview
- the view in which this event occured
JGoView.doMouseDblClick(int, org.eclipse.swt.graphics.Point, org.eclipse.swt.graphics.Point)
public boolean doUncapturedMouseMove(int flags, org.eclipse.swt.graphics.Point dc, org.eclipse.swt.graphics.Point vc, JGoView view)
The default behavior is to do nothing. Derived classes can override to handle this method in various manners, such as changing the cursor or updating a status window. JGoHandle overrides this method to change the cursor.
If this method returns false (the default), the view will call this object's parent with the same arguments, and so on up the parent chain, until a call returns true, or until there are no more parents. In the latter case the view will have some default behavior.
A special case of this kind of behavior is embodied by the getToolTipText() method.
flags
- event specific flagsdc
- the point of the click in document coordinatesvc
- the point of the click in view coordinatesview
- the view in which this event occured
JGoView.doUncapturedMouseMove(int, org.eclipse.swt.graphics.Point, org.eclipse.swt.graphics.Point)
public java.lang.String getToolTipText()
Return null if there should be no tooltip for this object.
The default behavior is to return null, so no object will have any tooltips unless one overrides this method.
protected void ownerChange(JGoObjectCollection oldOwner, JGoObjectCollection newOwner, JGoObject mainObject)
This is often useful when the newOwner is null, meaning this object is no longer part of its document (or view for view objects).
oldOwner
- the previous owner objectnewOwner
- the new owner objectmainObject
- the object being inserted or removed from the document or viewprotected void gainedSelection(JGoSelection selection)
The default behavior is to create the appropriate selection handle(s) for this object. The kind and number of selection handles depends on whether the object is resizable and whether the 4ResizeHandles property is true. The appearance of the standard selection handles is determined by JGoSelection.
If you want to display selection in completely different manner, not using the standard (or slightly altered) selection handles, override this function. One common technique is to change the appearance of the selected object itself, particularly for compound objects ("nodes"). You can change the border, background color, icon, or text's font or color or background.
Another way to get notified of an object becoming selected is to add a JGoViewListener and watch for SELECTION_GAINED events.
selection
- the selection into which this object was addedprotected void lostSelection(JGoSelection selection)
Another way to get notified of an object becoming unselected is to add a JGoViewListener and watch for SELECTION_LOST events.
selection
- the selection from which this object was removedpublic JGoObject redirectSelection()
public JGoObject getDraggingObject()
Normally this is just this object's top-level object. However, if isDragsNode() is false, this just returns itself. Furthermore, in the default case where isDragsNode() is true, this method searches up the chain of parents to find the first one whose DragsNode property is false. If it finds one, it returns that JGoArea; otherwise it returns the top-level object.
public void handleMove(JGoView view, int modifiers, int event, int spotNumber, int origX, int origY, int newX, int newY)
Basically this just calls setSpotLocation with the given spotNumber and the result of calling computeMove. However, you can override this method to constrain the places that this object can be moved to by the user. You will still be able to move this object programmatically by setting the bounding rectangle or by calling setLocation or setTopLeft.
view
- the JGoView in which the user is moving the selectionmodifiers
- which keys are depressed (see Event documentation)event
- one of: JGoView.EventMouseUp, JGoView.EventMouseMove, JGoView.EventMouseDownspotNumber
- a spot of this object, such as JGoObject.TopLeft or JGoObject.CenterorigX
- the original location's X coordinateorigY
- the original location's Y coordinatenewX
- the proposed new location's X coordinatenewY
- the proposed new location's Y coordinatepublic org.eclipse.swt.graphics.Point computeMove(int origX, int origY, int newX, int newY, org.eclipse.swt.graphics.Point result)
This is normally called by JGoDocument.copyFromCollection and JGoObject.handleMove
origX
- the original X coordinate of this object's locationorigY
- the original Y coordinate of this object's locationnewX
- the proposed new X coordinate for this object's locationnewY
- the proposed new Y coordinate for this object's locationresult
- a Point that is modified to hold the new X,Y location;
if this argument is null, a new Point is allocated, modified, and returned
protected org.eclipse.swt.graphics.Rectangle handleResize(Graphics2D g, JGoView view, org.eclipse.swt.graphics.Rectangle origRect, org.eclipse.swt.graphics.Point newPoint, int whichHandle, int event, int minWidth, int minHeight)
By default, the dragging a resize handle causes the object to be resized. Depending on which handle is being dragged, a corner or a side of the object is moved, thereby resizing and/or repositioning the object.
The bounding rectangle for this object is only changed on an EventMouseUp. This means that the object is not really resized interactively--the user only resizes a rectangular outline. If you want to really cause the object to be resized interactively, override this method and after the super method, call setBoundingRect() when the event is EventMouseMove.
Return null if you handle updating in realtime and don't want to have the view draw the XOR'd rectangle.
To enforce a minimum width or height while resizing, override this method and just call this super method passing in the desired minimums.
JGoStroke and JGoLink override this method to provide completely different behavior.
g
- the graphics context to draw onview
- the view we're being resizing inorigRect
- the object's original bounding rectanglenewPoint
- the location of the new pointwhichHandle
- the handle number of the point being movedevent
- one of: JGoView.EventMouseUp, JGoView.EventMouseMove, JGoView.EventMouseDownminWidth
- the minimum width of the object (defaults to zero)minHeight
- the minimum height of the object (defaults to zero)protected org.eclipse.swt.graphics.Rectangle computeResize(org.eclipse.swt.graphics.Rectangle origRect, org.eclipse.swt.graphics.Point newPoint, int whichHandle, int minWidth, int minHeight)
This is normally called by handleResize.
origRect
- the object's original bounding rectanglenewPoint
- the location of the new pointwhichHandle
- the handle number of the point being movedminWidth
- the minimum width of the object (defaults to zero)minHeight
- the minimum height of the object (defaults to zero)
protected void geometryChange(org.eclipse.swt.graphics.Rectangle prevRect)
The default implementation does nothing.
Another way to get notified of an object changing location or size is to add a JGoDocumentListener and watch for CHANGED events.
When this method (or the listener) gets called, the bounding rectangle for this object has already been changed, so it is already too late to prevent the change. Changing the bounding rectangle from this method (or the listener) should be avoided, or at least done extremely carefully to avoid situations such as ever-expanding objects or infinite adjustment loops.
protected boolean geometryChangeChild(JGoObject child, org.eclipse.swt.graphics.Rectangle prevRect)
Override this method with care to avoid situations where changing the geometry of other children (or especially of the given child) might cause infinite loops or indeterminate-appearing behavior. The latter can easily happen when layout algorithms implicitly depend on the order that objects have their geometry changed.
child
- the child that has changedprevRect
- the child's previous bounding rectangle
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
svgDoc
- the DomDoc in which to construct the SVG representation of this objectjGoElementGroup
- the DomElement to which to attach this objectSVGReadObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.JGoDocument, com.nwoods.jgo.DomElement, com.nwoods.jgo.DomElement)
,
SVGWriteAttributes(com.nwoods.jgo.DomElement)
,
SVGReadAttributes(com.nwoods.jgo.DomElement)
,
SVGUpdateReference(java.lang.String, java.lang.Object)
,
DomDoc
,
DomNode
,
DomElement
,
DomText
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
svgDoc
- the DomDoc containing the SVG representation of this objectjGoDoc
- the JGoDocument in which this object was createdsvgElement
- the element being read (typically the <g> element containing the JGoObject definition)jGoChildElement
- the current <JGoClass> element being read withing the <g>SVGWriteObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.DomElement)
,
SVGWriteAttributes(com.nwoods.jgo.DomElement)
,
SVGReadAttributes(com.nwoods.jgo.DomElement)
,
SVGUpdateReference(java.lang.String, java.lang.Object)
,
DomDoc
,
DomNode
,
DomElement
,
DomText
public void SVGWriteAttributes(DomElement svgElement)
Call this method from SVGWriteObject() if standard SVG elements are generated by this class or if this class may be subclassed and it should contribute arguments to SVG elements. For example, the JGoDrawable class implements this method to add standard SVG attributes for stroke, fill, and width. The JGoRectangle class calls this method to add all appropriate attributes to the <rect> element it generates. It is not necessary to implement this method if this class does not contribute any attributes to standard SVG elements. It is not necessary to call this method from SVGWriteObject() if this class does not generate any standard SVG elements.
Typically, an implementation of this method will first call the superclass and then call DomElement.setAttribute() to add attributes for this class.
svgElement
- the DomElement to which to add attributesSVGWriteObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.DomElement)
,
SVGReadObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.JGoDocument, com.nwoods.jgo.DomElement, com.nwoods.jgo.DomElement)
,
SVGWriteAttributes(com.nwoods.jgo.DomElement)
,
SVGReadAttributes(com.nwoods.jgo.DomElement)
,
SVGUpdateReference(java.lang.String, java.lang.Object)
,
DomDoc
,
DomNode
,
DomElement
,
DomText
public void SVGReadAttributes(DomElement svgElement)
Call this method from SVGReadObject() if standard SVG elements are being read by this class or if this class may be subclassed and it should read arguments from SVG elements. For example, the JGoDrawable class implements this method to read standard SVG attributes for stroke, fill, and width. The JGoRectangle class calls this method to read all appropriate attributes from the <rect> element it is reading. It is not necessary to implement this method if this class does not read any attributes from standard SVG elements. It is not necessary to call this method from SVGReadObject() if this class does not read any standard SVG elements.
Typically, an implementation of this method will first call the superclass and then call DomElement.getAttribute() to read the attributes for this class.
svgElement
- the DomElement from which to read attributesSVGWriteObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.DomElement)
,
SVGReadObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.JGoDocument, com.nwoods.jgo.DomElement, com.nwoods.jgo.DomElement)
,
SVGWriteAttributes(com.nwoods.jgo.DomElement)
,
SVGReadAttributes(com.nwoods.jgo.DomElement)
,
SVGUpdateReference(java.lang.String, java.lang.Object)
,
DomDoc
,
DomNode
,
DomElement
,
DomText
public void SVGUpdateReference(java.lang.String attr, java.lang.Object referencedObject)
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.
attr
- the attribute name specified by SVGReadDoc() in DomDoc.registerReferencingObject()referencedObject
- the object being referencedSVGWriteObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.DomElement)
,
SVGReadObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.JGoDocument, com.nwoods.jgo.DomElement, com.nwoods.jgo.DomElement)
,
SVGWriteAttributes(com.nwoods.jgo.DomElement)
,
SVGReadAttributes(com.nwoods.jgo.DomElement)
,
SVGUpdateReference(java.lang.String, java.lang.Object)
,
DomDoc
,
DomNode
,
DomElement
,
DomText
public JGoArea getParent()
protected void setParent(JGoArea parent)
In order to add an object to an area, don't call this method, but instead call one of the area's methods to add an object.
parent
- the area that this object will be a part ofpublic final boolean isTopLevel()
public JGoObject getTopLevelObject()
public JGoObject getParentNode()
public JGoNode getParentJGoNode()
public boolean isChildOf(JGoObject obj)
obj
- any JGoObject
public static JGoObject findCommonParent(JGoObject a, JGoObject b)
This will return null if either argument is null or if there is no parent JGoArea that contains both objects. If A is the same object as B, it will return it. If A is a parent of B, it will return A. If B is a parent of A, it will return B.
a
- any JGoObjectb
- any JGoObjectpublic void remove()
If this object is a child of a JGoArea, it is removed from that area. If this object is a top-level object in a JGoLayer, it is removed from that layer. If this object is an object owned by a JGoView, it is removed from that view.
public JGoDocument getDocument()
public JGoLayer getLayer()
public JGoView getView()
public void showSelectionHandles(JGoSelection selection)
public void hideSelectionHandles(JGoSelection selection)
public JGoObject getPartner()
By default this returns null.
public void setPartner(JGoObject obj)
By default this is a no-op.
public void setUpdatePartner(boolean bFlag)
Even if this object is not selectable, it can still be part of a view's selection, by adding it programmatically.
bFlag
- true if selectable, false if notpublic boolean isUpdatePartner()
If this property is true, the update method will call the partnerUpdate method on the object returned by getPartner(). If getPartner() returns null, the update method will instead call partnerUpdate on the parent area, assuming getParent() returns a non-null JGoObject.
protected void partnerUpdate(JGoObject partner, int hint, int prevInt, java.lang.Object prevVal)
By default this does nothing.
partner
- the partner or child object that was changedhint
- 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 propertyprevVal
- a previous value for a changed propertypublic void copyOldValueForUndo(JGoDocumentChangedEdit e)
The exact nature of the Object depends on the particular event hint or sub-hint, of course, but is typically a Rectangle or Point or some similar structure that is actually owned by the 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.
e
- the UndoableEdit that also remembers the kind of change and any
appropriate previous state that should be copied in-placepublic void copyNewValueForRedo(JGoDocumentChangedEdit e)
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.
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)
You will want to override this method to handle changing the additional state of your object subclasses.
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/valuepublic final void setFlags(int f)
Setting the flags does not call update, because the need for update must be determined by the application and the flags being changed.
f
- a new set of flag bitspublic final int getFlags()
public void setVisible(boolean bFlag)
Invisible objects, besides being hidden, tend not to be selectable or respond to mouse events.
bFlag
- true if visible, false if notpublic boolean isVisible()
Note that even if isVisible() is true, the object might not be seen by the user, perhaps because other objects are occluding this one, or because this object has been scrolled off beyond the view's canvas.
public boolean canView()
public void setSelectable(boolean bFlag)
Even if this object is not selectable, it can still be part of a view's selection, by adding it programmatically.
A selectable JGoArea will get selected when trying to select an unselectable child of the area. Call JGoArea.setPickableBackground(true) to make a click within an area but not in a child select the area.
bFlag
- true if selectable, false if notpublic boolean isSelectable()
public void setDraggable(boolean bFlag)
You can change the location programmatically by calling setBoundingRect() or setLocation() or related methods.
bFlag
- true if draggable, false if notpublic boolean isDraggable()
public void setResizable(boolean bFlag)
You can change the dimensions programmatically by calling setBoundingRect() or setSize() or related methods.
By default a resizable object will have four or eight resize handles at the corners and middles of the sides, depending on the 4ResizeHandles property.
bFlag
- true if resizable, false if notpublic boolean isResizable()
public void set4ResizeHandles(boolean bFlag)
bFlag
- true if only four, false if eightpublic boolean is4ResizeHandles()
public void setAutoRescale(boolean bFlag)
For most objects, particularly shapes, it is natural that when the size changes, the object adjusts its appearance appropriately smaller or larger, and accomodating any change in aspect ratio. Most classes ignore this property. However, there are certain circumstances where users do not expect this behavior, for example for JGoText instances that are part of a resizable area. Typically you will set this property false for text objects added to areas. JGoArea.rescaleChildren heeds this property.
public boolean isAutoRescale()
This defaults to true for most objects. However JGoText defaults this to false, since most resizings of areas don't expect the text size to change.
public void setDragsNode(boolean bFlag)
This is used by getDraggingObject, which in turn is called by JGoView.moveSelection.
bFlag
- true if drags top-level node, false if notpublic boolean isDragsNode()
By default this property is true.
public void setSuspendUpdates(boolean bFlag)
You can temporarily turn off updates for all objects in a document by using JGoDocument.setSuspendUpdates().
bFlag
- true if stop notifications, false if resume notificationspublic boolean isSuspendUpdates()
public void setSkipsUndoManager(boolean bFlag)
bFlag
- true if to stop recording JGoDocumentChangedEdits,
false if to record normallypublic boolean isSkipsUndoManager()
protected void setBoundingRectInvalid(boolean bFlag)
Typically you will call this method with a true value at the end of your geometryChange or geometryChangeChild method where the children of an area have been resized and rearranged and you need to make sure the bounding rectangle is up-to-date.
Setting this flag does not call update.
bFlag
- if true, getBoundingRect() should recompute this object's true boundsprotected boolean isBoundingRectInvalid()
public void setInitializing(boolean bFlag)
This is normally only used by JGoAreas when areas are constructed or initialized, to avoid repeated expensive calculations such as JGoNode.layoutChildren().
Setting this flag does not call update.
public boolean isInitializing()
public static void setBoundsRect(org.eclipse.swt.graphics.Rectangle r, org.eclipse.swt.graphics.Rectangle b)
public static org.eclipse.swt.graphics.Rectangle copyRect(org.eclipse.swt.graphics.Rectangle b)
public static void growRect(org.eclipse.swt.graphics.Rectangle b, int w, int h)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |