uchicago.src.sim.gui
Class Painter

java.lang.Object
  extended by uchicago.src.sim.gui.Painter
Direct Known Subclasses:
DummyPainter, LocalPainter

public abstract class Painter
extends java.lang.Object

Abstract class for local and remote painting objects that do the actual work of getting Displayables to paint themselves. Used by DisplaySurface.

Version:
$Revision: 1.9 $ $Date: 2004/11/03 19:50:59 $
Author:
Nick Collier
See Also:
LocalPainter

Field Summary
protected  java.awt.Color bgColor
           
protected  java.awt.image.BufferedImage buffImage
           
protected  java.util.ArrayList displayables
           
protected  java.awt.Graphics2D g2
           
protected  int height
           
protected  java.util.ArrayList orderedDisplayables
           
protected  float origHeight
           
protected  float origWidth
           
protected  SimGraphics simGraphics
           
protected  DisplaySurface surface
           
protected  java.awt.Toolkit toolkit
           
protected  int width
           
 
Constructor Summary
Painter()
          Creates a Painter.
Painter(DisplaySurface s, int w, int h)
          Creates a Painter using the specified displaySurface, and with the specified width and height.
 
Method Summary
 void addDisplayable(Displayable d)
          Adds a Displayable to the list of displayables to be displayed.
 void addDisplayable(DisplaySurface.DisplayableOrder displayableOrder)
          Addes a displayable order to the list of ordered displayables.
protected  void createBufferedImage()
          Creates a BufferedImage for use by sub class painters.
protected  void createGraphics2D()
          Creates and sets the drawing context.
 void dispose()
          Disposes of the graphics object
abstract  void drawRect(java.awt.Graphics g, int left, int top, int width, int height)
           
abstract  void eraseRect(java.awt.Graphics g)
           
 void finalize()
           
 java.awt.Image getCurrentImage()
          Gets the current BufferedImage
 java.awt.Graphics2D getGraphics()
          Gets the graphics context on which to draw.
 void init(DisplaySurface s, int w, int h)
          Associates this Painter with the specified DisplaySurface and initializes the width and height.
abstract  void paint(java.awt.Graphics g)
          Paints the displayables.
protected  void paintBackground()
          Paints the background to the currently specified color.
 void removeDisplayable(Displayable d)
          Removes a Displayable to the list of displayables to be displayed.
 void reSize(int newWidth, int newHeight)
          Resizes the buffered image on which all drawing is done to the specified newWidth and height
 void setBackgroundColor(java.awt.Color c)
          Sets the background color.
abstract  void takeSnapshot(java.io.DataOutputStream os)
          Takes a snapshot of the current screen image.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

orderedDisplayables

protected java.util.ArrayList orderedDisplayables

surface

protected DisplaySurface surface

buffImage

protected java.awt.image.BufferedImage buffImage

g2

protected java.awt.Graphics2D g2

width

protected int width

height

protected int height

origWidth

protected float origWidth

origHeight

protected float origHeight

displayables

protected java.util.ArrayList displayables

simGraphics

protected SimGraphics simGraphics

toolkit

protected java.awt.Toolkit toolkit

bgColor

protected java.awt.Color bgColor
Constructor Detail

Painter

public Painter()
Creates a Painter. Before this Painter can be used its init method must be called. This will done automatically by the DisplaySurface if this Painter is an argument to a DisplaySurface's constructor.


Painter

public Painter(DisplaySurface s,
               int w,
               int h)
Creates a Painter using the specified displaySurface, and with the specified width and height.

Parameters:
s - the displaySurface associated with this Painter
w - the width of the painter
h - the height of the painter
Method Detail

init

public void init(DisplaySurface s,
                 int w,
                 int h)
Associates this Painter with the specified DisplaySurface and initializes the width and height. This can be used in conjunction with the no-arg constructor to complete the construction of a Painter in situations when creating a DisplaySurface that takes a Painter as part of its construction. In these cases, the DisplaySurface will call this init method.

Parameters:
s - the displaySurface associated with this Painter
w - the width of the painter
h - the height of the painter

createBufferedImage

protected void createBufferedImage()
Creates a BufferedImage for use by sub class painters.


reSize

public void reSize(int newWidth,
                   int newHeight)
Resizes the buffered image on which all drawing is done to the specified newWidth and height

Parameters:
newWidth - the newWidth of the new buffered image
newHeight - the height of the new buffered image

createGraphics2D

protected void createGraphics2D()
Creates and sets the drawing context.


addDisplayable

public void addDisplayable(Displayable d)
Adds a Displayable to the list of displayables to be displayed.

Parameters:
d - the displayable to add

addDisplayable

public void addDisplayable(DisplaySurface.DisplayableOrder displayableOrder)
Addes a displayable order to the list of ordered displayables.

Parameters:
displayableOrder - the DisplayableOrder to add

removeDisplayable

public void removeDisplayable(Displayable d)
Removes a Displayable to the list of displayables to be displayed.

Parameters:
d - the displayable to remove

getGraphics

public java.awt.Graphics2D getGraphics()
Gets the graphics context on which to draw.


paint

public abstract void paint(java.awt.Graphics g)
Paints the displayables.


drawRect

public abstract void drawRect(java.awt.Graphics g,
                              int left,
                              int top,
                              int width,
                              int height)

eraseRect

public abstract void eraseRect(java.awt.Graphics g)

finalize

public void finalize()
Overrides:
finalize in class java.lang.Object

dispose

public void dispose()
Disposes of the graphics object


setBackgroundColor

public void setBackgroundColor(java.awt.Color c)
Sets the background color.


paintBackground

protected void paintBackground()
Paints the background to the currently specified color.


takeSnapshot

public abstract void takeSnapshot(java.io.DataOutputStream os)
Takes a snapshot of the current screen image.


getCurrentImage

public java.awt.Image getCurrentImage()
Gets the current BufferedImage