edu.usc.cse.desi.viewers
Class AbstractCalculator

java.lang.Object
  extended byedu.usc.cse.desi.viewers.AbstractCalculator
All Implemented Interfaces:
java.util.EventListener, java.beans.PropertyChangeListener
Direct Known Subclasses:
AvailabilityCalculator, LatencyCalculator

public abstract class AbstractCalculator
extends java.lang.Object
implements java.beans.PropertyChangeListener

This is an abstract class for properties such as availability or overall latency. It is a framework for listening to the model and then updating a label to reflect your newly calculated value.

Author:
NeLs Started on Jul 30, 2004

Field Summary
protected  org.eclipse.swt.widgets.Label myLabel
           
protected  DESIViewModel myModel
           
 
Constructor Summary
private AbstractCalculator()
           
  AbstractCalculator(DESIViewModel model, org.eclipse.swt.widgets.Label label)
          When the calculator is first created, set the model and the label.
 
Method Summary
protected abstract  void addThisAsAListenerToModel()
          This method should be overriden by all subclasses.
protected abstract  void calculate()
          In this method, do your calculation and then return the calculated value.
protected  void finalize()
          I overrode this method:
 void modelChanged(DESIViewModel new_model)
          If the model changes, you can call this method and the calculator will recalculate.
protected abstract  void removeThisAsAListenerFromModel()
          This method can be called to remove this as a listner.
 void setMyLabelText(java.lang.String arg0)
          This is a delegate method for the label that will set the text of the label to whatever is passed to it.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.beans.PropertyChangeListener
propertyChange
 

Field Detail

myLabel

protected org.eclipse.swt.widgets.Label myLabel

myModel

protected DESIViewModel myModel
Constructor Detail

AbstractCalculator

private AbstractCalculator()

AbstractCalculator

public AbstractCalculator(DESIViewModel model,
                          org.eclipse.swt.widgets.Label label)
When the calculator is first created, set the model and the label. Be sure to also add this as a listener to the model wherever it is needed.

Method Detail

modelChanged

public void modelChanged(DESIViewModel new_model)
If the model changes, you can call this method and the calculator will recalculate.

Parameters:
new_model -

addThisAsAListenerToModel

protected abstract void addThisAsAListenerToModel()
This method should be overriden by all subclasses. Use it to add yourself as a listener to the model.


removeThisAsAListenerFromModel

protected abstract void removeThisAsAListenerFromModel()
This method can be called to remove this as a listner. It must be overriden by subclasses.


calculate

protected abstract void calculate()
In this method, do your calculation and then return the calculated value. This method is called once for free when the Calculator is initialized but after that it must be called on property changes.


finalize

protected void finalize()
                 throws java.lang.Throwable
I overrode this method:

Throws:
java.lang.Throwable
See Also:
Object.finalize()

setMyLabelText

public void setMyLabelText(java.lang.String arg0)
This is a delegate method for the label that will set the text of the label to whatever is passed to it.

Parameters:
arg0 - String - The text that you want to set the label to.