|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.TextComponent | +--java.awt.TextField | +--edu.hws.jcm.awt.ExpressionInput
An ExpressionInput is an input box that allows the user input a mathematical expression. There is an associated object that belongs to the class Expression. The value of this object can change only when checkInput() is called. The checkInput() method is usually called by a Controller.
An ExpressionInput will ordinarily be registered with a Controller in TWO ways: It's added to a Controller with the Controller's add() method. This makes the Contrller call the ExpressionInput's checkInput() method during the Controller's compute() method. Secondly, the Controller is set as the "onUserAction" property. This causes the Controller's compute() method to be called when the user presses return in the ExpressionInput box. This is optional-- you might, for example, only want the Controller to compute() when a Compute button is pressed. You can also set the ExpressionInput's onTextChange property to a Controller if you want it to compute every time the text in the box changes.
Use the function getFunction() if you want to use an ExpressionInput as a way of inputting a function.
Inner Class Summary | |
protected class |
ExpressionInput.EI
The expression associated with an ExpressionInput belongs to this class. |
Inner classes inherited from class java.awt.TextField |
java.awt.TextField.AccessibleAWTTextField |
Inner classes inherited from class java.awt.TextComponent |
java.awt.TextComponent.AccessibleAWTTextComponent |
Inner classes inherited from class java.awt.Component |
java.awt.Component.AccessibleAWTComponent |
Field Summary | |
protected java.lang.String |
errorMessage
Error message from the most recent time the input was checked by a call to checkInput(). |
protected ExpressionInput.EI |
expr
The Expression associate with this input box. |
protected boolean |
hasChanged
True if the contents of the box have not changed since the last time the input was checked (by a call to checkInput()). |
protected Parser |
parser
A parser for parsing the user's input expression. |
protected boolean |
throwErrors
True if an error should be thrown when checkInput() is called, but the content of the box is not a legal expression. |
Fields inherited from class java.awt.TextComponent |
textListener |
Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
ExpressionInput()
Create a new ExpressionFunction with no associated parser. |
|
ExpressionInput(java.lang.String initialValue,
Parser p)
Create an ExpressionInputBox with initial contents given by initialValue. |
Method Summary | |
void |
checkInput()
Get the expression from the box, maybe throw a JBCError if a ParseError occurs. |
java.lang.String |
getErrorMessage()
Get error message from previous call to checkInput(). |
Expression |
getExpression()
Get the Expression associated with this ExpressionInput. |
Function |
getFunction(Variable v)
Get a function of one variable whose value at a real number x is computed by assigning x to the variable v and then returning the value of the expression associated with this ExpressionInput. |
Function |
getFunction(Variable[] v)
Get a function of one or more variables whose value at arguments x1, x2, ... |
Controller |
getOnTextChange()
Return the Controller, if any, that is notified whenever the text in this input box changes |
Controller |
getOnUserAction()
Return the Controller, if any, that is notified when the user presses return in this text-input box. |
boolean |
getThrowErrors()
Return the value of the throwErrors property, which determines whether errors can be thrown when checkInput() is called. |
double |
getVal()
Return the current value of the expression associated with this ExpressionInput. |
void |
notifyControllerOnChange(Controller c)
Method required by InputObject interface; in this class, it simply calls setOnUserAction(c). |
void |
processActionEvent(java.awt.event.ActionEvent evt)
Overridden to call onUserAction.compute() if onUserAction is non-null. |
void |
processKeyEvent(java.awt.event.KeyEvent evt)
Override processKeyEvent to only allow characters that are legal in expressions. |
void |
processTextEvent(java.awt.event.TextEvent evt)
Overridden to call onUserAction.compute() if onUserAction is non-null. |
void |
setOnTextChange(Controller c)
If the parameter, c, is non-null, then its compute method will be called whenever the text in this input box changes. |
void |
setOnUserAction(Controller c)
If the parameter c is non-null, then its compute method will be called whenever the user presses the return key while typing in this text-input box. |
void |
setParser(Parser p)
Set the parser that is used to parse the user's input strings. |
void |
setText(java.lang.String str)
Set the text displayed in this input box. |
void |
setThrowErrors(boolean throwErrors)
Set the throwErrors property. |
Methods inherited from class java.awt.TextField |
addActionListener, addNotify, echoCharIsSet, getAccessibleContext, getColumns, getEchoChar, getListeners, getMinimumSize, getMinimumSize, getPreferredSize, getPreferredSize, minimumSize, minimumSize, paramString, preferredSize, preferredSize, processEvent, removeActionListener, setColumns, setEchoChar, setEchoCharacter |
Methods inherited from class java.awt.TextComponent |
addTextListener, getBackground, getCaretPosition, getSelectedText, getSelectionEnd, getSelectionStart, getText, isEditable, removeNotify, removeTextListener, select, selectAll, setBackground, setCaretPosition, setEditable, setSelectionEnd, setSelectionStart |
Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAlignmentX, getAlignmentY, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, postEvent, prepareImage, prepareImage, print, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, update, validate |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected ExpressionInput.EI expr
protected Parser parser
protected boolean hasChanged
protected boolean throwErrors
protected java.lang.String errorMessage
Constructor Detail |
public ExpressionInput()
public ExpressionInput(java.lang.String initialValue, Parser p)
initialValue
- initial contents of ExpressionInputBox.p
- if non-null, this parser will be used to parse contents of the ExpressionInputBox.Method Detail |
public void setParser(Parser p)
p
- parser to register with user's input strings.public Expression getExpression()
public Function getFunction(Variable v)
v
- The function that is returned in a function of this variable.public Function getFunction(Variable[] v)
v
- The function that is returned is a function of the variables in this array.public double getVal()
getVal
in interface Value
public void setOnUserAction(Controller c)
public Controller getOnUserAction()
public void notifyControllerOnChange(Controller c)
notifyControllerOnChange
in interface InputObject
public void setOnTextChange(Controller c)
public Controller getOnTextChange()
public void setThrowErrors(boolean throwErrors)
public boolean getThrowErrors()
public java.lang.String getErrorMessage()
public void checkInput()
checkInput
in interface InputObject
public void setText(java.lang.String str)
setText
in class java.awt.TextField
public void processKeyEvent(java.awt.event.KeyEvent evt)
processKeyEvent
in class java.awt.Component
public void processActionEvent(java.awt.event.ActionEvent evt)
processActionEvent
in class java.awt.TextField
public void processTextEvent(java.awt.event.TextEvent evt)
processTextEvent
in class java.awt.TextComponent
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |