Package org.faceless.graph.output
Class Output
- java.lang.Object
-
- org.faceless.graph.output.Output
-
- Direct Known Subclasses:
PDF2Output
public abstract class Output extends java.lang.Object
The Output class is the abstract base class for all Output canvases in the graph Library. It defines some very primitive drawing methods (point, line, polygon and text) which need to be overridden by more concrete subclasses in order to render the graphs.
The main method in the
Output
class of interest to end-users is therender(org.faceless.graph.Graph)
method, which takes a Graph as an argument and renders that graph to this output stream.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
textAlign
textAlign shows where a line of text is drawn on the canvas in relation to the point that's given.
-
Constructor Summary
Constructors Modifier Constructor Description protected
Output()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract boolean
canPattern()
Return true if this subclass out Output can handle pattern fills.abstract boolean
canRotate()
Return true if this subclass out Output can handle rotated text.abstract BoundingBox
getCanvas()
Return the canvas as aBoundingBox
.abstract Graph
getGraph()
Return the graph being rendered.protected Point
getTextAnchor(double x, double y, double w, double h, int align)
Returns the point that the text should be placed at for this canvas, based on it's alignment.abstract BoundingBox
getTextBox(java.lang.String text, Style style)
Return the bounding box for given string in the specified style.abstract void
line(double x1, double y1, double x2, double y2)
Draw a line from x1,y1 to x2,y2 on the canvas, in the current colourabstract void
poly(java.lang.String name, double[] x, double[] y, int num)
Draw and fill a polygon on the canvas, in the current colour.abstract void
render(Graph g)
Render the Graph to this Output object.protected Point
rotate(Point cen, Point in, double ang)
For use only by subclasses of Output.abstract void
setColor(java.awt.Paint s)
Set the current pen, font and fill colourabstract void
setLineDash(double on, double off, double phase)
Set the line dash patternabstract void
setLineThickness(double thickness)
Set the line thickness (1 being default, 2 twice as thick, etc.) on platforms that support it.abstract void
text(java.lang.String text, double x, double y, Style s)
Draw a line of text at the specified position in the specified style.
-
-
-
Field Detail
-
textAlign
protected int textAlign
textAlign shows where a line of text is drawn on the canvas in relation to the point that's given.java.awt.Graphics
and most PostScript devices align the baseline (bottom for our purposes) and left of the text to the given point, so this is the default, but it may be overridden by subclasses
-
-
Method Detail
-
getTextBox
public abstract BoundingBox getTextBox(java.lang.String text, Style style)
Return the bounding box for given string in the specified style.- Parameters:
text
- The string to return the size for.style
- The style to apply to the text before returning it's size. The aspects of the style that may affect this include font, rotation and alignment
-
getCanvas
public abstract BoundingBox getCanvas()
Return the canvas as aBoundingBox
. The final graph will be sized to fit this box.
-
canRotate
public abstract boolean canRotate()
Return true if this subclass out Output can handle rotated text.
-
canPattern
public abstract boolean canPattern()
Return true if this subclass out Output can handle pattern fills.- Since:
- 1.0.13
-
setColor
public abstract void setColor(java.awt.Paint s)
Set the current pen, font and fill colour
-
setLineThickness
public abstract void setLineThickness(double thickness)
Set the line thickness (1 being default, 2 twice as thick, etc.) on platforms that support it.
-
setLineDash
public abstract void setLineDash(double on, double off, double phase)
Set the line dash pattern
-
text
public abstract void text(java.lang.String text, double x, double y, Style s)
Draw a line of text at the specified position in the specified style.- Parameters:
text
- The line of text to draw.x
- The x position to place the text at, measured from the left of the canvas.y
- The y position to place the text at, measured from the bottom of the canvas.style
- The style to apply to the text. Aspects of the style that will be used include Color, Font, Alignment and Rotation
-
line
public abstract void line(double x1, double y1, double x2, double y2)
Draw a line from x1,y1 to x2,y2 on the canvas, in the current colour
-
poly
public abstract void poly(java.lang.String name, double[] x, double[] y, int num)
Draw and fill a polygon on the canvas, in the current colour. The corners of the polygon are specified by the arrays of X and Y values. The polygon has no borders, and is filled with the current colour. Subclasses should handle the cases where several of the points are the same.- Parameters:
name
- The name of the dataset that is being drawn. Not used in the current release, but will eventually be user for interaction with rendered graphsx
- the array of X co-ordinatesy
- the array of Y co-ordinatesnum
- the number of co-ordinates in the array
-
render
public abstract void render(Graph g) throws java.io.IOException
Render the Graph to this Output object.- Throws:
java.io.IOException
-
getGraph
public abstract Graph getGraph()
Return the graph being rendered. For internal use.- Since:
- 1.0.3
-
rotate
protected final Point rotate(Point cen, Point in, double ang)
For use only by subclasses of Output. Rotate and return a given point around a given center by the specified angle- Parameters:
cen
- The center of rotationin
- The point to be rotatedang
- The angle in degrees clockwise
-
getTextAnchor
protected final Point getTextAnchor(double x, double y, double w, double h, int align)
Returns the point that the text should be placed at for this canvas, based on it's alignment. So, for example, if the canvas has an alignment of BOTTOM+LEFT, and the text has an alignment of TOP+LEFT, the returned point will be (x,y-height)- Parameters:
x
- The X position of the point in the text as specifed by aligny
- The Y position of the point in the text as specifed by alignw
- The width of the texth
- The height of the text *above the baseline*. For best results descenders should not be included in this height.align
- The alignment of the text. Taken from Style.getAlign()
-
-