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
,Remote
,Accessible
,RootPaneContainer
,WindowConstants
,org.djutils.event.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.AccessibleJFrame
Nested classes/interfaces inherited from class java.awt.Frame
Frame.AccessibleAWTFrame
Nested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow, Window.Type
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
Modifier and TypeFieldDescriptionstatic final Color
Color for expression nodes and values (background).static final Color
Color for inactive nodes (text).static final Color
Color for invalid nodes and values (background).static final org.djutils.event.EventType
Event when a a new file is started.static final org.djutils.event.EventType
Event when the selection in the tree is changed.static final Color
Color for status label.Fields inherited from class org.opentrafficsim.swing.gui.AppearanceApplication
frameProperties
Fields inherited from class javax.swing.JFrame
accessibleContext, rootPane, rootPaneCheckingEnabled
Fields 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_CURSOR
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface org.djutils.event.EventProducer
FIRST_POSITION, LAST_POSITION
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a listener to the cell editor of the attributes table.void
addEvalListener
(EvalWrapper.EvalListener listener) Adds listener to changes in the evaluator, i.e. added, removed or changed input parameters.boolean
addListener
(org.djutils.event.EventListener listener, org.djutils.event.EventType eventType) void
Adds a tab to the main window.boolean
Requests the user to confirm the deletion of a node.void
Place 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, ornull
if there is no custom icon specified for the path.org.djutils.eval.Eval
getEval()
Return an evaluator to evaluate expression values.org.djutils.event.EventListenerMap
Returns the node actions.Returns the component of the tab with given name.getUndo()
Returns the undo unit.static String
limitTooltip
(String message) Limits the length of a tooltip message.static ImageIcon
Loads an icon, possibly rescaled.boolean
Returns whether a choice may be presented.(package private) void
openFile()
Asks for confirmation to discard unsaved changes, if any, and show a dialog to open a file.void
Places a popup with options under the cell that is being clicked in a table.void
preparePopupRemoval
(JPopupMenu popup, JComponent component) Adds a listener to a popup to remove the popop from the component when the popup becomes invisible.void
Remove node that was cut.void
removeEvalListener
(EvalWrapper.EvalListener listener) Removes listener to changes in the evaluator, i.e. added, removed or changed input parameters.void
Removes the status label.protected void
runBatch
(boolean all) Batch run.void
saveFileAs
(XsdTreeNode root) Shows a dialog to define a file and saves in to it.void
setAppearance
(Appearance appearance) void
setChoiceNode
(XsdTreeNode choiceNode) Sets the node that is the currently selected choice.void
setClipboard
(XsdTreeNode clipboard, boolean cut) Sets a node in the clipboard.void
setCoupledNode
(XsdTreeNode coupledNode, XsdTreeNode backNode, String backAttribute) 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.void
setCustomIcon
(String path, ImageIcon icon) Sets a custom icon for nodes that comply to the path.void
Sets a new schema in the GUI.void
setStatusLabel
(String label) Sets a status label.void
setUnsavedChanges
(boolean unsavedChanges) Sets whether there are unsaved changes, resulting in a * in the window name, and confirmation pop-ups upon file changes.void
show
(XsdTreeNode node, String attribute) Shows and selects the given node in the tree.void
Show input parameters have a circular dependency.void
showDescription
(String description) Shows a description in a modal pane.void
Show tree invalid.void
Show unable to run.void
Creates a new undo action as the selection is changed in the tree table.Methods inherited from class org.opentrafficsim.swing.gui.AppearanceApplication
changeFont, changeFontSize, getAppearance, setDefaultFont, setFontScale
Methods 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, update
Methods 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, setUndecorated
Methods 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, toFront
Methods 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, validateTree
Methods 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, transferFocusUpCycle
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods 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, removeListener
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
-
Field Details
-
NEW_FILE
public static final org.djutils.event.EventType NEW_FILEEvent when a a new file is started. -
SELECTION_CHANGED
public static final org.djutils.event.EventType SELECTION_CHANGEDEvent when the selection in the tree is changed. -
INACTIVE_COLOR
Color for inactive nodes (text). -
STATUS_COLOR
Color for status label. -
INVALID_COLOR
Color for invalid nodes and values (background). -
EXPRESSION_COLOR
Color for expression nodes and values (background).
-
-
Constructor Details
-
OtsEditor
Constructor.- Throws:
IOException
- when a resource could not be loaded.
-
-
Method Details
-
runBatch
protected void runBatch(boolean all) Batch run.- Parameters:
all
- boolean; all scenarios, or only the selected scenario.
-
getUndo
Returns the undo unit.- Returns:
- Undo; undo unit.
-
show
Shows and selects the given node in the tree.- Parameters:
node
- XsdTreeNode; node.attribute
- String; attribute name, may benull
to just show the node.
-
setStatusLabel
Sets a status label.- Parameters:
label
- String; 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:
coupledNode
- XsdTreeNode; key node that is coupled to from a keyref node, may benull
.backNode
- XsdTreeNode; keyref node that is coupled from to a key node, may benull
.backAttribute
- String; 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
- boolean; whether there are unsaved changes.
-
setSchema
Sets a new schema in the GUI.- Parameters:
xsdDocument
- Document; 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. -
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-clicks on another location that should show a different popup, is not overruled by the popup of a previous click.- Parameters:
popup
- JPopupMenu; popup menu.component
- JComponent; 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"). The image should be a filename relative in resources.- Parameters:
path
- String; path.icon
- ImageIcon; image icon.
-
loadIcon
public static ImageIcon loadIcon(String image, int width, int height, int bgWidth, int bgHeight) throws IOException Loads an icon, possibly rescaled.- Parameters:
image
- String; image filename, relative in resources.width
- int; width to resize to, may be -1 to leave as is.height
- int; width to resize to, may be -1 to leave as is.bgWidth
- int; background image width icon will be centered in, may be -1 to leave as is.bgHeight
- int; background image height icon will be centered in, may be -1 to leave as is.- Returns:
- ImageIcon; image icon.
- Throws:
IOException
- if the file is not in resources.
-
getCustomIcon
Obtains a custom icon for the path, ornull
if there is no custom icon specified for the path.- Parameters:
path
- String; node path.- Returns:
- Icon; custom icon, or
null
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
- XsdTreeNode; node that is the currently selected choice.
-
mayPresentChoice
public boolean mayPresentChoice()Returns whether a choice may be presented.- Returns:
- whether a choice may be presented.
-
getEventListenerMap
- Specified by:
getEventListenerMap
in interfaceorg.djutils.event.EventProducer
- Throws:
RemoteException
-
addTab
Adds a tab to the main window.- Parameters:
name
- String; name of the tab.icon
- Icon; icon for the tab, may benull
.component
- Component; component that will fill the tab.tip
- String; tool-tip for the tab, may benull
.
-
getTab
Returns the component of the tab with given name.- Parameters:
name
- String; name of the tab.- Returns:
- Component; component of the tab with given name.
-
focusTab
Place focus on the tab with given name.- Parameters:
name
- String; 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
- XsdTreeNode; node.- Returns:
- boolean;
true
if the user confirms node removal.
-
showDescription
Shows a description in a modal pane.- Parameters:
description
- String; description.
-
showInvalidMessage
public void showInvalidMessage()Show tree invalid. -
showCircularInputParameters
public void showCircularInputParameters()Show input parameters have a circular dependency. -
showUnableToRun
public void showUnableToRun()Show unable to run. -
optionsPopup
Places a popup with options under the cell that is being clicked in a table. 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<String>; list of all options, will be filtered when typing.table
- JTable; table, will be either the tree table or the attributes table.action
- Consumer<String>; action to perform based on the option in the popup that was selected.
-
openFile
void openFile()Asks for confirmation to discard unsaved changes, if any, and show a dialog to open a file. -
saveFileAs
Shows a dialog to define a file and saves in to it.- Parameters:
root
- XsdTreeNode; 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 returnnull
if the input isnull
.- Parameters:
message
- String; tooltip message, may benull
.- Returns:
- String; possibly shortened tooltip message.
-
addAttributeCellEditorListener
Adds a listener to the cell editor of the attributes table.- Parameters:
listener
- CellEditorListener; listener to the cell editor of the attributes table.
-
setClipboard
Sets a node in the clipboard.- Parameters:
clipboard
- XsdTreeNode; node to set in the clipboard.cut
- boolean; whether the node was cut.
-
getClipboard
Returns the clipboard node.- Returns:
- XsdTreeNode; clipboard node.
-
removeClipboardWhenCut
public void removeClipboardWhenCut()Remove node that was cut. -
getNodeActions
Returns the node actions.- Returns:
- NodeActions; node actions.
-
addListener
public boolean addListener(org.djutils.event.EventListener listener, org.djutils.event.EventType eventType) - Specified by:
addListener
in interfaceorg.djutils.event.EventProducer
-
getEval
public org.djutils.eval.Eval getEval()Return an evaluator to evaluate expression values. This evaluator uses the input parameters of the currently selected scenario.- Returns:
- Eval; evaluator to evaluate expression values.
-
addEvalListener
Adds listener to changes in the evaluator, i.e. added, removed or changed input parameters.- Parameters:
listener
- EvalListener; listener.
-
removeEvalListener
Removes listener to changes in the evaluator, i.e. added, removed or changed input parameters.- Parameters:
listener
- EvalListener; listener.
-
setAppearance
- Overrides:
setAppearance
in classAppearanceApplication
-