haifa.shopsim.UI
Class ShopViewUpdater

java.lang.Object
  |
  +--haifa.shopsim.UI.ShopViewUpdater
All Implemented Interfaces:
java.util.EventListener, ShopChangeListener

public class ShopViewUpdater
extends java.lang.Object
implements ShopChangeListener

This class is designed to pace information between the simulation engine and the graphics components: animation, table, gant chart, etc..

It allows registration of a shopTraceMaker (that actually passes all of the event objects to the gant chart, and it also allows registration of the ShopChangeListeners (these all get time moved events). This means, that except for the gant chart that gets the info though the shop trace maker, the other components do not actually get the full information, they rather get TimeMovedEvents. That tell them to update from the shop state (which they have refernces to ).

The GUI application controlls this class by using the setRawSpeed() method. The GUI is to set a speed value between 0 and 100. 0 being the slowest and 100 the fastest.

Version:
1.1

Field Summary
protected  int eventCounter
          Counts the number of shopChangeEvents that occured since the last time the listeners and gantt were updated.
protected  double lastEventTime
          Stores the time of the last event recived from the ShopSimulation.
protected  long lastUpdateTimeMillis
          Stores the real world time (in millis) since the last time the system was updated.
protected  java.util.ArrayList listenerList
          List of listeners (anim, table, etc...).
protected static long MANDETORY_SLEEP_TIME
          The ShopViewUpdater alwasy sleeps for this time between updates so that the GUI may breath.
protected static long MAX_EVENT_SKIP
          The maximal number of appropriate events that are skipped (when rawSpeed=100).
protected static int MAX_SLEEP
          The maximal sleep time between GUI updates (when rawSpeed=0)
protected  int maxEventCount
          When the rawSpeed>50 this counts the number of appropriate events that are to occur before the shop is updated.
protected static long MILLS_LAST_EVENT
          Time that shop view updater allows between two events without "forcing" an update of the GUI
protected  int rawSpeed
          Value of 0,...,100, the rawSpeed value recieved from the GUI
protected  ShopTraceMaker shopTraceMaker
          A reference to the shopTrace Maker, this object is asked to send a display trace whenever the other listeners are modified.
protected  long sleepTime
          The time to sleep between appropriate event updates (when raw speed is less than 50).
protected  ThreadFastShopRun threadFastShopRun
          Refrence to the patient shop run object.
 
Constructor Summary
ShopViewUpdater(ShopTraceMaker shopTraceMaker_)
          Creates a ShopViewUpdater with a given shopTraceMaker.
 
Method Summary
 void addShopChangeListener(ShopChangeListener sce)
          Add a listener, a ShopChangeListener that will recieve TimeMovedEvents.
 void setRawSpeed(int rawSpeed_)
          Set the rawSpeed (between 0 and 100)
 void shopChanged(ShopChangeEvent sce)
          Called by the ShopSimulatiom (in this manner it passes a shop change event).
protected  void update(double simTime)
          Fires ShopTimeMovedEvents to all the listeners and tells the shopTraceMaker to display gantt.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

MANDETORY_SLEEP_TIME

protected static final long MANDETORY_SLEEP_TIME
The ShopViewUpdater alwasy sleeps for this time between updates so that the GUI may breath.

MILLS_LAST_EVENT

protected static final long MILLS_LAST_EVENT
Time that shop view updater allows between two events without "forcing" an update of the GUI

MAX_EVENT_SKIP

protected static final long MAX_EVENT_SKIP
The maximal number of appropriate events that are skipped (when rawSpeed=100).

MAX_SLEEP

protected static final int MAX_SLEEP
The maximal sleep time between GUI updates (when rawSpeed=0)

rawSpeed

protected int rawSpeed
Value of 0,...,100, the rawSpeed value recieved from the GUI

shopTraceMaker

protected ShopTraceMaker shopTraceMaker
A reference to the shopTrace Maker, this object is asked to send a display trace whenever the other listeners are modified.

listenerList

protected java.util.ArrayList listenerList
List of listeners (anim, table, etc...). All these listeners do not get the full events, they rather get time moved events.

threadFastShopRun

protected ThreadFastShopRun threadFastShopRun
Refrence to the patient shop run object.

eventCounter

protected int eventCounter
Counts the number of shopChangeEvents that occured since the last time the listeners and gantt were updated.

maxEventCount

protected int maxEventCount
When the rawSpeed>50 this counts the number of appropriate events that are to occur before the shop is updated.

lastEventTime

protected double lastEventTime
Stores the time of the last event recived from the ShopSimulation.

lastUpdateTimeMillis

protected long lastUpdateTimeMillis
Stores the real world time (in millis) since the last time the system was updated.

sleepTime

protected long sleepTime
The time to sleep between appropriate event updates (when raw speed is less than 50).
Constructor Detail

ShopViewUpdater

public ShopViewUpdater(ShopTraceMaker shopTraceMaker_)
Creates a ShopViewUpdater with a given shopTraceMaker.
Method Detail

addShopChangeListener

public void addShopChangeListener(ShopChangeListener sce)
Add a listener, a ShopChangeListener that will recieve TimeMovedEvents.

setRawSpeed

public void setRawSpeed(int rawSpeed_)
Set the rawSpeed (between 0 and 100)

shopChanged

public void shopChanged(ShopChangeEvent sce)
Called by the ShopSimulatiom (in this manner it passes a shop change event). The behaviour is as follows:

Events that arrive after a time of MILLS_LAST_EVENT since that lastUpdateTimeMillis are automatically thrown to the listeners (and gantt is displayed). This is so when the user "steps" through events (not clicking step faster than MILLS_LAST_EVENT), the GUI updates according to the steps. Note that in this case all events are passed, not just appropriate events. If the event recieved is a ShopStartedEvent or a ShopFinishedEvent, the GUI is always immidaitly updated.
Specified by:
shopChanged in interface ShopChangeListener

update

protected void update(double simTime)
Fires ShopTimeMovedEvents to all the listeners and tells the shopTraceMaker to display gantt. This method always sleeps for MANDETORY_SLEEP_TIME and this is to allow the GUI to breath.