uk.org.arlott.simon.hw.f24.lbsta
Class NetworkView

java.lang.Object
  extended by uk.org.arlott.simon.hw.f24.lbsta.NetworkView
All Implemented Interfaces:
java.util.EventListener, javax.swing.event.ChangeListener, CommonInterface

public class NetworkView
extends java.lang.Object
implements CommonInterface, javax.swing.event.ChangeListener

Network viewing mode.


Field Summary
private  MainWindow mainWindow
          The MainWindow.
private  Network network
          The Network.
private  boolean paused
          The pause state.
private  java.lang.Integer realSpeed
          The current speed of the simulation.
private  java.util.Timer repaint
          The redraw timer.
private  NetworkSimulation simulation
          The simulation.
private  boolean speedChanged
          Flag to indicate the speed has changed.
private  boolean steppingMode
          Flag to indicate if stepping mode is in use.
 
Fields inherited from interface uk.org.arlott.simon.hw.f24.lbsta.CommonInterface
MOUSE_PRIMARY, MOUSE_SECONDARY
 
Constructor Summary
NetworkView(Network network, MainWindow mainWindow, Script script)
          Creates a new NetworkView object.
 
Method Summary
 void hide()
          Switches from this mode.
 boolean keyPressed(int keyCode)
          Indicates that a key has been pressed.
 boolean mouseClick(int button, java.lang.Object hover)
          Handles mouse clicks.
 boolean mouseMoved(java.awt.Point position, java.lang.Object hover)
          Indicates that the mouse has been moved.
 void paint(java.awt.Graphics g, java.awt.Dimension size)
          Called after the network has been drawn to allow custom drawing to take place.
private  void pause()
          Pauses the simulation.
 void paused(java.lang.String text)
          Flags that the simulation has been paused.
 void restart()
          Restarts the simulation.
 void setSpeed(int speed)
          Changes the speed of the simulation.
 void show()
          Switches to this mode.
 void start()
          Starts the simulation.
 void stateChanged(javax.swing.event.ChangeEvent ce)
          Handles the setting of component being viewed changing.
 void step()
          Starts the simulation in stepping mode.
private  void unPause()
          Unpauses the simulation.
 void updateScriptState(java.lang.String text)
          Updates the script state status text.
 void updateSpeed(int speed)
          Updates the record of the simulation's current speed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

network

private Network network
The Network.


mainWindow

private final MainWindow mainWindow
The MainWindow.


repaint

private java.util.Timer repaint
The redraw timer.


simulation

private NetworkSimulation simulation
The simulation.


paused

private boolean paused
The pause state.


realSpeed

private java.lang.Integer realSpeed
The current speed of the simulation.


speedChanged

private boolean speedChanged
Flag to indicate the speed has changed.


steppingMode

private boolean steppingMode
Flag to indicate if stepping mode is in use.

Constructor Detail

NetworkView

public NetworkView(Network network,
                   MainWindow mainWindow,
                   Script script)
Creates a new NetworkView object.

Parameters:
network - The Network.
mainWindow - The MainWindow.
script - The Script.
Method Detail

stateChanged

public void stateChanged(javax.swing.event.ChangeEvent ce)
Handles the setting of component being viewed changing.

Specified by:
stateChanged in interface javax.swing.event.ChangeListener
Parameters:
ce - Ignored.

mouseClick

public boolean mouseClick(int button,
                          java.lang.Object hover)
Handles mouse clicks.

Specified by:
mouseClick in interface CommonInterface
Parameters:
button - The mouse button used.
hover - The network component that the mouse pointer is over.
Returns:
true if the network should be redrawn.

mouseMoved

public boolean mouseMoved(java.awt.Point position,
                          java.lang.Object hover)
Description copied from interface: CommonInterface
Indicates that the mouse has been moved.

Specified by:
mouseMoved in interface CommonInterface
Parameters:
position - The position of the mouse pointer.
hover - The object, if any, that the mouse pointer is hovering over at the time.
Returns:
A boolean indicating if the display should be redrawn or not.

keyPressed

public boolean keyPressed(int keyCode)
Description copied from interface: CommonInterface
Indicates that a key has been pressed.

Specified by:
keyPressed in interface CommonInterface
Parameters:
keyCode - The KeyCode.getKeyCode() value.
Returns:
A boolean indicating if the display should be redrawn or not.

paint

public void paint(java.awt.Graphics g,
                  java.awt.Dimension size)
Description copied from interface: CommonInterface
Called after the network has been drawn to allow custom drawing to take place.

Specified by:
paint in interface CommonInterface
Parameters:
g - The Graphics object to draw to.
size - The visible area of the panel to be drawn on.

show

public void show()
Switches to this mode.

Specified by:
show in interface CommonInterface

hide

public void hide()
Switches from this mode.

Specified by:
hide in interface CommonInterface

paused

public void paused(java.lang.String text)
Flags that the simulation has been paused.

Parameters:
text - Reason for pausing.

pause

private void pause()
Pauses the simulation.


unPause

private void unPause()
Unpauses the simulation.


setSpeed

public void setSpeed(int speed)
Changes the speed of the simulation.

Parameters:
speed - New speed.

updateSpeed

public void updateSpeed(int speed)
Updates the record of the simulation's current speed.

Parameters:
speed - New speed.

updateScriptState

public void updateScriptState(java.lang.String text)
Updates the script state status text.

Parameters:
text - New status text.

restart

public void restart()
Restarts the simulation.


start

public void start()
Starts the simulation.


step

public void step()
Starts the simulation in stepping mode.