1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package p3j.gui.misc;
17
18 import java.awt.BorderLayout;
19 import java.awt.Color;
20 import java.awt.event.MouseAdapter;
21 import java.awt.event.MouseEvent;
22 import java.util.List;
23
24 import javax.swing.BorderFactory;
25 import javax.swing.BoxLayout;
26 import javax.swing.JLabel;
27 import javax.swing.JPanel;
28 import javax.swing.JScrollPane;
29
30 import p3j.gui.panels.projections.IProjectionTree;
31 import p3j.gui.panels.projections.ProjectionTreeNode;
32 import p3j.misc.gui.GUI;
33
34
35
36
37
38
39
40
41
42
43
44
45 public class SubNodeSummary<E> extends JPanel {
46
47
48
49
50 private static final long serialVersionUID = 6979550281628665829L;
51
52
53
54
55
56
57
58
59
60
61
62 public SubNodeSummary(ProjectionTreeNode<?> node, IProjectionTree projTree,
63 Class<E> desiredClass) {
64 setLayout(GUI.getStdBorderLayout());
65
66 JPanel panel = new JPanel();
67 BoxLayout bl = new BoxLayout(panel, BoxLayout.Y_AXIS);
68 panel.setLayout(bl);
69
70 List<ProjectionTreeNode<E>> children = node.getChildsByType(desiredClass);
71
72 for (ProjectionTreeNode<E> child : children) {
73 String str = child.getEntityLabel();
74 JLabel label = new JLabel("<html><u>" + str + "</u></html>");
75 label.setForeground(Color.BLUE);
76 label.addMouseListener(new ClickAssignmentListener<E>(child.getEntity(),
77 node, projTree));
78
79 panel.add(label);
80 }
81
82 JScrollPane scrollPane = new JScrollPane(panel);
83 scrollPane.setBorder(BorderFactory.createEmptyBorder());
84 add(scrollPane, BorderLayout.CENTER);
85 }
86
87 }
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102 class ClickAssignmentListener<E> extends MouseAdapter {
103
104
105 private final E entity;
106
107
108 private final ProjectionTreeNode<?> node;
109
110
111 private final IProjectionTree projectionTree;
112
113 ClickAssignmentListener(E targetEntity, ProjectionTreeNode<?> piNode,
114 IProjectionTree projTree) {
115 entity = targetEntity;
116 node = piNode;
117 projectionTree = projTree;
118 }
119
120 @Override
121 public void mouseClicked(MouseEvent e) {
122 projectionTree.selectNode(node.getChildWithEntity(entity));
123 }
124 }