All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class psplot.PlotCanvas

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----psplot.PlotCanvas

public abstract class PlotCanvas
extends Canvas
implements Corners
The class PlotCanvas is the basic class in all these floating point graphics routines. It is instantiated as the child of an applet, its parent. There are several differences between the usual canvases availble in the java AWT library: (1) it uses floating point numbers as coordinates; the coordinate system on the page is set with the SetCorners method, which sets the coordinates of the corners of the canvas. (2) By default, it uses an offscreen image to draw to before putting anything on the screen. Furthermore, it overloads the default update() and paint() so as to avoid flicker. The reason for all of this is that is is simple to add components which involve animation or interactive motion. (3) Graphics drawing commands imitate PostScript. The basic class of things drawn is `PlotPath'. After one is instantiated, we build it with methods `moveto', `lineto', etc. and draw it with `stroke', `fill'. Coordiante systems are changed with commands `scale', `rotate', `translate'. There is no true graphics state, however; colours are used in the call directly. The class `PlotCanvas' is abstract. Extensions which are not abstract must have a method draw(), which draws paths on the offscreen image. Examples of usage are in various Applet files in this directory. Programs using this package must also use the `real' package, which has RealPoints and a few utilities for displaying real numbers.


Variable Index

 o height
 o parent
 o width

Constructor Index

 o PlotCanvas(Applet)
 o PlotCanvas(Applet, int, int)
The variables w and h determine the canvas size in pixels.

Method Index

 o boundary()
Locates corners.
 o clear()
Paints a blank canvas onto the offscreen image.
 o draw()
Draws paths onto the offscreen image.
 o drawString(String, double, double)
Uses float coordinates.
 o drawString(String, double, double, Color)
Uses float coordinates.
 o drawString(String, RealPoint)
Uses float coordinates.
 o drawString(String, RealPoint, Color)
 o interp(double, double, double)
A utility for animation.
 o isVisible(double, double)
Returns true if visible on the screen.
 o isVisible(Point)
Returns true if visible on the screen.
 o isVisible(RealPoint)
Returns true if visible on the screen.
 o paint(Graphics)
Reverses the normal ordering of paint() and update(0 for flicker-free performance.
 o pixel()
A RealRectangle holds four real points.
 o rotate(double)
Follows PostScript model.
 o scale(double, double)
Follows PostScript model.
 o setColor(Color)
 o setCorners(double, double, double, double)
The point (llx, lly) becomes lower left, (urx, ury) upper right.
 o setCorners(double, double, double, double, int, int)
Allows a margin.
 o setFont(Font)
 o toPoint(double, double)
Returns pixel with coordinates (x, y).
 o toPoint(RealPoint)
Returns pixel with coordinates P.
 o toRealPoint(int, int)
Pixels to floating point coordinates.
 o toRealPoint(Point)
Pixels to floating point coordinates.
 o translate(double, double)
Follows PostScript model.
 o update(Graphics)
Clears the offscreen image, draws into it, and blips it onto the screen.
 o zoom(double, double, RealPoint)
 o zoom(double, RealPoint)

Variables

 o width
 public int width
 o height
 public int height
 o parent
 public Applet parent

Constructors

 o PlotCanvas
 public PlotCanvas(Applet app)
 o PlotCanvas
 public PlotCanvas(Applet app,
                   int w,
                   int h)
The variables w and h determine the canvas size in pixels. There is a minor problem in aranging the canvas in the applet, that often causes things to be offset vertically by five pixels, so an undrsired boundary strip appears at the top.

Methods

 o setCorners
 public void setCorners(double llx,
                        double lly,
                        double urx,
                        double ury)
The point (llx, lly) becomes lower left, (urx, ury) upper right.

 o setCorners
 public void setCorners(double llx,
                        double lly,
                        double urx,
                        double ury,
                        int xmargin,
                        int ymargin)
Allows a margin.

 o pixel
 public RealRectangle pixel()
A RealRectangle holds four real points. This returns the floating point corners of the pixel at upper left. This can be used to determine true pixel size, often important for knowing how fine-grained to do plots at.

 o boundary
 public RealRectangle boundary()
Locates corners.

 o clear
 public void clear()
Paints a blank canvas onto the offscreen image.

 o paint
 public void paint(Graphics g)
Reverses the normal ordering of paint() and update(0 for flicker-free performance.

Overrides:
paint in class Canvas
 o update
 public void update(Graphics g)
Clears the offscreen image, draws into it, and blips it onto the screen. If there are extras involved in drawing this must be overridden. For example, in animations it often pays not to draw here, because diferent backgrounds should be saved.

Overrides:
update in class Component
 o draw
 public abstract void draw()
Draws paths onto the offscreen image.

 o interp
 public static double interp(double t,
                             double x,
                             double y)
A utility for animation. Interpolates linearly, gives (1-t)x + ty.

 o toPoint
 public Point toPoint(RealPoint p)
Returns pixel with coordinates P. Coordinates can be be infinity but not NaN.

 o toPoint
 public Point toPoint(double x,
                      double y)
Returns pixel with coordinates (x, y). Coordinates can be be infinity but not NaN.

 o toRealPoint
 public RealPoint toRealPoint(Point p)
Pixels to floating point coordinates.

 o toRealPoint
 public RealPoint toRealPoint(int x,
                              int y)
Pixels to floating point coordinates.

 o isVisible
 public boolean isVisible(double x,
                          double y)
Returns true if visible on the screen. Returns false if x or y is NaN.

 o isVisible
 public boolean isVisible(RealPoint p)
Returns true if visible on the screen. Returns false if x or y is NaN.

 o isVisible
 public boolean isVisible(Point p)
Returns true if visible on the screen.

 o scale
 public void scale(double a,
                   double b)
Follows PostScript model.

 o translate
 public void translate(double a,
                       double b)
Follows PostScript model.

 o rotate
 public void rotate(double theta)
Follows PostScript model.

 o zoom
 public void zoom(double z,
                  RealPoint t)
 o zoom
 public void zoom(double mx,
                  double my,
                  RealPoint t)
 o setFont
 public void setFont(Font f)
Overrides:
setFont in class Component
 o drawString
 public void drawString(String s,
                        RealPoint Q,
                        Color c)
 o setColor
 public void setColor(Color c)
 o drawString
 public void drawString(String s,
                        double x,
                        double y,
                        Color c)
Uses float coordinates.

 o drawString
 public void drawString(String s,
                        RealPoint Q)
Uses float coordinates.

 o drawString
 public void drawString(String s,
                        double x,
                        double y)
Uses float coordinates.


All Packages  Class Hierarchy  This Package  Previous  Next  Index