cox.jmatt.java.MathTools.graphing.xml
Class GraphPaperXML

java.lang.Object
  extended by cox.jmatt.java.MathTools.graphing.xml.RenderableXML
      extended by cox.jmatt.java.MathTools.graphing.xml.GraphPaperXML
All Implemented Interfaces:
GraphPaper, Renderable

public class GraphPaperXML
extends RenderableXML
implements GraphPaper

This is the bring-together class of the graphing.xml.* package. When GraphPaperXML is rendered it yields an XML document containing all of the graphing data. All Object arguments are toString()-ed to allow for proper representation, so implementations that do NOT use Strings won't get the best mileage from this one.

Implementations that do use Strings can use this package to persistently store graphs. The ONLY non-standard method used is setID() and it is used transparently.

Common XML attributes are ID, name, and type. The type is that set in Renderable, and the IDs are assigned when graphing components are added to GraphPaper. The 'name=' attribute is assigned when the component is created; from GraphEngine. This is all handled automatically. Calling GraphPaper's render() method both generates root tags and GraphPaper data and renders all contained elements, in order: Axes, Graphs, Polygons, Transforms, and parameters. The tags are simple, straightforward, and easy to use.

NOTE: None of the XML package classes need or use a rendering context Object. It is ignored in all cases.


Field Summary
 
Fields inherited from class cox.jmatt.java.MathTools.graphing.xml.RenderableXML
myID, myName, myParams, myType
 
Constructor Summary
GraphPaperXML()
          Zero-argument constructor.
GraphPaperXML(java.lang.String pName)
          Constructor for named GraphPaperXML.
 
Method Summary
 boolean addAxis(java.lang.String pKey, Axis pAxis)
          Add an Axis to this GraphPaper.
 boolean addGraph(java.lang.String pKey, Graphable pGraph)
          Add a Graphable to this GraphPaper.
 boolean addPolygon(java.lang.String pKey, Polygon pPoly)
          Add an Polygon to this GraphPaper.
 boolean addTransform(java.lang.Object pTransform)
          Transforms, if used, MUST be representable by String! If the transform is null, it is ignored and false is returned.
 java.lang.Object render(java.lang.Object pContext)
          Bring it all together and print it out as XML.
 boolean setRanges(double pXMin, double pYMin, double pXMax, double pYMax)
          Ranges are presented as attributes in the <GraphPaper> tag: xmin, ymin, xmax, ymax.
 boolean setSize(double pWidth, double pHeight)
          Height and width are rendered as 'height=' and 'width=' attributes on the <GraphPaper> tag.
 
Methods inherited from class cox.jmatt.java.MathTools.graphing.xml.RenderableXML
setID, setParameter, setType, testCondition
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface cox.jmatt.java.MathTools.graphing.Renderable
setParameter, setType, testCondition
 

Constructor Detail

GraphPaperXML

public GraphPaperXML()
Zero-argument constructor. No name supplied.


GraphPaperXML

public GraphPaperXML(java.lang.String pName)
Constructor for named GraphPaperXML.

Method Detail

setRanges

public boolean setRanges(double pXMin,
                         double pYMin,
                         double pXMax,
                         double pYMax)
Ranges are presented as attributes in the <GraphPaper> tag: xmin, ymin, xmax, ymax. Return value is always true.

Specified by:
setRanges in interface GraphPaper
Parameters:
pXMin - The minimum horizontal (X) value on the graph.
pYMin - The minimum vertical (Y) value for the graph.
pXMax - The maximum horizontal value for the graph.
pYMax - The maximum vertical (Y) value on the graph.
Returns:
true if the implementation can support these settings, false otherwise.

setSize

public boolean setSize(double pWidth,
                       double pHeight)
Height and width are rendered as 'height=' and 'width=' attributes on the <GraphPaper> tag. Always returns true.

Specified by:
setSize in interface GraphPaper
Parameters:
pWidth - The width of the graph.
pHeight - The height of the graph.
Returns:
true for valid settings, false otherwise.

addTransform

public boolean addTransform(java.lang.Object pTransform)
Transforms, if used, MUST be representable by String! If the transform is null, it is ignored and false is returned. If non-null, its toString() is added and the return value is true.

Specified by:
addTransform in interface GraphPaper
Parameters:
pTransform - The transformation to apply.
Returns:
true if the transform succeeds, false otherwise.

addAxis

public boolean addAxis(java.lang.String pKey,
                       Axis pAxis)
Add an Axis to this GraphPaper. The key argument becomes the Axis' ID attribute, it MUST NOT be null or blank! If pAxis is null it is removed, returning true if it was there and false if not.

Specified by:
addAxis in interface GraphPaper
Parameters:
pKey - The identification or description of the Axis being added.
pAxis - The Axis to add.
Returns:
true if it happened, false otherwise.

addGraph

public boolean addGraph(java.lang.String pKey,
                        Graphable pGraph)
Add a Graphable to this GraphPaper. The key argument becomes the Axis' ID attribute, it MUST NOT be null or blank! If pGraph is null it is removed, returning true if it was there and false if not.

Specified by:
addGraph in interface GraphPaper
Parameters:
pKey - The String key used to identify the graph.
pGraph - The graph to add.
Returns:
true if all is well, false if something bad happened.

addPolygon

public boolean addPolygon(java.lang.String pKey,
                          Polygon pPoly)
Add an Polygon to this GraphPaper. The key argument becomes the Axis' ID attribute, it MUST NOT be null or blank! If pPoly is null it is removed, returning true if it was there and false if not.

Specified by:
addPolygon in interface GraphPaper
Parameters:
pKey - The String key used to identify the polygon.
pPoly - The Polygon to add.
Returns:
true if all is well, false if something bad happened.

render

public java.lang.Object render(java.lang.Object pContext)
Bring it all together and print it out as XML. All elements are contained within the root <GraphPaper> tag which has NO ID attribute. No rendering context is used.

Specified by:
render in interface Renderable
Overrides:
render in class RenderableXML
Parameters:
pContext - The Context Object to be used for rendering.
Returns:
The graph-ready Object, requiring no further MathTools interaction.