com.approximatrix.charting.render
Class AbstractRenderer

java.lang.Object
  extended by com.approximatrix.charting.render.AbstractRenderer
All Implemented Interfaces:
Renderer
Direct Known Subclasses:
AbstractChart, CoordSystem, Legend, Title

public abstract class AbstractRenderer
extends java.lang.Object
implements Renderer

The AbstractRenderer provides default implementations for the set and get methods of every Renderer. Especially it provides a default mechanism for scaling Renderer instances whose actual bounds are smaller than their preferred size. As a consequence, every Renderer instance only needs to implement paintDefault() which has to render the object from coordinates 0,0 onwards using the preferred size.

Version:
1.0
Author:
mueller armstrong

Field Summary
(package private)  java.awt.Rectangle bounds
          The bounds within which this object should be rendered.
private static boolean DirectRender
          Flag which indicates whether rendering should be performed directly to the Graphics2D.
 
Constructor Summary
AbstractRenderer()
          Creates new AbstractRenderer
 
Method Summary
private  void directRender(java.awt.Graphics2D g)
          Calls the paintDefault method, passing directly the Graphics2D object on which to paint.
 java.awt.Rectangle getBounds()
          Gets the bounds for this renderer.
static boolean getDirectRender()
          Returns the current state of the direct rendering flag.
abstract  void paintDefault(java.awt.Graphics2D g)
          This method is called by the paint method to do the actual painting.
 void render(java.awt.Graphics2D g)
          Renders the Object in the Graphics object.
 void setBounds(java.awt.Rectangle bounds)
          Sets the bounds the layout manager has assigned to this renderer.
static void setDirectRender(boolean value)
          Sets the direct rendering flag appropriately.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.approximatrix.charting.render.Renderer
getPreferredSize
 

Field Detail

DirectRender

private static boolean DirectRender
Flag which indicates whether rendering should be performed directly to the Graphics2D. True forces direct rendering, false signals the use of the buffer image method (Openchart2 1.0 compatible).


bounds

java.awt.Rectangle bounds
The bounds within which this object should be rendered.

Constructor Detail

AbstractRenderer

public AbstractRenderer()
Creates new AbstractRenderer

Method Detail

setDirectRender

public static void setDirectRender(boolean value)
Sets the direct rendering flag appropriately. Only necessary to maintain Openchart2 1.0 compatibility.

Parameters:
value - true enables direct rendering the the Grpahics2D object, false uses a buffer image

getDirectRender

public static boolean getDirectRender()
Returns the current state of the direct rendering flag.

Returns:
true if rendering is performed directly to the Graphics2D object, false if using a buffer image

setBounds

public void setBounds(java.awt.Rectangle bounds)
Sets the bounds the layout manager has assigned to this renderer. Those, of course, have to be considered in the rendering process.

Specified by:
setBounds in interface Renderer
Parameters:
bounds - the new bounds for the renderer.

getBounds

public java.awt.Rectangle getBounds()
Gets the bounds for this renderer.

Specified by:
getBounds in interface Renderer
Returns:
the bounds of this renderer. If setBounds has not been called before, the bounds computed from getPreferredSize is returned.

directRender

private void directRender(java.awt.Graphics2D g)
Calls the paintDefault method, passing directly the Graphics2D object on which to paint. Unlike the render() method, this method does no scaling and does not adhere to bounds. However, Java AWT is safe enough thatthis shouldn't cause a problem.

Parameters:
g - the Graphics2D object in which to render

render

public void render(java.awt.Graphics2D g)
Renders the Object in the Graphics object. Creates a BufferedImage and the corresponding Graphics2D object to paint in. The Image is created using the preferred size. Afterwards paintDefault is called to perform a standard painting in the Graphics object. If the bounds and the preferred size don't match the image is scaled afterwards.

Specified by:
render in interface Renderer
Parameters:
g - the Graphics2D object in which to render

paintDefault

public abstract void paintDefault(java.awt.Graphics2D g)
This method is called by the paint method to do the actual painting. The painting is supposed to start at point (0,0) and the size is always the same as the preferred size. The paint method performs the possible scaling.

Parameters:
g - the Graphics2D object to paint in.