javalib.worldcanvas
Class WorldCanvas

java.lang.Object
  extended by javalib.worldcanvas.WorldCanvas

public class WorldCanvas
extends Object

Functional Canvas - allows the drawing of shapes, lines, and text in the window of the given size, window closing and re-opening.

Since:
July 12 2007, August 2, 2007, October 19, 2009
Author:
Viera K. Proulx

Field Summary
 JFrame f
          the frame that holds the canvas
protected  int height
          the height of the panel
 CanvasPanel panel
          the panel that allows us to paint graphics
protected  int width
          the width of the panel
protected  WindowAdapter winapt
          A WindowAdapter that allows us to close a window and re-open, provided there is at least one open window.
protected static int WINDOWS_OPEN
          records the number of canvases currently open
 
Constructor Summary
WorldCanvas(int width, int height)
          Create a new canvas with the default title "Canvas"
WorldCanvas(int width, int height, String title)
          Construct a new frame with the CanvasPanel panel as its component.
 
Method Summary
 void clear()
          Clear the canvas before painting the next scene
 boolean close()
          Close the window - if it is currently open, do nothing otherwise
 boolean drawImage(ImageMaker image, Posn nw)
          Draw the image provided by the ImageMaker on the Canvas at the given NW corner
 boolean drawImage(String fileName, Posn nw)
          Draw the image in the specified file at the location of the given NW corner
 boolean drawImage(WorldImage image)
          Draw the image on the Canvas at its pinhole location.
 Graphics2D getBufferGraphics()
          Returns a Graphics2D object that permits painting to the internal buffered image for this canvas.
 int getCurrentHeight()
          Get the current width of the animation window (which may have been adjusted by the user).
 int getCurrentWidth()
          Get the current width of the animation window (which may have been adjusted by the user).
 int getHeight()
          Get the initial height.
 int getWidth()
          Get the initial width.
static void main(String[] argv)
          Self test for the Canvas class
 void printCurrentFont()
           
 boolean show()
          Show the window with the canvas cleared
 String toIndentedString(String indent)
          Produce an indented String representation of this Canvas
 String toString()
          Produce a String representation of this Canvas
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

f

public transient JFrame f
the frame that holds the canvas


height

protected int height
the height of the panel


panel

public transient CanvasPanel panel
the panel that allows us to paint graphics


width

protected int width
the width of the panel


winapt

protected transient WindowAdapter winapt
A WindowAdapter that allows us to close a window and re-open, provided there is at least one open window. The program ends when all windows have been closed.


WINDOWS_OPEN

protected static int WINDOWS_OPEN
records the number of canvases currently open

Constructor Detail

WorldCanvas

public WorldCanvas(int width,
                   int height)
Create a new canvas with the default title "Canvas"

Parameters:
width - the width of the canvas
height - the height of the canvas

WorldCanvas

public WorldCanvas(int width,
                   int height,
                   String title)

Construct a new frame with the CanvasPanel panel as its component.

Parameters:
width - the width of the panel
height - the height of the panel
title - the title of the panel
Method Detail

clear

public void clear()
Clear the canvas before painting the next scene


close

public boolean close()
Close the window - if it is currently open, do nothing otherwise

Returns:
true if successfully closed, or closed already

drawImage

public boolean drawImage(ImageMaker image,
                         Posn nw)
Draw the image provided by the ImageMaker on the Canvas at the given NW corner

Parameters:
image - the image maker for the image file
nw - the NW corner for the image placement

drawImage

public boolean drawImage(String fileName,
                         Posn nw)
Draw the image in the specified file at the location of the given NW corner

Parameters:
fileName - the name of the image file
nw - the NW corner for the image placement

drawImage

public boolean drawImage(WorldImage image)
Draw the image on the Canvas at its pinhole location.

Parameters:
image - the image to be drawn
Returns:
true

getBufferGraphics

public final Graphics2D getBufferGraphics()

Returns a Graphics2D object that permits painting to the internal buffered image for this canvas.

The user should always use this object to paint to the buffer and thus indirectly modify this buffered panel.

To make painting changes to the buffer visible, the repaint() method must explicitly be called. This allows a number of painting operations to be done prior to screen repaint.


getCurrentHeight

public int getCurrentHeight()
Get the current width of the animation window (which may have been adjusted by the user).

Returns:
an int
Since:
Mar. 7, 2013

getCurrentWidth

public int getCurrentWidth()
Get the current width of the animation window (which may have been adjusted by the user).

Returns:
an int
Since:
Mar. 7, 2013

getHeight

public int getHeight()
Get the initial height.

Returns:
the height specified in the constructor.
Since:
Mar. 7, 2013

getWidth

public int getWidth()
Get the initial width.

Returns:
the width specified in the constructor.
Since:
Mar. 7, 2013

main

public static void main(String[] argv)
Self test for the Canvas class

Parameters:
argv -

printCurrentFont

public void printCurrentFont()

show

public boolean show()
Show the window with the canvas cleared

Returns:
true if successfully opened, or opened already

toIndentedString

public String toIndentedString(String indent)
Produce an indented String representation of this Canvas

Parameters:
indent - the desired indentation: ignored, because we only produce one line of text.

toString

public String toString()
Produce a String representation of this Canvas

Overrides:
toString in class Object