Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / test / java / org / gvsig / gui / beans / panelGroup / Test1TabbedPanel.java @ 40561

History | View | Annotate | Download (16.3 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.Dimension;
27
import java.util.ArrayList;
28

    
29
import javax.swing.JFrame;
30
import javax.swing.JTabbedPane;
31
import javax.swing.event.ChangeEvent;
32
import javax.swing.event.ChangeListener;
33

    
34
import org.gvsig.tools.exception.BaseException;
35
import org.gvsig.gui.beans.panelGroup.loaders.PanelGroupLoaderFromList;
36
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel;
37
import org.gvsig.gui.beans.panelGroup.panels.IPanel;
38
import org.gvsig.gui.beans.panelGroup.samples.SampleInfoPanel;
39
import org.gvsig.gui.beans.panelGroup.samples.Samples_Data;
40
import org.gvsig.gui.beans.panelGroup.tabbedPanel.TabbedPanel;
41

    
42
/**
43
 * <p>Tests the creation of a {@link TabbedPanel TabbedPanel} object using {@link PanelGroupLoaderFromList PanelGroupLoaderFromList} .</p>
44
 * 
45
 * @version 16/10/2007
46
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es) 
47
 */
48
public class Test1TabbedPanel {
49
        private static TabbedPanel panelGroup;
50
        
51
        /**
52
         * <p>Test method for the Test1TabbedPanel.</p>
53
         * 
54
         * @param args optional arguments
55
         */
56
        public static void main(String[] args) {
57
                try {
58
                        PanelGroupManager manager = PanelGroupManager.getManager();
59
                        manager.registerPanelGroup(TabbedPanel.class);
60
                        manager.setDefaultType(TabbedPanel.class);
61

    
62
                        panelGroup = (TabbedPanel) manager.getPanelGroup(Samples_Data.REFERENCE1);
63
                        PanelGroupLoaderFromList loader = new PanelGroupLoaderFromList(Samples_Data.TEST1_CLASSES);
64

    
65
                        // Begin: Test the normal load
66
                        System.out.println("----------> Begin: Test the normal load");
67

    
68
                        panelGroup.loadPanels(loader);
69

    
70
                        System.out.println("End: Test the normal load <----------");
71
                        // End: Test the normal load
72
                        
73
                        // Begin: Other tests
74
                        ArrayList<IPanel> panels = new ArrayList<IPanel>();
75

    
76
                        // Begin: Initialize sample classes
77
//                        int i = 0;
78
//
79
//                        for (AbstractPanel panel: panels) {
80
//                                panel.setPreferredSize(new Dimension(Samples_Data.PANELS_DEFAULT_WIDTH, Samples_Data.PANELS_DEFAULT_HEIGHT));
81
//                                panel.setReference(Samples_Data.REFERENCE1);
82
//                                
83
//                                panel.setID(Samples_Data.PANELS1_IDS[i]);
84
//                                panel.setLabel(Samples_Data.PANELS1_LABELS[i]);
85
//                                panel.setLabelGroup(Samples_Data.PANELS1_LABELGROUPS[i++]);
86
//                                
87
//                                panelGroup.addPanel(panel);
88
//                        }
89
                        // End: Initialize sample classes
90

    
91
                        // Begin: Tests adding and removing a panel without "label" -> this shoudn't add that panel
92
                        System.out.println("----------> Begin: Tests adding and removing a panel without \"label\" -> this shoudn't add that panel");
93
                        loader = new PanelGroupLoaderFromList(new Class[]{SampleInfoPanel.class});
94
                        loader.loadPanels(panels);
95

    
96
                        panels.get(0).setReference(Samples_Data.REFERENCE1);
97
                        panels.get(0).setID("ID");
98
                        panels.get(0).setLabel(null);
99
                        panels.get(0).setLabelGroup("LABEL_GROUP");
100
                        panelGroup.addPanel(panels.get(0));
101
                        panelGroup.removePanel(panels.get(0));
102
                        System.out.println("End: Tests adding and removing a panel without \"label\" -> this shoudn't add that panel <----------");
103
                        // End: Tests adding and removing a panel without "label" -> this shoudn't add that panel
104

    
105
                        // Begin: Tests: has changed?
106
                        System.out.println("----------> Begin: Tests: has changed?");
107
                        Object[] oPanels = panelGroup.values().toArray();
108

    
109
                        ((AbstractPanel)oPanels[0]).setPreferredSize(new Dimension(700, 600));
110
                        System.out.println("Has the new panel '" + ((AbstractPanel)oPanels[0]).getLabel() + "' changed?: " + ((AbstractPanel)oPanels[0]).hasChanged());
111

    
112
                        String old_Label = ((AbstractPanel)oPanels[0]).getLabel();
113
                        ((AbstractPanel)oPanels[0]).setLabel(((AbstractPanel)oPanels[0]).getLabel() + " modified");
114
                        System.out.println("Has the panel modified '" + ((AbstractPanel)oPanels[0]).getLabel() + "' changed?: " + ((AbstractPanel)oPanels[0]).hasChanged());
115

    
116
                        ((AbstractPanel)oPanels[0]).setLabel(old_Label);
117
                        ((AbstractPanel)oPanels[0]).resetChangedStatus();
118
                        ((AbstractPanel)oPanels[0]).setID(((AbstractPanel)oPanels[0]).getID() + " modified");
119
                        System.out.println("Has the panel modified '" + ((AbstractPanel)oPanels[0]).getLabel() + "' changed?: " + ((AbstractPanel)oPanels[0]).hasChanged());
120

    
121
                        ((AbstractPanel)oPanels[0]).resetChangedStatus();
122
                        ((AbstractPanel)oPanels[0]).setLabelGroup(((AbstractPanel)oPanels[0]).getLabelGroup() + " modified");
123
                        System.out.println("Has the panel modified '" + ((AbstractPanel)oPanels[0]).getLabel() + "' changed?: " + ((AbstractPanel)oPanels[0]).hasChanged());
124

    
125
                        ((AbstractPanel)oPanels[0]).resetChangedStatus();
126
                        System.out.println("Has the panel reseted '" + ((AbstractPanel)oPanels[0]).getLabel() + "' changed?: " + ((AbstractPanel)oPanels[0]).hasChanged());
127
                        System.out.println("End: Tests: has changed? <----------");
128
                        // End: Tests: has changed?
129

    
130
                        // Begin: Test visibility
131
                        System.out.println("----------> Begin: Test visibility");
132
                        ((AbstractPanel)oPanels[0]).setID("ID");
133
                        ((AbstractPanel)oPanels[0]).setLabel("LABEL_TEST_VISIBILITY");
134
                        ((AbstractPanel)oPanels[0]).setLabelGroup("LABEL_GROUP");
135

    
136
                        panelGroup.addPanel(((AbstractPanel)oPanels[0]));
137
                        
138
                        ((AbstractPanel)oPanels[0]).setInGroupGUI(false);    // test change the visibility from a panel child
139
                        if (!((AbstractPanel)oPanels[0]).isInGroupGUI()) {
140
                                System.out.println("Test OK: the panel isn't in the GUI");
141
                                System.out.println("Hay " + panelGroup.getPanelInGUICount() + " paneles en GUI, de los " + panelGroup.getPanelCount() + " registrados.");
142
                        }
143
                        else {
144
                                System.out.println("Test FAILED: the panel is in the GUI");
145
                        }
146
                        
147
                        ((AbstractPanel)oPanels[0]).setInGroupGUI(true);     // test change the visibility from a panel child
148
                        if (((AbstractPanel)oPanels[0]).isInGroupGUI()) {
149
                                System.out.println("Test OK: the panel is in the GUI");
150
                                System.out.println("Hay " + panelGroup.getPanelInGUICount() + " paneles en GUI, de los " + panelGroup.getPanelCount() + " registrados.");
151
                        }
152
                        else {
153
                                System.out.println("Test FAILED: the panel isn't in the GUI");
154
                        }
155
                        
156
                        panelGroup.setPanelInGUI(((AbstractPanel)oPanels[0]), false);
157
                        if (!panelGroup.isPanelInGUI(((AbstractPanel)oPanels[0]))) {
158
                                System.out.println("Test OK: the panel isn't in the GUI");
159
                                System.out.println("Hay " + panelGroup.getPanelInGUICount() + " paneles en GUI, de los " + panelGroup.getPanelCount() + " registrados.");
160
                        }
161
                        else {
162
                                System.out.println("Test FAILED: the panel is in the GUI");
163
                        }
164
                        
165
                        panelGroup.setPanelInGUI(((AbstractPanel)oPanels[0]), true);
166
                        if (panelGroup.isPanelInGUI(((AbstractPanel)oPanels[0]))) {
167
                                System.out.println("Test OK: the panel is in the GUI");
168
                                System.out.println("Hay " + panelGroup.getPanelInGUICount() + " paneles en GUI, de los " + panelGroup.getPanelCount() + " registrados.");
169
                        }
170
                        else {
171
                                System.out.println("Test FAILED: the panel isn't in the GUI");
172
                        }
173
                        System.out.println("End: Test visibility <----------");
174
                        // End: Test visibility
175

    
176
                        // Begin: Tests: Is a panel enabled?
177
                        System.out.println("----------> Begin: Tests: Is a panel enabled?");
178
                        panelGroup.setEnabledAt(0, false); // test change the enable status to a panel
179
                        if (!panelGroup.isEnabledAt(0)) {
180
                                System.out.println("Test OK: the panel isn't enabled.");
181
                        }
182
                        else {
183
                                System.out.println("Test FAILED: the panel is enabled.");
184
                        }
185
                        
186
                        panelGroup.setEnabledAt(0, true); // test change the enable status to a panel
187
                        if (panelGroup.isEnabledAt(0)) {
188
                                System.out.println("Test OK: the panel is enabled.");
189
                        }
190
                        else {
191
                                System.out.println("Test FAILED: the panel isn't enabled.");
192
                        }
193
                        
194
                        panelGroup.setEnabledAt(3, false); // test change the enable status to a panel
195
                        if (!panelGroup.isEnabledAt(3)) {
196
                                System.out.println("Test OK: the panel isn't enabled.");
197
                        }
198
                        else {
199
                                System.out.println("Test FAILED: the panel is enabled.");
200
                        }
201
                        
202
                        panelGroup.setEnabledAt(3, true); // test change the enable status to a panel
203
                        if (panelGroup.isEnabledAt(3)) {
204
                                System.out.println("Test OK: the panel is enabled.");
205
                        }
206
                        else {
207
                                System.out.println("Test FAILED: the panel isn't enabled.");
208
                        }
209
                        System.out.println("End: Tests: Is a panel enabled? <----------");
210
                        // End: Tests: Is a panel enabled?
211
                        
212
                        // Begin: Test: accept, apply or cancel, after request if has changed?
213
                        System.out.println("----------> Begin: Test: accept, apply or cancel, after request if has changed?");
214
//                        Object[] obj_panels = (((Collection<IPanel>) panelGroup.values()).toArray());
215
                        
216
                        // First part:
217
                        System.out.println("First part:");
218
                        System.out.println("Is the new panel '" + ((AbstractPanel)oPanels[1]).getLabel() + "' always applicable?: " + ((AbstractPanel)oPanels[1]).isAlwaysApplicable());
219
                        System.out.println("Has the new panel '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed?: " + ((AbstractPanel)oPanels[1]).hasChanged());
220

    
221
                        ((AbstractPanel)oPanels[1]).setLabel(((AbstractPanel)oPanels[1]).getLabel() + " modified");
222
                        System.out.println("Has the panel modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed?: " + ((AbstractPanel)oPanels[1]).hasChanged());
223
                        panelGroup.accept();
224
                        System.out.println("Has the panel modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed after accept?: " + ((AbstractPanel)oPanels[1]).hasChanged());
225

    
226
                        ((AbstractPanel)oPanels[1]).setLabel(((AbstractPanel)oPanels[1]).getLabel() + " modified");
227
                        System.out.println("Has the panel modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed?: " + ((AbstractPanel)oPanels[1]).hasChanged());
228
                        panelGroup.apply();
229
                        System.out.println("Has the panel modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed after apply?: " + ((AbstractPanel)oPanels[1]).hasChanged());
230

    
231
                        ((AbstractPanel)oPanels[1]).setLabel(((AbstractPanel)oPanels[1]).getLabel() + " modified");
232
                        System.out.println("Has the panel modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed?: " + ((AbstractPanel)oPanels[1]).hasChanged());
233
                        panelGroup.cancel();
234
                        System.out.println("Has the panel modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed after cancel?: " + ((AbstractPanel)oPanels[1]).hasChanged());
235

    
236
                        System.out.println("Has the panel not modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed?: " + ((AbstractPanel)oPanels[1]).hasChanged());
237
                        panelGroup.accept();
238
                        System.out.println("Has the panel not modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed after accept?: " + ((AbstractPanel)oPanels[1]).hasChanged());
239

    
240
                        System.out.println("Has the panel not modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed?: " + ((AbstractPanel)oPanels[1]).hasChanged());
241
                        panelGroup.apply();
242
                        System.out.println("Has the panel not modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed after apply?: " + ((AbstractPanel)oPanels[1]).hasChanged());
243

    
244
                        System.out.println("Has the panel not modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed?: " + ((AbstractPanel)oPanels[1]).hasChanged());
245
                        panelGroup.cancel();
246
                        System.out.println("Has the panel not modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed after cancel?: " + ((AbstractPanel)oPanels[1]).hasChanged());
247

    
248
                        // Second part:
249
                        System.out.println("Second part:");
250
                        ((AbstractPanel)oPanels[1]).setAlwaysApplicable(false);
251
                        System.out.println("Is the new panel '" + ((AbstractPanel)oPanels[1]).getLabel() + "' always applicable?: " + ((AbstractPanel)oPanels[1]).isAlwaysApplicable());
252
                        System.out.println("Has the new panel '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed?: " + ((AbstractPanel)oPanels[1]).hasChanged());
253

    
254
                        ((AbstractPanel)oPanels[1]).setLabel(((AbstractPanel)oPanels[1]).getLabel() + " modified");
255
                        System.out.println("Has the panel modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed?: " + ((AbstractPanel)oPanels[1]).hasChanged());
256
                        panelGroup.accept();
257
                        System.out.println("Has the panel modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed after accept?: " + ((AbstractPanel)oPanels[1]).hasChanged());
258

    
259
                        ((AbstractPanel)oPanels[1]).setLabel(((AbstractPanel)oPanels[1]).getLabel() + " modified");
260
                        System.out.println("Has the panel modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed?: " + ((AbstractPanel)oPanels[1]).hasChanged());
261
                        panelGroup.apply();
262
                        System.out.println("Has the panel modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed after apply?: " + ((AbstractPanel)oPanels[1]).hasChanged());
263

    
264
                        ((AbstractPanel)oPanels[1]).setLabel(((AbstractPanel)oPanels[1]).getLabel() + " modified");
265
                        System.out.println("Has the panel modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed?: " + ((AbstractPanel)oPanels[1]).hasChanged());
266
                        panelGroup.cancel();
267
                        System.out.println("Has the panel modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed after cancel?: " + ((AbstractPanel)oPanels[1]).hasChanged());
268

    
269
                        System.out.println("Has the panel not modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed?: " + ((AbstractPanel)oPanels[1]).hasChanged());
270
                        panelGroup.accept();
271
                        System.out.println("Has the panel not modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed after accept?: " + ((AbstractPanel)oPanels[1]).hasChanged());
272

    
273
                        System.out.println("Has the panel not modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed?: " + ((AbstractPanel)oPanels[1]).hasChanged());
274
                        panelGroup.apply();
275
                        System.out.println("Has the panel not modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed after apply?: " + ((AbstractPanel)oPanels[1]).hasChanged());
276

    
277
                        System.out.println("Has the panel not modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed?: " + ((AbstractPanel)oPanels[1]).hasChanged());
278
                        panelGroup.cancel();
279
                        System.out.println("Has the panel not modified '" + ((AbstractPanel)oPanels[1]).getLabel() + "' changed after cancel?: " + ((AbstractPanel)oPanels[1]).hasChanged());
280
                        System.out.println("End: Test: accept, apply or cancel, after request if has changed? <----------");
281
                        // End: Test: accept, apply or cancel, after request if has changed?
282
                        
283
                        JFrame jFrame = new JFrame();
284
                        jFrame.setTitle("Test TabbedPanel using PanelGroupLoaderFromList");
285
                    jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
286
                    jFrame.setSize(panelGroup.getPreferredSize());
287
                    jFrame.getContentPane().add(panelGroup);
288
                        jFrame.setVisible(true);
289
                        
290
                        // Test the methods 'getSelectedIndex()' and 'getActivePanel()'
291
                        // Register a change listener
292
                        panelGroup.addChangeListener(new ChangeListener() {
293
                        // This method is called whenever the selected tab changes
294
                        public void stateChanged(ChangeEvent evt) {
295
                                JTabbedPane jTabbedPanel = (JTabbedPane) evt.getSource();
296
                                
297
                                System.out.println("Selection changed. New selection index: " + jTabbedPanel.getSelectedIndex());
298

    
299
                                showActivePanelInformation();
300
                        }
301
                    });
302
                        
303
                        // Test the method 'getSelectedIndex()':
304
                        panelGroup.setSelectedIndex(2);
305
                        
306
                        // Test the change of the reference of the group
307
                        panelGroup.updateReference("NEW REFERENCE");
308

    
309
                // End: Other tests
310
                } catch (BaseException e) {
311
                        System.out.println(e.getLocalizedMessageStack());
312
                } catch (Exception e) {
313
                        e.printStackTrace();
314
                }
315
        }
316
        
317
        /**
318
         * <p>Shows information about the current active panel using the standard output.</p>
319
         */
320
        private static void showActivePanelInformation() {
321
                // Test the method 'getActivePanel()'
322
                IPanel panel = panelGroup.getActivePanel();
323
                
324
            System.out.println("New active panel:\n\tID: " + panel.getID() + "\n\tLABEL_GROUP: " + panel.getLabelGroup() + "\n\tLABEL: " + panel.getLabel() + "\n\tCLASS: " + panel.getClass());
325
        }
326
}