1 package org.opentrafficsim.editor.extensions;
2
3 import java.rmi.RemoteException;
4 import java.time.LocalDateTime;
5 import java.util.function.Consumer;
6
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 import org.opentrafficsim.editor.XsdTreeNodeRoot;
15
16
17
18
19
20
21
22
23
24 public class RouteEditor implements EventListener, Consumer<XsdTreeNode>
25 {
26
27 private static final long serialVersionUID = 20230313L;
28
29
30 private OtsEditor editor;
31
32
33
34
35
36
37 public RouteEditor(final OtsEditor editor) throws RemoteException
38 {
39 editor.addTab("Route", null, buildRoutePane(), null);
40 editor.addListener(this, OtsEditor.NEW_FILE);
41 this.editor = editor;
42 }
43
44
45
46
47
48 private static JComponent buildRoutePane()
49 {
50 JLabel route = new JLabel("route");
51 route.setOpaque(true);
52 route.setHorizontalAlignment(JLabel.CENTER);
53 return route;
54 }
55
56
57 @Override
58 public void notify(final Event event) throws RemoteException
59 {
60
61 if (event.getType().equals(OtsEditor.NEW_FILE))
62 {
63 XsdTreeNodeRoot root = (XsdTreeNodeRoot) event.getContent();
64 root.addListener(this, XsdTreeNodeRoot.NODE_CREATED);
65 }
66 else if (event.getType().equals(XsdTreeNodeRoot.NODE_CREATED))
67 {
68 XsdTreeNode node = (XsdTreeNode) ((Object[]) event.getContent())[0];
69 if (node.isType("Ots.Demand.Route"))
70 {
71 node.addConsumer("Show in panel...", this);
72 node.addConsumer("Compute shortest...", new Consumer<XsdTreeNode>()
73 {
74
75 @Override
76 public void accept(final XsdTreeNode t)
77 {
78 System.out.println("We are not going to do that.");
79 }
80 });
81 }
82 }
83 }
84
85
86 @Override
87 public void accept(final XsdTreeNode t)
88 {
89 JLabel label = ((JLabel) this.editor.getTab("Route"));
90 label.setText(LocalDateTime.now().toString());
91 this.editor.focusTab("Route");
92 }
93 }