Class OtsEditor

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

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

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:
  • Field Details

    • NEW_FILE

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

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

      public static final Color INACTIVE_COLOR
      Color for inactive nodes (text).
  • 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
    • 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.
    • 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
    • preparePopupRemoval

      public void preparePopupRemoval(JPopupMenu popup, JComponent component)
      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

      public void setCustomIcon(String path, ImageIcon 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.
    • confirmNodeRemoval

      public boolean confirmNodeRemoval(XsdTreeNode node)
      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:
      true if the user confirms node removal.
    • showDescription

      public void showDescription(String description)
      Shows a description in a modal pane.
      Parameters:
      description - description.
    • showInvalidToRunMessage

      public void showInvalidToRunMessage()
      Show tree invalid.
    • showCircularInputParameters

      public void showCircularInputParameters(String message)
      Show input parameters have a circular dependency.
      Parameters:
      message - exception message
    • showInvalidExpression

      public void showInvalidExpression(String message)
      Show message about invalid expression.
      Parameters:
      message - exception message
    • showUnableToRunFromTempFile

      public void showUnableToRunFromTempFile()
      Show unable to run.
    • valueOptionsPopup

      public void valueOptionsPopup(List<String> allOptions, JTable table, Consumer<String> action)
      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 MAX_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

      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.
    • getNodeActions

      public NodeActions getNodeActions()
      Returns the node actions.
      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