com.nwoods.jgo.instruments
Class GraduatedScaleLinear

java.lang.Object
  extended bycom.nwoods.jgo.JGoObject
      extended bycom.nwoods.jgo.JGoDrawable
          extended bycom.nwoods.jgo.instruments.AbstractGraduatedScale
              extended bycom.nwoods.jgo.instruments.GraduatedScaleLinear
All Implemented Interfaces:
GraduatedScale, JGoXMLSaveRestore, java.io.Serializable

public class GraduatedScaleLinear
extends AbstractGraduatedScale

A subclass of AbstractGraduatedScale, which represents the scale as a straight line between two end points.

See Also:
Serialized Form

Field Summary
static int ChangedEndPoint
          This is a JGoObject update subhint.
static int ChangedStartPoint
          This is a JGoObject update subhint.
 
Fields inherited from class com.nwoods.jgo.instruments.AbstractGraduatedScale
ChangedLabelDistance, ChangedLabelFormat, ChangedLabelFrequency, ChangedLabelStyle, ChangedLabelTemplate, ChangedMaximum, ChangedMinimum, ChangedTickBase, ChangedTickColor, ChangedTickLabels, ChangedTickLengthLeft, ChangedTickLengthRight, ChangedTickMajorFrequency, ChangedTickMajorLengthRatio, ChangedTickMajorWidth, ChangedTickUnit, ChangedTickWidth, LabelStyleAlternateStartLeft, LabelStyleAlternateStartRight, LabelStyleLeft, LabelStyleRight
 
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
GraduatedScaleLinear()
          Construct a linear graduated scale whose start and end points are the origin.
 
Method Summary
protected  void adjustTickOffset()
          This function is called to refresh the internal parameters used when drawing tickmarks.
 void changeValue(JGoDocumentChangedEdit e, boolean undo)
          Handle undo and redo changes.
protected  java.awt.Rectangle computeBoundingRect()
          Computes the bounds of the GraduatedScaleLinear by finding the smallest rectangle that contains both the GraduatedScaleLinear.StartPoint and GraduatedScaleLinear.EndPoint.
protected  void computePath(java.awt.geom.GeneralPath path)
          Determines the main path of the AbstractGraduatedScale.
 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)
          Copy the field values and the internal data structures to avoid sharing references
protected  void gainedSelection(JGoSelection selection)
          Display the appropriate selected appearance, normally resize selection handles at the StartPoint and EndPoint.
protected  void geometryChange(java.awt.Rectangle old)
          Called after this object's bounds has changed.
 java.awt.Point getEndPoint()
          Gets the point where the drawing of the GraduatedScaleLinear ends.
 boolean getIntersectionWithLine(java.awt.geom.Point2D.Float p1, java.awt.geom.Point2D.Float p2, DoubleRef outval)
          Finds the value that corresponds to the point where the AbstractGraduatedScale and the line defined by p1 and p2 intersect.
 java.awt.Point getLabelCenter(double val, boolean drawLeft)
          Compute the appropriate position for the center of each label compared to the tick mark.
 java.awt.geom.Point2D.Float getPointForValue(double val)
          Returns the point on the AbstractGraduatedScale that corresponds to the given value.
 java.awt.Point getStartPoint()
          Gets the point where the drawing of the GraduatedScaleLinear begins.
 void getTickEnds(double v, boolean isMajor, java.awt.geom.Point2D.Float outp1, java.awt.geom.Point2D.Float outp2)
          Calculates the two end points of a tick mark corresponding to the given value.
 double getValueAtPoint(java.awt.geom.Point2D.Float pf)
          Returns the value that is associated with point p.
protected  java.awt.Rectangle handleResize(java.awt.Graphics2D g, JGoView view, java.awt.Rectangle origRect, java.awt.Point newPoint, int whichHandle, int event, int minWidth, int minHeight)
          When the resize handles are at each point of the stroke, the user's dragging of a resize handle should just change that point in the stroke.
 boolean isPointInObj(java.awt.Point p)
          Determine if a given point is inside and on this object.
 void setEndPoint(java.awt.Point value)
          Sets the point where the drawing of the GraduatedScaleLinear ends.
 void setStartPoint(java.awt.Point value)
          Sets the point where the drawing of the GraduatedScaleLinear begins.
 void setTickLengthLeft(float value)
          Sets the length that each minor tick is drawn to the left of the AbstractGraduatedScale's path.
 void setTickLengthRight(float value)
          Sets the length that each minor tick is drawn to the right of the AbstractGraduatedScale's path.
 DomNode SVGReadObject(DomDoc svgDoc, JGoDocument jGoDoc, DomElement svgElement, DomElement jGoChildElement)
          Read this object in from a DomDoc representing a Scalable Vector Graphics (SVG) XML document.
 void SVGWriteObject(DomDoc svgDoc, DomElement jGoElementGroup)
          Write this object out to a DomDoc representing a Scalable Vector Graphics (SVG) XML document.
 
Methods inherited from class com.nwoods.jgo.instruments.AbstractGraduatedScale
expandRectByPenWidth, getLabelDistance, getLabelFormat, getLabelFrequency, getLabelString, getLabelStyle, getLabelTemplate, getLength, getMaximum, getMinimum, getNearestIntersectionOnLine, getNearestPointOnLine, getPath, getRange, getTickBase, getTickColor, getTickLengthLeft, getTickLengthRight, getTickMajorFrequency, getTickMajorLengthRatio, getTickMajorWidth, getTickUnit, getTickWidth, isDefaultBufferingImage, isTickLabels, makePath, paint, paintLabel, resetPath, setDefaultBufferingImage, setLabelDistance, setLabelFormat, setLabelFrequency, setLabelStyle, setLabelTemplate, setMaximum, setMinimum, setTickBase, setTickColor, setTickLabels, setTickMajorFrequency, setTickMajorLengthRatio, setTickMajorWidth, setTickUnit, setTickWidth, SVGUpdateReference
 
Methods inherited from class com.nwoods.jgo.JGoDrawable
draw3DRect, draw3DRect, drawEllipse, drawEllipse, drawEllipse, drawLine, drawLine, drawPath, drawPolygon, drawPolygon, drawRect, drawRect, drawRect, drawRoundRect, drawRoundRect, getBrush, getNearestIntersectionPoint, getPen, setBrush, setPen, SVGAddPathArgs, SVGReadAttributes, SVGWriteAttributes
 
Methods inherited from class com.nwoods.jgo.JGoObject
canView, computeMove, computeResize, copy, copyObjectDelayed, copyOldValueForUndo, copyRect, doMouseClick, doMouseDblClick, doUncapturedMouseMove, findCommonParent, foredate, geometryChangeChild, getBoundingRect, getDocument, getDraggingObject, getFlags, getHeight, getLayer, getLeft, getLocation, getLocation, getParent, getParentJGoNode, getParentNode, getPartner, getRectangleSpotLocation, getSize, getSize, getSpotLocation, getSpotLocation, getToolTipText, getTop, getTopLeft, getTopLeft, getTopLevelObject, getView, getWidth, growRect, handleMove, hideSelectionHandles, is4ResizeHandles, isAutoRescale, isBoundingRectInvalid, isChildOf, isDraggable, isDragsNode, isInitializing, isResizable, isSelectable, isSkipsUndoManager, isSuspendChildUpdates, isSuspendUpdates, isTopLevel, isUpdatePartner, isVisible, lostSelection, ownerChange, partnerUpdate, pick, redirectSelection, remove, set4ResizeHandles, setAutoRescale, setBoundingRect, setBoundingRect, setBoundingRect, setBoundingRectForce, setBoundingRectForce, setBoundingRectInvalid, setBoundsRect, setDraggable, setDragsNode, setFlags, setHeight, setInitializing, setLeft, setLocation, setLocation, setLocationOffset, setLocationOffset, setParent, setPartner, setRectangleSpotLocation, setResizable, setSelectable, setSize, setSize, setSizeKeepingLocation, setSkipsUndoManager, setSpotLocation, setSpotLocation, setSpotLocation, setSpotLocationOffset, setSuspendChildUpdates, setSuspendUpdates, setTop, setTopLeft, setTopLeft, setUpdatePartner, setVisible, setWidth, showSelectionHandles, spotOpposite, update, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ChangedStartPoint

public static final int ChangedStartPoint
This is a JGoObject update subhint.

See Also:
Constant Field Values

ChangedEndPoint

public static final int ChangedEndPoint
This is a JGoObject update subhint.

See Also:
Constant Field Values
Constructor Detail

GraduatedScaleLinear

public GraduatedScaleLinear()
Construct a linear graduated scale whose start and end points are the origin.

Method Detail

copyObject

public JGoObject copyObject(JGoCopyEnvironment env)
Copy the field values and the internal data structures to avoid sharing references

Overrides:
copyObject in class AbstractGraduatedScale
Parameters:
env - the environment for the copy operation - keeps track of copied objects.
Returns:
the new GraduatedScaleLinear

getStartPoint

public java.awt.Point getStartPoint()
Gets the point where the drawing of the GraduatedScaleLinear begins.

The return Point must not be modified.


setStartPoint

public void setStartPoint(java.awt.Point value)
Sets the point where the drawing of the GraduatedScaleLinear begins.

Parameters:
value - a Point in document coordinates

getEndPoint

public java.awt.Point getEndPoint()
Gets the point where the drawing of the GraduatedScaleLinear ends.

The return Point must not be modified.


setEndPoint

public void setEndPoint(java.awt.Point value)
Sets the point where the drawing of the GraduatedScaleLinear ends.

Parameters:
value - a Point in document coordinates

setTickLengthLeft

public void setTickLengthLeft(float value)
Sets the length that each minor tick is drawn to the left of the AbstractGraduatedScale's path.

Overridden to refresh the internal parameters used to draw the tick marks.

Overrides:
setTickLengthLeft in class AbstractGraduatedScale
Parameters:
value - a positive float value in document coordinates

setTickLengthRight

public void setTickLengthRight(float value)
Sets the length that each minor tick is drawn to the right of the AbstractGraduatedScale's path.

Overridden to refresh the internal parameters used to draw the tick marks.

Overrides:
setTickLengthRight in class AbstractGraduatedScale
Parameters:
value - a positive float value in document coordinates

getIntersectionWithLine

public boolean getIntersectionWithLine(java.awt.geom.Point2D.Float p1,
                                       java.awt.geom.Point2D.Float p2,
                                       DoubleRef outval)
Finds the value that corresponds to the point where the AbstractGraduatedScale and the line defined by p1 and p2 intersect.

Specified by:
getIntersectionWithLine in interface GraduatedScale
Specified by:
getIntersectionWithLine in class AbstractGraduatedScale
Parameters:
p1 - a Point2D.Float in document coordinates
p2 - a Point2D.Float in document coordinates
outval - a DoubleRef that is modified to hold the double value of the scale at the intersection point
Returns:
true if there is an intersection and if outval holds the corresponding double value

getValueAtPoint

public double getValueAtPoint(java.awt.geom.Point2D.Float pf)
Returns the value that is associated with point p.

Specified by:
getValueAtPoint in interface GraduatedScale
Specified by:
getValueAtPoint in class AbstractGraduatedScale
Parameters:
pf - if P is not on this finite line segment, the nearest point on the line is used instead
Returns:
a double

getPointForValue

public java.awt.geom.Point2D.Float getPointForValue(double val)
Returns the point on the AbstractGraduatedScale that corresponds to the given value.

Specified by:
getPointForValue in interface GraduatedScale
Specified by:
getPointForValue in class AbstractGraduatedScale
Parameters:
val -
Returns:
a Point2D.Float in document coordinates

computeBoundingRect

protected java.awt.Rectangle computeBoundingRect()
Computes the bounds of the GraduatedScaleLinear by finding the smallest rectangle that contains both the GraduatedScaleLinear.StartPoint and GraduatedScaleLinear.EndPoint.

Overrides:
computeBoundingRect in class JGoObject

geometryChange

protected void geometryChange(java.awt.Rectangle old)
Called after this object's bounds has changed.

Needs to be overriden to adjust StartPoint and EndPoint accordingly.

Overrides:
geometryChange in class AbstractGraduatedScale
Parameters:
old - a Rectangle in document coordinates holding the previous bounds.

handleResize

protected java.awt.Rectangle handleResize(java.awt.Graphics2D g,
                                          JGoView view,
                                          java.awt.Rectangle origRect,
                                          java.awt.Point newPoint,
                                          int whichHandle,
                                          int event,
                                          int minWidth,
                                          int minHeight)
When the resize handles are at each point of the stroke, the user's dragging of a resize handle should just change that point in the stroke.

Overrides:
handleResize in class JGoObject
Parameters:
g - a Graphics2D
view - the JGoView
origRect -
newPoint -
whichHandle -
event -
minWidth -
minHeight -

gainedSelection

protected void gainedSelection(JGoSelection selection)
Display the appropriate selected appearance, normally resize selection handles at the StartPoint and EndPoint.

Overrides:
gainedSelection in class JGoObject
Parameters:
selection -

isPointInObj

public boolean isPointInObj(java.awt.Point p)
Determine if a given point is inside and on this object.

Overrides:
isPointInObj in class JGoObject
Parameters:
p -
Returns:
true if the point is within the rectangle created by sweeping a minor tickmark across the linear scale.

computePath

protected void computePath(java.awt.geom.GeneralPath path)
Determines the main path of the AbstractGraduatedScale. Does not include tick marks.

Specified by:
computePath in class AbstractGraduatedScale
Parameters:
path - a GeneralPath that is modified

adjustTickOffset

protected void adjustTickOffset()
This function is called to refresh the internal parameters used when drawing tickmarks.

Whenever a change is made that would adjust how tick marks are drawn this function should be called, after that change is made.


getTickEnds

public void getTickEnds(double v,
                        boolean isMajor,
                        java.awt.geom.Point2D.Float outp1,
                        java.awt.geom.Point2D.Float outp2)
Calculates the two end points of a tick mark corresponding to the given value.

Specified by:
getTickEnds in class AbstractGraduatedScale
Parameters:
v - the double-precision floating point value that the tick mark would represent
isMajor - whether to find the end points for a major or a minor tick mark
outp1 - a Point2D.Float that is modified with one end point
outp2 - a Point2D.Float that is modified with the other end point

getLabelCenter

public java.awt.Point getLabelCenter(double val,
                                     boolean drawLeft)
Compute the appropriate position for the center of each label compared to the tick mark.

Specified by:
getLabelCenter in class AbstractGraduatedScale
Parameters:
val -
drawLeft -
Returns:
a Point in document coordinates

copyNewValueForRedo

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

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

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

Overrides:
copyNewValueForRedo in class AbstractGraduatedScale

changeValue

public void changeValue(JGoDocumentChangedEdit e,
                        boolean undo)
Handle undo and redo changes.

Overrides:
changeValue in class AbstractGraduatedScale
Parameters:
e -
undo -

SVGWriteObject

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

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

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

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

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

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

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

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

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

SVGReadObject

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

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

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

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

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

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

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