1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package p3j.gui.panels;
17
18 import java.awt.BorderLayout;
19
20 import javax.swing.JPanel;
21 import javax.swing.JScrollPane;
22 import javax.swing.JTree;
23 import javax.swing.tree.DefaultTreeModel;
24 import javax.swing.tree.TreePath;
25
26 import p3j.pppm.ProjectionModel;
27
28
29
30
31
32
33
34
35 public abstract class AbstractNavigationPanel extends JPanel {
36
37
38 private static final long serialVersionUID = -8802994657383849297L;
39
40
41 private JTree tree;
42
43
44 private DefaultTreeModel treeModel;
45
46
47 private JScrollPane scrollPane;
48
49
50 private ProjectionModel projection;
51
52
53 private final JPanel contentPanel;
54
55
56
57
58
59
60
61
62
63 public AbstractNavigationPanel(ProjectionModel projectionModel,
64 JPanel content) {
65 projection = projectionModel;
66 contentPanel = content;
67 if (projection == null) {
68 return;
69 }
70 setProjection(projection);
71 }
72
73
74
75
76
77
78
79 public final void setProjection(ProjectionModel projMod) {
80 projection = projMod;
81 removeAll();
82 initTree();
83 setLayout(new BorderLayout());
84 if (getScrollPane() != null) {
85 add(getScrollPane(), BorderLayout.CENTER);
86 }
87 }
88
89
90
91
92 protected abstract void initTree();
93
94
95
96
97 public void selectRoot() {
98 tree.setSelectionPath(new TreePath(treeModel.getRoot()));
99 }
100
101 public final JTree getTree() {
102 return tree;
103 }
104
105 public void setTree(JTree tree) {
106 this.tree = tree;
107 }
108
109 public final DefaultTreeModel getTreeModel() {
110 return treeModel;
111 }
112
113 public void setTreeModel(DefaultTreeModel treeModel) {
114 this.treeModel = treeModel;
115 }
116
117 public final JScrollPane getScrollPane() {
118 return scrollPane;
119 }
120
121 public void setScrollPane(JScrollPane scrollPane) {
122 this.scrollPane = scrollPane;
123 }
124
125 public ProjectionModel getProjectionModel() {
126 return projection;
127 }
128
129 public JPanel getContentPanel() {
130 return contentPanel;
131 }
132 }