org.simbrain.world.odorworld
Class OdorWorld

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.simbrain.world.World
                      extended by org.simbrain.world.odorworld.OdorWorld
All Implemented Interfaces:
ActionListener, KeyListener, MouseListener, MouseMotionListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible

public class OdorWorld
extends World
implements MouseListener, MouseMotionListener, ActionListener, KeyListener

OdorWorld is the lowest-level environment panel which contains most of the world's "logic". Creature and flower/food icons are drawn here. Movement of the mouse in response to clicks and (very minimal) world-editing features are also handled here. Finally, the stimulus to the network is calculated here, on the basis of the creature's distance from objects, as follows:

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
accessibleContext, 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
OdorWorld()
          Default constructor.
OdorWorld(OdorWorldFrame wf)
          Construct a world, set its background color.
 
Method Summary
 void actionPerformed(ActionEvent e)
          Tasks to perform when actions are performed.
 void addAgent(Point p)
          Add an agent at point p.
 void addEntity(Point p)
          Add a world object at point p.
 void addWall()
          Adds a wall to the world.
 JPopupMenu buildPopupMenu(AbstractEntity theEntity)
          Create a popup menu based on location of mouse click.
 void clear()
          Remove all objects from world.
 void clearAllEntities()
          Clears all entities from the world.
 ArrayList getAbstractEntityList()
           
 ArrayList getAgentList()
          Return the list of agents for this world.
 int getBackgroundColor()
           
 ArrayList getDeadEntityList()
           
 ArrayList getEntityList()
           
 ArrayList getEntityNames()
           
 int getHighestDimensionalStimulus()
          Go through entities in this world and find the one with the greatest number of dimensions.
 JMenu getMotorCommandMenu(ActionListener al)
          Returns a menu with the motor commands available to this agent.
 boolean getObjectDraggingInitiatesMovement()
           
 boolean getObjectInhibitsMovement()
           
 int getObjectSize()
           
 OdorWorldFrame getParentFrame()
           
 Workspace getParentWorkspace()
          Return the parent workspace.
 AbstractEntity getSelectedEntity()
           
 JMenu getSensorIdMenu(ActionListener al)
          Returns a menu with a sub-menu for each agent.
 String getType()
          Return the type of this world.
 boolean getUpdateWhileDragging()
           
 boolean getUseLocalBounds()
           
 int getWallColor()
           
 int getWorldHeight()
           
 String getWorldName()
          Return the name of this world.
 int getWorldWidth()
           
 void init()
          Initialize world; used by Castor for persistences.
 boolean isUpdateCompleted()
          Used by script thread to ensure that an update cycle is complete before updating again.
 void keyPressed(KeyEvent k)
          Task to perform when keyboard button is pressed.
 void keyReleased(KeyEvent k)
          Task to perform when keyboard button is released.
 void keyTyped(KeyEvent k)
          Task to perform when keyboard button is typed.
 void mouseClicked(MouseEvent mouseEvent)
          Task to perform when mouse button is clicked.
 void mouseDragged(MouseEvent e)
          Task to perform when mouse button is held and mouse moved.
 void mouseEntered(MouseEvent mouseEvent)
          Task to perform when mouse enters world.
 void mouseExited(MouseEvent mouseEvent)
          Task to perform when the mouse exits world.
 void mouseMoved(MouseEvent e)
          Task to perform when mouse is moved within the world.
 void mousePressed(MouseEvent mouseEvent)
          Task to perform when mouse button is pressed.
 void mouseReleased(MouseEvent mouseEvent)
          Task to perform when mouse button is released.
 void paintComponent(Graphics g)
          Paints graphical component.
 void paintWorld(Graphics g)
          Paint all the objects in the world.
 void removeEntity(AbstractEntity entity)
          Remove the specified world entity.
 void resize()
          Sets maximum size for the parent window.
 void setAbstractEntityList(ArrayList theList)
          Sets the abstract entity list.
 void setBackgroundColor(int backgroundColor)
          Sets the background color of the world.
 void setDeadEntityList(ArrayList deadEntityList)
          Array list of dead or eaten entities.
 void setObjectDraggingInitiatesMovement(boolean objectDraggingInitiatesMovement)
           
 void setObjectInhibitsMovement(boolean objectInhibitsMovement)
           
 void setObjectSize(int objectSize)
           
 void setParentFrame(OdorWorldFrame parentFrame)
           
 void setParentWorkspace(Workspace parentWorkspace)
          Workspace the world is contained.
 void setUpdateCompleted(boolean b)
          Used by script thread to ensure that an update cycle is complete before updating again.
 void setUpdateWhileDragging(boolean b)
           
 void setUseLocalBounds(boolean val)
          Sets whether to use local bounds.
 void setWallColor(int wallColor)
           
 void setWorldHeight(int worldHeight)
           
 void setWorldName(String worldName)
           
 void setWorldWidth(int worldWidth)
           
 void showEntityDialog(OdorWorldEntity theEntity)
          Call up a DialogOdorWorldEntity for a world object nearest to a specified point.
 void showGeneralDialog()
          Shows the general world preferences dialog.
 void showScriptDialog()
          Shows the script dialog box.
 void showWallDialog(Wall theWall)
          Shows the wall properties dialog box.
 
Methods inherited from class org.simbrain.world.World
addWorldListener, fireWorldChanged, removeWorldListener
 
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, getName, 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, 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
 

Constructor Detail

OdorWorld

public OdorWorld()
Default constructor.


OdorWorld

public OdorWorld(OdorWorldFrame wf)
Construct a world, set its background color.

Parameters:
wf - the frame in which this world is rendered
Method Detail

clear

public void clear()
Remove all objects from world.


init

public void init()
Initialize world; used by Castor for persistences.


mouseEntered

public void mouseEntered(MouseEvent mouseEvent)
Task to perform when mouse enters world.

Specified by:
mouseEntered in interface MouseListener
Parameters:
mouseEvent - Mouse event

mouseExited

public void mouseExited(MouseEvent mouseEvent)
Task to perform when the mouse exits world.

Specified by:
mouseExited in interface MouseListener
Parameters:
mouseEvent - Mouse event

mouseMoved

public void mouseMoved(MouseEvent e)
Task to perform when mouse is moved within the world.

Specified by:
mouseMoved in interface MouseMotionListener
Parameters:
e - Mouse event

mouseClicked

public void mouseClicked(MouseEvent mouseEvent)
Task to perform when mouse button is clicked.

Specified by:
mouseClicked in interface MouseListener
Parameters:
mouseEvent - Mouse event

mouseReleased

public void mouseReleased(MouseEvent mouseEvent)
Task to perform when mouse button is released.

Specified by:
mouseReleased in interface MouseListener
Parameters:
mouseEvent - Mouse event

mouseDragged

public void mouseDragged(MouseEvent e)
Task to perform when mouse button is held and mouse moved.

Specified by:
mouseDragged in interface MouseMotionListener
Parameters:
e - Mouse event

mousePressed

public void mousePressed(MouseEvent mouseEvent)
Task to perform when mouse button is pressed.

Specified by:
mousePressed in interface MouseListener
Parameters:
mouseEvent - Mouse event

actionPerformed

public void actionPerformed(ActionEvent e)
Tasks to perform when actions are performed.

Specified by:
actionPerformed in interface ActionListener
Parameters:
e - Action event

keyReleased

public void keyReleased(KeyEvent k)
Task to perform when keyboard button is released.

Specified by:
keyReleased in interface KeyListener
Parameters:
k - Keyboard event.

keyTyped

public void keyTyped(KeyEvent k)
Task to perform when keyboard button is typed.

Specified by:
keyTyped in interface KeyListener
Parameters:
k - Keyboard event.

keyPressed

public void keyPressed(KeyEvent k)
Task to perform when keyboard button is pressed.

Specified by:
keyPressed in interface KeyListener
Parameters:
k - Keyboard event.

clearAllEntities

public void clearAllEntities()
Clears all entities from the world.


removeEntity

public void removeEntity(AbstractEntity entity)
Remove the specified world entity.

Parameters:
entity - world entity to delete

addEntity

public void addEntity(Point p)
Add a world object at point p. Note that it currently has a set of default values specified within the code.

Parameters:
p - the location where the object should be added

addAgent

public void addAgent(Point p)
Add an agent at point p.

Parameters:
p - the location where the agent should be added

addWall

public void addWall()
Adds a wall to the world.


paintComponent

public void paintComponent(Graphics g)
Paints graphical component.

Overrides:
paintComponent in class JComponent
Parameters:
g - Graphic to paint

paintWorld

public void paintWorld(Graphics g)
Paint all the objects in the world.

Parameters:
g - Reference to the world's graphics object

showEntityDialog

public void showEntityDialog(OdorWorldEntity theEntity)
Call up a DialogOdorWorldEntity for a world object nearest to a specified point.

Parameters:
theEntity - the non-creature entity closest to this point will have a dialog called up

showWallDialog

public void showWallDialog(Wall theWall)
Shows the wall properties dialog box.

Parameters:
theWall - Wall for which to set properties

showGeneralDialog

public void showGeneralDialog()
Shows the general world preferences dialog.


showScriptDialog

public void showScriptDialog()
Shows the script dialog box.


resize

public void resize()
Sets maximum size for the parent window.


getAbstractEntityList

public ArrayList getAbstractEntityList()
Returns:
The list of abstract entitys.

setUseLocalBounds

public void setUseLocalBounds(boolean val)
Sets whether to use local bounds.

Parameters:
val - Local bounds

getUseLocalBounds

public boolean getUseLocalBounds()
Returns:
Whether or not to use local bounds.

getSelectedEntity

public AbstractEntity getSelectedEntity()
Returns:
The selected abstract entity.

setAbstractEntityList

public void setAbstractEntityList(ArrayList theList)
Sets the abstract entity list.

Parameters:
theList - List of entities

getUpdateWhileDragging

public boolean getUpdateWhileDragging()
Returns:
true if the network should be updated as the creature is dragged, false otherwise

setUpdateWhileDragging

public void setUpdateWhileDragging(boolean b)
Parameters:
b - true if the network should be updated as the creature is dragged, false otherwise

buildPopupMenu

public JPopupMenu buildPopupMenu(AbstractEntity theEntity)
Create a popup menu based on location of mouse click.

Parameters:
theEntity - the entity for which to build the menu
Returns:
the popup menu

getHighestDimensionalStimulus

public int getHighestDimensionalStimulus()
Go through entities in this world and find the one with the greatest number of dimensions. This will determine the dimensionality of the proximal stimulus sent to the network

Returns:
the number of dimensions in the highest dimensional stimulus

getEntityNames

public ArrayList getEntityNames()
Returns:
the list of entity names

getEntityList

public ArrayList getEntityList()
Returns:
a list of entities

getSensorIdMenu

public JMenu getSensorIdMenu(ActionListener al)
Returns a menu with a sub-menu for each agent.

Specified by:
getSensorIdMenu in class World
Parameters:
al - the action listener (currently in the network panel) which listens to these menu events
Returns:
a JMenu with a list of sensors for each agent

getMotorCommandMenu

public JMenu getMotorCommandMenu(ActionListener al)
Returns a menu with the motor commands available to this agent.

Specified by:
getMotorCommandMenu in class World
Parameters:
al - the action listener (currently in the network panel) which listens to these menu events
Returns:
a JMenu with the motor commands available for this agent

getAgentList

public ArrayList getAgentList()
Description copied from class: World
Return the list of agents for this world.

Specified by:
getAgentList in class World
Returns:
Returns the agentList.

getWorldName

public String getWorldName()
Description copied from class: World
Return the name of this world.

Specified by:
getWorldName in class World
Returns:
Returns the worldName.

setWorldName

public void setWorldName(String worldName)
Parameters:
worldName - The worldName to set.

getWorldHeight

public int getWorldHeight()
Returns:
Returns the worldHeight.

setWorldHeight

public void setWorldHeight(int worldHeight)
Parameters:
worldHeight - The worldHeight to set.

getWorldWidth

public int getWorldWidth()
Returns:
Returns the worldWidth.

setWorldWidth

public void setWorldWidth(int worldWidth)
Parameters:
worldWidth - The worldWidth to set.

getObjectDraggingInitiatesMovement

public boolean getObjectDraggingInitiatesMovement()
Returns:
Returns the objectDraggingInitiateMovement.

setObjectDraggingInitiatesMovement

public void setObjectDraggingInitiatesMovement(boolean objectDraggingInitiatesMovement)
Parameters:
objectDraggingInitiatesMovement - The objectDraggingInitiateMovement to set.

getObjectInhibitsMovement

public boolean getObjectInhibitsMovement()
Returns:
Returns the objectInhibitsMovement.

setObjectInhibitsMovement

public void setObjectInhibitsMovement(boolean objectInhibitsMovement)
Parameters:
objectInhibitsMovement - The objectInhibitsMovement to set.

getObjectSize

public int getObjectSize()
Returns:
Returns the objectSize.

setObjectSize

public void setObjectSize(int objectSize)
Parameters:
objectSize - The objectSize to set.

getParentFrame

public OdorWorldFrame getParentFrame()
Returns:
Returns the parentFrame.

setParentFrame

public void setParentFrame(OdorWorldFrame parentFrame)
Parameters:
parentFrame - The parentFrame to set.

getType

public String getType()
Description copied from class: World
Return the type of this world.

Specified by:
getType in class World
Returns:
type of world

getWallColor

public int getWallColor()
Returns:
Returns the wallColor.

setWallColor

public void setWallColor(int wallColor)
Parameters:
wallColor - The wallColor to set.

getParentWorkspace

public Workspace getParentWorkspace()
Return the parent workspace.

Returns:
Parent workspace

setParentWorkspace

public void setParentWorkspace(Workspace parentWorkspace)
Workspace the world is contained.

Parameters:
parentWorkspace - Parent workspace

getBackgroundColor

public int getBackgroundColor()
Returns:
Background color of world.

setBackgroundColor

public void setBackgroundColor(int backgroundColor)
Sets the background color of the world.

Parameters:
backgroundColor - Color

getDeadEntityList

public ArrayList getDeadEntityList()
Returns:
List of dead or eaten entities.

setDeadEntityList

public void setDeadEntityList(ArrayList deadEntityList)
Array list of dead or eaten entities.

Parameters:
deadEntityList - List of entities

isUpdateCompleted

public boolean isUpdateCompleted()
Used by script thread to ensure that an update cycle is complete before updating again.

Returns:
whether the world has been updated or not

setUpdateCompleted

public void setUpdateCompleted(boolean b)
Used by script thread to ensure that an update cycle is complete before updating again.

Parameters:
b - whether the world has been updated or not.