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