jcckit
Class GraphicsPlotCanvas

java.lang.Object
  extended byjcckit.plot.PlotCanvas
      extended byjcckit.GraphicsPlotCanvas
All Implemented Interfaces:
PlotListener
Direct Known Subclasses:
GraphicsPlotCanvas2

public class GraphicsPlotCanvas
extends PlotCanvas

Class which handles plotting into a Graphics context based on the GraphicsRenderer. This class is not a subclass of java.awt.Component. The actual AWT component presenting the plot is an innerclass. Its instance wrapped by GraphicsPlotCanvas can be obtained with getGraphicsCanvas().

The plot is painted by using double-buffering and pre-rendered view of the coordinate system. That is, the coordinate system is drawn into an off-screen image. It will be redrawn only if the size of the embedding AWT component is changed.

Author:
Franz-Josef Elmer

Nested Class Summary
protected  class GraphicsPlotCanvas.GraphicsCanvas
          AWT component which actually shows the rendered plot.
protected  class GraphicsPlotCanvas.GraphicsPainter
          Class which does the actual painting.
 
Field Summary
protected  GraphicsPlotCanvas.GraphicsCanvas _canvas
          Wrapped AWT component.
static java.lang.String BACKGROUND_KEY
          Key of a configuration parameter.
static java.lang.String DOUBLE_BUFFERING_KEY
          Key of a configuration parameter.
static java.lang.String FOREGROUND_KEY
          Key of a configuration parameter.
 
Fields inherited from class jcckit.plot.PlotCanvas
HORIZONTAL_ANCHOR_KEY, PAPER_KEY, PLOT_KEY, VERTICAL_ANCHOR_KEY
 
Constructor Summary
GraphicsPlotCanvas(ConfigParameters config)
          Creates an instance from the specified configuration parameters.
 
Method Summary
protected  void createGraphicsCanvas()
          Creates an instance of GraphicsPlotCanvas.GraphicsCanvas which wraps the rendered plot.
 void drawInto(java.awt.Image image)
          Draws the plot into the specified image.
 java.awt.Canvas getGraphicsCanvas()
          Returns an AWT component which wraps the rendered plot.
static void main(java.lang.String[] args)
          Shows a plot in a Frame.
 GraphPoint mapCursorPosition(int x, int y)
          Maps the cursor position onto a point in device-independent coordinates.
 void plotChanged(PlotEvent event)
          Repaints the wrapping GUI component.
protected static void run(java.lang.String[] args, java.lang.String plotCanvas)
           
 void setDoubleBuffering(boolean doubleBuffering)
          Sets the flag for double buffering.
 void setMarker(GraphicalElement marker)
          Defines a graphical marker which will be drawn on top of the plot.
 void setRenderer(java.lang.String className)
          Sets the renderer used to render the plot.
 
Methods inherited from class jcckit.plot.PlotCanvas
connect, getHorizontalAnchor, getPaper, getPlot, getVerticalAnchor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BACKGROUND_KEY

public static final java.lang.String BACKGROUND_KEY
Key of a configuration parameter.

See Also:
Constant Field Values

FOREGROUND_KEY

public static final java.lang.String FOREGROUND_KEY
Key of a configuration parameter.

See Also:
Constant Field Values

DOUBLE_BUFFERING_KEY

public static final java.lang.String DOUBLE_BUFFERING_KEY
Key of a configuration parameter.

See Also:
Constant Field Values

_canvas

protected GraphicsPlotCanvas.GraphicsCanvas _canvas
Wrapped AWT component.

Constructor Detail

GraphicsPlotCanvas

public GraphicsPlotCanvas(ConfigParameters config)
Creates an instance from the specified configuration parameters.
Key & Default ValueTypeMandatory Description
background = default background color of the wrapped AWT component Colorno Background color of the wrapped AWT component.
foreground = default foreground color of the wrapped AWT component Colorno Foreground color of the wrapped AWT component.
doubleBuffering = true booleanno If true the plot will be painted by using double-buffering and pre-rendered view of the coordinate system.
In addition the configuration parameters of the constructor of the superclass PlotCanvas apply.

Method Detail

setRenderer

public void setRenderer(java.lang.String className)
Sets the renderer used to render the plot. The default value is GraphicsRenderer.

Parameters:
className - Fully qualified name of the renderer class.

setDoubleBuffering

public void setDoubleBuffering(boolean doubleBuffering)
Sets the flag for double buffering. For off-screen rendering this flag has to be set false.


drawInto

public void drawInto(java.awt.Image image)
Draws the plot into the specified image. Can be used for off-screen renderering if double-buffering is switched off and if all texts are not rotated. Otherwise NullPointerException will be thrown.


createGraphicsCanvas

protected void createGraphicsCanvas()
Creates an instance of GraphicsPlotCanvas.GraphicsCanvas which wraps the rendered plot.


plotChanged

public void plotChanged(PlotEvent event)
Repaints the wrapping GUI component.

Specified by:
plotChanged in interface PlotListener
Overrides:
plotChanged in class PlotCanvas

getGraphicsCanvas

public java.awt.Canvas getGraphicsCanvas()
Returns an AWT component which wraps the rendered plot. Note that the returned Canvas object has preferred size zero. This is important to know when used with certain LayoutManagers like FlowLayout.


mapCursorPosition

public GraphPoint mapCursorPosition(int x,
                                    int y)
Maps the cursor position onto a point in device-independent coordinates.

Parameters:
x - X-coordinate of the cursor.
y - Y-coordinate of the cursor.

setMarker

public void setMarker(GraphicalElement marker)
Defines a graphical marker which will be drawn on top of the plot. To remove the marker call this method with argument null.

Parameters:
marker - Marker element. Can be null.

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Shows a plot in a Frame. The plot (data and layout) is defined in the .properties file specified by the first command line argument.

Usage: java jcckit.GraphicsPlotCanvas [-r <renderer class>] <properties file>

Throws:
java.lang.Exception

run

protected static void run(java.lang.String[] args,
                          java.lang.String plotCanvas)
                   throws java.lang.Exception
Throws:
java.lang.Exception