Class OtsEditor

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants, EventProducer, OtsEditorProperties

public class OtsEditor extends AppearanceApplication implements EventProducer, OtsEditorProperties
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.

Copyright (c) 2023-2026 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:
  • Field Details

    • NEW_FILE

      public static final EventType NEW_FILE
      Event when a new file is started.
    • SELECTION_CHANGED

      public static final EventType SELECTION_CHANGED
      Event when the selection in the tree is changed.
  • Constructor Details

    • OtsEditor

      public OtsEditor() throws IOException
      Constructor.
      Throws:
      IOException - when a resource could not be loaded.
  • Method Details

    • getInvalidColor

      public static Color getInvalidColor()
      Returns the invalid cell color.
      Returns:
      the invalid cell color
    • getExpressionColor

      public static Color getExpressionColor()
      Returns the expression cell color.
      Returns:
      the expression cell color
    • getInactiveColor

      public static Color getInactiveColor()
      Returns the inactive cell color.
      Returns:
      the inactive cell color
    • runBatch

      protected void runBatch(boolean all)
      Batch run.
      Parameters:
      all - all scenarios, or only the selected scenario.
    • getUndo

      public Undo getUndo()
      Returns the undo unit.
      Returns:
      undo unit.
    • collapse

      public void collapse(XsdTreeNode node)
      Collapses the given node, if expanded.
      Parameters:
      node - node
    • show

      public void show(XsdTreeNode node, String attribute)
      Shows and selects the given node in the tree.
      Parameters:
      node - node.
      attribute - attribute name, may be null to just show the node.
    • invalidateAndRepaint

      public void invalidateAndRepaint()
      Invalidate the entire tree and repaint both the tree and attributes table. This method may take a bit of time. Be careful and conservative in invoking this method on the AWT thread. Consider invoking with SwingUtilities.invokeLater(java.lang.Runnable).
    • updateTree

      public void updateTree()
      Updates the tree. Call this method when a repaint does not work.
    • setStatusLabel

      public void setStatusLabel(String label)
      Sets a status label.
      Parameters:
      label - status label.
    • removeStatusLabel

      public void removeStatusLabel()
      Removes the status label.
    • setCoupledNode

      public void setCoupledNode(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.
      Parameters:
      toNode - key node that is coupled to from a keyref node, may be null.
      fromNode - keyref node that is coupled from to a key node, may be null.
      fromAttribute - attribute in keyref node that refers to coupled node, may be null.
    • 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

      public void setSchema(Document xsdDocument) throws IOException
      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

      public XsdTreeNode getTreeNodeAtPoint(Point point)
      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
    • setCustomIcon

      public void setCustomIcon(String path, Icon icon)
      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

      public Optional<Icon> getCustomIcon(String path)
      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

      public XsdTreeNode getChoiceNode()
      Returns the node that is the currently selected choice.
      Returns:
      node that is the currently selected choice.
    • setChoiceNode

      public void setChoiceNode(XsdTreeNode choiceNode)
      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

      public EventListenerMap getEventListenerMap()
      Specified by:
      getEventListenerMap in interface EventProducer
    • addTab

      public void addTab(String name, Icon icon, Component component, String tip)
      Adds a tab to the main window.
      Parameters:
      name - name of the tab.
      icon - icon for the tab, may be null.
      component - component that will fill the tab.
      tip - tool-tip for the tab, may be null.
    • getTab

      public Optional<Component> getTab(String name)
      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

      public void focusTab(String name)
      Place focus on the tab with given name.
      Parameters:
      name - name of the tab.
    • dialogs

      public Dialogs dialogs()
      Return utility for dialogs.
      Returns:
      utility for dialogs
    • valueOptionsPopup

      public void valueOptionsPopup(List<String> allOptions, JTable table, Consumer<String> action, String currentValue)
      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 to the max_dropdown_items app property.
      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
      currentValue - current value
    • preparePopupRemoval

      public void preparePopupRemoval(JPopupMenu popup, JTable table)
      Adds a listener to a pop-up to remove the pop-up from the component when the pop-up becomes invisible. This makes sure that a right-click on another location that should show a different pop-up, is not overruled by the pop-up of a previous click.
      Parameters:
      popup - pop-up menu
      table - component from which the menu will be removed
    • ignoreChanges

      public boolean ignoreChanges()
      Whether to ignore changes during loading.
      Returns:
      whether to ignore changes during loading
    • saveFileAs

      public void saveFileAs(XsdTreeNode root)
      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

      public static String limitTooltip(String message)
      Limits the length of a tooltip message. This is to prevent absurd tooltip texts based on really long patterns that should be matched. Will return null if the input is null.
      Parameters:
      message - tooltip message, may be null.
      Returns:
      possibly shortened tooltip message.
    • addAttributeCellEditorListener

      public void addAttributeCellEditorListener(CellEditorListener listener)
      Adds an external listener to the cell editor of the attributes table.
      Parameters:
      listener - listener to the cell editor of the attributes table.
    • setClipboard

      public void setClipboard(XsdTreeNode clipboard, boolean cut)
      Sets a node in the clipboard.
      Parameters:
      clipboard - node to set in the clipboard.
      cut - whether the node was cut.
    • getClipboard

      public XsdTreeNode 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.
    • actions

      public Actions actions()
      Returns the actions that can be performed on the editor.
      Returns:
      node actions.
    • addListener

      public boolean addListener(EventListener listener, EventType eventType)
      Specified by:
      addListener in interface EventProducer
    • getEval

      public Eval 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

      public void addEvalListener(EvalWrapper.EvalListener listener)
      Adds listener to changes in the evaluator, i.e. added, removed or changed input parameters.
      Parameters:
      listener - listener.
    • removeEvalListener

      public void removeEvalListener(EvalWrapper.EvalListener listener)
      Removes listener to changes in the evaluator, i.e. added, removed or changed input parameters.
      Parameters:
      listener - listener.
    • setAppearance

      public void setAppearance(Appearance appearance)
      Overrides:
      setAppearance in class AppearanceApplication