svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / test / java / org / gvsig / gui / beans / panelGroup / Test1TreePanel.java @ 40561
History | View | Annotate | Download (10.9 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.gui.beans.panelGroup; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Dimension; |
28 |
import java.util.ArrayList; |
29 |
|
30 |
import javax.swing.JFrame; |
31 |
import javax.swing.JTree; |
32 |
import javax.swing.event.TreeSelectionEvent; |
33 |
import javax.swing.event.TreeSelectionListener; |
34 |
|
35 |
import org.gvsig.tools.exception.BaseException; |
36 |
import org.gvsig.gui.beans.panelGroup.loaders.PanelGroupLoaderFromList; |
37 |
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel; |
38 |
import org.gvsig.gui.beans.panelGroup.panels.IPanel; |
39 |
import org.gvsig.gui.beans.panelGroup.samples.SampleInfoPanel; |
40 |
import org.gvsig.gui.beans.panelGroup.samples.SamplePanelWithoutGroupLabel; |
41 |
import org.gvsig.gui.beans.panelGroup.samples.Samples_Data; |
42 |
import org.gvsig.gui.beans.panelGroup.treePanel.TreePanel; |
43 |
|
44 |
/**
|
45 |
* <p>Tests the creation of a {@link TreePanel TreePanel} object using {@link PanelGroupLoaderFromList PanelGroupLoaderFromList} .</p>
|
46 |
*
|
47 |
* @version 17/10/2007
|
48 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
49 |
*/
|
50 |
public class Test1TreePanel { |
51 |
private static JFrame jFrame; |
52 |
private static TreePanel panelGroup; |
53 |
|
54 |
/**
|
55 |
* <p>Test method for the Test1TreePanel.</p>
|
56 |
*
|
57 |
* @param args optional arguments
|
58 |
*/
|
59 |
public static void main(String[] args) { |
60 |
try {
|
61 |
PanelGroupManager manager = PanelGroupManager.getManager(); |
62 |
manager.registerPanelGroup(TreePanel.class); |
63 |
manager.setDefaultType(TreePanel.class); |
64 |
|
65 |
// Use the defined samples
|
66 |
// Class[] panelClass = new Class[Samples_Data.TEST1_CLASSES.length];
|
67 |
// int i;
|
68 |
//
|
69 |
// for (i = 0; i < Samples_Data.TEST1_CLASSES.length; i ++) {
|
70 |
// panelClass[i] = Samples_Data.TEST1_CLASSES[i];
|
71 |
// }
|
72 |
|
73 |
panelGroup = (TreePanel) manager.getPanelGroup(Samples_Data.REFERENCE1); |
74 |
PanelGroupLoaderFromList loader = new PanelGroupLoaderFromList(Samples_Data.TEST1_CLASSES);
|
75 |
|
76 |
// Begin: Test the normal load
|
77 |
panelGroup.loadPanels(loader); |
78 |
// End: Test the normal load
|
79 |
|
80 |
// Begin: Other tests
|
81 |
ArrayList<IPanel> panels = new ArrayList<IPanel>(); |
82 |
|
83 |
loader.loadPanels(panels); |
84 |
|
85 |
// Begin: Initialise sample classes
|
86 |
// i = 0;
|
87 |
//
|
88 |
// for (AbstractPanel panel: panels) {
|
89 |
// panel.setPreferredSize(new Dimension(Samples_Data.PANELS_DEFAULT_WIDTH, Samples_Data.PANELS_DEFAULT_HEIGHT));
|
90 |
// panel.setReference(Samples_Data.REFERENCE1);
|
91 |
//
|
92 |
// panel.setID(Samples_Data.PANELS1_IDS[i]);
|
93 |
// panel.setLabel(Samples_Data.PANELS1_LABELS[i]);
|
94 |
// panel.setLabelGroup(Samples_Data.PANELS1_LABELGROUPS[i++]);
|
95 |
//
|
96 |
// panelGroup.addPanel(panel);
|
97 |
// }
|
98 |
// End: Initialise sample classes
|
99 |
|
100 |
// Begin: Tests adding and removing a panel without "label" -> this shoudn't add that panel
|
101 |
panels = new ArrayList<IPanel>(); |
102 |
loader = new PanelGroupLoaderFromList(new Class[]{SampleInfoPanel.class, SampleInfoPanel.class, SamplePanelWithoutGroupLabel.class}); |
103 |
loader.loadPanels(panels); |
104 |
((AbstractPanel)panels.get(0)).setPreferredSize(new Dimension(600, 700)); |
105 |
panels.get(0).setReference(Samples_Data.REFERENCE1);
|
106 |
panels.get(0).setID("ID"); |
107 |
panels.get(0).setLabel(null); |
108 |
panels.get(0).setLabelGroup("LABEL_GROUP"); |
109 |
panelGroup.addPanel(panels.get(0));
|
110 |
AbstractPanel incorrectAPanel = (AbstractPanel) panels.get(0);
|
111 |
//panelGroup.removePanel(panels.get(0));
|
112 |
// End: Tests adding and removing a panel without "label" -> this shoudn't add that panel
|
113 |
|
114 |
// Begin: Tests adding and removing a panel
|
115 |
((AbstractPanel)panels.get(1)).setPreferredSize(new Dimension(Samples_Data.PANELS_DEFAULT_WIDTH, Samples_Data.PANELS_DEFAULT_HEIGHT)); |
116 |
panels.get(1).setReference(Samples_Data.REFERENCE1);
|
117 |
panels.get(1).setID("ID"); |
118 |
panels.get(1).setLabel("LABEL_TEST_REPEATED_GROUP"); |
119 |
panels.get(1).setLabelGroup(Samples_Data.PANELS1_LABELGROUPS[0]); |
120 |
panelGroup.addPanel(panels.get(1));
|
121 |
AbstractPanel repeatedGroupAPanel = (AbstractPanel) panels.get(1);
|
122 |
//panelGroup.removePanel(panels.get(0));
|
123 |
// End: Tests adding and removing a panel
|
124 |
|
125 |
// Begin: Tests adding and removing a panel without "labelGroup"
|
126 |
((AbstractPanel)panels.get(2)).setPreferredSize(new Dimension(Samples_Data.PANELS_DEFAULT_WIDTH, Samples_Data.PANELS_DEFAULT_HEIGHT)); |
127 |
panels.get(2).setReference(Samples_Data.REFERENCE1);
|
128 |
panelGroup.addPanel(panels.get(2));
|
129 |
//panelGroup.removePanel(panels.get(1));
|
130 |
// End: Tests adding and removing a panel without "labelGroup"
|
131 |
|
132 |
// Begin: Test visibility
|
133 |
Object[] oPanels = panelGroup.values().toArray(); |
134 |
panelGroup.setPanelInGUI(repeatedGroupAPanel, false);// test set false a panel with a repeated group |
135 |
panelGroup.setPanelInGUI((IPanel)oPanels[1], false); // intermediate element |
136 |
((AbstractPanel)oPanels[1]).setInGroupGUI(true); // test change the visibility from a panel child |
137 |
((AbstractPanel)oPanels[1]).setInGroupGUI(false); // test change the visibility from a panel child |
138 |
((AbstractPanel)oPanels[1]).setInGroupGUI(true); // test change the visibility from a panel child |
139 |
panelGroup.setPanelInGUI((IPanel)oPanels[0], false); // first element |
140 |
panelGroup.setPanelInGUI(incorrectAPanel, false); // incorrect element |
141 |
panelGroup.setPanelInGUI(panels.get(2), false); // last element (and labelGroup = null) |
142 |
panelGroup.setPanelInGUI((IPanel)oPanels[2], false); // intermediate element |
143 |
panelGroup.setPanelInGUI((IPanel)oPanels[2], false); // test set false two times the same node |
144 |
panelGroup.setPanelInGUI((IPanel)oPanels[0], true); // first element |
145 |
panelGroup.setPanelInGUI(incorrectAPanel, true); // incorrect element |
146 |
panelGroup.setPanelInGUI((IPanel)oPanels[1], true); // intermediate element |
147 |
panelGroup.setPanelInGUI((IPanel)oPanels[1], true); // test set true two times the same node |
148 |
panelGroup.setPanelInGUI((IPanel)oPanels[2], true); // intermediate element |
149 |
panelGroup.setPanelInGUI(panels.get(2), true); // last element (and labelGroup = null) |
150 |
panelGroup.setPanelInGUI(repeatedGroupAPanel, true); // test set false a panel with a repeated group |
151 |
|
152 |
panels.get(1).setInGroupGUI(false); // test change the visibility from a panel child |
153 |
if (!panels.get(1).isInGroupGUI()) { |
154 |
System.out.println("Test OK: the panel isn't in the GUI"); |
155 |
System.out.println("Hay " + panelGroup.getPanelInGUICount() + " paneles en GUI, de los " + panelGroup.getPanelCount() + " registrados."); |
156 |
} |
157 |
else {
|
158 |
System.out.println("Test FAILED: the panel is in the GUI"); |
159 |
} |
160 |
|
161 |
panels.get(1).setInGroupGUI(true); // test change the visibility from a panel child |
162 |
if (panels.get(1).isInGroupGUI()) { |
163 |
System.out.println("Test OK: the panel is in the GUI"); |
164 |
System.out.println("Hay " + panelGroup.getPanelInGUICount() + " paneles en GUI, de los " + panelGroup.getPanelCount() + " registrados."); |
165 |
} |
166 |
else {
|
167 |
System.out.println("Test FAILED: the panel isn't in the GUI"); |
168 |
} |
169 |
|
170 |
panelGroup.setPanelInGUI(panels.get(1), false); |
171 |
if (!panelGroup.isPanelInGUI(panels.get(1))) { |
172 |
System.out.println("Test OK: the panel isn't in the GUI"); |
173 |
System.out.println("Hay " + panelGroup.getPanelInGUICount() + " paneles en GUI, de los " + panelGroup.getPanelCount() + " registrados."); |
174 |
} |
175 |
else {
|
176 |
System.out.println("Test FAILED: the panel is in the GUI"); |
177 |
} |
178 |
|
179 |
panelGroup.setPanelInGUI(panels.get(1), true); |
180 |
if (panelGroup.isPanelInGUI(panels.get(1))) { |
181 |
System.out.println("Test OK: the panel is in the GUI"); |
182 |
System.out.println("Hay " + panelGroup.getPanelInGUICount() + " paneles en GUI, de los " + panelGroup.getPanelCount() + " registrados."); |
183 |
} |
184 |
else {
|
185 |
System.out.println("Test FAILED: the panel isn't in the GUI"); |
186 |
} |
187 |
// End: Test visibility -> True or False
|
188 |
|
189 |
jFrame = new JFrame(); |
190 |
jFrame.setTitle("Test TreePanel using PanelGroupLoaderFromList");
|
191 |
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
192 |
jFrame.setSize(panelGroup.getPreferredSize()); |
193 |
jFrame.getContentPane().setLayout(new BorderLayout()); |
194 |
jFrame.getContentPane().add(panelGroup, BorderLayout.CENTER);
|
195 |
|
196 |
jFrame.setVisible(true);
|
197 |
|
198 |
// Begin: Test the method 'getSelectedIndex()':
|
199 |
panelGroup.addTreeSelectionListener(new TreeSelectionListener() { |
200 |
/*
|
201 |
* (non-Javadoc)
|
202 |
* @see javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent)
|
203 |
*/
|
204 |
public void valueChanged(TreeSelectionEvent e) { |
205 |
JTree jTree = (JTree) e.getSource(); |
206 |
|
207 |
System.out.println("Selection changed. New selection path: " + jTree.getSelectionPath()); |
208 |
|
209 |
showActivePanelInformation(); |
210 |
} |
211 |
}); |
212 |
// End: Test the method 'getSelectedIndex()':
|
213 |
|
214 |
// Begin: Test the methods: 'getDividerLocation()' and 'setDividerLocation(int)'
|
215 |
System.out.println("Divider location before setting it to the position 250 : " + panelGroup.getDividerLocation()); |
216 |
panelGroup.setDividerLocation(250);
|
217 |
System.out.println("Divider location after setting it to the position 250 : " + panelGroup.getDividerLocation()); |
218 |
// End: Test the methods: 'getDividerLocation()' and 'setDividerLocation(int)'
|
219 |
|
220 |
// Begin: Test the methods: 'getDividerSize()' and 'setDividerSize(int)'
|
221 |
System.out.println("Divider size before setting it to the position 10 : " + panelGroup.getDividerSize()); |
222 |
panelGroup.setDividerSize(10);
|
223 |
System.out.println("Divider size after setting it to the position 10 : " + panelGroup.getDividerSize()); |
224 |
// End: Test the methods: 'getDividerSize()' and 'setDividerSize(int)'
|
225 |
|
226 |
// End: Other tests
|
227 |
} catch (BaseException e) {
|
228 |
System.out.println(e.getLocalizedMessageStack());
|
229 |
} catch (Exception e) { |
230 |
e.printStackTrace(); |
231 |
} |
232 |
} |
233 |
|
234 |
/**
|
235 |
* <p>Shows information about the current active panel using the standard output.</p>
|
236 |
*/
|
237 |
private static void showActivePanelInformation() { |
238 |
// Test the method 'getActivePanel()'
|
239 |
IPanel panel = panelGroup.getActivePanel(); |
240 |
|
241 |
if (panel == null) { |
242 |
System.out.println("The node selected of the JTree in the TreePanel object isn't a IPanel ."); |
243 |
} |
244 |
else {
|
245 |
System.out.println("New active panel:\n\tID: " + panel.getID() + "\n\tLABEL_GROUP: " + panel.getLabelGroup() + "\n\tLABEL: " + panel.getLabel() + "\n\tCLASS: " + panel.getClass()); |
246 |
} |
247 |
} |
248 |
} |