View Javadoc
1   package org.opentrafficsim.editor.extensions;
2   
3   import java.io.IOException;
4   import java.rmi.RemoteException;
5   
6   import javax.swing.ImageIcon;
7   import javax.swing.JComponent;
8   import javax.swing.JLabel;
9   
10  import org.djutils.event.Event;
11  import org.djutils.event.EventListener;
12  import org.opentrafficsim.editor.OtsEditor;
13  import org.opentrafficsim.editor.XsdTreeNode;
14  
15  /**
16   * Editor for OD.
17   * <p>
18   * Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
19   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
20   * </p>
21   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
22   */
23  public class OdEditor implements EventListener
24  {
25  
26      /** */
27      private static final long serialVersionUID = 20230313L;
28  
29      /** Editor. */
30      private final OtsEditor editor;
31  
32      /**
33       * Constructor.
34       * @param editor OtsEditor; editor.
35       * @throws IOException if icon cannot be loaded or listener cannot be added.
36       */
37      public OdEditor(final OtsEditor editor) throws IOException
38      {
39          ImageIcon odIcon = OtsEditor.loadIcon("./Table_blue.png", 16, 16, -1, -1);
40          editor.addTab("OD", odIcon, buildOdPane(), null);
41          editor.addListener(this, OtsEditor.SELECTION_CHANGED);
42          this.editor = editor;
43      }
44  
45      /**
46       * Temporary stub to create OD pane.
47       * @return JComponent; component.
48       */
49      private static JComponent buildOdPane()
50      {
51          JLabel od = new JLabel("od");
52          od.setOpaque(true);
53          od.setHorizontalAlignment(JLabel.CENTER);
54          return od;
55      }
56  
57      /** {@inheritDoc} */
58      @Override
59      public void notify(final Event event) throws RemoteException
60      {
61          // TODO: this is a dummy implementation
62          if (event.getType().equals(OtsEditor.SELECTION_CHANGED))
63          {
64              JLabel label = ((JLabel) this.editor.getTab("OD"));
65              XsdTreeNode node = (XsdTreeNode) event.getContent();
66              if (node.getPathString().startsWith("Ots.Demand.Od"))
67              {
68                  label.setText(node.getPathString());
69              }
70              else
71              {
72                  label.setText("od");
73              }
74          }
75      }
76  
77  }