svn: r6898

This commit is contained in:
Matthias Felleisen 2007-07-12 16:52:40 +00:00
parent 1162acb990
commit 39a0c69f13

View File

@ -7,6 +7,11 @@ public class Canvas {
private int width = 0; private int width = 0;
private int height = 0; private int height = 0;
/**
*@author Matthias Felleisen, Kathy Gray
*@param width positive int, the width of the visible canvas
*@param height positive int, the height of the visible canvas
*/
public Canvas(int width, int height) { public Canvas(int width, int height) {
this.width = width; this.width = width;
this.height = height; this.height = height;
@ -19,6 +24,14 @@ public class Canvas {
// directly at the Scheme level w/o going thru the Java layer. // directly at the Scheme level w/o going thru the Java layer.
private boolean showing = false; private boolean showing = false;
/**
*@return true, if it can display a white canvas
*The method initializes the canvas to a white area,
*enables the drawing methods, and finally displays the canvas. If it
*succeeds, it produces <code>true</code>. Invoking the method a second
*time without calling <code>close</code> before has no effect.
*/
public boolean show() { public boolean show() {
if (!showing) { if (!showing) {
xshow(); xshow();
@ -26,6 +39,12 @@ public class Canvas {
} }
return true; return true;
} }
/**
*@return true, if it can hide the canvas
*The method hides the canvas and erases the current content.
*/
public boolean close() { public boolean close() {
xclose(); xclose();
showing = false; showing = false;
@ -34,13 +53,64 @@ public class Canvas {
public native boolean xshow(); public native boolean xshow();
public native boolean xclose(); public native boolean xclose();
/**
*@param p the center of the circle
*@param r its radius
*@param c its outline color
*@return true, if it can draw the circle into this canvas
*/
public native boolean drawCircle(Posn p, int r, AColor c); public native boolean drawCircle(Posn p, int r, AColor c);
/**
*@param p the center of the disk
*@param r its radius
*@param c its fill and outline color
*@return true, if it can draw the disk into this canvas
*/
public native boolean drawDisk(Posn p, int r, AColor c); public native boolean drawDisk(Posn p, int r, AColor c);
/**
*@param p the upper left of the rectangle
*@param width positive int
*@param height positive int
*@param c its outline color
*@return true, if it can draw the rectangle into this canvas
*/
public native boolean drawRect(Posn p, int width, int height, AColor c); public native boolean drawRect(Posn p, int width, int height, AColor c);
/**
*@param p0 the first point on the line
*@param p1 the second point on the line
*@param c its color
*@return true, if it can draw the line into this canvas
*/
public native boolean drawLine(Posn p0, Posn p1, AColor c); public native boolean drawLine(Posn p0, Posn p1, AColor c);
/**
*@param p the position of the baseline of the string
*@param s the message to be drawn
*@return true, if it can draw the string into this canvas
*/
public native boolean drawString(Posn p, String s); public native boolean drawString(Posn p, String s);
/**
*@return true, if it can erase the specified circle from this canvas
*/
public native boolean clearCircle(Posn p, int r, AColor c); public native boolean clearCircle(Posn p, int r, AColor c);
/**
*@return true, if it can erase the specified disk from this canvas
*/
public native boolean clearDisk(Posn p, int r, AColor c); public native boolean clearDisk(Posn p, int r, AColor c);
/**
*@return true, if it can erase the specified rectangle from this canvas
*/
public native boolean clearRect(Posn p, int width, int height, AColor c); public native boolean clearRect(Posn p, int width, int height, AColor c);
/**
*@return true, if it can erase the specified string from this canvas
*/
public native boolean clearLine(Posn p0, Posn p1, AColor c); public native boolean clearLine(Posn p0, Posn p1, AColor c);
} }