org.ascape.view.vis
Class PanelView

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by org.ascape.view.vis.PanelView
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.accessibility.Accessible, ScapeListener, HasName, ComponentView
Direct Known Subclasses:
AgentSelectionView, BaseCustomizer, BatchView, BufferView, ChartView, Navigator, ScapeTransitionPanelView, SearchView, SimpleControlView

public class PanelView
extends javax.swing.JPanel
implements ComponentView, java.io.Externalizable

A base class for a panel that acts as an observer of scapes. Provides notification of scape updates.

Since:
1.0
Version:
2.9
Author:
Miles Parker
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  ComponentViewDelegate delegate
          The delegate.
protected  int iterationsPerRedraw
          Specifies the number of updates that occur between each draw.
protected  java.lang.String name
          The name of the view.
protected  Scape scape
          The scape being viewed.
 
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 java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
PanelView()
          Constructs a panel view.
PanelView(java.lang.String name)
          Constructs a panel view.
 
Method Summary
 void build()
          Called to create and layout the components of the component view, once the view's scape has been created.
 java.lang.Object clone()
          Clones this object.
 void environmentQuiting(ScapeEvent scapeEvent)
          Method called when the environment quits.
 void forceScapeNotify()
          Forces the view to notify its scape.
 ComponentViewDelegate getDelegate()
          Gets the delegate.
 javax.swing.ImageIcon getIcon()
          Return an icon that can be used to represent this frame.
 int getIterationsPerRedraw()
          Returns the number of iterations that occur before the view is updated.
 java.lang.String getName()
          Returns a name for the view as defined by set name.
 java.awt.Dimension getPreferredSizeWithin(java.awt.Dimension d)
          Default behavior for a component.
 Scape getScape()
          Returns the scape this canvas views.
 ViewFrameBridge getViewFrame()
          Returns the frame this view occupies, null if none.
 void iconUpdated()
          Should be called when the view has updated itself in a way that changes icon.
 boolean isGraphic()
          Returns true; this is a GUI view.
 boolean isLifeOfScape()
          Returns true (default) if the listener is intended to be used only for the current scape; typical of all but control related listeners.
 void notifyScapeUpdated()
          Called to notify the parent scape that the view has been updated.
 void onChangeIterationsPerRedraw()
          Called when the scape requests a change to iterations per redraw.
 void paintComponent(java.awt.Graphics g)
          Paints the panel.
 void readExternal(java.io.ObjectInput in)
          The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays.
 void scapeAdded(ScapeEvent scapeEvent)
          Notifies the listener that the scape has added it.
 void scapeClosing(ScapeEvent scapeEvent)
          Method called when the scape is closed.
 void scapeDeserialized(ScapeEvent scapeEvent)
          Method called once a model is deserialized.
 void scapeInitialized(ScapeEvent scapeEvent)
          Method called when the scape is initialized.
 void scapeIterated(ScapeEvent scapeEvent)
          Called when scape is iterated.
 void scapeNotification(ScapeEvent scapeEvent)
          Notifies this view that something has happened on the scape.
 void scapeRemoved(ScapeEvent scapeEvent)
          Notifies the listener that the scape has removed it.
 void scapeSetup(ScapeEvent scapeEvent)
          Method called when the scape is ready for setup.
 void scapeStarted(ScapeEvent scapeEvent)
          Method called when the scape is started.
 void scapeStopped(ScapeEvent scapeEvent)
          Method called when the scape is stopped.
 void setDelegate(ComponentViewDelegate delegate)
          Sets the delegate.
 void setIterationsPerRedraw(int iterationsPerRedraw)
          Sets the number of iterations that occur before the view is updated.
 void setMovieRecorder(MovieRecorder recorder)
          Sets the recorder that can be used to record the graphics of this view.
 void setName(java.lang.String name)
          Sets the name of this view.
 void setViewFrame(ViewFrameBridge frame)
          Sets the frame this view appears in.
 java.lang.String toString()
          Returns a short description of this view.
 void updateScapeGraphics()
          Called when scape reports an update event.
 void writeExternal(java.io.ObjectOutput out)
          The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setSize, setSize, show, show, size, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

scape

protected Scape scape
The scape being viewed.


delegate

protected ComponentViewDelegate delegate
The delegate.


iterationsPerRedraw

protected int iterationsPerRedraw
Specifies the number of updates that occur between each draw. Default is 1, so that every update is drawn.


name

protected java.lang.String name
The name of the view.

Constructor Detail

PanelView

public PanelView()
Constructs a panel view.


PanelView

public PanelView(java.lang.String name)
Constructs a panel view.

Parameters:
name - a user relevant name for this view
Method Detail

build

public void build()
Called to create and layout the components of the component view, once the view's scape has been created.

Specified by:
build in interface ComponentView

scapeAdded

public void scapeAdded(ScapeEvent scapeEvent)
                throws java.util.TooManyListenersException
Notifies the listener that the scape has added it.

Specified by:
scapeAdded in interface ScapeListener
Parameters:
scapeEvent - the scape added notification event
Throws:
java.util.TooManyListenersException - the too many listeners exception
java.util.TooManyListenersException - on attempt to add this listener to another scape when one has already been assigned

scapeRemoved

public void scapeRemoved(ScapeEvent scapeEvent)
Notifies the listener that the scape has removed it.

Specified by:
scapeRemoved in interface ScapeListener
Parameters:
scapeEvent - the scape removed notification event
See Also:
scapeAdded

scapeNotification

public void scapeNotification(ScapeEvent scapeEvent)
Notifies this view that something has happened on the scape. This view then has a chance to update itself, and this super method then notifies the scape that the view itself has been updated. By default, calls the onStart, updateScapeGraphics, or onStop method as appropriate, and then notifies scape.

Specified by:
scapeNotification in interface ScapeListener
Parameters:
scapeEvent - a scape event update

scapeIterated

public void scapeIterated(ScapeEvent scapeEvent)
Called when scape is iterated.

Specified by:
scapeIterated in interface ScapeListener
Parameters:
scapeEvent - the scape event

scapeSetup

public void scapeSetup(ScapeEvent scapeEvent)
Method called when the scape is ready for setup.

Specified by:
scapeSetup in interface ScapeListener
Parameters:
scapeEvent - the scape event

updateScapeGraphics

public void updateScapeGraphics()
Called when scape reports an update event. (No need to call this method after updating panel.)

Specified by:
updateScapeGraphics in interface ComponentView

scapeInitialized

public void scapeInitialized(ScapeEvent scapeEvent)
Method called when the scape is initialized.

Specified by:
scapeInitialized in interface ScapeListener
Parameters:
scapeEvent - the scape event

scapeStarted

public void scapeStarted(ScapeEvent scapeEvent)
Method called when the scape is started.

Specified by:
scapeStarted in interface ScapeListener
Parameters:
scapeEvent - the scape event

scapeStopped

public void scapeStopped(ScapeEvent scapeEvent)
Method called when the scape is stopped.

Specified by:
scapeStopped in interface ScapeListener
Parameters:
scapeEvent - the scape event

scapeClosing

public void scapeClosing(ScapeEvent scapeEvent)
Method called when the scape is closed.

Specified by:
scapeClosing in interface ScapeListener
Parameters:
scapeEvent - the scape event

environmentQuiting

public void environmentQuiting(ScapeEvent scapeEvent)
Method called when the environment quits.

Specified by:
environmentQuiting in interface ScapeListener
Parameters:
scapeEvent - the scape event

onChangeIterationsPerRedraw

public void onChangeIterationsPerRedraw()
Description copied from interface: ComponentView
Called when the scape requests a change to iterations per redraw. He component may choose to ignore the request.

Specified by:
onChangeIterationsPerRedraw in interface ComponentView

scapeDeserialized

public void scapeDeserialized(ScapeEvent scapeEvent)
Method called once a model is deserialized.

Specified by:
scapeDeserialized in interface ScapeListener
Parameters:
scapeEvent - the scape event

getName

public java.lang.String getName()
Returns a name for the view as defined by set name.

Specified by:
getName in interface HasName
Overrides:
getName in class java.awt.Component
Returns:
the name

setName

public void setName(java.lang.String name)
Sets the name of this view.

Overrides:
setName in class java.awt.Component
Parameters:
name - a user relevant name for this view

setMovieRecorder

public void setMovieRecorder(MovieRecorder recorder)
Sets the recorder that can be used to record the graphics of this view. If null, do not record.

Specified by:
setMovieRecorder in interface ComponentView
Parameters:
recorder - the recorder

isGraphic

public final boolean isGraphic()
Returns true; this is a GUI view.

Specified by:
isGraphic in interface ScapeListener
Returns:
true, if is graphic

isLifeOfScape

public boolean isLifeOfScape()
Returns true (default) if the listener is intended to be used only for the current scape; typical of all but control related listeners.

Specified by:
isLifeOfScape in interface ScapeListener
Returns:
true, if is life of scape

getScape

public Scape getScape()
Returns the scape this canvas views.

Specified by:
getScape in interface ScapeListener
Specified by:
getScape in interface ComponentView
Returns:
the scape

getIterationsPerRedraw

public int getIterationsPerRedraw()
Returns the number of iterations that occur before the view is updated.

Specified by:
getIterationsPerRedraw in interface ComponentView
Returns:
the iterations per redraw

setIterationsPerRedraw

public void setIterationsPerRedraw(int iterationsPerRedraw)
Sets the number of iterations that occur before the view is updated.

Specified by:
setIterationsPerRedraw in interface ComponentView
Parameters:
iterationsPerRedraw - the number of iterations to wait between paints

getViewFrame

public ViewFrameBridge getViewFrame()
Returns the frame this view occupies, null if none.

Specified by:
getViewFrame in interface ComponentView
Returns:
the view frame

setViewFrame

public void setViewFrame(ViewFrameBridge frame)
Sets the frame this view appears in.

Specified by:
setViewFrame in interface ComponentView
Parameters:
frame - the frame

paintComponent

public void paintComponent(java.awt.Graphics g)
Paints the panel. If view is awaiting update, paint calls updated so that the scape will be notified when we are done painting. This method should rarely need to be overridden; use scapeNotification to update component state.

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - the g

notifyScapeUpdated

public void notifyScapeUpdated()
Called to notify the parent scape that the view has been updated.


writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

Specified by:
writeExternal in interface java.io.Externalizable
Parameters:
out - the stream to write the object to
Throws:
java.io.IOException - Signals that an I/O exception has occurred.
java.io.IOException - Includes any I/O exceptions that may occur

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. The readExternal method must read the values in the same sequence and with the same types as were written by writeExternal.

Specified by:
readExternal in interface java.io.Externalizable
Parameters:
in - the stream to read data from in order to restore the object
Throws:
java.io.IOException - Signals that an I/O exception has occurred.
java.lang.ClassNotFoundException - the class not found exception
java.io.IOException - if I/O errors occur
java.lang.ClassNotFoundException - If the class for an object being restored cannot be found.

clone

public java.lang.Object clone()
Clones this object.

Specified by:
clone in interface ScapeListener
Overrides:
clone in class java.lang.Object
Returns:
the object

getDelegate

public ComponentViewDelegate getDelegate()
Gets the delegate.

Returns:
the delegate

setDelegate

public void setDelegate(ComponentViewDelegate delegate)
Sets the delegate.

Parameters:
delegate - the new delegate

forceScapeNotify

public void forceScapeNotify()
Description copied from interface: ComponentView
Forces the view to notify its scape. Neccessary if the view suddenly (say by being iconfied) becomes unable to repaint itself.

Specified by:
forceScapeNotify in interface ComponentView

getPreferredSizeWithin

public java.awt.Dimension getPreferredSizeWithin(java.awt.Dimension d)
Default behavior for a component. Simply returns same size.

Specified by:
getPreferredSizeWithin in interface ComponentView
Parameters:
d - the d
Returns:
the preferred size within

getIcon

public javax.swing.ImageIcon getIcon()
Return an icon that can be used to represent this frame. Returns null in this case, use default. Implementors should specify an icon that makes sense for the view.

Specified by:
getIcon in interface ComponentView
Returns:
the icon

iconUpdated

public void iconUpdated()
Should be called when the view has updated itself in a way that changes icon.

Specified by:
iconUpdated in interface ComponentView

toString

public java.lang.String toString()
Returns a short description of this view. Sames as name unless overridden.

Overrides:
toString in class java.awt.Component
Returns:
the string


Copyright © 1998-2008 The Brookings Institution, NuTech Solutions, Metascape, LLC All Rights Reserved.