1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package p3j.gui.panels.projections;
17
18 import javax.swing.JPanel;
19 import javax.swing.event.TreeSelectionEvent;
20 import javax.swing.event.TreeSelectionListener;
21 import javax.swing.tree.TreePath;
22
23
24
25
26
27
28
29
30 public class ProjectionTreeSelectionListener implements TreeSelectionListener {
31
32
33 private final JPanel contentPanel;
34
35
36 private final IProjectionTree projectionTree;
37
38
39
40
41
42
43
44
45
46 public ProjectionTreeSelectionListener(JPanel content, IProjectionTree tree) {
47 contentPanel = content;
48 projectionTree = tree;
49 }
50
51 @Override
52 public void valueChanged(TreeSelectionEvent e) {
53 TreePath oldPath = e.getOldLeadSelectionPath();
54 if (oldPath != null) {
55 ((ProjectionTreeNode<?>) oldPath.getLastPathComponent()).deselected();
56 }
57 contentPanel.removeAll();
58 TreePath newPath = e.getNewLeadSelectionPath();
59 if (newPath != null) {
60 ((ProjectionTreeNode<?>) newPath.getLastPathComponent()).selected(
61 newPath, contentPanel, projectionTree);
62 }
63 contentPanel.repaint();
64 contentPanel.updateUI();
65 }
66 }