Class World

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byWorld
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, ModelDisplay, java.io.Serializable

public class World
extends javax.swing.JComponent
implements ModelDisplay

Class to represent a 2d world that can hold turtles and display them Copyright Georgia Institute of Technology 2004

Author:
Barb Ericson ericson@cc.gatech.edu
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
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.Container
 
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
World()
          Constructor that takes no arguments
World(boolean visibleFlag)
          Constructor that takes a boolean to say if this world should be visible or not
World(int w, int h)
          Constructor that takes a width and height for this world
 
Method Summary
 void addModel(java.lang.Object model)
          Method to add a model to this model displayer
 void clearBackground()
          Method to clear the background picture
 boolean containsTurtle(Turtle turtle)
          Method to check if this world contains the passed turtle
 java.awt.Graphics getGraphics()
          Method to get the graphics context for drawing on
 int getHeight()
          Method to get the height in pixels
 Turtle getLastTurtle()
          Metod to get the last turtle in this world
 Picture getPicture()
          Method to get the background picture
 java.util.Iterator getTurtleIterator()
          Method to get an iterator on the list of turtles
 java.util.List getTurtleList()
          Method to get the list of turtles in the world
 int getWidth()
          Method to get the width in pixels
 void hide()
          Method to hide the frame
 void modelChanged()
          Method that allows the model to notify the display
 void paintComponent(java.awt.Graphics g)
          Method to paint this component
 void remove(java.lang.Object model)
          Method to remove the passed object from the world
 void setAutoRepaint(boolean value)
          Method to set the automatically repaint flag
 void setPicture(Picture pict)
          Method to set the background picture
 void show()
          Method to show the frame
 java.lang.String toString()
          Method that returns information about this world in the form of a string
 
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, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, 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, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, 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, paintComponents, 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, addKeyListener, 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, 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, paintAll, 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, setLocation, setName, setSize, setSize, show, size, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

World

public World()
Constructor that takes no arguments


World

public World(boolean visibleFlag)
Constructor that takes a boolean to say if this world should be visible or not

Parameters:
visibleFlag - if true will be visible else if false will not be visible

World

public World(int w,
             int h)
Constructor that takes a width and height for this world

Parameters:
w - the width for the world
h - the height for the world
Method Detail

getGraphics

public java.awt.Graphics getGraphics()
Method to get the graphics context for drawing on

Specified by:
getGraphics in interface ModelDisplay
Returns:
the graphics context of the background picture

clearBackground

public void clearBackground()
Method to clear the background picture

Specified by:
clearBackground in interface ModelDisplay

getPicture

public Picture getPicture()
Method to get the background picture

Returns:
the background picture

setPicture

public void setPicture(Picture pict)
Method to set the background picture

Parameters:
pict - the background picture to use

paintComponent

public void paintComponent(java.awt.Graphics g)
Method to paint this component

Parameters:
g - the graphics context

getLastTurtle

public Turtle getLastTurtle()
Metod to get the last turtle in this world

Returns:
the last turtle added to this world

addModel

public void addModel(java.lang.Object model)
Method to add a model to this model displayer

Specified by:
addModel in interface ModelDisplay
Parameters:
model - the model object to add

containsTurtle

public boolean containsTurtle(Turtle turtle)
Method to check if this world contains the passed turtle

Returns:
true if there else false

remove

public void remove(java.lang.Object model)
Method to remove the passed object from the world

Specified by:
remove in interface ModelDisplay
Parameters:
model - the model object to remove

getWidth

public int getWidth()
Method to get the width in pixels

Specified by:
getWidth in interface ModelDisplay
Returns:
the width in pixels

getHeight

public int getHeight()
Method to get the height in pixels

Specified by:
getHeight in interface ModelDisplay
Returns:
the height in pixels

modelChanged

public void modelChanged()
Method that allows the model to notify the display

Specified by:
modelChanged in interface ModelDisplay

setAutoRepaint

public void setAutoRepaint(boolean value)
Method to set the automatically repaint flag

Parameters:
value - if true will auto repaint

hide

public void hide()
Method to hide the frame


show

public void show()
Method to show the frame


getTurtleList

public java.util.List getTurtleList()
Method to get the list of turtles in the world

Returns:
a list of turtles in the world

getTurtleIterator

public java.util.Iterator getTurtleIterator()
Method to get an iterator on the list of turtles

Returns:
an iterator for the list of turtles

toString

public java.lang.String toString()
Method that returns information about this world in the form of a string

Returns:
a string of information about this world