public class Controller extends Object implements Serializable, Computable, InputObject, AdjustmentListener, ActionListener, TextListener, ItemListener
InputObjects and Computables have to be added to a Controller to be processed, using the Controller's add method. (If you build your inteface out of JCMPanels, then this is done automatically.) (Note that an InputObject is added to a Controller to have its value checked -- This is separate from registering the Controller to listen for changes in the InputObject. Often, you have to do both.) The gatherInputs() method in class JCMPanel can be used to do most of this registration automaticaly.
A Tie that synchronizes two or more Values, to be effective, has to be added to a Controller. See the Tie class for inforamtion about what Ties are and how they are used.
A Controller can have an associated ErrorReporter, which is used to report any errors that occur during the processing. Currently, an ErrorReporter is either a DisplayCanvas or a MessagePopup.
A Controller can be added to another Controller, which then becomes a sub-controller. Whenever the main Controller hears some action, it also notifies all its sub-controllers about the action. Furthermore, it can report errors that occur in the sub-controllers, if they don't have their own error reporters. (Usually, you will just set an error reporter for the top-level Controller.)
Modifier and Type | Field and Description |
---|---|
protected Vector |
computables
Computable objects controlled by this controller.
|
protected String |
errorMessage
If non-null, this is an error message
that has been reported and not yet cleared.
|
protected ErrorReporter |
errorReporter
Used for reporting errors that occur in the
compute() method of this controller.
|
protected Vector |
inputs
InputObjects controlled by this controller.
|
protected Controller |
parent
The parent of this controller, if any.
|
protected Vector |
ties
Ties that have been added to this controller.
|
Constructor and Description |
---|
Controller()
Create a Controller.
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(ActionEvent evt)
Simply calls compute when the Controller hears an ActionEvent.
|
void |
add(Object obj)
Add an object to be controlled by this controller.
|
void |
adjustmentValueChanged(AdjustmentEvent evt)
Simply calls compute when the Controller hears an AdjustmantEvent.
|
void |
checkInput()
Call checkInput() of each InputObject.
|
protected void |
clearErrorMessage()
Clear the error message.
|
void |
compute()
When an contoller computes, it first calls checkInput() for any
InputOjects that it controls (including those in sub-controllers).
|
protected void |
doCompute()
Compute the Computables in this controller and its sub-controllers.
|
protected void |
doTies()
Check the Ties in this controller and its sub-controllers.
|
void |
errorCleared()
Should be called by the ErrorReporter if the ErrorReporter clears the error itself.
|
void |
gatherInputs()
Calles notifyControllerOnChange(this).
|
ErrorReporter |
getErrorReporter()
Get the ErrorReporter for this Controller.
|
void |
itemStateChanged(ItemEvent evt)
Simply calls compute when the Controller hears an ItemEvent.
|
void |
notifyControllerOnChange(Controller c)
Method required by InputObject interface; in this class, calls the same method
recursively on any input objects controlled by this controller.
|
void |
remove(Object obj)
Remove the object from the controller (if present).
|
void |
removeFromParent()
If this controller has a parent, remove it from its parent.
|
void |
reportError(String message)
Report the specified error message.
|
void |
setErrorReporter(ErrorReporter r)
Set the ErrorReporter used to report errors that occur when the
compute() method of this Controller is executed.
|
void |
textValueChanged(TextEvent evt)
Simply calls compute when the Controller hears a TextEvent.
|
protected Vector computables
protected Vector inputs
protected Vector ties
protected ErrorReporter errorReporter
protected Controller parent
protected String errorMessage
public void setErrorReporter(ErrorReporter r)
public ErrorReporter getErrorReporter()
public void add(Object obj)
public void remove(Object obj)
public void removeFromParent()
public void actionPerformed(ActionEvent evt)
actionPerformed
in interface ActionListener
public void textValueChanged(TextEvent evt)
textValueChanged
in interface TextListener
public void adjustmentValueChanged(AdjustmentEvent evt)
adjustmentValueChanged
in interface AdjustmentListener
public void itemStateChanged(ItemEvent evt)
itemStateChanged
in interface ItemListener
public void compute()
compute
in interface Computable
public void checkInput()
checkInput
in interface InputObject
protected void doTies()
protected void doCompute()
public void reportError(String message)
protected void clearErrorMessage()
public void errorCleared()
public void notifyControllerOnChange(Controller c)
notifyControllerOnChange
in interface InputObject
public void gatherInputs()