element
Class DrawingWindow

java.lang.Object
  |
  +--element.DrawingWindow

public class DrawingWindow
extends java.lang.Object

A simple drawing window class. Allows the programmer to construct a free standing or contained slate to draw on.


Field Summary
protected static java.awt.Graphics exampleContext
          A context for finding out information about fonts on this device.
 
Constructor Summary
DrawingWindow()
          Constructs a 200x200 standalone drawing window.
DrawingWindow(java.awt.Container c)
          Construct a 200x200 drawing window within another container.
DrawingWindow(int width, int height)
          Construct a free-standing drawing window of a particular size.
DrawingWindow(int width, int height, java.awt.Container c)
          Construct a contained drawing window of a particular size.
DrawingWindow(int width, int height, java.lang.String title)
          Construct a drawing window with a paritcular dimension and title
 
Method Summary
 char awaitKey()
          Wait for a key to be pressed.
 Pt awaitMouseClick()
          post: blocks until mouse is released
returns point of press
 Pt awaitMousePress()
          Waits for the mouse to be pressed.
 Pt awaitMouseRelease()
          Waits for the mouse to be released.
 Rect bounds()
          Determine the current size of the drawing window's canvas.
 void clear(Drawable d)
          Erases a general drawable object.
 void clearArc(int x, int y, int width, int height, int sa, int da)
          Erase a portion of an oval.
 void clearCircle(int x, int y, int radius)
          Erase the circle described by (x,y,radius)
 void clearLine(int x0, int y0, int x1, int y1)
          Erases a line from (x0,y0) to (x1,y1).
 void clearLine(Pt src, Pt dest)
          Erases a line from (x0, y0) to (x1, y1)
 void clearOval(int x, int y, int width, int height)
          Erase the oval described by the rectangle (x,y,width,height)
 void clearPt(int x, int y)
          Erases the point at (x,y).
 void clearRect(int x, int y, int width, int height)
          Erase the rectangle described by (x,y,width,height).
 void clearRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
          Erase a rounded rectangle.
 void clearText(Text t)
          Erases a positioned text element on the screen.
 void draw(Drawable d)
          Draws a general drawable object.
 void drawArc(int x, int y, int width, int height, int sa, int da)
          Draw (or invert) a portion of an oval.
 void drawCircle(int x, int y, int radius)
          Draw the circle described by (x,y,radius)
 void drawLine(int x0, int y0, int x1, int y1)
          Draws a line from (x0,y0) to (x1,y1).
 void drawLine(Pt src, Pt dest)
          Draws a line from src to dest.
 void drawOval(int x, int y, int width, int height)
          Draw the oval described by the rectangle (x,y,width,height)
 void drawPt(int x, int y)
          Draw a single point at (x,y).
 void drawRect(int x, int y, int width, int height)
          Draw the rectangle described by (x,y,width,height)
 void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
          Draw (or invert) the rounded rectangle.
 void drawString(java.lang.String s, int x, int y)
          Draws a text string at the point (x,y)
 void drawText(Text t)
          Draws a positioned text element on the screen.
 void fill(Drawable d)
          Fills in a general drawable object.
 void fillArc(int x, int y, int width, int height, int sa, int da)
          Fill (or invert) a solid portion of an oval.
 void fillCircle(int x, int y, int radius)
          Fill in (or invert) the circle described by (x,y,radius)
 void fillLine(int x0, int y0, int x1, int y1)
          Fills the line from src to dest.
 void fillLine(Pt src, Pt dest)
          Draws a line from src to dest.
 void fillOval(int x, int y, int width, int height)
          Fill the oval described by the rectangle (x,y,width,height)
 void fillPt(int x, int y)
          Fills the point at (x,y).
 void fillRect(int x, int y, int width, int height)
          Fill in the rectangle described by (x,y,width,height).
 void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)
          Fill (or invert) the rounded rectangle.
 void fillText(Text t)
          Draws a positioned text element on the screen.
 Pt getMouse()
          Get the current mouse position as a Pt.
 void hold()
          Hold the updating process until the matching release.
 void invertMode()
          Sets the drawing mode to invert the drawings on the screen.
 void line(int dx, int dy)
          Draws a line relative to the current position.
 void lineTo(int x, int y)
          Draws a line from the current position to a point (x,y).
 void lineTo(Pt p)
          Draws a line segment from the current position to p.
 boolean mousePressed()
          Return true iff the mouse is currently pressed.
 void move(int dx, int dy)
          Moves to a position relative to the current position.
 void moveTo(int x, int y)
          Moves the current position to (x,y).
 void moveTo(Pt p)
          Moves the current position to p.
 void paintMode()
          Sets the drawing mode to accumulate drawings on the screen.
 void release()
          Release the updating process, allowing real-time drawing to the window.
 void setBackground(java.awt.Color c)
          Sets the background color for the window to c.
 void setForeground(java.awt.Color c)
          Sets the foreground color for the window to c.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

exampleContext

protected static java.awt.Graphics exampleContext
A context for finding out information about fonts on this device.
Constructor Detail

DrawingWindow

public DrawingWindow()
Constructs a 200x200 standalone drawing window.

DrawingWindow

public DrawingWindow(java.awt.Container c)
Construct a 200x200 drawing window within another container. Size is only approximate, especially if the window is smaller than the container.
Parameters:
c - the container that holds the drawing window.

DrawingWindow

public DrawingWindow(int width,
                     int height)
Construct a free-standing drawing window of a particular size.
Parameters:
width - the desired width of the window.
height - the desired height of the window.

DrawingWindow

public DrawingWindow(int width,
                     int height,
                     java.awt.Container c)
Construct a contained drawing window of a particular size.
Parameters:
width - the desired width of the window
height - the desired height of the window
c - the frame/panel/applet that contains the window

DrawingWindow

public DrawingWindow(int width,
                     int height,
                     java.lang.String title)
Construct a drawing window with a paritcular dimension and title
Parameters:
width - the desired width of the window
height - the desired height of the window
title - the title of the window
Method Detail

hold

public void hold()
Hold the updating process until the matching release. May be nested.

release

public void release()
Release the updating process, allowing real-time drawing to the window. May be nested. Drawing resumes only when all holds have been released.

bounds

public Rect bounds()
Determine the current size of the drawing window's canvas.
Returns:
the rect describing the current drawing canvas size.

getMouse

public Pt getMouse()
Get the current mouse position as a Pt.
Returns:
Pt describing the current mouse position.

mousePressed

public boolean mousePressed()
Return true iff the mouse is currently pressed.
Returns:
true iff the mouse is currently pressed.

awaitMousePress

public Pt awaitMousePress()
Waits for the mouse to be pressed.
Returns:
the point of the press.

awaitMouseRelease

public Pt awaitMouseRelease()
Waits for the mouse to be released.
Returns:
the point of the mouse release.

awaitMouseClick

public Pt awaitMouseClick()
post: blocks until mouse is released
returns point of press

awaitKey

public char awaitKey()
Wait for a key to be pressed.
Returns:
the character associated with the key press.

moveTo

public void moveTo(int x,
                   int y)
Moves the current position to (x,y). No marks are made to the screen.
Parameters:
x - the new current horizontal position
y - the new current vertical position

moveTo

public void moveTo(Pt p)
Moves the current position to p. No marks are made to the screen.
Parameters:
p - the new current position.

move

public void move(int dx,
                 int dy)
Moves to a position relative to the current position. No marks are made to the screen
Parameters:
dx - the horizontal offset to the new current position.
dy - the vertical offset to the new current position.

lineTo

public void lineTo(int x,
                   int y)
Draws a line from the current position to a point (x,y). Afterwards, (x,y) becomes the new current position.
Parameters:
x - the horizontal component of the far endpoint
y - the vertical component of the far endpoint
See Also:
moveTo(int, int)

lineTo

public void lineTo(Pt p)
Draws a line segment from the current position to p. Afterwards, p becomes the new current position.
Parameters:
p - the far endpoint of the line segment.
See Also:
moveTo(int, int)

line

public void line(int dx,
                 int dy)
Draws a line relative to the current position.
Parameters:
dx - the horizontal span of the line segment
dy - the vertical span of the line segment

drawPt

public void drawPt(int x,
                   int y)
Draw a single point at (x,y). (x,y) becomes the current position.
Parameters:
x - the horizontal coordinate of the point
y - the vertical coordinate of the point

fillPt

public void fillPt(int x,
                   int y)
Fills the point at (x,y). (x,y) becomes the current position. Same as drawPt.
Parameters:
x - the horizontal coordinate of the point
y - the vertical coordinate of the point
See Also:
drawPt(int, int)

clearPt

public void clearPt(int x,
                    int y)
Erases the point at (x,y). (x,y) becomes the current position.
Parameters:
x - the horizontal coordinate of the point
y - the vertical coordinate of the point

drawLine

public void drawLine(int x0,
                     int y0,
                     int x1,
                     int y1)
Draws a line from (x0,y0) to (x1,y1).
Parameters:
x0 - the horizontal position of one end of line
y0 - the vertical position of one end of the line
x1 - the horizontal position of other end of line
y1 - the vertical position of other end of the line

drawLine

public void drawLine(Pt src,
                     Pt dest)
Draws a line from src to dest.
Parameters:
src - the beginning of the line segment
dest - the end of the line segment

fillLine

public void fillLine(int x0,
                     int y0,
                     int x1,
                     int y1)
Fills the line from src to dest.
Parameters:
x0 - the horizontal position of one end of line
y0 - the vertical position of one end of the line
x1 - the horizontal position of other end of line
y1 - the vertical position of other end of the line
See Also:
drawLine(int, int, int, int)

fillLine

public void fillLine(Pt src,
                     Pt dest)
Draws a line from src to dest.
Parameters:
src - the beginning of the line segment
dest - the end of the line segment
See Also:
drawLine(int, int, int, int)

clearLine

public void clearLine(int x0,
                      int y0,
                      int x1,
                      int y1)
Erases a line from (x0,y0) to (x1,y1).
Parameters:
x0 - the horizontal position of one end of line
y0 - the vertical position of one end of the line
x1 - the horizontal position of other end of line
y1 - the vertical position of other end of the line

clearLine

public void clearLine(Pt src,
                      Pt dest)
Erases a line from (x0, y0) to (x1, y1)
Parameters:
src - the beginning of the line segment
dest - the end of the line segment

setForeground

public void setForeground(java.awt.Color c)
Sets the foreground color for the window to c. Colors may be found in java.awt.Color
Parameters:
c - a java.awt.Color describing the color of drawing

setBackground

public void setBackground(java.awt.Color c)
Sets the background color for the window to c. Background color is used for erasing. Colors may be found in java.awt.Color
Parameters:
c - a java.awt.Color describing the color of drawing

paintMode

public void paintMode()
Sets the drawing mode to accumulate drawings on the screen. Pixels drawn on screen have color of the foreground. This is the default drawing mode.
See Also:
invertMode()

invertMode

public void invertMode()
Sets the drawing mode to invert the drawings on the screen. Pixels drawn on the screen have color that is opposite the color found on the screen beforehand.
See Also:
paintMode()

fill

public void fill(Drawable d)
Fills in a general drawable object. In invert mode, the object is inverted.
Parameters:
d - the drawable object to be filled in.

clear

public void clear(Drawable d)
Erases a general drawable object.
Parameters:
d - the drawable object to be erased.

draw

public void draw(Drawable d)
Draws a general drawable object. In invert mode, the object is inverted.
Parameters:
d - the general object to be drawn.

drawRect

public void drawRect(int x,
                     int y,
                     int width,
                     int height)
Draw the rectangle described by (x,y,width,height)
Parameters:
x - the left coordinate of the rectangle
y - the top coordinate of the rectangle
width - the width of the rectangle
height - the height of the rectangle

fillRect

public void fillRect(int x,
                     int y,
                     int width,
                     int height)
Fill in the rectangle described by (x,y,width,height).
Parameters:
x - the left coordinate of the rectangle.
y - the top coordinate of the rectangle
width - the width of the rectangle to be drawn
height - the height of the rectangle to be drawn

clearRect

public void clearRect(int x,
                      int y,
                      int width,
                      int height)
Erase the rectangle described by (x,y,width,height).
Parameters:
x - the left coordinate of the rectangle.
y - the top coordinate of the rectangle
width - the width of the rectangle to be drawn
height - the height of the rectangle to be drawn

drawRoundRect

public void drawRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
Draw (or invert) the rounded rectangle.
Parameters:
x - the left coordinate of the rounded rectangle.
y - the top coordinate of the rounded rectangle
width - the width of the rounded rectangle to be drawn
height - the height of the rounded rectangle to be drawn
arcwidth - the bounding box width of the arc used to make the corners
archeight - the bounding box height of the arc used to make the corners

fillRoundRect

public void fillRoundRect(int x,
                          int y,
                          int width,
                          int height,
                          int arcWidth,
                          int arcHeight)
Fill (or invert) the rounded rectangle.
Parameters:
x - the left coordinate of the rounded rectangle.
y - the top coordinate of the rounded rectangle
width - the width of the rounded rectangle to be drawn
height - the height of the rounded rectangle to be drawn
arcwidth - the bounding box width of the arc used to make the corners
archeight - the bounding box height of the arc used to make the corners

clearRoundRect

public void clearRoundRect(int x,
                           int y,
                           int width,
                           int height,
                           int arcWidth,
                           int arcHeight)
Erase a rounded rectangle.
Parameters:
x - the left coordinate of the rounded rectangle.
y - the top coordinate of the rounded rectangle
width - the width of the rounded rectangle to be drawn
height - the height of the rounded rectangle to be drawn
arcwidth - the bounding box width of the arc used to make the corners
archeight - the bounding box height of the arc used to make the corners

drawOval

public void drawOval(int x,
                     int y,
                     int width,
                     int height)
Draw the oval described by the rectangle (x,y,width,height)
Parameters:
x - the left coordinate of the oval
y - the top coordinate of the oval
width - the width of the oval
height - the height of the oval

fillOval

public void fillOval(int x,
                     int y,
                     int width,
                     int height)
Fill the oval described by the rectangle (x,y,width,height)
Parameters:
x - the left coordinate of the oval
y - the top coordinate of the oval
width - the width of the oval
height - the height of the oval

clearOval

public void clearOval(int x,
                      int y,
                      int width,
                      int height)
Erase the oval described by the rectangle (x,y,width,height)
Parameters:
x - the left coordinate of the oval
y - the top coordinate of the oval
width - the width of the oval
height - the height of the oval

drawCircle

public void drawCircle(int x,
                       int y,
                       int radius)
Draw the circle described by (x,y,radius)
Parameters:
x - the left coordinate of the circle
y - the top coordinate of the circle
radius - the radius of the circle

fillCircle

public void fillCircle(int x,
                       int y,
                       int radius)
Fill in (or invert) the circle described by (x,y,radius)
Parameters:
x - the left coordinate of the circle
y - the top coordinate of the circle
radius - the radius of the circle

clearCircle

public void clearCircle(int x,
                        int y,
                        int radius)
Erase the circle described by (x,y,radius)
Parameters:
x - the left coordinate of the circle
y - the top coordinate of the circle
radius - the radius of the circle

drawArc

public void drawArc(int x,
                    int y,
                    int width,
                    int height,
                    int sa,
                    int da)
Draw (or invert) a portion of an oval. All angles are measured in degrees, with zero pointing to the right, and increasing counterclockwise.
Parameters:
x - the left coordinate of the rectangle that describes the oval
y - the top coordinate of the rectangle that describes the oval
width - the width of the oval to be drawn
height - the height of the oval
sa - the starting angle of the arc
da - the angle spanned by the arc

fillArc

public void fillArc(int x,
                    int y,
                    int width,
                    int height,
                    int sa,
                    int da)
Fill (or invert) a solid portion of an oval. All angles are measured in degrees, with zero pointing to the right, and increasing counterclockwise.
Parameters:
x - the left coordinate of the rectangle that describes the oval
y - the top coordinate of the rectangle that describes the oval
width - the width of the oval to be drawn
height - the height of the oval
sa - the starting angle of the arc
da - the angle spanned by the arc

clearArc

public void clearArc(int x,
                     int y,
                     int width,
                     int height,
                     int sa,
                     int da)
Erase a portion of an oval. All angles are measured in degrees, with zero pointing to the right, and increasing counterclockwise.
Parameters:
x - the left coordinate of the rectangle that describes the oval
y - the top coordinate of the rectangle that describes the oval
width - the width of the oval to be drawn
height - the height of the oval
sa - the starting angle of the arc
da - the angle spanned by the arc

drawString

public void drawString(java.lang.String s,
                       int x,
                       int y)
Draws a text string at the point (x,y)
Parameters:
s - the text to be drawn
x - the horizontal location of the text
y - the vertical location of the text

drawText

public void drawText(Text t)
Draws a positioned text element on the screen.
Parameters:
t - a text element that describe the location of a string

fillText

public void fillText(Text t)
Draws a positioned text element on the screen.
Parameters:
t - a text element that describe the location of a string
See Also:
drawText(element.Text)

clearText

public void clearText(Text t)
Erases a positioned text element on the screen.
Parameters:
t - a text element that describe the location of a string