Package org.opentrafficsim.editor
Class OtsEditor
java.lang.Object
java.awt.Component
java.awt.Container
java.awt.Window
java.awt.Frame
javax.swing.JFrame
org.opentrafficsim.swing.gui.AppearanceApplication
org.opentrafficsim.editor.OtsEditor
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible,RootPaneContainer,WindowConstants,EventProducer
Editor window to load, edit and save OTS XML files. The class uses an underlying data structure that is based on the XML
Schema for the XML (XSD).
This functionality is currently in development.
This functionality is currently in development.
Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
- Author:
- Wouter Schakel
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JFrame
JFrame.AccessibleJFrameNested classes/interfaces inherited from class java.awt.Frame
Frame.AccessibleAWTFrameNested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow, Window.TypeNested 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 ColorColor for inactive nodes (text).static final EventTypeEvent when a a new file is started.static final EventTypeEvent when the selection in the tree is changed.Fields inherited from class org.opentrafficsim.swing.gui.AppearanceApplication
framePropertiesFields inherited from class javax.swing.JFrame
accessibleContext, rootPane, rootPaneCheckingEnabledFields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSORFields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface org.djutils.event.EventProducer
FIRST_POSITION, LAST_POSITIONFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an external listener to the cell editor of the attributes table.voidaddEvalListener(EvalWrapper.EvalListener listener) Adds listener to changes in the evaluator, i.e. added, removed or changed input parameters.booleanaddListener(EventListener listener, EventType eventType) voidAdds a tab to the main window.voidcollapse(XsdTreeNode node) Collapses the given node, if expanded.booleanRequests the user to confirm the deletion of a node.voidPlace focus on the tab with given name.Returns the node that is the currently selected choice.Returns the clipboard node.getCustomIcon(String path) Obtains a custom icon for the path.getEval()Return an evaluator to evaluate expression values.static ColorReturns the expression cell color.static ColorReturns the invalid cell color.Returns the node actions.Returns the component of the tab with given name.getTreeNodeAtPoint(Point point) Returns the XsdTreeNode of the row under the given point (from a mouse or key event).getUndo()Returns the undo unit.static StringlimitTooltip(String message) Limits the length of a tooltip message.booleanReturns whether a choice may be presented.voidpreparePopupRemoval(JPopupMenu popup, JComponent component) Adds a listener to a popup to remove the popop from the component when the popup becomes invisible.voidRemove node that was cut.voidremoveEvalListener(EvalWrapper.EvalListener listener) Removes listener to changes in the evaluator, i.e. added, removed or changed input parameters.voidRemoves the status label.protected voidrunBatch(boolean all) Batch run.voidsaveFileAs(XsdTreeNode root) Shows a dialog to define a file and saves in to it.voidsetAppearance(Appearance appearance) voidsetChoiceNode(XsdTreeNode choiceNode) Sets the node that is the currently selected choice.voidsetClipboard(XsdTreeNode clipboard, boolean cut) Sets a node in the clipboard.voidsetCoupledNode(XsdTreeNode toNode, XsdTreeNode fromNode, String fromAttribute) Sets coupled node from user action, i.e. the node that contains the key value to which a user selected node with keyref refers to.voidsetCustomIcon(String path, ImageIcon icon) Sets a custom icon for nodes that comply to the path.voidsetMayPresentChoice(boolean mayPresentChoice) Sets whether the choice menu may appear.voidSets a new schema in the GUI.voidsetStatusLabel(String label) Sets a status label.voidsetUnsavedChanges(boolean unsavedChanges) Sets whether there are unsaved changes, resulting in a * in the window name, and confirmation pop-ups upon file changes.voidshow(XsdTreeNode node, String attribute) Shows and selects the given node in the tree.voidshowCircularInputParameters(String message) Show input parameters have a circular dependency.voidshowDescription(String description) Shows a description in a modal pane.voidshowInvalidExpression(String message) Show message about invalid expression.voidShow tree invalid.voidShow unable to run.voidCreates a new undo action as the selection is changed in the tree table, editing is stopped, or focus is gained/lost.voidPlaces a popup with value options under the cell that is being clicked in a table (tree or attributes).Methods inherited from class org.opentrafficsim.swing.gui.AppearanceApplication
changeFont, changeFontSize, getAppearance, setDefaultFont, setFontScaleMethods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, updateMethods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setBackground, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setOpacity, setResizable, setShape, setState, setTitle, setUndecoratedMethods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, setVisible, show, toBack, toFrontMethods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, 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, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setMixingCutoutShape, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djutils.event.EventProducer
addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListenerMethods inherited from interface java.awt.MenuContainer
getFont, postEvent
-
Field Details
-
NEW_FILE
Event when a a new file is started. -
SELECTION_CHANGED
Event when the selection in the tree is changed. -
INACTIVE_COLOR
Color for inactive nodes (text).
-
-
Constructor Details
-
OtsEditor
Constructor.- Throws:
IOException- when a resource could not be loaded.
-
-
Method Details
-
getInvalidColor
Returns the invalid cell color.- Returns:
- the invalid cell color
-
getExpressionColor
Returns the expression cell color.- Returns:
- the expression cell color
-
runBatch
protected void runBatch(boolean all) Batch run.- Parameters:
all- all scenarios, or only the selected scenario.
-
getUndo
Returns the undo unit.- Returns:
- undo unit.
-
collapse
Collapses the given node, if expanded.- Parameters:
node- node
-
show
Shows and selects the given node in the tree.- Parameters:
node- node.attribute- attribute name, may benullto just show the node.
-
setStatusLabel
Sets a status label.- Parameters:
label- status label.
-
removeStatusLabel
public void removeStatusLabel()Removes the status label. -
setCoupledNode
Sets coupled node from user action, i.e. the node that contains the key value to which a user selected node with keyref refers to.- Parameters:
toNode- key node that is coupled to from a keyref node, may benull.fromNode- keyref node that is coupled from to a key node, may benull.fromAttribute- attribute in keyref node that refers to coupled node, may benull.
-
setUnsavedChanges
public void setUnsavedChanges(boolean unsavedChanges) Sets whether there are unsaved changes, resulting in a * in the window name, and confirmation pop-ups upon file changes.- Parameters:
unsavedChanges- whether there are unsaved changes.
-
setSchema
Sets a new schema in the GUI.- Parameters:
xsdDocument- main node from an XSD schema file.- Throws:
IOException- when a resource could not be loaded.
-
startUndoActionOnTreeTable
public void startUndoActionOnTreeTable()Creates a new undo action as the selection is changed in the tree table, editing is stopped, or focus is gained/lost. -
getTreeNodeAtPoint
Returns the XsdTreeNode of the row under the given point (from a mouse or key event).- Parameters:
point- point (from an event)- Returns:
- the XsdTreeNode of the row under the given point
-
preparePopupRemoval
Adds a listener to a popup to remove the popop from the component when the popup becomes invisible. This makes sure that a right-click on another location that should show a different popup, is not overruled by the popup of a previous click.- Parameters:
popup- popup menu.component- component from which the menu will be removed.
-
setCustomIcon
Sets a custom icon for nodes that comply to the path. The path may be an absolute path (e.g. "Ots.Network.Connector") or a relative path (e.g. ".Node").- Parameters:
path- path.icon- image icon.
-
getCustomIcon
Obtains a custom icon for the path.- Parameters:
path- node path.- Returns:
- custom icon, empty if there is no custom icon specified for the path.
-
getChoiceNode
Returns the node that is the currently selected choice.- Returns:
- node that is the currently selected choice.
-
setChoiceNode
Sets the node that is the currently selected choice.- Parameters:
choiceNode- node that is the currently selected choice.
-
setMayPresentChoice
public void setMayPresentChoice(boolean mayPresentChoice) Sets whether the choice menu may appear.- Parameters:
mayPresentChoice- whether the choice menu may appear
-
mayPresentChoice
public boolean mayPresentChoice()Returns whether a choice may be presented.- Returns:
- whether a choice may be presented.
-
getEventListenerMap
- Specified by:
getEventListenerMapin interfaceEventProducer
-
addTab
Adds a tab to the main window.- Parameters:
name- name of the tab.icon- icon for the tab, may benull.component- component that will fill the tab.tip- tool-tip for the tab, may benull.
-
getTab
Returns the component of the tab with given name.- Parameters:
name- name of the tab.- Returns:
- component of the tab with given name or empty if no such tab
-
focusTab
Place focus on the tab with given name.- Parameters:
name- name of the tab.
-
confirmNodeRemoval
Requests the user to confirm the deletion of a node. The default button is "Ok". The window popping up is considered sufficient warning, and in this way a speedy succession of "del" and "enter" may delete a consecutive range of nodes to be deleted.- Parameters:
node- node.- Returns:
trueif the user confirms node removal.
-
showDescription
Shows a description in a modal pane.- Parameters:
description- description.
-
showInvalidToRunMessage
public void showInvalidToRunMessage()Show tree invalid. -
showCircularInputParameters
Show input parameters have a circular dependency.- Parameters:
message- exception message
-
showInvalidExpression
Show message about invalid expression.- Parameters:
message- exception message
-
showUnableToRunFromTempFile
public void showUnableToRunFromTempFile()Show unable to run. -
valueOptionsPopup
Places a popup with value options under the cell that is being clicked in a table (tree or attributes). The popup will show items relevant to what is being typed in the cell. The maximum number of items shown is limited toMAX_DROPDOWN_ITEMS.- Parameters:
allOptions- list of all options, will be filtered when typing.table- table, will be either the tree table or the attributes table.action- action to perform based on the option in the popup that was selected.
-
saveFileAs
Shows a dialog to define a file and saves in to it.- Parameters:
root- root node of tree to save, can be a sub-tree of the full tree.
-
limitTooltip
Limits the length of a tooltip message. This is to prevent absurd tooltip texts based on really long patterns that should be matched. Will returnnullif the input isnull.- Parameters:
message- tooltip message, may benull.- Returns:
- possibly shortened tooltip message.
-
addAttributeCellEditorListener
Adds an external listener to the cell editor of the attributes table.- Parameters:
listener- listener to the cell editor of the attributes table.
-
setClipboard
Sets a node in the clipboard.- Parameters:
clipboard- node to set in the clipboard.cut- whether the node was cut.
-
getClipboard
Returns the clipboard node.- Returns:
- clipboard node.
-
removeClipboardWhenCut
public void removeClipboardWhenCut()Remove node that was cut. This can be called safely while not knowing the clipboard was cut. -
getNodeActions
Returns the node actions.- Returns:
- node actions.
-
addListener
- Specified by:
addListenerin interfaceEventProducer
-
getEval
Return an evaluator to evaluate expression values. This evaluator uses the input parameters of the currently selected scenario.- Returns:
- evaluator to evaluate expression values.
-
addEvalListener
Adds listener to changes in the evaluator, i.e. added, removed or changed input parameters.- Parameters:
listener- listener.
-
removeEvalListener
Removes listener to changes in the evaluator, i.e. added, removed or changed input parameters.- Parameters:
listener- listener.
-
setAppearance
- Overrides:
setAppearancein classAppearanceApplication
-