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 TypeClassDescriptionclass
A class to undo/redo edits.static interface
implemented by DataFunction, UserFunction, and Parameterclass
Class descriptionprotected class
The table model.Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
protected boolean
static final boolean
protected boolean
protected BitSet
protected boolean
static final String
protected static String[]
protected BitSet
protected List<FunctionEditor.FObject>
static final int
protected FunctionPanel
static final int
protected String[]
protected String
protected ArrayList<FunctionEditor.FObject>
static final String
protected ParamEditor
static final String
static final String
static final String
static final String
static final String
static final String
protected boolean
static final int
protected String
set to "t" in InitialValueEditor for getVariablesStringprotected FunctionEditor.Table
protected org.opensourcephysics.tools.FunctionEditor.CellEditor
protected org.opensourcephysics.tools.FunctionEditor.CellRenderer
protected FunctionEditor.TableModel
static final String
protected String
protected static boolean
Fields inherited from class javax.swing.JComponent
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
accessibleContext, 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
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.void
checkGUI()
boolean
Returns true if any objects have invalid expressions.protected void
Creates the GUI.protected abstract FunctionEditor.FObject
createObject
(String name, String expression, FunctionEditor.FObject obj) Creates an object with specified name and expression.protected FunctionEditor.FObject
createUniqueObject
(FunctionEditor.FObject obj, String proposedName, boolean confirmChanges) Creates an object with a unique name.protected void
Refreshes button states.abstract void
Evaluates all current objects.static String
format
(double value, double zeroLevel) Formats a number.protected void
Gets the clipboard contents.boolean
Gets the confirmChanges flag.protected String
Returns the default name for newly created objects.abstract String
Returns the description of the object.abstract String
Returns the expression of the object.Gets the FunctionPanel that manages this editor.abstract String
Returns 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 ParamEditor
Gets the param editor that defines parameters for functions.protected int
Returns the number of editable rows.Override getPreferredSize().protected FunctionEditor.FObject
Returns the currently selected object, if any.protected FunctionEditor.FObject[]
Returns the currently selected objects, if any.getTable()
Gets the table.abstract String
Returns a tooltip for the object.protected UndoableEdit
getUndoableEdit
(int type, Object redo, int redoRow, int redoCol, Object undo, int undoRow, int undoCol, String name) Gets an undoable edit.protected static boolean
getVariablePoints
(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 String
getVariablesString
(String separator) Returns a String with the names of variables available for expressions.getVariablesString
(StringBuffer vars, String separator) boolean
hasReference
(int i1, int i2) protected boolean
haveGUI()
protected boolean
isDisallowedName
(FunctionEditor.FObject obj, String name) Returns true if a name is forbidden or in use.boolean
Determines if an object's expression is editable.protected abstract boolean
Determines if an object is important.protected abstract boolean
Returns true if the object expression is invalid.boolean
Determines if an object's name is editable.protected boolean
Determines if an object is removable.protected boolean
isValidExpression
(String expression) Determines if a test expression is valid.protected void
Pastes the clipboard contents.void
Responds to property change events.protected boolean
references
(String name, HashSet<String> checked) Determines if a name is referenced by any functions in this editorvoid
Refreshes the GUI.void
Refreshes button strings based on current locale.removeObject
(FunctionEditor.FObject obj, boolean postEdit) Removes an object.static double
round
(double value, int sigfigs) Rounds a number.void
setAnglesInDegrees
(boolean degrees) Sets the anglesInDegrees flag.protected void
void
setBorderTitle
(String title) Sets the border title.void
setConfirmChanges
(boolean confirm) Sets the confirmChanges flag.void
setCustomButtons
(AbstractButton[] buttons) Sets custom buttons on the button panel.void
setDescription
(FunctionEditor.FObject obj, String desc) Sets the description of the object.void
setExpression
(String name, String expression, boolean postEdit) Sets the expression of an existing named object, if any.void
setFunctionPanel
(FunctionPanel panel) Sets the FunctionPanel that contains this editor.void
setObjects
(List<FunctionEditor.FObject> newObjects) Replaces the current objects with new ones.protected void
setParamEditor
(ParamEditor editor) Sets the param editor that defines parameters for functions.protected abstract void
setReferences
(FunctionEditor.FObject obj, BitSet directRefrences) Subclasses implement to set objects referenced in an object's expression.protected abstract void
void
setVisible
(boolean visible) void
protected void
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
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, 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, 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, transferFocusDownCycle, validate, validateTree
Methods 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:
getPreferredSize
in 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:
propertyChange
in 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:
setVisible
in 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()
-