View Javadoc

1   /*
2    * Copyright 2006 - 2012 Christina Bohk and Roland Ewald
3    *  
4    * Licensed under the Apache License, Version 2.0 (the "License"); 
5    * you may not use this file except in compliance with the License. 
6    * You may obtain a copy of the License at 
7    *  
8    *  http://www.apache.org/licenses/LICENSE-2.0
9    *  
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License. 
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  
25  import p3j.pppm.ProjectionModel;
26  
27  /**
28   * Super class for navigation panels.
29   * 
30   * @author Christina Bohk
31   * @author Roland Ewald
32   * 
33   */
34  public abstract class AbstractNavigationPanel extends JPanel {
35  
36  	/** Serialization ID. */
37  	private static final long serialVersionUID = -8802994657383849297L;
38  
39  	/** Tree to display current structure of the projection. */
40  	private JTree tree;
41  
42  	/** The model of the projection tree. */
43  	private DefaultTreeModel treeModel;
44  
45  	/** Scroll pane for the tree. */
46  	private JScrollPane scrollPane;
47  
48  	/** The projection to be edited. */
49  	private ProjectionModel projection;
50  
51  	/** Panel from {@link import p3j.gui.P3J} that holds the content. */
52  	private final JPanel contentPanel;
53  
54  	/**
55  	 * Instantiates a new abstract navigation panel.
56  	 * 
57  	 * @param projectionModel
58  	 *          the projectionModel
59  	 * @param content
60  	 *          the content panel
61  	 */
62  	public AbstractNavigationPanel(ProjectionModel projectionModel, JPanel content) {
63  		projection = projectionModel;
64  		contentPanel = content;
65  		if (projection == null) {
66  			return;
67  		}
68  		setProjection(projection);
69  	}
70  
71  	/**
72  	 * Sets the new projection model to be displayed.
73  	 * 
74  	 * @param projMod
75  	 *          the new projection model
76  	 */
77  	public final void setProjection(ProjectionModel projMod) {
78  		projection = projMod;
79  		removeAll();
80  		initTree();
81  		setLayout(new BorderLayout());
82  		if (getScrollPane() != null) {
83  			add(getScrollPane(), BorderLayout.CENTER);
84  		}
85  	}
86  
87  	/**
88  	 * Initializes tree (after projection changed, for example).
89  	 */
90  	protected abstract void initTree();
91  
92  	public final JTree getTree() {
93  		return tree;
94  	}
95  
96  	public void setTree(JTree tree) {
97  		this.tree = tree;
98  	}
99  
100 	public final DefaultTreeModel getTreeModel() {
101 		return treeModel;
102 	}
103 
104 	public void setTreeModel(DefaultTreeModel treeModel) {
105 		this.treeModel = treeModel;
106 	}
107 
108 	public final JScrollPane getScrollPane() {
109 		return scrollPane;
110 	}
111 
112 	public void setScrollPane(JScrollPane scrollPane) {
113 		this.scrollPane = scrollPane;
114 	}
115 
116 	public ProjectionModel getProjectionModel() {
117 		return projection;
118 	}
119 
120 	public JPanel getContentPanel() {
121 		return contentPanel;
122 	}
123 }