1 package org.opentrafficsim.editor.extensions;
2
3 import java.io.IOException;
4 import java.rmi.RemoteException;
5 import java.time.LocalDateTime;
6 import java.util.function.Consumer;
7
8 import javax.swing.ImageIcon;
9 import javax.swing.JComponent;
10 import javax.swing.JLabel;
11
12 import org.djutils.event.Event;
13 import org.djutils.event.EventListener;
14 import org.opentrafficsim.editor.OtsEditor;
15 import org.opentrafficsim.editor.XsdPaths;
16 import org.opentrafficsim.editor.XsdTreeNode;
17 import org.opentrafficsim.editor.XsdTreeNodeRoot;
18
19
20
21
22
23
24
25
26
27 public class RoadLayoutEditor implements EventListener, Consumer<XsdTreeNode>
28 {
29
30
31 private static final long serialVersionUID = 20230313L;
32
33
34 private final OtsEditor editor;
35
36
37
38
39
40
41 public RoadLayoutEditor(final OtsEditor editor) throws IOException
42 {
43 ImageIcon roadIcon = OtsEditor.loadIcon("./OTS_road.png", -1, -1, -1, -1);
44 editor.addTab("Road layout", roadIcon, buildRoadLayoutPane(), null);
45 editor.addListener(this, OtsEditor.NEW_FILE);
46 this.editor = editor;
47 }
48
49
50
51
52
53 private static JComponent buildRoadLayoutPane()
54 {
55 JLabel roadLayout = new JLabel("road layout");
56 roadLayout.setOpaque(true);
57 roadLayout.setHorizontalAlignment(JLabel.CENTER);
58 return roadLayout;
59 }
60
61
62 @Override
63 public void notify(final Event event) throws RemoteException
64 {
65
66 if (event.getType().equals(OtsEditor.NEW_FILE))
67 {
68 XsdTreeNodeRoot root = (XsdTreeNodeRoot) event.getContent();
69 root.addListener(this, XsdTreeNodeRoot.NODE_CREATED);
70 root.addListener(this, XsdTreeNodeRoot.NODE_REMOVED);
71 }
72 else if (event.getType().equals(XsdTreeNodeRoot.NODE_CREATED))
73 {
74 XsdTreeNode node = (XsdTreeNode) ((Object[]) event.getContent())[0];
75 if (node.getPathString().equals(XsdPaths.DEFINED_ROADLAYOUT)
76 || node.getPathString().equals(XsdPaths.ROADLAYOUT))
77 {
78 node.addConsumer("Edit...", this);
79 }
80 }
81 }
82
83
84 @Override
85 public void accept(final XsdTreeNode t)
86 {
87
88 JLabel label = (JLabel) this.editor.getTab("Road layout");
89 label.setText(LocalDateTime.now().toString());
90 this.editor.focusTab("Road layout");
91 }
92
93 }