net.sourceforge.webcompmath.awt.beans
Class WCMExpressionInputBean

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.text.JTextComponent
                  extended by javax.swing.JTextField
                      extended by net.sourceforge.webcompmath.awt.ExpressionInput
                          extended by net.sourceforge.webcompmath.awt.beans.WCMExpressionInputBean
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.DocumentListener, javax.swing.Scrollable, javax.swing.SwingConstants, InputObject, ParserMathObject, ExpressionCommand, Function, MathObject, ParserExtension, Value

public class WCMExpressionInputBean
extends ExpressionInput
implements Function, ParserExtension, ExpressionCommand, ParserMathObject

This class is primarily for use with GUI builders like Eclipse VE. To make it easier to create the most common case (an ExpressionInput represents a function's definition), this class extends ExpressionInput but then decorates it with Function, ParserExtension, and ExpressionCommand features. Hence you can set the function property of a WCMGraph1DBean to this class, since this class implements function. You can also add an instance of this class to a parser, since this class implements ParserExtendion.

Author:
Tom Downey
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class net.sourceforge.webcompmath.awt.ExpressionInput
ExpressionInput.EI
 
Nested classes/interfaces inherited from class javax.swing.JTextField
javax.swing.JTextField.AccessibleJTextField
 
Nested classes/interfaces inherited from class javax.swing.text.JTextComponent
javax.swing.text.JTextComponent.AccessibleJTextComponent, javax.swing.text.JTextComponent.DropLocation, javax.swing.text.JTextComponent.KeyBinding
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class net.sourceforge.webcompmath.awt.ExpressionInput
errorMessage, expr, hasChanged, parser, throwErrors
 
Fields inherited from class javax.swing.JTextField
notifyAction
 
Fields inherited from class javax.swing.text.JTextComponent
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
WCMExpressionInputBean()
          Default constructor; create a bean with a default parser, a variable called "x", and uses a default definition of "1" for the function.
 
Method Summary
 void appendOutputString(ExpressionProgram prog, int myIndex, java.lang.StringBuffer buffer)
          Just pass this method on to func
 void apply(StackOfDouble stack, Cases cases)
          Just pass this method on to func
 void compileDerivative(ExpressionProgram prog, int myIndex, ExpressionProgram deriv, Variable wrt)
          Just pass this method on to func
 boolean dependsOn(Variable x)
          Just pass this method on to func
 Function derivative(int wrt)
          Just pass this method on to func
 Function derivative(Variable x)
          Just pass this method on to func
 void doParse(Parser p, ParserContext context)
          Just pass this method on to func
 int extent(ExpressionProgram prog, int myIndex)
          Just pass this method on to func
 int getArity()
          Pass this through to func.
 Function getFunction()
          Just pass this method on to func
 MathObject getMathObject()
          Since this is a ParserExtension, just returns itself.
 java.lang.String getName()
          Just pass this method on to func
 int getNumVariables()
          Just pass this method on to func
 double getVal(double[] arguments)
          Just pass this method on to func
 double getValueWithCases(double[] arguments, Cases cases)
          Just pass this method on to func
 double getValWithCases(Cases cases)
          Get the value, when used as just an expression, but with cases.
 Variable getVariable()
          Get the variable to be used when this class is treaded as a function of one variable
 Variable getVariable2()
          Get the variable to be used when this class is treaded as a function of one variable
 void setName(java.lang.String name)
          Pass this on to func.
 void setNumVariables(int a)
          Set the arity, which can be either 1 or 2.
 void setParensCanBeOptional(boolean b)
          Set this property true if this is a function of one variable and you want it to behave like a standard function in that parentheses can be optional around the argument of the function.
 void setVariable(Variable v)
          Set the variable to be used when this class is treated as a function of one variable.
 void setVariable2(Variable v)
          Set the variable to be used when this class is treated as a function of one variable.
 
Methods inherited from class net.sourceforge.webcompmath.awt.ExpressionInput
actionPerformed, changedUpdate, checkInput, forceCheckInput, getErrorMessage, getExpression, getFunction, getFunction, getOnTextChange, getOnUserAction, getParser, getThrowErrors, getVal, insertUpdate, notifyControllerOnChange, removeUpdate, setOnTextChange, setOnUserAction, setParser, setText, setThrowErrors, toString
 
Methods inherited from class javax.swing.JTextField
actionPropertyChanged, addActionListener, configurePropertiesFromAction, createActionPropertyChangeListener, createDefaultModel, fireActionPerformed, getAccessibleContext, getAction, getActionListeners, getActions, getColumns, getColumnWidth, getHorizontalAlignment, getHorizontalVisibility, getPreferredSize, getScrollOffset, getUIClassID, isValidateRoot, paramString, postActionEvent, removeActionListener, scrollRectToVisible, setAction, setActionCommand, setColumns, setDocument, setFont, setHorizontalAlignment, setScrollOffset
 
Methods inherited from class javax.swing.text.JTextComponent
addCaretListener, addInputMethodListener, addKeymap, copy, cut, fireCaretUpdate, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPreferredScrollableViewportSize, getPrintable, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getText, getToolTipText, getUI, isEditable, loadKeymap, modelToView, moveCaretPosition, paste, print, print, print, processInputMethodEvent, read, removeCaretListener, removeKeymap, removeNotify, replaceSelection, select, selectAll, setCaret, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setMargin, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setUI, updateUI, viewToModel, write
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setSize, setSize, show, show, size, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sourceforge.webcompmath.data.beans.ParserMathObject
addPropertyChangeListener, removePropertyChangeListener
 

Constructor Detail

WCMExpressionInputBean

public WCMExpressionInputBean()
Default constructor; create a bean with a default parser, a variable called "x", and uses a default definition of "1" for the function. Also creates a second variable, "y", to be used if the user sets the arity to two.

Method Detail

setVariable

public void setVariable(Variable v)
Set the variable to be used when this class is treated as a function of one variable.

Parameters:
v -

getVariable

public Variable getVariable()
Get the variable to be used when this class is treaded as a function of one variable

Returns:
the variable

setVariable2

public void setVariable2(Variable v)
Set the variable to be used when this class is treated as a function of one variable.

Parameters:
v -

getVariable2

public Variable getVariable2()
Get the variable to be used when this class is treaded as a function of one variable

Returns:
the variable

getArity

public int getArity()
Pass this through to func.

Specified by:
getArity in interface Function
Returns:
the arity

getNumVariables

public int getNumVariables()
Just pass this method on to func

Returns:
1 or 2
See Also:
Function.getArity()

setNumVariables

public void setNumVariables(int a)
Set the arity, which can be either 1 or 2. If you need a function of more than 2 variables, you will need to hand code.

Parameters:
a - either 1 or 2

getValWithCases

public double getValWithCases(Cases cases)
Get the value, when used as just an expression, but with cases.

Parameters:
cases - the cases
Returns:
the value

getVal

public double getVal(double[] arguments)
Just pass this method on to func

Specified by:
getVal in interface Function
Parameters:
arguments - array of argument values
Returns:
function's value
See Also:
Function.getVal(double[])

getValueWithCases

public double getValueWithCases(double[] arguments,
                                Cases cases)
Just pass this method on to func

Specified by:
getValueWithCases in interface Function
Parameters:
arguments - array of argument values
cases - the cases to use
Returns:
function's value
See Also:
Function.getValueWithCases(double[], net.sourceforge.webcompmath.data.Cases)

derivative

public Function derivative(int wrt)
Just pass this method on to func

Specified by:
derivative in interface Function
Parameters:
wrt - argument Number with respect to
Returns:
the derivative
See Also:
Function.derivative(int)

derivative

public Function derivative(Variable x)
Just pass this method on to func

Specified by:
derivative in interface Function
Parameters:
x - variable with respect to
Returns:
the derivative
See Also:
Function.derivative(net.sourceforge.webcompmath.data.Variable)

dependsOn

public boolean dependsOn(Variable x)
Just pass this method on to func

Specified by:
dependsOn in interface ExpressionCommand
Specified by:
dependsOn in interface Function
Parameters:
x - variable to check
Returns:
true or false
See Also:
Function.dependsOn(net.sourceforge.webcompmath.data.Variable)

doParse

public void doParse(Parser p,
                    ParserContext context)
Just pass this method on to func

Specified by:
doParse in interface ParserExtension
Parameters:
p - parser to use
context - parser context to use
See Also:
ParserExtension.doParse(net.sourceforge.webcompmath.data.Parser, net.sourceforge.webcompmath.data.ParserContext)

apply

public void apply(StackOfDouble stack,
                  Cases cases)
Just pass this method on to func

Specified by:
apply in interface ExpressionCommand
Parameters:
stack - contains results of previous commands in the program.
cases - if non-null, any case information generated during evaluation should be recorded here.
See Also:
ExpressionCommand.apply(net.sourceforge.webcompmath.data.StackOfDouble, net.sourceforge.webcompmath.data.Cases)

compileDerivative

public void compileDerivative(ExpressionProgram prog,
                              int myIndex,
                              ExpressionProgram deriv,
                              Variable wrt)
Just pass this method on to func

Specified by:
compileDerivative in interface ExpressionCommand
Parameters:
prog - program in which ExpressionCommand occurs.
myIndex - point at which ExpressionCommand occurs in the ExpressionProgram.
deriv - the derivative of the ExpressionPorgram prog, which is in the process of being computed. Commands should added to deriv that will compute the derivative of this ExpressionCommand.
wrt - commands are added to deriv with respect to this Variable.
See Also:
ExpressionCommand.compileDerivative(net.sourceforge.webcompmath.data.ExpressionProgram, int, net.sourceforge.webcompmath.data.ExpressionProgram, net.sourceforge.webcompmath.data.Variable)

extent

public int extent(ExpressionProgram prog,
                  int myIndex)
Just pass this method on to func

Specified by:
extent in interface ExpressionCommand
Parameters:
prog - ExpressionProgram in which this ExpressionCommand occurs.
myIndex - index at which ExpressionCommand occurs in prog.
Returns:
total number of indices in prog occupied by this command and commands that generate data used by this command.
See Also:
ExpressionCommand.extent(net.sourceforge.webcompmath.data.ExpressionProgram, int)

appendOutputString

public void appendOutputString(ExpressionProgram prog,
                               int myIndex,
                               java.lang.StringBuffer buffer)
Just pass this method on to func

Specified by:
appendOutputString in interface ExpressionCommand
Parameters:
prog - program containing the expression
myIndex - location of the expression
buffer - string to append
See Also:
ExpressionCommand.appendOutputString(net.sourceforge.webcompmath.data.ExpressionProgram, int, java.lang.StringBuffer)

getMathObject

public MathObject getMathObject()
Since this is a ParserExtension, just returns itself.

Specified by:
getMathObject in interface ParserMathObject
Returns:
the MathObject that will be added to a parser
See Also:
ParserMathObject.getMathObject()

getFunction

public Function getFunction()
Just pass this method on to func

Returns:
the wrapped function
See Also:
WrapperFunction.getFunction()

getName

public java.lang.String getName()
Just pass this method on to func

Specified by:
getName in interface MathObject
Overrides:
getName in class java.awt.Component
Returns:
the name
See Also:
FunctionParserExtension.getName()

setName

public void setName(java.lang.String name)
Pass this on to func. Also, fire a property change event so WCMParserBeans that care can update themselves.

Specified by:
setName in interface MathObject
Overrides:
setName in class java.awt.Component
Parameters:
name - the new name
See Also:
FunctionParserExtension.setName(java.lang.String)

setParensCanBeOptional

public void setParensCanBeOptional(boolean b)
Set this property true if this is a function of one variable and you want it to behave like a standard function in that parentheses can be optional around the argument of the function. For the parentheses to be treated as optional, the option Parser.OPTIONAL_PARENS must ALSO be set in the parser. As an example, if you wanted to define the function sinh and allow the syntax "sinh x", you would turn this option and turn OTPTIONAL_PARENS on in the Parser.

Parameters:
b - true or false
See Also:
FunctionParserExtension.setParensCanBeOptional(boolean)