uwcse.graphics
Class GWindow

java.lang.Object
  |
  +--uwcse.graphics.GWindow

public class GWindow
extends java.lang.Object

The GWindow class defines a simple graphics window. The default size is 500 by 400 pixels. A "pixel" is one "dot" on the screen. It is the smallest unit that can be displayed on a window. The coordinate system is x and y, where x and y are offsets from the upper left corner of the window. (Note the y coordinate grows positively in the downward direction -- which is different from the traditional Cartesian coordinate system.)

The GWindow supports two modes of displaying objects. In the first, using the add() and remove() operations, a GWindow maintains a collection of Shape objects. When the GWindow paints itself, it paints each of its shape objects, in the order in which they are added. Shapes obscure other shapes, depending upon the order of their addition (and their position); a shape added later overpaints shapes added earlier.

In the second, using the display() method, the GWindow keeps a list of objects to be displayed. The next time the window repaints itself, all objects in the list are displayed, and then discarded. This mode is used in the (old) simulation framework.


Constructor Summary
GWindow()
          Create a new window, with default name and size.
GWindow(AppletGWindow appletGWindow)
          Create a new window interface to use for an applet
GWindow(int width, int height)
          Create a new window of the given dimensions.
GWindow(java.lang.String name)
          Create a new window of the default size.
GWindow(java.lang.String name, int width, int height)
          Create a new window of the given name and dimensions.
 
Method Summary
 boolean add(Shape s)
          Add the given shape and paint it onto the screen.
 void addEventHandler(GWindowEventHandler handler)
          Add the given event handler.
 void display(Shape s)
          Simply adds this shape to the to-be-displayed queue.
 void dispose()
          Close the window.
 void doRepaint()
          Update the screen, if updates aren't suspended.
 void erase()
          Discards all of the shape objects and clears the screen.
 GWindowEventHandler getEventHandler()
          Answer the current event handler.
 java.awt.Image getImageFromFilename(java.lang.String imageName)
          Create and return a new Image, given the filename of the image.
 java.awt.Image getImageFromURL(java.lang.String imageURL)
          Create and return a new Image, given the URL of the image.
 int getWindowHeight()
          Return the height of the drawing area of the window (ignoring title bar, borders, etc.)
 int getWindowWidth()
          Return the width of the drawing area of the window (ignoring title bar, borders, etc.)
 Shape intersects(Shape aShape)
          Return the shape that the argument shape intersects with, or null if none.
static void main(java.lang.String[] args)
           
 void moveAllBy(int deltaX, int deltaY)
          Translate the position of every object by the given deltas, and repaint the screen.
 void print(java.lang.String msg)
          Display a dialog message in a pop-up window.
 boolean remove(Shape s)
          Remove the given shape and repaint the screen.
 void resumeRepaints()
          Resume repaints.
 void setExitOnClose()
          If this is called, the application will exit when a GWindow is closed.
static void showColorTable()
          Opens a color picker application.
 void startTimerEvents(int intervalInMSecs)
          Start delivering timer events to the GWindow.
 void stopTimerEvents()
          Stop delivering timer events to the GWindow.
 void suspendRepaints()
          Suspend repaints.
 java.lang.String toString()
           
 double version()
          Answer the version number.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GWindow

public GWindow()
Create a new window, with default name and size.

GWindow

public GWindow(AppletGWindow appletGWindow)
Create a new window interface to use for an applet
Parameters:
appletGWindow - the AppletGWindow object

GWindow

public GWindow(int width,
               int height)
Create a new window of the given dimensions.
Parameters:
width - the initial width of the window, in pixels
height - the initial height of the window, in pixels

GWindow

public GWindow(java.lang.String name)
Create a new window of the default size.
Parameters:
name - the title of the window

GWindow

public GWindow(java.lang.String name,
               int width,
               int height)
Create a new window of the given name and dimensions.
Parameters:
name - the title of the window
width - the initial width of the window, in pixels
height - the initial height of the window, in pixels
Method Detail

add

public boolean add(Shape s)
Add the given shape and paint it onto the screen.
Parameters:
s - a shape object (Rectangle, etc)
Returns:
true if the shape was actually added (a shape is only added if it hasn't already been added)

addEventHandler

public void addEventHandler(GWindowEventHandler handler)
Add the given event handler. Right now, only one handler may exist at a time.

display

public void display(Shape s)
Simply adds this shape to the to-be-displayed queue.

dispose

public void dispose()
Close the window.

doRepaint

public void doRepaint()
Update the screen, if updates aren't suspended. This is the operation that other classes should invoke if they've done something to a graphical shape that might change its appearance.

erase

public void erase()
Discards all of the shape objects and clears the screen.

getEventHandler

public GWindowEventHandler getEventHandler()
Answer the current event handler.

getImageFromFilename

public java.awt.Image getImageFromFilename(java.lang.String imageName)
Create and return a new Image, given the filename of the image.
Parameters:
imageName - the filename containing the image

getImageFromURL

public java.awt.Image getImageFromURL(java.lang.String imageURL)
Create and return a new Image, given the URL of the image.
Parameters:
imageURL - the URL containing the image

getWindowHeight

public int getWindowHeight()
Return the height of the drawing area of the window (ignoring title bar, borders, etc.)

getWindowWidth

public int getWindowWidth()
Return the width of the drawing area of the window (ignoring title bar, borders, etc.)

intersects

public Shape intersects(Shape aShape)
Return the shape that the argument shape intersects with, or null if none.
Parameters:
aShape - the shape to test intersection against
Returns:
the shape that aStape intersects, or null if no shapes intersect aShape

main

public static void main(java.lang.String[] args)

moveAllBy

public void moveAllBy(int deltaX,
                      int deltaY)
Translate the position of every object by the given deltas, and repaint the screen.
Parameters:
x - the deltaX
y - the deltaY

print

public void print(java.lang.String msg)
Display a dialog message in a pop-up window.
Parameters:
msg - the message to display

remove

public boolean remove(Shape s)
Remove the given shape and repaint the screen.
Parameters:
s - a shape object (Rectangle, etc)
Returns:
true if the shape was actually removed, false if not

resumeRepaints

public void resumeRepaints()
Resume repaints.

setExitOnClose

public void setExitOnClose()
If this is called, the application will exit when a GWindow is closed.

showColorTable

public static void showColorTable()
Opens a color picker application. Click on the color in the window and the console will show the color you have chosen.

startTimerEvents

public void startTimerEvents(int intervalInMSecs)
Start delivering timer events to the GWindow.

stopTimerEvents

public void stopTimerEvents()
Stop delivering timer events to the GWindow.

suspendRepaints

public void suspendRepaints()
Suspend repaints. This can be called before doing a whole bunch of updates to shapes, so that each change doesn't appear on the screen. Then resumeRepaints can be called, to do all the repainting in one step.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

version

public double version()
Answer the version number.