|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.faceless.graph.output.Output
org.faceless.graph.output.ImageOutput
public class ImageOutput
The ImageOutput class is a subclass of Output, which
allows Graphs to be drawn to a java.awt.Image
.
Unless you just want the Image (for use in an applet,
for example), you should probably use one of the subclasses
like PNGOutput
so the image can be written to
a file.
If run with the Swing classes provided with JDK 1.2 and above, this class
provides anti-aliasing and text-rotation. If run without the
Swing classes, these features are not available. This can be
checked by the return value from the canRotate()
method.
An example use would be:
ImageOutput out = new ImageOutput(400,400); Graph g = makeMyGraph(); out.render(g); Image i = out.getImage(); // For display in an applet or wherever
All the functions within are defined in the Output class, and you should look there for definitions.
Since 1.0.3, custom fonts must be defined using the setFontMap method.
Constructor Summary | |
---|---|
ImageOutput(Image image)
|
|
ImageOutput(int width,
int height)
Create a new ImageOutput of the specified width and height, and with no background color specified. |
|
ImageOutput(int width,
int height,
Color color)
Create a new ImageOutput of the specified width, height and background color. |
Method Summary | |
---|---|
boolean |
canPattern()
Return true if this subclass out Output can handle pattern fills. |
boolean |
canRotate()
Return true if this subclass out Output can handle rotated text. |
BoundingBox |
getCanvas()
Return the canvas as a BoundingBox . |
Graph |
getGraph()
Return the graph being rendered. |
Image |
getImage()
Return the Image created by the render() method. |
Image |
getReducedColorImage(int numcolors,
Color mask)
Return the Image created by the render() method, after
it's been reduced to the specified number of colors. |
BoundingBox |
getTextBox(String text,
Style s)
Return the bounding box for given string in the specified style. |
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 |
void |
poly(String name,
double[] dx,
double[] dy,
int num)
Draw and fill a polygon on the canvas, in the current colour. |
void |
render(Graph gr)
Render the Graph to this Output object. |
void |
setColor(Paint s)
Set the current pen, font and fill colour |
void |
setFontMap(String name,
int style,
Font font)
Define a custom mapping from the specified font description to the specified font. |
void |
setLineDash(double on,
double off,
double phase)
Set the line dash pattern |
void |
setLineThickness(double thickness)
Set the line thickness. |
void |
setMargin(int left,
int top,
int right,
int bottom)
Set the margin between the graph and the edge of the image. |
void |
setRenderingHint(RenderingHints.Key key,
Object val)
For Java 1.2 systems and above, set a rendering hint for drawing the image. |
void |
text(String text,
double x,
double y,
Style s)
Draw a line of text at the specified position in the specified style. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ImageOutput(int width, int height)
width
- the width of the image in pixelsheight
- the height of the image in pixelspublic ImageOutput(int width, int height, Color color)
width
- the width of the image in pixelsheight
- the height of the image in pixelscolor
- the color to use as the background colorpublic ImageOutput(Image image)
Method Detail |
---|
public void setRenderingHint(RenderingHints.Key key, Object val)
For Java 1.2 systems and above, set a rendering hint for drawing the image. For Java 1.1 systems, this method has no effect.
The following rendering hints are set by default:
RenderingHints.KEY_ANTIALIASING = RenderingHints.VALUE_ANTIALIAS_ON RenderingHints.KEY_TEXT_ANTIALIASING = RenderingHints.VALUE_TEXT_ANTIALIAS_ON RenderingHints.KEY_RENDERING = RenderingHints.VALUE_RENDER_QUALITY RenderingHints.KEY_INTERPOLATION = RenderingHints.VALUE_INTERPOLATION_BICUBIC
public void setMargin(int left, int top, int right, int bottom)
top
- the top margin in pixelsleft
- the left margin in pixelsright
- the right margin in pixelsbottom
- the bottom margin in pixelspublic final boolean canRotate()
Output
canRotate
in class Output
public final boolean canPattern()
Output
canPattern
in class Output
public BoundingBox getCanvas()
Output
BoundingBox
. The final graph
will be sized to fit this box.
getCanvas
in class Output
public void setColor(Paint s)
Output
setColor
in class Output
public void setLineThickness(double thickness)
setLineThickness
in class Output
public void setLineDash(double on, double off, double phase)
Output
setLineDash
in class Output
public void line(double x1, double y1, double x2, double y2)
Output
line
in class Output
public void poly(String name, double[] dx, double[] dy, int num)
Output
poly
in class Output
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 graphsdx
- the array of X co-ordinatesdy
- the array of Y co-ordinatesnum
- the number of co-ordinates in the arraypublic void setFontMap(String name, int style, Font font)
output.setFontMap("myfont",Font.PLAIN, Font.createFont("myfont.ttf"));
public BoundingBox getTextBox(String text, Style s)
Output
getTextBox
in class Output
text
- The string to return the size for.s
- 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 alignmentpublic void text(String text, double x, double y, Style s)
Output
text
in class Output
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.public void render(Graph gr) throws IOException
Output
render
in class Output
IOException
public Graph getGraph()
Output
getGraph
in class Output
public Image getImage()
render()
method.
public Image getReducedColorImage(int numcolors, Color mask)
render()
method, after
it's been reduced to the specified number of colors. This is useful
for saving to bitmap formats like GIF and 8-bit PNG. Note the
color-reduction algorithm is fairly timeconsuming.
colors
- the number of colors to reduce the image to - must
be a power of two between 2 and 256mask
- the Color to mask transparent colors against during the
color reduction. Generally this is the background color you intend to
display the graph on, but it may be null for no masking.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |