fr.lifl.jedi.gui.display.colorGrid.view.agentDisplay
Class StaticIconDisplayer

java.lang.Object
  extended by fr.lifl.jedi.gui.display.colorGrid.view.agentDisplay.StaticIconDisplayer
All Implemented Interfaces:
AgentDisplayer

public class StaticIconDisplayer
extends java.lang.Object
implements AgentDisplayer

This class defines a tool used to display agents in the environment.

It displays agents as an icon. The size of the rectangle is independent from the width and height of the agent. Nevertheless, it scales with the scaling factor of the simulation.

Version:
JEDI V 2.2
Created the 4th nov. 2008
Modified the 5th may 2009
Author:
Yoann Kubera
SMAC Team (Systèmes Multi-Agents et Comportement)
LIFL (Laboratoire d'Informatique Fondamentale de Lille)
University of Lille, France
See Also:
ColorGridModel.getScaleFactor()

Field Summary
protected  double height
          The height of the icon displaying the agent
protected  java.awt.Image icon
          The icon used to fill the rectangle representing the agent.
protected  boolean inBackground
          Checks if this displayers displays agents in the foreground or in the background of the frame.
protected  double width
          The width of the icon displaying the agent
 
Constructor Summary
StaticIconDisplayer(java.awt.Image icon, double width, double height, boolean inBg)
          Constructor of the displayer.
 
Method Summary
 void drawAgent(java.awt.Graphics g, Environment e, Agent a, int factor, int height)
          Displays the agent in the environment.
 java.awt.Image getIconFor(Agent a)
          Gets the icon used to display a particular agent instance.
 boolean isDisplayable(Agent a)
          Checks if the agent is displayed in GUI or not.
 boolean isDisplayedInBackground()
          Checks if the agent has to be displayed on the background of the GUI.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

width

protected double width
The width of the icon displaying the agent


height

protected double height
The height of the icon displaying the agent


icon

protected java.awt.Image icon
The icon used to fill the rectangle representing the agent.


inBackground

protected boolean inBackground
Checks if this displayers displays agents in the foreground or in the background of the frame.

Constructor Detail

StaticIconDisplayer

public StaticIconDisplayer(java.awt.Image icon,
                           double width,
                           double height,
                           boolean inBg)
Constructor of the displayer.

Parameters:
icon - The icon used to fill the rectangle displaying the agent.
width - The width of the rectangle displaying the agent.
height - The height of the rectangle displaying the agent.
inBg - true if this displayer displays agents in the background of the frame rather than in the foreground.
Method Detail

drawAgent

public void drawAgent(java.awt.Graphics g,
                      Environment e,
                      Agent a,
                      int factor,
                      int height)
Description copied from interface: AgentDisplayer
Displays the agent in the environment.

Sadly, Swing uses a cartesian coordinate system where the y axis goes from up to down. Thus, y coordinates have to be inverted, in order to correspond to coordinates in the model used in JEDI.

This requires a particular additional parameter, that corresponds to the total height of displayed simulation.

The width of the black border around the environment is equal to factor. Keep in mind that the black border all around the environment has to be taken into account when computing displayed areas: the (0, 0) coordinate of the environment lies in the (factor, factor - height) coordinate of the panel.

Specified by:
drawAgent in interface AgentDisplayer
Parameters:
g - The object where drawing is made.
e - The environment of the simulation.
a - The agent to be displayed.
factor - The scaling factor used. It defines the number of pixels corresponding to a unit in the environment.
height - The height of the rectangle displaying the environment. It is equal to the height of the environment * the scaling factor.
See Also:
AgentDisplayer.drawAgent(java.awt.Graphics, fr.lifl.jedi.model.Environment, fr.lifl.jedi.model.Agent, int, int)

isDisplayable

public boolean isDisplayable(Agent a)
Description copied from interface: AgentDisplayer
Checks if the agent is displayed in GUI or not.

Specified by:
isDisplayable in interface AgentDisplayer
Parameters:
a - The agent checked by this method
Returns:
true if the agent is displayed in the GUI.
See Also:
AgentDisplayer.isDisplayable(fr.lifl.jedi.model.Agent)

isDisplayedInBackground

public boolean isDisplayedInBackground()
Description copied from interface: AgentDisplayer
Checks if the agent has to be displayed on the background of the GUI.

Specified by:
isDisplayedInBackground in interface AgentDisplayer
Returns:
true if the agent has to be displayed on the background of the GUI.
See Also:
AgentDisplayer.isDisplayedInBackground()

getIconFor

public java.awt.Image getIconFor(Agent a)
Gets the icon used to display a particular agent instance.

Parameters:
a - The agent instance to display
Returns:
the icon used to display this agent instance.