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.JLabel;
8
9 import org.djutils.event.Event;
10 import org.djutils.event.EventListener;
11 import org.opentrafficsim.editor.OtsEditor;
12 import org.opentrafficsim.editor.XsdTreeNode;
13 import org.opentrafficsim.editor.XsdTreeNodeRoot;
14
15
16
17
18
19
20
21
22
23 public class TrafCodEditor implements EventListener, Consumer<XsdTreeNode>
24 {
25
26 private static final long serialVersionUID = 20230313L;
27
28
29 private OtsEditor editor;
30
31
32
33
34
35
36 public TrafCodEditor(final OtsEditor editor) throws RemoteException
37 {
38 editor.addListener(this, OtsEditor.NEW_FILE);
39 this.editor = editor;
40 }
41
42
43 @Override
44 public void notify(final Event event) throws RemoteException
45 {
46
47 if (event.getType().equals(OtsEditor.NEW_FILE))
48 {
49 XsdTreeNodeRoot root = (XsdTreeNodeRoot) event.getContent();
50 root.addListener(this, XsdTreeNodeRoot.NODE_CREATED);
51 }
52 else if (event.getType().equals(XsdTreeNodeRoot.NODE_CREATED))
53 {
54 XsdTreeNode node = (XsdTreeNode) ((Object[]) event.getContent())[0];
55 if (node.isType("Ots.Control.TrafCod.Program"))
56 {
57 node.addConsumer("Configure...", this);
58 }
59 }
60 }
61
62
63 @Override
64 public void accept(final XsdTreeNode t)
65 {
66 JLabel label = (JLabel) this.editor.getTab("Text");
67 label.setText(LocalDateTime.now().toString());
68 this.editor.focusTab("Text");
69 }
70 }