Package org.opensourcephysics.tools
Class FunctionEditor
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
org.opensourcephysics.tools.FunctionEditor
- All Implemented Interfaces:
ImageObserver,MenuContainer,PropertyChangeListener,Serializable,EventListener,Accessible
- Direct Known Subclasses:
DataFunctionEditor,ParamEditor,UserFunctionEditor
A JPanel that manages a table of objects with editable names and expressions.
Main component of FunctionTool.
subclassed as DataFunctionEditor, ParamEditor (incl. InitialValueEditor), and
UserFunctionEditor
FunctionEditor
DataFunctionEditor
ParamEditor
InitialValueEditor
UserFunctionEditor
- Author:
- Douglas Brown
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassA class to undo/redo edits.static interfaceimplemented by DataFunction, UserFunction, and ParameterclassClass descriptionprotected classThe table model.Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intprotected booleanstatic final booleanprotected booleanprotected BitSetprotected booleanstatic final Stringprotected static String[]protected BitSetprotected List<FunctionEditor.FObject>static final intprotected FunctionPanelstatic final intprotected String[]protected Stringprotected ArrayList<FunctionEditor.FObject>static final Stringprotected ParamEditorstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected booleanstatic final intprotected Stringset to "t" in InitialValueEditor for getVariablesStringprotected FunctionEditor.Tableprotected org.opensourcephysics.tools.FunctionEditor.CellEditorprotected org.opensourcephysics.tools.FunctionEditor.CellRendererprotected FunctionEditor.TableModelstatic final Stringprotected Stringprotected static booleanFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddObject(FunctionEditor.FObject obj, boolean postEdit) Adds an object.addObject(FunctionEditor.FObject obj, int row, boolean postEdit, boolean firePropertyChange) Adds an object at a specified row.voidcheckGUI()booleanReturns true if any objects have invalid expressions.protected voidCreates the GUI.protected abstract FunctionEditor.FObjectcreateObject(String name, String expression, FunctionEditor.FObject obj) Creates an object with specified name and expression.protected FunctionEditor.FObjectcreateUniqueObject(FunctionEditor.FObject obj, String proposedName, boolean confirmChanges) Creates an object with a unique name.protected voidRefreshes button states.abstract voidEvaluates all current objects.static Stringformat(double value, double zeroLevel) Formats a number.protected voidGets the clipboard contents.booleanGets the confirmChanges flag.protected StringReturns the default name for newly created objects.abstract StringReturns the description of the object.abstract StringReturns the expression of the object.Gets the FunctionPanel that manages this editor.abstract StringReturns the name of the object.String[]getNames()Gets an array containing the names of the objects.Gets an existing object with specified name.Gets a shallow clone of the objects list.protected ParamEditorGets the param editor that defines parameters for functions.protected intReturns the number of editable rows.Override getPreferredSize().protected FunctionEditor.FObjectReturns the currently selected object, if any.protected FunctionEditor.FObject[]Returns the currently selected objects, if any.getTable()Gets the table.abstract StringReturns a tooltip for the object.protected UndoableEditgetUndoableEdit(int type, Object redo, int redoRow, int redoCol, Object undo, int undoRow, int undoCol, String name) Gets an undoable edit.protected static booleangetVariablePoints(JTextPane variablesPane, Point pt, int[] ret) Scan a JTextPane entry such as blah blah blah: vr fr x y t for the mouse being over one of these.protected StringgetVariablesString(String separator) Returns a String with the names of variables available for expressions.getVariablesString(StringBuffer vars, String separator) booleanhasReference(int i1, int i2) protected booleanhaveGUI()protected booleanisDisallowedName(FunctionEditor.FObject obj, String name) Returns true if a name is forbidden or in use.booleanDetermines if an object's expression is editable.protected abstract booleanDetermines if an object is important.protected abstract booleanReturns true if the object expression is invalid.booleanDetermines if an object's name is editable.protected booleanDetermines if an object is removable.protected booleanisValidExpression(String expression) Determines if a test expression is valid.protected voidPastes the clipboard contents.voidResponds to property change events.protected booleanreferences(String name, HashSet<String> checked) Determines if a name is referenced by any functions in this editorvoidRefreshes the GUI.voidRefreshes button strings based on current locale.removeObject(FunctionEditor.FObject obj, boolean postEdit) Removes an object.static doubleround(double value, int sigfigs) Rounds a number.voidsetAnglesInDegrees(boolean degrees) Sets the anglesInDegrees flag.protected voidvoidsetBorderTitle(String title) Sets the border title.voidsetConfirmChanges(boolean confirm) Sets the confirmChanges flag.voidsetCustomButtons(AbstractButton[] buttons) Sets custom buttons on the button panel.voidsetDescription(FunctionEditor.FObject obj, String desc) Sets the description of the object.voidsetExpression(String name, String expression, boolean postEdit) Sets the expression of an existing named object, if any.voidsetFunctionPanel(FunctionPanel panel) Sets the FunctionPanel that contains this editor.voidsetObjects(List<FunctionEditor.FObject> newObjects) Replaces the current objects with new ones.protected voidsetParamEditor(ParamEditor editor) Sets the param editor that defines parameters for functions.protected abstract voidsetReferences(FunctionEditor.FObject obj, BitSet directRefrences) Subclasses implement to set objects referenced in an object's expression.protected abstract voidvoidsetVisible(boolean visible) voidprotected voidMethods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods 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, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, unregisterKeyboardAction, updateMethods 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, transferFocusDownCycle, validate, validateTreeMethods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, 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, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
PROPERTY_FUNCTIONEDITOR_EDIT
- See Also:
-
PROPERTY_FUNCTIONEDITOR_CLIPBOARD
- See Also:
-
PROPERTY_FUNCTIONEDITOR_PARAM_DESCRIPTION
- See Also:
-
PROPERTY_FUNCTIONEDITOR_DESCRIPTION
- See Also:
-
PROPERTY_FUNCTIONEDITOR_FOCUS
- See Also:
-
PROPERTY_FUNCTIONEDITOR_ANGLESINRADIANS
- See Also:
-
THETA
-
OMEGA
-
DEGREES
- See Also:
-
ADD_EDIT
public static final int ADD_EDIT- See Also:
-
REMOVE_EDIT
public static final int REMOVE_EDIT- See Also:
-
NAME_EDIT
public static final int NAME_EDIT- See Also:
-
EXPRESSION_EDIT
public static final int EXPRESSION_EDIT- See Also:
-
allowPopopFieldTooltip
public static final boolean allowPopopFieldTooltip -
undoEditsEnabled
protected static boolean undoEditsEnabled -
editTypes
-
paramEditor
-
functionPanel
-
objects
-
names
-
forbiddenNames
-
removablesAtTop
protected boolean removablesAtTop -
circularErrors
-
errors
-
evaluate
-
referencesChecked
-
anglesInDegrees
protected boolean anglesInDegrees -
confirmChanges
protected boolean confirmChanges -
skipAllName
set to "t" in InitialValueEditor for getVariablesString -
table
-
tableModel
-
tableCellEditor
protected org.opensourcephysics.tools.FunctionEditor.CellEditor tableCellEditor -
tableCellRenderer
protected org.opensourcephysics.tools.FunctionEditor.CellRenderer tableCellRenderer -
addButtonPanel
protected boolean addButtonPanel -
newButtonTipText
-
titledBorderText
-
-
Constructor Details
-
FunctionEditor
public FunctionEditor()No-arg constructor
-
-
Method Details
-
checkGUI
public void checkGUI() -
getTable
Gets the table.- Returns:
- the table
-
getPreferredSize
Override getPreferredSize().- Overrides:
getPreferredSizein classJComponent- Returns:
- the table size plus button and instruction heights
-
setObjects
Replaces the current objects with new ones.- Parameters:
newObjects- a list of objects
-
updateTable
protected void updateTable() -
getObjects
Gets a shallow clone of the objects list.- Returns:
- a list of objects
-
getNames
Gets an array containing the names of the objects.- Returns:
- an array of names
-
getName
Returns the name of the object.- Parameters:
obj- the object- Returns:
- the name
-
getExpression
Returns the expression of the object.- Parameters:
obj- the object- Returns:
- the expression
-
getDescription
Returns the description of the object.- Parameters:
obj- the object- Returns:
- the description
-
setDescription
Sets the description of the object. Subclasses should override and call this AFTER changing the object description.- Parameters:
obj- the objectdesc- the description
-
getTooltip
Returns a tooltip for the object.- Parameters:
obj- the object- Returns:
- the tooltip
-
getObject
Gets an existing object with specified name. May return null.- Parameters:
name- the name- Returns:
- the object
-
setExpression
Sets the expression of an existing named object, if any.- Parameters:
name- the nameexpression- the expressionpostEdit- true to post an undoable edit
-
getConfirmChanges
public boolean getConfirmChanges()Gets the confirmChanges flag.- Returns:
- true if users are required to confirm changes to function names
-
setConfirmChanges
public void setConfirmChanges(boolean confirm) Sets the confirmChanges flag.- Parameters:
confirm- true to require users to confirm changes to function names
-
addObject
Adds an object.- Parameters:
obj- the objectpostEdit- true to post an undoable edit- Returns:
- the added object
-
addObject
public FunctionEditor.FObject addObject(FunctionEditor.FObject obj, int row, boolean postEdit, boolean firePropertyChange) Adds an object at a specified row.- Parameters:
obj- the objectrow- the rowpostEdit- true to post an undoable editfirePropertyChange- true to fire a property change event- Returns:
- the added object
-
removeObject
Removes an object.- Parameters:
obj- the object to removepostEdit- true to post an undoable edit- Returns:
- the removed object
-
refreshStrings
public void refreshStrings()Refreshes button strings based on current locale. -
propertyChange
Responds to property change events.- Specified by:
propertyChangein interfacePropertyChangeListener- Parameters:
e- the event
-
setCustomButtons
Sets custom buttons on the button panel. Setting buttons to null removes all buttons from this editor. -
getUndoableEdit
protected UndoableEdit getUndoableEdit(int type, Object redo, int redoRow, int redoCol, Object undo, int undoRow, int undoCol, String name) Gets an undoable edit.- Parameters:
type- may be ADD_EDIT, REMOVE_EDIT, NAME_EDIT, or EXPRESSION_EDITredo- the new stateredoRow- the newly selected rowredoCol- the newly selected columnundo- the previous stateundoRow- the previously selected rowundoCol- the previously selected columnname- the name of the edited object
-
isNameEditable
Determines if an object's name is editable.- Parameters:
obj- the object- Returns:
- true if the name is editable
-
isExpressionEditable
Determines if an object's expression is editable.- Parameters:
obj- the object- Returns:
- true if the expression is editable
-
isRemovable
Determines if an object is removable.- Parameters:
obj- the object- Returns:
- true if removable
-
isImportant
Determines if an object is important.- Parameters:
obj- the object- Returns:
- true if important
-
setAnglesInDegrees
public void setAnglesInDegrees(boolean degrees) Sets the anglesInDegrees flag. Angles are displayed in degrees when true, radians when false.- Parameters:
degrees- true to display angles in degrees
-
evaluateAll
public abstract void evaluateAll()Evaluates all current objects. -
setArrays
protected void setArrays() -
hasReference
public boolean hasReference(int i1, int i2) -
isValidExpression
Determines if a test expression is valid.- Parameters:
statement-- Returns:
- true if valid
-
references
Determines if a name is referenced by any functions in this editor- Parameters:
name- the name to look forchecked- a set of previously checked names (to prevent endless loops)- Returns:
-
setReferences
Subclasses implement to set objects referenced in an object's expression. -
haveGUI
protected boolean haveGUI() -
setTitles
protected abstract void setTitles() -
createGUI
protected void createGUI()Creates the GUI. -
refreshGUI
public void refreshGUI()Refreshes the GUI. -
setBorderTitle
Sets the border title. -
enableMenuButtons
protected void enableMenuButtons()Refreshes button states. -
setVisible
public void setVisible(boolean visible) - Overrides:
setVisiblein classJComponent
-
getParamEditor
Gets the param editor that defines parameters for functions. -
setParamEditor
Sets the param editor that defines parameters for functions. By default, the editor pasted in is ignored unless not yet set. -
getFunctionPanel
Gets the FunctionPanel that manages this editor. -
setFunctionPanel
Sets the FunctionPanel that contains this editor.- Parameters:
panel- the function panel
-
getDefaultName
Returns the default name for newly created objects. -
getVariablesString
Returns a String with the names of variables available for expressions. This default returns the names of all objects in this panel except the selected object.- Parameters:
separator-- Returns:
-
getVariablesString
-
getPartlyEditableRowCount
protected int getPartlyEditableRowCount()Returns the number of editable rows. -
isInvalidExpression
Returns true if the object expression is invalid. -
containsInvalidExpressions
public boolean containsInvalidExpressions()Returns true if any objects have invalid expressions. -
pasteAction
protected void pasteAction()Pastes the clipboard contents. -
getClipboardContentsAsync
Gets the clipboard contents. -
getSelectedObject
Returns the currently selected object, if any. -
getSelectedObjects
Returns the currently selected objects, if any. -
createObject
protected abstract FunctionEditor.FObject createObject(String name, String expression, FunctionEditor.FObject obj) Creates an object with specified name and expression. An existing object may be passed in for modification or cloning, but there is no guarantee the same object will be returned.- Parameters:
name- the nameexpression- the expressionobj- an object to assign values (may be null)- Returns:
- the object
-
isDisallowedName
Returns true if a name is forbidden or in use.- Parameters:
obj- the object (may be null)name- the proposed name for the object- Returns:
- true if disallowed
-
createUniqueObject
protected FunctionEditor.FObject createUniqueObject(FunctionEditor.FObject obj, String proposedName, boolean confirmChanges) Creates an object with a unique name.- Parameters:
obj- the object (may be null)proposedName- the proposed nameconfirmChanges- true to require user to confirm changes- Returns:
- the object
-
getVariablePoints
Scan a JTextPane entry such as blah blah blah: vr fr x y t for the mouse being over one of these. Turn it red and return the character positions in the ret array.- Parameters:
variablesPane-pt-ret- [pt, pt+len]- Returns:
- true if variable was found
-
format
Formats a number.- Parameters:
value- the numberzeroLevel- the level below which the value is considered zero- Returns:
- the formatted string
-
round
public static double round(double value, int sigfigs) Rounds a number.- Parameters:
value- the numbersigfigs- the number of significant figures in the rounded value- Returns:
- the rounded value
-
tabToNext
public void tabToNext()
-