|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sourceforge.webcompmath.awt.Controller
public class Controller
Controllers are the focus of all the action in the JCM system. A Controller can be set to listen for changes (generally changes in user input). This is done by registering the Controller with (usally) an InputObject. For example, if a Controller, c, is to respond when the user presses return in a VariableInput, v, then v.setOnUserAction(c) should be called to arrange to have the Controller listen for such actions. VariableSliders, ExpressionInputs, MouseTrackers, Animators have a similar methods. It is also possible to set the Controller to listen for events of type AdjustmentEvent, ActionEvent, TextEvent, or ItemEvent (but this feature is left over from an older version of JCM, and I'm not sure whether it's necessary). Whenever a Controller learns of some change, it will process any InputObjects, Ties, and Computables that have been registered with it.
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.)
Field Summary | |
---|---|
protected java.util.Vector |
computables
Computable objects controlled by this controller. |
protected java.lang.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 java.util.Vector |
inputs
InputObjects controlled by this controller. |
protected Controller |
parent
The parent of this controller, if any. |
protected java.util.Vector |
ties
Ties that have been added to this controller. |
Constructor Summary | |
---|---|
Controller()
Create a Controller. |
Method Summary | |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent evt)
Simply calls compute when the Controller hears an ActionEvent. |
void |
add(java.lang.Object obj)
Add an object to be controlled by this controller. |
void |
adjustmentValueChanged(java.awt.event.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. |
Controller |
getParent()
Get the parent of this controller. |
void |
itemStateChanged(java.awt.event.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(java.lang.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(java.lang.String message)
Report the specified error message. |
void |
setAllErrorReporters(ErrorReporter r)
Method for recursively setting this controller's error reporter and all child controllers. |
void |
setErrorReporter(ErrorReporter r)
Set the ErrorReporter used to report errors that occur when the compute() method of this Controller is executed. |
void |
textValueChanged(java.awt.event.TextEvent evt)
Simply calls compute when the Controller hears a TextEvent. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.util.Vector computables
protected java.util.Vector inputs
protected java.util.Vector ties
protected ErrorReporter errorReporter
protected Controller parent
protected java.lang.String errorMessage
Constructor Detail |
---|
public Controller()
Method Detail |
---|
public void setErrorReporter(ErrorReporter r)
r
- the error reporter to usepublic void setAllErrorReporters(ErrorReporter r)
r
- public ErrorReporter getErrorReporter()
public void add(java.lang.Object obj)
obj
- the object to be controlledpublic void remove(java.lang.Object obj)
obj
- the object to be removedpublic void removeFromParent()
public void actionPerformed(java.awt.event.ActionEvent evt)
actionPerformed
in interface java.awt.event.ActionListener
evt
- the eventpublic void textValueChanged(java.awt.event.TextEvent evt)
textValueChanged
in interface java.awt.event.TextListener
evt
- the eventpublic void adjustmentValueChanged(java.awt.event.AdjustmentEvent evt)
adjustmentValueChanged
in interface java.awt.event.AdjustmentListener
evt
- the eventpublic void itemStateChanged(java.awt.event.ItemEvent evt)
itemStateChanged
in interface java.awt.event.ItemListener
evt
- the eventpublic void compute()
compute
in interface Computable
public void checkInput()
checkInput
in interface InputObject
protected void doTies()
protected void doCompute()
public void reportError(java.lang.String message)
message
- the message to be reportedprotected void clearErrorMessage()
public void errorCleared()
public void notifyControllerOnChange(Controller c)
notifyControllerOnChange
in interface InputObject
c
- the controller to usepublic void gatherInputs()
public Controller getParent()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |