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.
-
height
-
-
parent
-
-
width
-
-
PlotCanvas(Applet)
-
-
PlotCanvas(Applet, int, int)
- The variables w and h determine the canvas size in pixels.
-
boundary()
- Locates corners.
-
clear()
- Paints a blank canvas onto the offscreen image.
-
draw()
- Draws paths onto the offscreen image.
-
drawString(String, double, double)
- Uses float coordinates.
-
drawString(String, double, double, Color)
- Uses float coordinates.
-
drawString(String, RealPoint)
- Uses float coordinates.
-
drawString(String, RealPoint, Color)
-
-
interp(double, double, double)
- A utility for animation.
-
isVisible(double, double)
- Returns true if visible on the screen.
-
isVisible(Point)
- Returns true if visible on the screen.
-
isVisible(RealPoint)
- Returns true if visible on the screen.
-
paint(Graphics)
- Reverses the normal ordering of paint() and
update(0 for flicker-free performance.
-
pixel()
- A RealRectangle holds four real points.
-
rotate(double)
- Follows PostScript model.
-
scale(double, double)
- Follows PostScript model.
-
setColor(Color)
-
-
setCorners(double, double, double, double)
- The point
(llx, lly) becomes lower left, (urx, ury) upper right.
-
setCorners(double, double, double, double, int, int)
- Allows a margin.
-
setFont(Font)
-
-
toPoint(double, double)
- Returns pixel with coordinates (x, y).
-
toPoint(RealPoint)
- Returns pixel with coordinates P.
-
toRealPoint(int, int)
- Pixels to floating point coordinates.
-
toRealPoint(Point)
- Pixels to floating point coordinates.
-
translate(double, double)
- Follows PostScript model.
-
update(Graphics)
- Clears the offscreen image,
draws into it, and blips it onto the screen.
-
zoom(double, double, RealPoint)
-
-
zoom(double, RealPoint)
-
width
public int width
height
public int height
parent
public Applet parent
PlotCanvas
public PlotCanvas(Applet app)
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.
setCorners
public void setCorners(double llx,
double lly,
double urx,
double ury)
- The point
(llx, lly) becomes lower left, (urx, ury) upper right.
setCorners
public void setCorners(double llx,
double lly,
double urx,
double ury,
int xmargin,
int ymargin)
- Allows a margin.
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.
boundary
public RealRectangle boundary()
- Locates corners.
clear
public void clear()
- Paints a blank canvas onto the offscreen image.
paint
public void paint(Graphics g)
- Reverses the normal ordering of paint() and
update(0 for flicker-free performance.
- Overrides:
- paint in class Canvas
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
draw
public abstract void draw()
- Draws paths onto the offscreen image.
interp
public static double interp(double t,
double x,
double y)
- A utility for animation. Interpolates linearly,
gives (1-t)x + ty.
toPoint
public Point toPoint(RealPoint p)
- Returns pixel with coordinates P.
Coordinates can be be infinity but not NaN.
toPoint
public Point toPoint(double x,
double y)
- Returns pixel with coordinates (x, y).
Coordinates can be be infinity but not NaN.
toRealPoint
public RealPoint toRealPoint(Point p)
- Pixels to floating point coordinates.
toRealPoint
public RealPoint toRealPoint(int x,
int y)
- Pixels to floating point coordinates.
isVisible
public boolean isVisible(double x,
double y)
- Returns true if visible on the screen.
Returns false if x or y is NaN.
isVisible
public boolean isVisible(RealPoint p)
- Returns true if visible on the screen.
Returns false if x or y is NaN.
isVisible
public boolean isVisible(Point p)
- Returns true if visible on the screen.
scale
public void scale(double a,
double b)
- Follows PostScript model.
translate
public void translate(double a,
double b)
- Follows PostScript model.
rotate
public void rotate(double theta)
- Follows PostScript model.
zoom
public void zoom(double z,
RealPoint t)
zoom
public void zoom(double mx,
double my,
RealPoint t)
setFont
public void setFont(Font f)
- Overrides:
- setFont in class Component
drawString
public void drawString(String s,
RealPoint Q,
Color c)
setColor
public void setColor(Color c)
drawString
public void drawString(String s,
double x,
double y,
Color c)
- Uses float coordinates.
drawString
public void drawString(String s,
RealPoint Q)
- Uses float coordinates.
drawString
public void drawString(String s,
double x,
double y)
- Uses float coordinates.
All Packages Class Hierarchy This Package Previous Next Index