Class OtsEditor

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Remote, Accessible, RootPaneContainer, WindowConstants, org.djutils.event.EventProducer

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

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 org.djutils.event.EventType NEW_FILE
      Event when a a new file is started.
    • SELECTION_CHANGED

      public static final org.djutils.event.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).
    • STATUS_COLOR

      public static final Color STATUS_COLOR
      Color for status label.
    • INVALID_COLOR

      public static final Color INVALID_COLOR
      Color for invalid nodes and values (background).
    • EXPRESSION_COLOR

      public static final Color EXPRESSION_COLOR
      Color for expression nodes and values (background).
  • Constructor Details

    • OtsEditor

      public OtsEditor() throws IOException
      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

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

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

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

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

      public 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.
      Parameters:
      coupledNode - XsdTreeNode; key node that is coupled to from a keyref node, may be null.
      backNode - XsdTreeNode; keyref node that is coupled from to a key node, may be null.
      backAttribute - String; 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 - boolean; whether there are unsaved changes.
    • setSchema

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

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

      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"). 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

      public Icon getCustomIcon(String path)
      Obtains a custom icon for the path, or null 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

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

      public org.djutils.event.EventListenerMap getEventListenerMap() throws RemoteException
      Specified by:
      getEventListenerMap in interface org.djutils.event.EventProducer
      Throws:
      RemoteException
    • addTab

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

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

      public void focusTab(String name)
      Place focus on the tab with given name.
      Parameters:
      name - String; 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 - XsdTreeNode; node.
      Returns:
      boolean; true if the user confirms node removal.
    • showDescription

      public void showDescription(String description)
      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

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

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

      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 - String; tooltip message, may be null.
      Returns:
      String; possibly shortened tooltip message.
    • addAttributeCellEditorListener

      public void addAttributeCellEditorListener(CellEditorListener listener)
      Adds a listener to the cell editor of the attributes table.
      Parameters:
      listener - CellEditorListener; 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 - XsdTreeNode; node to set in the clipboard.
      cut - boolean; whether the node was cut.
    • getClipboard

      public XsdTreeNode getClipboard()
      Returns the clipboard node.
      Returns:
      XsdTreeNode; clipboard node.
    • removeClipboardWhenCut

      public void removeClipboardWhenCut()
      Remove node that was cut.
    • getNodeActions

      public NodeActions 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 interface org.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

      public void addEvalListener(EvalWrapper.EvalListener listener)
      Adds listener to changes in the evaluator, i.e. added, removed or changed input parameters.
      Parameters:
      listener - EvalListener; 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 - EvalListener; listener.
    • setAppearance

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