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.Misc;
33 import p3j.misc.gui.GUI;
34
35
36
37
38
39
40
41
42
43
44
45
46 public class SubNodeSummary<E> extends JPanel {
47
48
49 private static final long serialVersionUID = 6979550281628665829L;
50
51
52 private static final String SUBNODE_CUTOFF_LABEL = "...";
53
54
55
56
57
58
59
60
61
62
63
64 public SubNodeSummary(ProjectionTreeNode<?> node, IProjectionTree projTree,
65 Class<E> desiredClass) {
66 setLayout(GUI.getStdBorderLayout());
67
68 JPanel panel = new JPanel();
69 BoxLayout bl = new BoxLayout(panel, BoxLayout.Y_AXIS);
70 panel.setLayout(bl);
71
72 List<ProjectionTreeNode<E>> children = node.getChildsByType(desiredClass);
73
74 int childCounter = 0;
75 for (ProjectionTreeNode<E> child : children) {
76 String str = child.getEntityLabel();
77 JLabel label = new JLabel("<html><u>" + str + "</u></html>");
78 label.setForeground(Color.BLUE);
79 label.addMouseListener(new ClickAssignmentListener<E>(child.getEntity(),
80 node, projTree));
81 panel.add(label);
82 childCounter++;
83 if (childCounter >= Misc.MAX_SUBNODE_SUMMARY_ELEMENTS) {
84 panel.add(new JLabel(SUBNODE_CUTOFF_LABEL));
85 break;
86 }
87 }
88
89 JScrollPane scrollPane = new JScrollPane(panel);
90 scrollPane.setBorder(BorderFactory.createEmptyBorder());
91 add(scrollPane, BorderLayout.CENTER);
92 }
93
94 }
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109 class ClickAssignmentListener<E> extends MouseAdapter {
110
111
112 private final E entity;
113
114
115 private final ProjectionTreeNode<?> node;
116
117
118 private final IProjectionTree projectionTree;
119
120 ClickAssignmentListener(E targetEntity, ProjectionTreeNode<?> piNode,
121 IProjectionTree projTree) {
122 entity = targetEntity;
123 node = piNode;
124 projectionTree = projTree;
125 }
126
127 @Override
128 public void mouseClicked(MouseEvent e) {
129 projectionTree.selectNode(node.getChildWithEntity(entity));
130 }
131 }