From d844256e25c588857055ab6c2655ce2c8048f136 Mon Sep 17 00:00:00 2001 From: Matthias Felleisen Date: Sat, 30 Jul 2005 16:52:06 +0000 Subject: [PATCH] - modified World so that it contains a specific Canvas deleted the canvas methods made it abstract so that programmers _must_ override the essential methods svn: r502 --- collects/htdch/draw/World-native-methods.ss | 14 +-- collects/htdch/draw/World.java | 46 +++------- collects/htdch/draw/doc.txt | 95 +++++---------------- 3 files changed, 42 insertions(+), 113 deletions(-) diff --git a/collects/htdch/draw/World-native-methods.ss b/collects/htdch/draw/World-native-methods.ss index 3dbf671719..f1c02429b6 100644 --- a/collects/htdch/draw/World-native-methods.ss +++ b/collects/htdch/draw/World-native-methods.ss @@ -35,6 +35,7 @@ (lower (cdr s)))))))) (list->string (lower (string->list s))))) +#| (define/provide (start-int-int-native this accs gets privates x y) (start x y)) @@ -69,7 +70,8 @@ (define/provide (sleepForAWhile-int-native this accs gets privates s) (sleep-for-a-while s)) - +|# + (define/provide (bigBang-double-native this accs gets privates i) (big-bang i this) (on-tick-event @@ -93,17 +95,19 @@ (define (keyevent->string ke) (if (char? ke) (string ke) (symbol->string ke))) +#| (define/provide (draw-native this accs gets privates) - #t) + (error 'draw "abstract method")) (define/provide (erase-native this accs gets privates) - #t) + (error 'erase "abstract method")) (define/provide (onTick-native this accs gets privates) - this) + (error 'onTick "abstract method")) (define/provide (onKeyEvent-java.lang.String-native this accs gets privates ke) - this) + (error 'onKeyEvent "abstract method")) +|# (define last-world #f) diff --git a/collects/htdch/draw/World.java b/collects/htdch/draw/World.java index 966d364237..03a25975a7 100644 --- a/collects/htdch/draw/World.java +++ b/collects/htdch/draw/World.java @@ -1,44 +1,22 @@ package draw; -public class World { +public abstract class World { - public native boolean start(int width, int height); + Canvas theCanvas = new Canvas(); - public native boolean stop(); + public native boolean bigBang(double s); + + public native boolean endOfTime(); + + public native World endOfWorld(); - public native boolean drawCircle(Posn p, int r, Color c); + public native World lastWorld(); - public native boolean drawDisk(Posn p, int r, Color c); + public abstract World onTick(); - public native boolean drawRect(Posn p, int width, int height, Color c); + public abstract World onKeyEvent(String ke); - public native boolean drawLine(Posn p0, Posn p1, Color c); + public abstract boolean draw(); - public native boolean drawString(Posn p, String s); - - public native boolean clearCircle(Posn p, int r, Color c); - - public native boolean clearDisk(Posn p, int r, Color c); - - public native boolean clearRect(Posn p, int width, int height, Color c); - - public native boolean clearLine(Posn p0, Posn p1, Color c); - - // public native boolean sleepForAWhile(int s); - - public native boolean bigBang(double s); - - public native World onTick(); - - public native World onKeyEvent(String ke); - - public native boolean draw(); - - public native boolean erase(); - - public native boolean endOfTime(); - - public native World endOfWorld(); - - public native World lastWorld(); + public abstract boolean erase(); } diff --git a/collects/htdch/draw/doc.txt b/collects/htdch/draw/doc.txt index fe8d08823f..ad459aea8c 100644 --- a/collects/htdch/draw/doc.txt +++ b/collects/htdch/draw/doc.txt @@ -1,7 +1,6 @@ This `draw' package provides libraries for modeling in a visual world. It consists of two sets of classes: - - World +----------+ +----------+ | World | +->| Canvas | @@ -11,70 +10,18 @@ consists of two sets of classes: +----------+ | clear | +----------+ - // start the clock and make this world the current one - boolean bigBang(double s) + - abstract class World - // process a tick of the clock in this world - World onTick() + - class Canvas - // process a keystroke event in this world - World onKeyEvent(String ke) + - class Posn - // stop this world's clock - World endOfWorld() - - // draw this world - boolean draw() - - // erase this world - boolean erase() - - // view the last World that onTick or onKeyEvent or bigBang created - World lastWorld() - - - Canvas - - // create the visual aspect - boolean start(int width, int height) - - // tear down the canvas and shut down the program - boolean stop() - - // draw a circle at p, paint circle c - boolean drawCircle(Posn p, int r, Color c) - - // draw a solid disk at p, fill with color c - boolean drawDisk(Posn p, int r, Color c) - - // draw a width x height rectangle at p, fill with color c - boolean drawRect(Posn p, int width, int height, Color c) - - // draw a line from p0 to p1, use color c - boolean drawLine(Posn p0, Posn p1, Color c) - - // draw a string at position p - boolean drawString(Posn p, String s) - - // clear a circle at p, paint circle c - boolean clearCircle(Posn p, int r, Color c) - - // clear a solid disk at p, fill with color c - boolean clearDisk(Posn p, int r, Color c) - - // clear a width x height rectangle at p, fill with color c - boolean clearRect(Posn p, int width, int height, Color c) - - // clear a line from p0 to p1, use color c - boolean clearLine(Posn p0, Posn p1, Color c) - - - Posn - - +----------+ - | Posn | - +----------+ - | int x | - | int y | - +----------+ + +----------+ + | Posn | + +----------+ + | int x | + | int y | + +----------+ - Color with five subclasses: + Blue @@ -83,16 +30,16 @@ consists of two sets of classes: + White + Yellow - +-------+ - | Color | - +-------+ - | - / \ - --- - | - ------------------------------------------ - | | | | | -+-------+ +-------+ +-------+ +-------+ +-------+ -| Blue | | Green | | Red | | White | | Yellow| -+-------+ +-------+ +-------+ +-------+ +-------+ + +-------+ + | Color | + +-------+ + | + / \ + --- + | + ------------------------------------------ + | | | | | + +-------+ +-------+ +-------+ +-------+ +-------+ + | Blue | | Green | | Red | | White | | Yellow| + +-------+ +-------+ +-------+ +-------+ +-------+