|
||||||||||
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.JGoDrawable
The parent of any class that is drawn by lines and fills. This class takes care of managing Pens and Brushes for a drawable object.
Pens define the line style used -- their color, their width, and their pattern. Brushes define the fill style used -- their color and pattern.
Users of a JGoDrawable class use these functions to change fill color and line style, etc.
JGoPen
,
JGoBrush
,
Serialized FormField Summary |
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 | |
JGoDrawable()
Create a new drawable object with no dimensions. |
|
JGoDrawable(org.eclipse.swt.graphics.Point location,
Dimension size)
Create a new drawable object with the given location and size. |
|
JGoDrawable(org.eclipse.swt.graphics.Rectangle rect)
Create a new drawable object with the given bounding rectangle. |
Method Summary | |
void |
changeValue(JGoDocumentChangedEdit e,
boolean undo)
This method is called by the JGoDocumentChangedEdit.undo and redo methods to actually perform the property value change for a JGoObject. |
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 |
draw3DRect(Graphics2D g,
int x,
int y,
int width,
int height,
boolean raised)
Draw a 3D rectangle using the current pen and brush. |
static void |
draw3DRect(Graphics2D g,
JGoPen pen,
JGoBrush brush,
int x,
int y,
int width,
int height,
boolean raised)
Draw a rectangle with a 3D appearance, using a specified pen and brush. |
void |
drawEllipse(Graphics2D g,
int x,
int y,
int width,
int height)
Draw an ellipse, using the current pen and brush. |
static void |
drawEllipse(Graphics2D g,
JGoPen pen,
JGoBrush brush,
int x,
int y,
int width,
int height)
Draw an ellipse, using a specified pen and brush. |
void |
drawEllipse(Graphics2D g,
org.eclipse.swt.graphics.Rectangle rect)
Draw an ellipse, using the current pen and brush, given a rectangle. |
void |
drawLine(Graphics2D g,
int x1,
int y1,
int x2,
int y2)
Draw a straight line, using the current pen (and no brush). |
static void |
drawLine(Graphics2D g,
JGoPen pen,
int x1,
int y1,
int x2,
int y2)
Draw a straight line, using a specified pen. |
static void |
drawPath(Graphics2D g,
JGoPen pen,
JGoBrush brush,
GeneralPath path)
Draw a GeneralPath using a specified pen and brush. |
void |
drawPolygon(Graphics2D g,
int[] xpoints,
int[] ypoints,
int npoints)
Draw a polygon using the current pen and brush. |
static void |
drawPolygon(Graphics2D g,
JGoPen pen,
JGoBrush brush,
int[] xpoints,
int[] ypoints,
int npoints)
Draw a polygon using a specified pen and brush. |
void |
drawRect(Graphics2D g,
int x,
int y,
int width,
int height)
Draw a rectangle, using the current pen and brush. |
static void |
drawRect(Graphics2D g,
JGoPen pen,
JGoBrush brush,
int x,
int y,
int width,
int height)
Draw a rectangle, using a specified pen and brush. |
void |
drawRect(Graphics2D g,
org.eclipse.swt.graphics.Rectangle rect)
Draw a rectangle using the current pen and brush, given a Rectangle. |
void |
drawRoundRect(Graphics2D g,
int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
Draw a rectangle with rounded corners, using the current pen and brush. |
static void |
drawRoundRect(Graphics2D g,
JGoPen pen,
JGoBrush brush,
int x,
int y,
int width,
int height,
int arcWidth,
int arcHeight)
Draw a rectangle with rounded corners, using a specified pen and brush. |
void |
expandRectByPenWidth(org.eclipse.swt.graphics.Rectangle rect)
Modify the given rectangle representing an object's bounding rectangle to account for any additional drawing region caused by the thickness of the pen. |
JGoBrush |
getBrush()
Returns the current "paint brush" for this object. |
boolean |
getNearestIntersectionPoint(int px,
int py,
int cx,
int cy,
org.eclipse.swt.graphics.Point result)
Consider the pen width in determining the nearest intersection point. |
JGoPen |
getPen()
Returns the current "pen stroke" for this object. |
void |
setBrush(JGoBrush b)
Sets the current "paint brush" to use when filling this drawable object. |
void |
setPen(JGoPen pen)
Sets the current "pen stroke" to use when drawing this drawable object. |
static void |
SVGAddPathArgs(DomElement svgElement,
GeneralPath path)
|
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. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public JGoDrawable()
Any subclass that you write should call one of these constructors.
public JGoDrawable(org.eclipse.swt.graphics.Rectangle rect)
Any subclass that you write should call one of these constructors.
public JGoDrawable(org.eclipse.swt.graphics.Point location, Dimension size)
Any subclass that you write should call one of these constructors.
Method Detail |
public JGoObject copyObject(JGoCopyEnvironment env)
copyObject
in class JGoObject
env
- the environment for the copy operation - keeps track of copied objects.
public void setPen(JGoPen pen)
The CHANGED event fired by this routine will have a ChangedPen value as the flag/subhint.
pen
- the JGoPen to use when drawing the lines.public JGoPen getPen()
public void setBrush(JGoBrush b)
The CHANGED event fired by this routine will have a ChangedBrush value as the flag/subhint.
b
- the brush to use when filling the object.public JGoBrush getBrush()
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/valuepublic void expandRectByPenWidth(org.eclipse.swt.graphics.Rectangle rect)
expandRectByPenWidth
in class JGoObject
rect
- the rectangle to be enlargedpublic boolean getNearestIntersectionPoint(int px, int py, int cx, int cy, org.eclipse.swt.graphics.Point result)
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 SVGWriteAttributes(DomElement svgElement)
JGoObject
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.
SVGWriteAttributes
in class JGoObject
svgElement
- the DomElement to which to add attributesJGoObject.SVGWriteObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.DomElement)
,
JGoObject.SVGReadObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.JGoDocument, com.nwoods.jgo.DomElement, com.nwoods.jgo.DomElement)
,
JGoObject.SVGWriteAttributes(com.nwoods.jgo.DomElement)
,
JGoObject.SVGReadAttributes(com.nwoods.jgo.DomElement)
,
JGoObject.SVGUpdateReference(java.lang.String, java.lang.Object)
,
DomDoc
,
DomNode
,
DomElement
,
DomText
public void SVGReadAttributes(DomElement svgElement)
JGoObject
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.
SVGReadAttributes
in class JGoObject
svgElement
- the DomElement from which to read attributesJGoObject.SVGWriteObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.DomElement)
,
JGoObject.SVGReadObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.JGoDocument, com.nwoods.jgo.DomElement, com.nwoods.jgo.DomElement)
,
JGoObject.SVGWriteAttributes(com.nwoods.jgo.DomElement)
,
JGoObject.SVGReadAttributes(com.nwoods.jgo.DomElement)
,
JGoObject.SVGUpdateReference(java.lang.String, java.lang.Object)
,
DomDoc
,
DomNode
,
DomElement
,
DomText
public void SVGUpdateReference(java.lang.String attr, java.lang.Object referencedObject)
JGoObject
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.
SVGUpdateReference
in class JGoObject
attr
- the attribute name specified by SVGReadDoc() in DomDoc.registerReferencingObject()referencedObject
- the object being referencedJGoObject.SVGWriteObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.DomElement)
,
JGoObject.SVGReadObject(com.nwoods.jgo.DomDoc, com.nwoods.jgo.JGoDocument, com.nwoods.jgo.DomElement, com.nwoods.jgo.DomElement)
,
JGoObject.SVGWriteAttributes(com.nwoods.jgo.DomElement)
,
JGoObject.SVGReadAttributes(com.nwoods.jgo.DomElement)
,
JGoObject.SVGUpdateReference(java.lang.String, java.lang.Object)
,
DomDoc
,
DomNode
,
DomElement
,
DomText
public static void drawLine(Graphics2D g, JGoPen pen, int x1, int y1, int x2, int y2)
This is a static method, so that JGoView and JGoObjects other than JGoDrawable are able to use it.
g
- the graphics object to actually draw onpen
- the pen to draw withx1
- the start point X coordinatey1
- the start point Y coordinatex2
- the end point X coordinatey2
- the end point Y coordinatepublic void drawLine(Graphics2D g, int x1, int y1, int x2, int y2)
g
- the graphics object to actually draw onx1
- the start point X coordinatey1
- the start point Y coordinatex2
- the end point X coordinatey2
- the end point Y coordinatepublic static void drawEllipse(Graphics2D g, JGoPen pen, JGoBrush brush, int x, int y, int width, int height)
This is a static method, so that JGoView and JGoObjects other than JGoDrawable are able to use it.
g
- the graphics object to actually draw onpen
- the pen to draw withbrush
- the brush to fill withx
- the left side of the bounding boxy
- the top side of the bounding boxwidth
- the width of the bounding boxheight
- the height of the bounding boxpublic void drawEllipse(Graphics2D g, int x, int y, int width, int height)
g
- the graphics object to actually draw onx
- the left side of the bounding boxy
- the top side of the bounding boxwidth
- the width of the bounding boxheight
- the height of the bounding boxpublic void drawEllipse(Graphics2D g, org.eclipse.swt.graphics.Rectangle rect)
g
- the graphics object to actually draw onrect
- the bounding rectangle of the ellipsepublic static void drawRect(Graphics2D g, JGoPen pen, JGoBrush brush, int x, int y, int width, int height)
This is a static method, so that JGoView and JGoObjects other than JGoDrawable are able to use it.
g
- the graphics object to actually draw onpen
- the pen to draw withbrush
- the brush to fill withx
- the left side of the rectangley
- the top side of the rectanglewidth
- the width of the rectangleheight
- the height of the rectanglepublic void drawRect(Graphics2D g, int x, int y, int width, int height)
g
- the graphics object to actually draw onx
- the left side of the rectangley
- the top side of the rectanglewidth
- the width of the rectangleheight
- the height of the rectanglepublic void drawRect(Graphics2D g, org.eclipse.swt.graphics.Rectangle rect)
g
- the graphics object to actually draw onrect
- the bounding rectanglepublic static void drawRoundRect(Graphics2D g, JGoPen pen, JGoBrush brush, int x, int y, int width, int height, int arcWidth, int arcHeight)
This is a static method, so that JGoView and JGoObjects other than JGoDrawable are able to use it.
g
- the graphics object to actually draw onpen
- the pen to draw withbrush
- the brush to fill withx
- the left side of the rectangley
- the top side of the rectanglewidth
- the width of the rectangleheight
- the height of the rectanglearcWidth
- the width of the rounded corner arcarcHeight
- the height of the rounded corner arcpublic void drawRoundRect(Graphics2D g, int x, int y, int width, int height, int arcWidth, int arcHeight)
g
- the graphics object to actually draw onx
- the left side of the bounding boxy
- the top side of the bounding boxwidth
- the width of the bounding boxheight
- the height of the bounding boxarcWidth
- the width of the arcarcHeight
- the height of the arcpublic static void draw3DRect(Graphics2D g, JGoPen pen, JGoBrush brush, int x, int y, int width, int height, boolean raised)
This is a static method, so that JGoView and JGoObjects other than JGoDrawable are able to use it.
g
- the graphics object to actually draw onpen
- the pen to draw withbrush
- the brush to fill withx
- the left side of the rectangley
- the top side of the rectanglewidth
- the width of the rectangleheight
- the height of the rectangleraised
- the 3D state of the rectanglepublic void draw3DRect(Graphics2D g, int x, int y, int width, int height, boolean raised)
g
- the graphics object to actually draw onx
- the left side of the bounding boxy
- the top side of the bounding boxwidth
- the width of the bounding boxheight
- the height of the bounding boxraised
- the 3D state of the rectangle.public static void drawPolygon(Graphics2D g, JGoPen pen, JGoBrush brush, int[] xpoints, int[] ypoints, int npoints)
This is a static method, so that JGoView and JGoObjects other than JGoDrawable are able to use it.
g
- the graphics object to actually draw onpen
- the pen to draw withbrush
- the brush to fill withxpoints
- the x-coordinates of all the pointsypoints
- the y-coordinates of all the pointsnpoints
- the number of pointspublic void drawPolygon(Graphics2D g, int[] xpoints, int[] ypoints, int npoints)
g
- the graphics object to actually draw onxpoints
- the x-coordinates of all the pointsypoints
- the y-coordinates of all the pointsnpoints
- the number of pointspublic static void drawPath(Graphics2D g, JGoPen pen, JGoBrush brush, GeneralPath path)
This is a static method, so that JGoView and JGoObjects other than JGoDrawable are able to use it.
g
- the graphics object to actually draw onpen
- the pen to draw withbrush
- the brush to fill withpath
- a GeneralPathpublic static void SVGAddPathArgs(DomElement svgElement, GeneralPath path)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |