Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.faceless.graph.output
Class ImageOutput

    java.lang.Object
      org.faceless.graph.output.Output
          org.faceless.graph.output.ImageOutput

Direct Known Subclasses:
  GIFOutput, JimiOutput, PNGOutput

    public class ImageOutput

extends Output

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

### ImageOutput

    public ImageOutput(int width,
                       int height)

  Create a new ImageOutput of the specified width and height, and with no background color specified.

  Parameters:
    `width` - the width of the image in pixels
    `height` - the height of the image in pixels

### ImageOutput

    public ImageOutput(int width,
                       int height,
                       Color color)

  Create a new ImageOutput of the specified width, height and background color.

  Parameters:
    `width` - the width of the image in pixels
    `height` - the height of the image in pixels
    `color` - the color to use as the background color

### ImageOutput

    public ImageOutput(Image image)

Method Detail

### setRenderingHint

    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

### setMargin

    public void setMargin(int left,
                          int top,
                          int right,
                          int bottom)

  Set the margin between the graph and the edge of the image. By default, these are all zero (ie. the graph expands to fill the entire image

  Parameters:
    `top` - the top margin in pixels
    `left` - the left margin in pixels
    `right` - the right margin in pixels
    `bottom` - the bottom margin in pixels

### canRotate

    public final boolean canRotate()

  Description copied from class: `Output`
  Return true if this subclass out Output can handle rotated text.

  Specified by:
    `canRotate` in class `Output`

### canPattern

    public final boolean canPattern()

  Description copied from class: `Output`
  Return true if this subclass out Output can handle pattern fills.

  Specified by:
    `canPattern` in class `Output`

### getCanvas

    public BoundingBox getCanvas()

  Description copied from class: `Output`
  Return the canvas as a `BoundingBox`. The final graph will be sized to fit this box.

  Specified by:
    `getCanvas` in class `Output`

### setColor

    public void setColor(Paint s)

  Description copied from class: `Output`
  Set the current pen, font and fill colour

  Specified by:
    `setColor` in class `Output`

### setLineThickness

    public void setLineThickness(double thickness)

  Set the line thickness. Since version 1.1 this value works as you would expect.

  Specified by:
    `setLineThickness` in class `Output`

### setLineDash

    public void setLineDash(double on,
                            double off,
                            double phase)

  Description copied from class: `Output`
  Set the line dash pattern

  Specified by:
    `setLineDash` in class `Output`

### line

    public void line(double x1,
                     double y1,
                     double x2,
                     double y2)

  Description copied from class: `Output`
  Draw a line from x1,y1 to x2,y2 on the canvas, in the current colour

  Specified by:
    `line` in class `Output`

### poly

    public void poly(String name,
                     double[] dx,
                     double[] dy,
                     int num)

  Description copied from class: `Output`
  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.

  Specified by:
    `poly` in class `Output`
  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 graphs
    `dx` - the array of X co-ordinates
    `dy` - the array of Y co-ordinates
    `num` - the number of co-ordinates in the array

### setFontMap

    public void setFontMap(String name,
                           int style,
                           Font font)

  Define a custom mapping from the specified font description to the specified font. Use this to use custom fonts in the graph, e.g.

         output.setFontMap("myfont",Font.PLAIN, Font.createFont("myfont.ttf"));

  Since:
    1.0.3

### getTextBox

    public BoundingBox getTextBox(String text,
                                  Style s)

  Description copied from class: `Output`
  Return the bounding box for given string in the specified style.

  Specified by:
    `getTextBox` in class `Output`
  Parameters:
    `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 alignment

### text

    public void text(String text,
                     double x,
                     double y,
                     Style s)

  Description copied from class: `Output`
  Draw a line of text at the specified position in the specified style.

  Specified by:
    `text` in class `Output`
  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.

### render

    public void render(Graph gr)
                throws IOException

  Description copied from class: `Output`
  Render the Graph to this Output object.

  Specified by:
    `render` in class `Output`
  Throws:
    `IOException`

### getGraph

    public Graph getGraph()

  Description copied from class: `Output`
  Return the graph being rendered. For internal use.

  Specified by:
    `getGraph` in class `Output`

### getImage

    public Image getImage()

  Return the Image created by the `render()` method.

### getReducedColorImage

    public 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. This is useful for saving to bitmap formats like GIF and 8-bit PNG. Note the color-reduction algorithm is fairly timeconsuming.

  Parameters:
    `colors` - the number of colors to reduce the image to - must be a power of two between 2 and 256
    `mask` - 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.
  Since:
    1.1

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2012 Big Faceless Organization