com.objectplanet.chart
Class Renderer

java.lang.Object
  extended by com.objectplanet.chart.Renderer
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ChartRenderer, GridRenderer, LegendRenderer

public class Renderer
extends java.lang.Object
implements java.io.Serializable

This class is the abstract superclass of all renderers.

Author:
Bjorn J. Kvande., Philipp Kolibaba.
See Also:
Serialized Form

Field Summary
protected  GenericChart chart
          The chart object
static java.awt.Cursor DEFAULT_CURSOR
           
protected static int DOUBLE_CLICK_TIME
           
static java.awt.Cursor GRID_CURSOR_HORZ
           
static java.awt.Cursor GRID_CURSOR_VERT
           
static java.awt.Cursor HAND_CURSOR
           
static java.awt.Cursor RESIZE_CURSOR
           
static java.awt.Cursor RESIZE_HOR_CURSOR
           
 
Constructor Summary
Renderer()
          Default constructor.
Renderer(GenericChart chart)
          Creates a basic renderer.
 
Method Summary
protected  void clearBackground(java.awt.Graphics g, java.awt.Dimension size)
          Clears the backgrond making it transparent.
static void fifo_add(java.lang.Object[] image_and_key)
          Adds a new object at the end of the fifo queue.
static void fifo_clear()
          Clears the image queue and cache and flushes the images.
static java.lang.Object[] fifo_remove()
          Returns and removes the first object in the fifo queue.
static java.util.Hashtable getAngledLabelCache()
          Getter for the angledLabelCache where the angled labels are stored.
protected  java.awt.Dimension getAngledLabelSize(java.awt.Dimension size, int angle)
          Calculates the size of the angled label size.
protected static java.awt.Color getBrighter(java.awt.Color color)
          Creates a new Color that is a brighter version of this Color.
protected static java.awt.Color getDarker(java.awt.Color color)
          Creates a new Color that is a darker version of this Color.
static int getfifo_count()
          Getter for the fifo_count.
static java.lang.Object[] getfifo_queue()
          Getter for the fifo_queue.
protected  java.awt.Font getFont(java.lang.String label)
          Gets the font for the specified label.
protected  java.awt.FontMetrics getFontMetrics(java.awt.Font font)
          Gets the font metrics for the specified font.
protected  java.awt.Dimension getImageSize(java.lang.String name)
          Calculates the size of an image.
protected  java.lang.String getLabel(java.lang.String name)
          Gets the specified label from the chart.
protected  int getLabelAngle(java.lang.String name)
          Gets the angle of the specified label.
protected  java.awt.Dimension getLabelSize(java.lang.String label, java.awt.FontMetrics fm)
          Calculates the size of a multiline label.
protected  int getSampleCount()
          Gets the number of samples.
protected  int getSeriesCount()
          Gets the number of series.
static int hashCode(java.lang.String s)
          Returns a hashcode for the specified string.
protected  void paintBox(java.awt.Graphics g, java.awt.Color c, int x, int y, int w, int h, boolean pushed)
          Paints a 3D box with the specified size.
protected  void paintLabel(java.awt.Graphics g, java.lang.String label, int label_x, int label_y, java.awt.Dimension size, int style, int angle, boolean underlined)
          Paints a normal, multiline, and angled label.
static void setLabelAngleCacheSize(int count)
          Sets the angled label cache size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

chart

protected GenericChart chart
The chart object


DEFAULT_CURSOR

public static java.awt.Cursor DEFAULT_CURSOR

DOUBLE_CLICK_TIME

protected static final int DOUBLE_CLICK_TIME
See Also:
Constant Field Values

GRID_CURSOR_HORZ

public static java.awt.Cursor GRID_CURSOR_HORZ

GRID_CURSOR_VERT

public static java.awt.Cursor GRID_CURSOR_VERT

HAND_CURSOR

public static java.awt.Cursor HAND_CURSOR

RESIZE_CURSOR

public static java.awt.Cursor RESIZE_CURSOR

RESIZE_HOR_CURSOR

public static java.awt.Cursor RESIZE_HOR_CURSOR
Constructor Detail

Renderer

public Renderer()
Default constructor.


Renderer

public Renderer(GenericChart chart)
Creates a basic renderer.

Parameters:
chart - The chart object attached to this renderer.
Method Detail

clearBackground

protected void clearBackground(java.awt.Graphics g,
                               java.awt.Dimension size)
Clears the backgrond making it transparent. Uses reflection in order to escape NoSuchMethodException thrown by the Microsoft VM.

Parameters:
g - The graphics context used to paint with.
size - The size of the chart component.

fifo_add

public static void fifo_add(java.lang.Object[] image_and_key)
Adds a new object at the end of the fifo queue. Normally should not be used by the outer code.

Parameters:
image_and_key - An array with the key in [0] and the image in [1]

fifo_clear

public static void fifo_clear()
Clears the image queue and cache and flushes the images. Normally should not be used by the outer code.


fifo_remove

public static java.lang.Object[] fifo_remove()
Returns and removes the first object in the fifo queue. Normally should not be used by the outer code.

Returns:
An array with the key in [0] and the image in [1].

getAngledLabelCache

public static java.util.Hashtable getAngledLabelCache()
Getter for the angledLabelCache where the angled labels are stored. Used by the PlotterChart. Nomally should not be used by the outer code.

Returns:
The angled labels hashtable.

getAngledLabelSize

protected java.awt.Dimension getAngledLabelSize(java.awt.Dimension size,
                                                int angle)
Calculates the size of the angled label size.

Parameters:
size - The unrotated size.
angle - The angle of the label to be painted.
Returns:
A new dimension object, or the same if the angle does not change.

getBrighter

protected static java.awt.Color getBrighter(java.awt.Color color)
Creates a new Color that is a brighter version of this Color. Takes in account also the alpha component of the given Color.

Parameters:
color - The source Color.
Returns:
a new Color object that is a darker version of this Color.

getDarker

protected static java.awt.Color getDarker(java.awt.Color color)
Creates a new Color that is a darker version of this Color. Takes in account also the alpha component of the given Color.

Parameters:
color - The source Color.
Returns:
a new Color object that is a darker version of this Color.

getfifo_count

public static int getfifo_count()
Getter for the fifo_count. Used by the PlotterChart. Normally should not be used by the outer code.

Returns:
The fifo_count.

getfifo_queue

public static java.lang.Object[] getfifo_queue()
Getter for the fifo_queue. Used by the PlotterChart. Normally should not be used by the outer code.

Returns:
The fifo_queue.

getFont

protected java.awt.Font getFont(java.lang.String label)
Gets the font for the specified label. If no specific font is specified for this label, it returns the font returned by getFont().

Parameters:
label - The name of the label.
Returns:
The font (never null).

getFontMetrics

protected java.awt.FontMetrics getFontMetrics(java.awt.Font font)
Gets the font metrics for the specified font.

Parameters:
font - The name of the font.
Returns:
The font metrics.

getImageSize

protected java.awt.Dimension getImageSize(java.lang.String name)
Calculates the size of an image. If there is no image for this index, 0 is returned.

Parameters:
name - The name of the image to check size for.
Returns:
The size of an image.

getLabel

protected java.lang.String getLabel(java.lang.String name)
Gets the specified label from the chart.

Parameters:
name - The name of the label.
Returns:
The label, or null if not found.

getLabelAngle

protected int getLabelAngle(java.lang.String name)
Gets the angle of the specified label.

Parameters:
name - The name of the label.
Returns:
The label, or null if not found.

getLabelSize

protected java.awt.Dimension getLabelSize(java.lang.String label,
                                          java.awt.FontMetrics fm)
Calculates the size of a multiline label. If the label is empty, the size of the font is returned.

Parameters:
label - The label to check the size of.
fm - The font metrics used to measure labels with.
Returns:
The size.

getSampleCount

protected int getSampleCount()
Gets the number of samples.


getSeriesCount

protected int getSeriesCount()
Gets the number of series.


hashCode

public static int hashCode(java.lang.String s)
Returns a hashcode for the specified string.

Parameters:
s - The string to calculate hash code for.
Returns:
a hash code value for the specified string.

paintBox

protected void paintBox(java.awt.Graphics g,
                        java.awt.Color c,
                        int x,
                        int y,
                        int w,
                        int h,
                        boolean pushed)
Paints a 3D box with the specified size.

Parameters:
g - The graphics context used to paint with.
c - The background color of the button.
x - The x position of the upper left corner.
y - The y position of the upper left corner.
w - The box width.
h - The box height.
pushed - True if button should be pushed.

paintLabel

protected void paintLabel(java.awt.Graphics g,
                          java.lang.String label,
                          int label_x,
                          int label_y,
                          java.awt.Dimension size,
                          int style,
                          int angle,
                          boolean underlined)
Paints a normal, multiline, and angled label. The lines are broken with \n.

Parameters:
g - The graphics context used to paint with.
label - The label to paint.
label_x - The x position of the label.
label_y - The y position of the label.
size - The size of the unrotated label.
style - -1 for left, 0 for center, 1 for right.
angle - The degrees to turn the label (only 0, 90, 180, 270 works fine).
underlined - If true the label is underlined (can be used for URLs, ony for non-angled labels).

setLabelAngleCacheSize

public static void setLabelAngleCacheSize(int count)
Sets the angled label cache size. Since JDK 1.1 is used, angled labels are not available using the normal drawing operations. Instead a label is drawn on an image and the image is then rotated, before painted as the label. Since the image rotation takes quite a long time, the images are cached to save rendering time. However, this causes a problem with Internet Explorer wich will throw a security exception if more than 1000 images are created and held on to in the VM. To avoid this the size of the cache is set to 900 by default. This can be adjusted if you will create other images in your applet. Also, the angled label image cache will increase memory and resource usage, so you might want to turn it off (set the cachec size to 0 or less. The angled label cache is static so it is shared across all applets running in the same browser instance. Good luck :)

Parameters:
count - The image cache count, less than 0 to turn it off.