edu.turtlekit2.kernel.agents
Class Viewer

java.lang.Object
  extended by madkit.kernel.AbstractAgent
      extended by madkit.kernel.Watcher
          extended by edu.turtlekit2.kernel.agents.Observer
              extended by edu.turtlekit2.kernel.agents.Viewer
All Implemented Interfaces:
MouseListener, MouseMotionListener, MouseWheelListener, Serializable, EventListener, MouseInputListener, madkit.kernel.ReferenceableAgent
Direct Known Subclasses:
GasObserver, LifeViewer, LifeViewer2, LifeViewer3, LineCharter, MyObserver, MyViewer, Phero3DViewer, Phero3DViewer, PheromoneCharter, PheroViewer, PheroViewer2, PopulationCharter, SoccerViewer, SolsticeObserver, SpecialViewer, Viewer2D, Viewer3D

public class Viewer
extends Observer
implements MouseInputListener, MouseWheelListener

Viewer is the simulation default world displayer agent (an specialized Observer, it can be extended to redefine the default representation of patches and turtles (a square fill with the color return by the getColor() method of them).

Version:
1.4 - 4/2010
Author:
Fabien MICHEL, Gregory Beurier
See Also:
Serialized Form

Nested Class Summary
protected  class Viewer.GridCanvas
          Titre : GridCanvas Description : a convenient class to display a view of the world
 
Field Summary
 TurtleProbe allTurtles
           
 int cellSize
           
 Point clickedPoint
          Mouse interaction
 Viewer.GridCanvas onScreen
           
 boolean redrawAll
           
 int xDecay
           
 int yDecay
           
 
Fields inherited from class edu.turtlekit2.kernel.agents.Observer
attrib, envHeight, envWidth, flavors, gridValues, patchGrid, probe1, probe2, simulationGroup
 
Constructor Summary
Viewer()
           
 
Method Summary
 void display()
          the display itself
 void initGUI()
          MadKit usage, no redefinition
 void mouseClicked(MouseEvent e)
           
 void mouseDragged(MouseEvent e)
           
 void mouseEntered(MouseEvent e)
           
 void mouseExited(MouseEvent e)
           
 void mouseMoved(MouseEvent e)
           
 void mousePressed(MouseEvent e)
           
 void mouseReleased(MouseEvent e)
           
 void mouseWheelMoved(MouseWheelEvent e)
           
 void paintInfo(Graphics g)
           
 void paintPatch(Graphics g, Patch p, int x, int y, int cellS)
          override this method if you want an other patch graphic representation giving an on screen location (x,y), a patch p to draw and a reserved on screen patch size: a square of pixels with a side of cellS.
 void paintTurtle(Graphics g, Turtle t, int x, int y, int cellS)
          In the same way, you can give a special graphic representation of your turtles.
 boolean readyToDisplay()
           
 void setup()
          init the GUI
 
Methods inherited from class edu.turtlekit2.kernel.agents.Observer
activate, flavorsContains, getAllValues, getAttrib, getBooleanParam, getBooleanParam, getColorParam, getColorParam, getDoubleParam, getDoubleParam, getFlavor, getFlavorName, getFlavors, getFloatParam, getFloatParam, getIntParam, getIntParam, getParam, getParam, getSimulationGroup, getStringParam, getStringParam, setAttrib, setFlavors, watch
 
Methods inherited from class madkit.kernel.Watcher
addProbe, addProbe, end, getProbes, removeAllProbes, removeProbe, update
 
Methods inherited from class madkit.kernel.AbstractAgent
broadcastMessage, broadcastMessage, connectedWithCommunity, createGroup, createGroup, debug, disposeMyGUI, foundGroup, getAddress, getAgentInformation, getAgentsWithRole, getAgentsWithRole, getAgentWithRole, getAgentWithRole, getAvailableCommunities, getBean, getController, getCurrentKernelAddress, getDebug, getExistingGroups, getExistingGroups, getExistingRoles, getExistingRoles, getGroups, getGUIObject, getMessageBoxSize, getMyGroups, getMyGroups, getMyRoles, getMyRoles, getName, getRoles, hasGUI, hashCode, isBelongingToGroup, isBelongingToGroup, isCommunity, isGroup, isGroup, isMemberOf, isMemberOf, isMessageBoxEmpty, isRole, isRole, joinGroup, killAgent, launchAgent, launchAgent, leaveGroup, leaveGroup, leaveRole, leaveRole, nextMessage, print, println, receiveMessage, redisplayMyGUI, requestRole, requestRole, requestRole, restoreAgent, sendMessage, sendMessage, sendMessage, setBean, setController, setDebug, setGUIObject, setName, setOutput, setOutputWriter, toString, windowClosing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

cellSize

public int cellSize

onScreen

public Viewer.GridCanvas onScreen

allTurtles

public TurtleProbe allTurtles

redrawAll

public boolean redrawAll

xDecay

public int xDecay

yDecay

public int yDecay

clickedPoint

public Point clickedPoint
Mouse interaction

Constructor Detail

Viewer

public Viewer()
Method Detail

initGUI

public void initGUI()
MadKit usage, no redefinition

Overrides:
initGUI in class madkit.kernel.AbstractAgent

setup

public void setup()
init the GUI

Overrides:
setup in class Observer

paintPatch

public void paintPatch(Graphics g,
                       Patch p,
                       int x,
                       int y,
                       int cellS)
override this method if you want an other patch graphic representation giving an on screen location (x,y), a patch p to draw and a reserved on screen patch size: a square of pixels with a side of cellS. As the simulation display is optimized, be sure that you draw a figure that is contained in the reserved square or set the redrawAll variable to true (in the property box or in constructor so the patches are all repainted first, then the turtles (avoid to leave turtle trace on the floor, but realy slow down the simulation). By example you can use the patch access methods to decide the color to display for this. default: g.setColor(p.getColor()); g.fillRect(x,y,cellS,cellS);


paintTurtle

public void paintTurtle(Graphics g,
                        Turtle t,
                        int x,
                        int y,
                        int cellS)
In the same way, you can give a special graphic representation of your turtles. Default: g.setColor(t.getColor()); g.fillRect(x,y,cellS,cellS);


paintInfo

public void paintInfo(Graphics g)

display

public void display()
the display itself


readyToDisplay

public boolean readyToDisplay()

mouseClicked

public void mouseClicked(MouseEvent e)
Specified by:
mouseClicked in interface MouseListener

mouseEntered

public void mouseEntered(MouseEvent e)
Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent e)
Specified by:
mouseExited in interface MouseListener

mousePressed

public void mousePressed(MouseEvent e)
Specified by:
mousePressed in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent e)
Specified by:
mouseReleased in interface MouseListener

mouseDragged

public void mouseDragged(MouseEvent e)
Specified by:
mouseDragged in interface MouseMotionListener

mouseMoved

public void mouseMoved(MouseEvent e)
Specified by:
mouseMoved in interface MouseMotionListener

mouseWheelMoved

public void mouseWheelMoved(MouseWheelEvent e)
Specified by:
mouseWheelMoved in interface MouseWheelListener