|
||||||||||
| 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
com.nwoods.jgo.instruments.AbstractGraduatedScale
An implementation of the GraduatedScale class, used to depict a scale as a path between two end points, representing a minimum and maximum value, with all the points along that path representing uniformly delineated values.
| Field Summary | |
static int |
ChangedLabelDistance
This is a JGoObject update subhint. |
static int |
ChangedLabelFormat
This is a JGoObject update subhint. |
static int |
ChangedLabelFrequency
This is a JGoObject update subhint. |
static int |
ChangedLabelStyle
This is a JGoObject update subhint. |
static int |
ChangedLabelTemplate
This is a JGoObject update subhint. |
static int |
ChangedMaximum
This is a JGoObject update subhint. |
static int |
ChangedMinimum
This is a JGoObject update subhint. |
static int |
ChangedTickBase
This is a JGoObject update subhint. |
static int |
ChangedTickColor
This is a JGoObject update subhint. |
static int |
ChangedTickLabels
This is a JGoObject update subhint. |
static int |
ChangedTickLengthLeft
This is a JGoObject update subhint. |
static int |
ChangedTickLengthRight
This is a JGoObject update subhint. |
static int |
ChangedTickMajorFrequency
This is a JGoObject update subhint. |
static int |
ChangedTickMajorLengthRatio
This is a JGoObject update subhint. |
static int |
ChangedTickMajorWidth
This is a JGoObject update subhint. |
static int |
ChangedTickUnit
This is a JGoObject update subhint. |
static int |
ChangedTickWidth
This is a JGoObject update subhint. |
static int |
LabelStyleAlternateStartLeft
A style for the layout of tick labels for AbstractGraduatedScale. |
static int |
LabelStyleAlternateStartRight
A style for the layout of tick labels for AbstractGraduatedScale. |
static int |
LabelStyleLeft
A style for the layout of tick labels for AbstractGraduatedScale. |
static int |
LabelStyleRight
A style for the layout of tick labels for AbstractGraduatedScale. |
| 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 | |
protected |
AbstractGraduatedScale()
This constructor creates a AbstractGraduatedScale with all default properties, including not being Selectable. |
| Method Summary | |
void |
changeValue(JGoDocumentChangedEdit e,
boolean undo)
Handle undo and redo changes. |
protected abstract 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)
Make sure the JGoText object that is the LabelTemplate is copied. |
void |
expandRectByPenWidth(java.awt.Rectangle rect)
The paint bounds needs to include tick marks and labels. |
protected void |
geometryChange(java.awt.Rectangle old)
Whenever the size and/or position is changed, we need to recalculate the GeneralPath. |
abstract 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 scale and the line defined by p1 and p2 intersect. |
abstract java.awt.Point |
getLabelCenter(double val,
boolean drawLeft)
Returns the point at which the Label should be centered. |
int |
getLabelDistance()
Gets the distance at which labels are centered away from the tick mark. |
java.lang.String |
getLabelFormat()
Gets the format string for formatting label values. |
int |
getLabelFrequency()
Gets how often to label major tick marks. |
java.lang.String |
getLabelString(double val)
Returns the text string that a label marking the given value would contain. |
int |
getLabelStyle()
Gets the layout style with which the tick labels are drawn. |
JGoText |
getLabelTemplate()
Gets the instance of a JGoText that contains the font, size, and other text properties used when drawing labels. |
protected double |
getLength()
Gets the length of the scale, in document units. |
double |
getMaximum()
Gets the maximum value represented on the AbstractGraduatedScale. |
double |
getMinimum()
Gets the minimum value represented on the AbstractGraduatedScale. |
static boolean |
getNearestIntersectionOnLine(float Ax,
float Ay,
float Bx,
float By,
float Px,
float Py,
float Qx,
float Qy,
java.awt.geom.Point2D.Float R)
|
static boolean |
getNearestPointOnLine(float Ax,
float Ay,
float Bx,
float By,
float Px,
float Py,
java.awt.geom.Point2D.Float R)
|
java.awt.geom.GeneralPath |
getPath()
Get a cached GeneralPath that is produced by a call to makePath. |
abstract java.awt.geom.Point2D.Float |
getPointForValue(double v)
Returns a point that represents the given value. |
double |
getRange()
Gets the range of values represented by the AbstractGraduatedScale. |
double |
getTickBase()
Gets the base value which is marked with a tick. |
java.awt.Color |
getTickColor()
Gets the color used to draw tick marks. |
abstract void |
getTickEnds(double v,
boolean isMajor,
java.awt.geom.Point2D.Float outp1,
java.awt.geom.Point2D.Float outp2)
Finds the two end points of the tick mark for a given value. |
float |
getTickLengthLeft()
Gets the length that each minor tick is drawn to the left of the AbstractGraduatedScale's path, as seen when drawing from the Minimum value to the Maximum value. |
float |
getTickLengthRight()
Gets the length that each minor tick is drawn to the right of the scale's path, as seen when drawing from the Minimum value to the Maximum value. |
int |
getTickMajorFrequency()
Gets when to draw emphasized tick marks. |
float |
getTickMajorLengthRatio()
Gets the relative length of major tick marks compared to minor ones. |
int |
getTickMajorWidth()
Gets the pen width of major tick marks. |
double |
getTickUnit()
Gets the difference between two consecutive values marked by minor ticks. |
int |
getTickWidth()
Gets the pen width of the tick marks. |
abstract double |
getValueAtPoint(java.awt.geom.Point2D.Float p)
Returns the value which would be represented at a given point. |
static boolean |
isDefaultBufferingImage()
This is true when the appearance of all AbstractGraduatedScales, including labels, may be cached in an image, for painting efficiency. |
boolean |
isTickLabels()
Gets whether to draw tick labels at major tick marks. |
java.awt.geom.GeneralPath |
makePath()
Make sure that whenever we reconstruct the main GeneralPath for this shape, we also reconstruct the paths for the ticks. |
void |
paint(java.awt.Graphics2D g,
JGoView view)
Render this object to a Graphics2D object. |
void |
paintLabel(java.awt.Graphics2D g,
JGoView view,
java.awt.Point p,
java.lang.String text)
This method is responsible for properly painting a label for the given value parameter. |
protected void |
resetPath()
Clear any cached GeneralPath. |
static void |
setDefaultBufferingImage(boolean b)
Enable more efficient painting by caching an image of the scale, including any labels. |
void |
setLabelDistance(int value)
Sets the distance at which labels are centered away from the tick mark. |
void |
setLabelFormat(java.lang.String value)
Sets the format string for formatting label values. |
void |
setLabelFrequency(int value)
Set how often to label major tick marks. |
void |
setLabelStyle(int value)
Sets the layout style with which the tick labels are drawn. |
void |
setLabelTemplate(JGoText value)
Sets the instance of a JGoText that contains the font, size, and other text properties used when drawing labels. |
void |
setMaximum(double value)
Sets the maximum value represented on the AbstractGraduatedScale. |
void |
setMinimum(double value)
Sets the minimum value represented on the AbstractGraduatedScale. |
void |
setTickBase(double value)
Sets the base value which is marked with a tick. |
void |
setTickColor(java.awt.Color value)
Sets the color used to draw tick marks. |
void |
setTickLabels(boolean value)
Sets whether to draw tick labels at major tick marks. |
void |
setTickLengthLeft(float value)
Sets the length that each minor tick is drawn to the left of the AbstractGraduatedScale's path, as seen when drawing from the Minimum value to the Maximum value. |
void |
setTickLengthRight(float value)
Sets the length that each minor tick is drawn to the right of the scale's path, as seen when drawing from the Minimum value to the Maximum value. |
void |
setTickMajorFrequency(int value)
Sets when to draw emphasized tick marks. |
void |
setTickMajorLengthRatio(float value)
Sets the relative length of major tick marks compared to minor ones. |
void |
setTickMajorWidth(int value)
Sets the pen width of major tick marks. |
void |
setTickUnit(double value)
Sets the difference between two consecutive values marked by minor ticks. |
void |
setTickWidth(int value)
Sets the pen width of the tick marks. |
DomNode |
SVGReadObject(DomDoc svgDoc,
JGoDocument jGoDoc,
DomElement svgElement,
DomElement jGoChildElement)
Read this object in from a DomDoc representing a Scalable Vector Graphics (SVG) XML document. |
void |
SVGUpdateReference(java.lang.String attr,
java.lang.Object referencedObject)
This method will be called to fill in object references. |
void |
SVGWriteObject(DomDoc svgDoc,
DomElement jGoElementGroup)
Write this object out to a DomDoc representing a Scalable Vector Graphics (SVG) XML document. |
| Methods inherited from class com.nwoods.jgo.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 java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int LabelStyleLeft
All ticks are labeled on the end that is left of the AbstractGraduatedScale's path.
public static final int LabelStyleRight
All ticks are labeled on the end that is right of the AbstractGraduatedScale's path.
public static final int LabelStyleAlternateStartLeft
Alternates which side of the tick gets labeled. The first label tick is labeled to the left.
public static final int LabelStyleAlternateStartRight
Alternates which side of the tick gets labeled. The first label tick is labeled to the right.
public static final int ChangedMaximum
public static final int ChangedMinimum
public static final int ChangedTickLengthLeft
public static final int ChangedTickLengthRight
public static final int ChangedTickUnit
public static final int ChangedTickBase
public static final int ChangedTickMajorFrequency
public static final int ChangedTickColor
public static final int ChangedTickLabels
public static final int ChangedLabelStyle
public static final int ChangedLabelFrequency
public static final int ChangedLabelDistance
public static final int ChangedLabelTemplate
public static final int ChangedLabelFormat
public static final int ChangedTickMajorLengthRatio
public static final int ChangedTickMajorWidth
public static final int ChangedTickWidth
| Constructor Detail |
protected AbstractGraduatedScale()
Because AbstractGraduatedScale is an abstract class, this constructor is protected instead of public.
| Method Detail |
public JGoObject copyObject(JGoCopyEnvironment env)
copyObject in class JGoDrawableenv - the environment for the copy operation - keeps track of copied objects.
public double getMinimum()
getMinimum in interface GraduatedScalepublic void setMinimum(double value)
setMinimum in interface GraduatedScalevalue - This value must be less than the Maximum.public double getMaximum()
getMaximum in interface GraduatedScalepublic void setMaximum(double value)
setMaximum in interface GraduatedScalevalue - This value must be greater than Minimum.public double getRange()
This is just the Maximum minus the Minimum.
getRange in interface GraduatedScalepublic double getTickUnit()
public void setTickUnit(double value)
value - The value must be positive.public double getTickBase()
public void setTickBase(double value)
value - a double value, typically the same as the Minimumpublic java.awt.Color getTickColor()
public void setTickColor(java.awt.Color value)
value - a non-null Colorpublic int getTickWidth()
public void setTickWidth(int value)
value - an integer value describing the width of the penpublic float getTickLengthLeft()
public void setTickLengthLeft(float value)
value - a positive float value in document coordinatespublic float getTickLengthRight()
public void setTickLengthRight(float value)
value - a positive float value in document coordinatespublic int getTickMajorFrequency()
A tick mark will be drawn as a major tick mark every TickMajorFrequency ticks. This defaults to 10.
public void setTickMajorFrequency(int value)
A tick mark will be drawn as a major tick mark every TickMajorFrequency ticks. If this equals 1, then only major tick marks will be drawn.
value - The value must be positive.public int getTickMajorWidth()
This defaults to 2.
public void setTickMajorWidth(int value)
value - a positive integer value describing the width of the penpublic float getTickMajorLengthRatio()
This defaults to 2.
public void setTickMajorLengthRatio(float value)
value - this ratio must be non-negative.public boolean isTickLabels()
The default value is true.
public void setTickLabels(boolean value)
public int getLabelStyle()
public void setLabelStyle(int value)
value - one of: LabelStyleLeft, LabelStyleRight, LabelStyleAlternateStartLeft, or LabelStyleAlternateStartRightpublic int getLabelFrequency()
The default value is 1, to label every major tick mark.
public void setLabelFrequency(int value)
value - the value must be non-negativepublic int getLabelDistance()
public void setLabelDistance(int value)
value - a distance in document coordinates, possibly negative.public java.lang.String getLabelFormat()
The default value is "{0,number}".
public void setLabelFormat(java.lang.String value)
value - a format string, with directives in curly braces.public JGoText getLabelTemplate()
This JGoText object must not be part of any JGoArea or any JGoLayer; it is just used as a template for drawing labels.
public void setLabelTemplate(JGoText value)
This JGoText object must not be part of any JGoArea or any JGoLayer; it is just used as a template for drawing labels.
public abstract boolean getIntersectionWithLine(java.awt.geom.Point2D.Float p1,
java.awt.geom.Point2D.Float p2,
DoubleRef outval)
getIntersectionWithLine in interface GraduatedScalep1 - a Point2D.Float in document coordinatesp2 - a Point2D.Float in document coordinatesoutval - a DoubleRef that is modified to hold the double value of the scale at the intersection point
public abstract double getValueAtPoint(java.awt.geom.Point2D.Float p)
getValueAtPoint in interface GraduatedScalep - a Point2D.Float in document coordinates
public abstract java.awt.geom.Point2D.Float getPointForValue(double v)
getPointForValue in interface GraduatedScalev - a double-precision floating point number
public abstract void getTickEnds(double v,
boolean isMajor,
java.awt.geom.Point2D.Float outp1,
java.awt.geom.Point2D.Float outp2)
v - the double-precision floating point value that the tick mark would representisMajor - whether to find the end points for a major or a minor tick markoutp1 - a Point2D.Float that is modified with one end pointoutp2 - a Point2D.Float that is modified with the other end pointpublic java.lang.String getLabelString(double val)
Default behavior returns the string produced by formatting the value using MessageFormat and the getLabelFormat() format string.
val - the double value to display
public abstract java.awt.Point getLabelCenter(double val,
boolean drawLeft)
val - the double-float value that is being labeleddrawLeft - whether to position the label on the left or the right side of the path from minimum to maximum
public void paintLabel(java.awt.Graphics2D g,
JGoView view,
java.awt.Point p,
java.lang.String text)
g - a Graphics2Dview - a JGoViewp - a Point in document coordinatestext - the text string, produced by getLabelString()
public void paint(java.awt.Graphics2D g,
JGoView view)
This draws the main path and all the tick marks and labels. If the tick marks would be too close to each other, the minor tick marks, and possibly even the major tick marks, are not drawn.
If AbstractGraduatedScale.isDefaultBufferingImage() is true,
and if the JGoView's getScale() == 1, then this method
caches an image of the whole scale, including labels, and paints that
instead of painting all of the lines, tick marks and labels each time.
paint in class JGoObjectg - the graphics context on which to drawview - the view we're drawing inprotected abstract void computePath(java.awt.geom.GeneralPath path)
The abstract implementation does nothing.
path - a GeneralPath to be modifiedpublic java.awt.geom.GeneralPath getPath()
protected void resetPath()
public java.awt.geom.GeneralPath makePath()
This calls both computePath and an internal method for computing and remembering tick marks.
public void expandRectByPenWidth(java.awt.Rectangle rect)
expandRectByPenWidth in class JGoDrawablerect - the Rectangle that is grown to cover the tick marks and labelsprotected void geometryChange(java.awt.Rectangle old)
geometryChange in class JGoObjectprotected double getLength()
By default this is just the distance between the points on the scale for the minimum and maximum values.
public static boolean getNearestPointOnLine(float Ax,
float Ay,
float Bx,
float By,
float Px,
float Py,
java.awt.geom.Point2D.Float R)
public static boolean getNearestIntersectionOnLine(float Ax,
float Ay,
float Bx,
float By,
float Px,
float Py,
float Qx,
float Qy,
java.awt.geom.Point2D.Float R)
public void copyNewValueForRedo(JGoDocumentChangedEdit e)
JGoObjectJust 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 JGoDrawable
public void changeValue(JGoDocumentChangedEdit e,
boolean undo)
changeValue in class JGoDrawablee - undo -
public void SVGWriteObject(DomDoc svgDoc,
DomElement jGoElementGroup)
JGoXMLSaveRestoreThis 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 JGoXMLSaveRestoreSVGWriteObject in class JGoDrawable
public DomNode SVGReadObject(DomDoc svgDoc,
JGoDocument jGoDoc,
DomElement svgElement,
DomElement jGoChildElement)
JGoXMLSaveRestoreThis 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 JGoXMLSaveRestoreSVGReadObject in class JGoDrawable
public void SVGUpdateReference(java.lang.String attr,
java.lang.Object referencedObject)
JGoObjectThis 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 JGoDrawablepublic static boolean isDefaultBufferingImage()
public static void setDefaultBufferingImage(boolean b)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||