RePast
v. 2.0

uchicago.src.sim.gui
Class DisplaySurface

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--uchicago.src.sim.gui.DisplaySurface
All Implemented Interfaces:
ComponentListener, EventListener, ImageObserver, MediaProducer, MenuContainer, Serializable, SimEventListener

public class DisplaySurface
extends JComponent
implements SimEventListener, MediaProducer, ComponentListener

See Also:
Serialized Form

Field Summary
protected  JMenuBar bar
          The menu bar for the DisplaySurface JFrame
protected  Dimension defaultSize
           
protected  Hashtable displays
          Dictionary of the Displays contained by this DisplaySurface.
protected  MouseInputAdapter dsMouseAdapter
           
protected  WindowAdapter dsWindowAdapter
           
protected  JFrame frame
          The JFrame in which this DisplaySurface is displayed.
protected  ArrayList keyListeners
          List of keyListeners for this DisplaySurface.
protected  Legend legend
           
protected  Point location
           
protected  JMenu menu
          The option menu.
protected  SimModel model
          The model associated with this display surface.
protected  boolean mousePressed
          This is set to true via a mouse motion listener on the frame.
protected  MovieMaker movieMaker
           
protected  String name
          The name of this display.
protected  boolean needsUpdate
          Whether or not this DisplaySurface needs to be updated.
protected  Painter painter
          The Painter used by this DisplaySurface to do the actual drawing.
protected  ArrayList probeables
          List of probeable displays.
protected  Dimension size
           
protected  String snapshotFile
          Filename for snapshots taken of this display surface.
protected  ArrayList zoomables
           
protected  uchicago.src.sim.gui.DisplaySurface.Rect zoomRect
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface uchicago.src.sim.gui.MediaProducer
MPEG, QUICK_TIME
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
DisplaySurface(Dimension size, SimModel model, String name)
          Creates a DisplaySurface of the specified size and with the specified model and the specified name.
DisplaySurface(SimModel model, String name)
          Creates a DisplaySurface for the specified model and with the specified name.
DisplaySurface(SimModel model, String name, Painter painter)
          Creates a DisplaySurface for the specified model, with the specified name and using the specified Painter.
 
Method Summary
 void addDisplayable(Displayable display, String name)
          Adds a Displayable to the list of displayables that are displayed when updateDisplay is called.
 void addDisplayableProbeable(Displayable display, String name)
          Adds the specified Displayable to the displayables list and the probeables list.
 void addKeyListener(KeyListener listener)
           
 void addLegendLabel(String label, int iconType, Color color, boolean hollow)
           
 void addLegendLabel(String label, int iconType, Color color, boolean hollow, int iconWidth, int iconHeight)
           
 void addMovieFrame()
          Adds the currently displayed image as frame to a movie.
 void addProbeable(Probeable probeable)
          Adds the specified Probeable to the list of probeables.
 void addZoomable(Zoomable zoomable)
           
 void closeMovie()
          Closes the movie, writing any remaining frames to the file.
 void componentHidden(ComponentEvent e)
           
 void componentMoved(ComponentEvent e)
           
 void componentResized(ComponentEvent e)
           
 void componentShown(ComponentEvent e)
           
 void createLegend(String title)
           
 void display()
          Displays this DisplaySurface, that is, makes it visible on the screen in a JFrame etc.
 void dispose()
          Dispose this DisplaySurface
 JFrame getFrame()
          Returns the JFrame for this DisplaySurface.
 JMenu getOptionsMenu()
          Returns the options menu for this DisplaySurface.
 Dimension getPreferredSize()
          Gets the preferred size of this DisplaySurface.
 boolean isFrameVisible()
           
 void paint(Graphics g)
          Paints this surface.
 void paintAll(Graphics g)
           
 void paintComponents(Graphics g)
           
 void removeDisplayable(Displayable display)
          Removes the specified Displayable from the list of displayables to display
 void removeProbeable(Probeable probeable)
          Removes the specified Probeable from the list of probeables.
 void removeProbeableDisplayable(Displayable display)
          Removes the specified Displayable from the ist of displayables to display.
 void setBackground(Color c)
          Sets the background color for this display
 void setLocation(int x, int y)
          Sets the screen location for this OpenGraph.
 void setMovieName(String fileName, String movieType)
          Sets the name and type of a movie.
 void setSnapshotFileName(String fileName)
          Sets the snapshot file name.
 void simEventPerformed(SimEvent evt)
          Repaints the display on a pause or a stop event.
 void takeSnapshot()
          Takes a snapshot of the current displayed image and writes it to the file specified by setSnapshotFileName(String fileName).
 void update(Graphics g)
           
 void updateDisplay()
          Updates the display.
 void updateDisplayDirect()
          Updates the display.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

painter

protected Painter painter
The Painter used by this DisplaySurface to do the actual drawing.


probeables

protected ArrayList probeables
List of probeable displays.


frame

protected JFrame frame
The JFrame in which this DisplaySurface is displayed.


needsUpdate

protected boolean needsUpdate
Whether or not this DisplaySurface needs to be updated.


snapshotFile

protected String snapshotFile
Filename for snapshots taken of this display surface.


model

protected SimModel model
The model associated with this display surface.


displays

protected Hashtable displays
Dictionary of the Displays contained by this DisplaySurface. The menu text associated with the display is the key and the display itself is the value.


menu

protected JMenu menu
The option menu.


bar

protected JMenuBar bar
The menu bar for the DisplaySurface JFrame


name

protected String name
The name of this display.


movieMaker

protected MovieMaker movieMaker

legend

protected Legend legend

keyListeners

protected ArrayList keyListeners
List of keyListeners for this DisplaySurface.


zoomables

protected ArrayList zoomables

location

protected Point location

size

protected Dimension size

defaultSize

protected Dimension defaultSize

mousePressed

protected boolean mousePressed
This is set to true via a mouse motion listener on the frame.


zoomRect

protected uchicago.src.sim.gui.DisplaySurface.Rect zoomRect

dsWindowAdapter

protected WindowAdapter dsWindowAdapter

dsMouseAdapter

protected MouseInputAdapter dsMouseAdapter
Constructor Detail

DisplaySurface

public DisplaySurface(Dimension size,
                      SimModel model,
                      String name)
Creates a DisplaySurface of the specified size and with the specified model and the specified name. The size of the display surface should be equal to the size of the largest displayable is going to display. For example,
Object2DDisplay display = new Object2DDisplay(someGrid);
DisplaySurface ds = new DisplaySurface(display.getSize(), someModel, "Display");
. The name appears in the title bar of the actual screen window that contains the display.

Parameters:
size - the size of the DisplaySurface
model - the model associated with this display surface
name - the name that appears in the title bar of the physical display

DisplaySurface

public DisplaySurface(SimModel model,
                      String name,
                      Painter painter)
Creates a DisplaySurface for the specified model, with the specified name and using the specified Painter. The name appears in the title bar of the actual screen window that contains the display.

Note that specifying your own Painter is an advanced feature and shouldn't be done unless you know what you are doing. Of course, if you've written your own Painter then you probably do.

Parameters:
model - the model associated with this display surface
name - the name that appears in the title bar of the physical display
painter - the Painter object used to do the actual painting of the Displayables contained by this DisplaySurface.

DisplaySurface

public DisplaySurface(SimModel model,
                      String name)
Creates a DisplaySurface for the specified model and with the specified name. The name appears in the title bar of the actual screen window that contains the display.

Parameters:
model - the model associated with this display surface
name - the name that appears in the title bar of the physical display
Method Detail

setBackground

public void setBackground(Color c)
Sets the background color for this display

Overrides:
setBackground in class JComponent
Parameters:
c - the background color

addDisplayable

public void addDisplayable(Displayable display,
                           String name)
Adds a Displayable to the list of displayables that are displayed when updateDisplay is called.

Parameters:
display - the displayable to add
name - the name of the displayable (is shown under the view menu)

removeDisplayable

public void removeDisplayable(Displayable display)
Removes the specified Displayable from the list of displayables to display

Parameters:
display - the displayable to remove

addProbeable

public void addProbeable(Probeable probeable)
Adds the specified Probeable to the list of probeables.

Parameters:
probeable - the probeable to add

removeProbeable

public void removeProbeable(Probeable probeable)
Removes the specified Probeable from the list of probeables.

Parameters:
probeable - the probeable to remove

removeProbeableDisplayable

public void removeProbeableDisplayable(Displayable display)
Removes the specified Displayable from the ist of displayables to display. If this Displayable is also a Probeable it is removed from that list as well.

Parameters:
display - the Displayable to remove

addZoomable

public void addZoomable(Zoomable zoomable)

addDisplayableProbeable

public void addDisplayableProbeable(Displayable display,
                                    String name)
Adds the specified Displayable to the displayables list and the probeables list.

Parameters:
display - the Displayable to add to this to DisplaySurface.
name - the name of the displayable to add. Name will be shown on the view menu
Throws:
IllegalArgumentException - if the specified object is not a probable and a displayable

updateDisplay

public void updateDisplay()
Updates the display. Painting all the displayables to the screen. This method is typically added to the schedule with an interval of however often the user wants the display to refresh.


updateDisplayDirect

public void updateDisplayDirect()
Updates the display. Painting all the displayables to the screen. Use this when you want to update the display in response to a gui event: button press, key typed, etc. Use updateDisplay to update the display from within your model.


paint

public void paint(Graphics g)
Paints this surface.

Overrides:
paint in class JComponent

paintComponents

public void paintComponents(Graphics g)
Overrides:
paintComponents in class Container

paintAll

public void paintAll(Graphics g)
Overrides:
paintAll in class Component

update

public void update(Graphics g)
Overrides:
update in class JComponent

isFrameVisible

public boolean isFrameVisible()

setLocation

public void setLocation(int x,
                        int y)
Sets the screen location for this OpenGraph.

Overrides:
setLocation in class Component
Parameters:
x - the x screen coordinate
y - the y screen coordinate

display

public void display()
Displays this DisplaySurface, that is, makes it visible on the screen in a JFrame etc.


dispose

public void dispose()
Dispose this DisplaySurface


createLegend

public void createLegend(String title)

addLegendLabel

public void addLegendLabel(String label,
                           int iconType,
                           Color color,
                           boolean hollow)

addLegendLabel

public void addLegendLabel(String label,
                           int iconType,
                           Color color,
                           boolean hollow,
                           int iconWidth,
                           int iconHeight)

setMovieName

public void setMovieName(String fileName,
                         String movieType)
Sets the name and type of a movie. Currently type can only be DisplaySurface.QUICK_TIME.

Specified by:
setMovieName in interface MediaProducer
Parameters:
fileName - the name of the movie
movieType - the type of movie (e.g. DisplaySurface.QUICK_TIME)

addMovieFrame

public void addMovieFrame()
Adds the currently displayed image as frame to a movie. setMovieName must be called before this method is called.

Specified by:
addMovieFrame in interface MediaProducer

closeMovie

public void closeMovie()
Closes the movie, writing any remaining frames to the file. This must be called if making a movie.

Specified by:
closeMovie in interface MediaProducer

getOptionsMenu

public JMenu getOptionsMenu()
Returns the options menu for this DisplaySurface.


getFrame

public JFrame getFrame()
Returns the JFrame for this DisplaySurface.


setSnapshotFileName

public void setSnapshotFileName(String fileName)
Sets the snapshot file name.

Specified by:
setSnapshotFileName in interface MediaProducer
Parameters:
fileName - then file name to record to image to.

takeSnapshot

public void takeSnapshot()
Takes a snapshot of the current displayed image and writes it to the file specified by setSnapshotFileName(String fileName). The name of the file has the tickcount appended to it, as well as an appropriate extension. For example, a fileName of 'SugarScape', and calling takeSnapShot every 25 ticks would generate files like the following: SugarScape25.gif, SugarScape50.gif, and so on.

Specified by:
takeSnapshot in interface MediaProducer

getPreferredSize

public Dimension getPreferredSize()
Gets the preferred size of this DisplaySurface.

Overrides:
getPreferredSize in class JComponent

addKeyListener

public void addKeyListener(KeyListener listener)
Overrides:
addKeyListener in class Component

simEventPerformed

public void simEventPerformed(SimEvent evt)
Repaints the display on a pause or a stop event. Consequently, adding a DisplaySurface as SimEventListener to a SimModel causes the display to update whenever a simulation run is paused or stopped.

Specified by:
simEventPerformed in interface SimEventListener

componentShown

public void componentShown(ComponentEvent e)
Specified by:
componentShown in interface ComponentListener

componentHidden

public void componentHidden(ComponentEvent e)
Specified by:
componentHidden in interface ComponentListener

componentMoved

public void componentMoved(ComponentEvent e)
Specified by:
componentMoved in interface ComponentListener

componentResized

public void componentResized(ComponentEvent e)
Specified by:
componentResized in interface ComponentListener

RePast
v. 2.0

Bug reports and feature requests to RePast