controller
Class Controller

java.lang.Object
  |
  +--controller.Controller
All Implemented Interfaces:
SocketReceiverListener

public class Controller
extends java.lang.Object
implements SocketReceiverListener

This class is the core of the simulator. It initializes the interface components, holds the agents, and controls the sockets for sending and recieving data.


Nested Class Summary
(package private)  class Controller.MessageSender
          This class is used for Multicasting a message to all users in wireless range.
 
Field Summary
private  gui.ChartComp chart
          The chart is the visual map.
private  agent.Agent current_agent
          The agent that is being moved, or has center of screen.
private  gui.SimulatorFrame frame
          The main frame which displays the map ChartComp.
private  java.util.Vector listeners
          Components that want to listen for when information changes in controller.
private  java.util.Vector points
          The list of all access points in the simulation.
private  gui.tray.TrayDialog tray
          An interface component for viewing agent stats, etc.
private  java.util.Vector users
          The list of all users in the simulation.
 
Constructor Summary
Controller()
          This constructor initializes the controller by creating the interface components, so that the user can begin interacting with the simulator.
 
Method Summary
 void addAccessPoint(int r)
          This method is for adding a new access point into the simulator.
 void addControllerListener(controller.ControllerListener listener)
          This methods adds a listener to the list of listeners this controller knows about.
 void addUser(int r, int p)
          This method is for adding a new user into the simulator.
 agent.Agent centerAgent(java.lang.String name)
          This method is for centering the given agent on the map.
 void changeChart(java.lang.String chartName)
          This method changes the current map/chart used in the simulation.
private  double diff(java.awt.Point p1, java.awt.Point p2)
          This method returns the pixel distance between two points.
 void fireControllerChange()
          This method notifies all subscribed listeners that they must refresh themselves.
 gui.ChartComp getChartComp()
          This method returns the ChartComp which holds the simulation map, and draws all the users.
 agent.Agent getCurrentAgent()
          This method returns the current agent in focus or being moved around in the simulator map.
 javax.swing.JFrame getFrame()
          This method returns the main JFrame for the iSIM application.
 java.util.Vector getPoints()
          This method returns the Vector of all current access points in the simulator.
 java.util.Vector getUsers()
          This method returns the Vector of all the current users in the simulator.
 void incomingMessage(transport.protocol.Message msg)
          This method is required by SocketReceiverListener and is called by the SocketReceiver object.
 boolean isTrayAlive()
          This method simply tests to see if the tray is visible, if not visible then it is assumed to be dead.
 void locationChange(agent.User u)
          This method is called when a User's location has changed.
 void makeTray()
          This method creates a new TrayDialog for performing various functions in the simulator, and viewing information.
 void removeAccessPoint(agent.AccessPoint u)
          This method is for removing a access point from the simulator.
 void removeControllerListener(controller.ControllerListener listener)
          This method removes a listener from the list of listeners that this controller knows about.
 void removeUser(agent.User u)
          This method is for removing a user from the simulator.
 void reset()
          This method is for reseting the data insdie the controller.
 void setCurrentAgent(agent.Agent a)
          This method sets who the current is.
 void setRanges(boolean ranges)
          This method sets whether the wireless ranges should be displayed or not.
 void updateAgentPosition(agent.Agent u)
          This method
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

chart

private gui.ChartComp chart
The chart is the visual map.


frame

private gui.SimulatorFrame frame
The main frame which displays the map ChartComp.


tray

private gui.tray.TrayDialog tray
An interface component for viewing agent stats, etc.


current_agent

private agent.Agent current_agent
The agent that is being moved, or has center of screen.


points

private java.util.Vector points
The list of all access points in the simulation.


users

private java.util.Vector users
The list of all users in the simulation.


listeners

private java.util.Vector listeners
Components that want to listen for when information changes in controller.

Constructor Detail

Controller

public Controller()
This constructor initializes the controller by creating the interface components, so that the user can begin interacting with the simulator. It also starts the SocketReceiver for listening to incoming messages.

Method Detail

addUser

public void addUser(int r,
                    int p)
This method is for adding a new user into the simulator. The user is created based on the given information, and is added into the map, and all controller listeners are notified of the new addition.

Parameters:
r - The range for the new user.
p - The port for the new user.

removeUser

public void removeUser(agent.User u)
This method is for removing a user from the simulator. The actual user is given to the method, and the remove from the simulation, and all controller listeners are notified of the new removal.

Parameters:
u - The User object to remove from the users list.

addAccessPoint

public void addAccessPoint(int r)
This method is for adding a new access point into the simulator. The accesspoint is created based on the given information, and is added into the map, and all controller listeners are notified of the new addition.

Parameters:
r - The range for the new Access Point

removeAccessPoint

public void removeAccessPoint(agent.AccessPoint u)
This method is for removing a access point from the simulator. The actual access point is given to the method, and the remove from the simulation, and all controller listeners are notified of the new removal.

Parameters:
u - The Access Point object to remove from the points list.

updateAgentPosition

public void updateAgentPosition(agent.Agent u)
This method

Parameters:
u - The agent whose Position needs to be set by this method.

getUsers

public java.util.Vector getUsers()
This method returns the Vector of all the current users in the simulator.

Returns:
Vector All users in the simulation.

getPoints

public java.util.Vector getPoints()
This method returns the Vector of all current access points in the simulator.

Returns:
Vector All Access Points in the simulation.

getCurrentAgent

public agent.Agent getCurrentAgent()
This method returns the current agent in focus or being moved around in the simulator map.

Returns:
Agent The current Agent being moved or center on screen.

setCurrentAgent

public void setCurrentAgent(agent.Agent a)
This method sets who the current is.

Parameters:
a - The Agent to make the current agent.

centerAgent

public agent.Agent centerAgent(java.lang.String name)
This method is for centering the given agent on the map. Also returns the agent object in case it is needed once centered.

Parameters:
name - The name of Agent to find and center on screen.
Returns:
Agent The Agent object that was centered.

locationChange

public void locationChange(agent.User u)
This method is called when a User's location has changed. A NMEA Message is created and then sent to the User's corresponding iPAQ via a port number.

Parameters:
u - The user who has changed location.

isTrayAlive

public boolean isTrayAlive()
This method simply tests to see if the tray is visible, if not visible then it is assumed to be dead.

Returns:
boolean True if tray is alive and visible, false otherwise.

makeTray

public void makeTray()
This method creates a new TrayDialog for performing various functions in the simulator, and viewing information.


getFrame

public javax.swing.JFrame getFrame()
This method returns the main JFrame for the iSIM application.

Returns:
JFrame The main JFrame for the simulation.

getChartComp

public gui.ChartComp getChartComp()
This method returns the ChartComp which holds the simulation map, and draws all the users.

Returns:
CharComp The JComponent that is the map.

setRanges

public void setRanges(boolean ranges)
This method sets whether the wireless ranges should be displayed or not.

Parameters:
ranges - True to show the wireless range on map, false otherwise.

changeChart

public void changeChart(java.lang.String chartName)
This method changes the current map/chart used in the simulation. The GUI Frame and ChartComp handle the details behind this.

Parameters:
chartName - The new chart file name.

reset

public void reset()
This method is for reseting the data insdie the controller. It removes all agents (users and access points).


diff

private double diff(java.awt.Point p1,
                    java.awt.Point p2)
This method returns the pixel distance between two points.

Parameters:
p1 - The first point.
p2 - The second point.

incomingMessage

public void incomingMessage(transport.protocol.Message msg)
This method is required by SocketReceiverListener and is called by the SocketReceiver object. It delivers a message to us from some other client application wanting to send a message. This method uses a multicasting approach and sends the message to all agents in range and up to a certain number of hops designated in the message itself. It calls a Thread now to do the message passing, so that bandwidth delays can be simulated.

Specified by:
incomingMessage in interface SocketReceiverListener
Parameters:
msg - The incoming Message that the simulator has received.

addControllerListener

public void addControllerListener(controller.ControllerListener listener)
This methods adds a listener to the list of listeners this controller knows about.

Parameters:
listener -

removeControllerListener

public void removeControllerListener(controller.ControllerListener listener)
This method removes a listener from the list of listeners that this controller knows about.

Parameters:
listener -

fireControllerChange

public void fireControllerChange()
This method notifies all subscribed listeners that they must refresh themselves.