root / trunk / applications / appgvSIG / src-test / com / iver / cit / gvsig / panelGroup / Test3ButtonsPanel.java @ 15734
History | View | Annotate | Download (6.83 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
|
20 |
package com.iver.cit.gvsig.panelGroup; |
21 |
|
22 |
import java.awt.Dimension; |
23 |
import java.awt.event.ComponentAdapter; |
24 |
import java.awt.event.ComponentEvent; |
25 |
|
26 |
import javax.swing.JFrame; |
27 |
|
28 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
29 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent; |
30 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener; |
31 |
import org.gvsig.gui.beans.panelGroup.PanelGroupManager; |
32 |
import org.gvsig.gui.beans.panelGroup.loaders.PanelGroupLoaderFromList; |
33 |
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel; |
34 |
import org.gvsig.gui.beans.panelGroup.treePanel.TreePanel; |
35 |
|
36 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
37 |
import com.iver.cit.gvsig.panelGroup.PanelGroupDialog; |
38 |
import com.iver.cit.gvsig.panelGroup.samples.Sample_ExtensionPointsOfIPanels; |
39 |
|
40 |
/**
|
41 |
* <p>Tests {@link PanelGroupDialog PanelGroupDialog}.</p>
|
42 |
* <p>Tests {@link PanelGroupManager PanelGroupManager}, {@link PanelGroupLoaderFromList PanelGroupLoaderFromList},
|
43 |
* {@link TreePanel TreePanel}, and a resizable {@link PanelGroupDialog PanelGroupDialog}.</p>
|
44 |
*
|
45 |
* @version 22/10/2007
|
46 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
47 |
*/
|
48 |
public class Test3ButtonsPanel { |
49 |
/**
|
50 |
* <p>Element for the interface.</p>
|
51 |
*/
|
52 |
private static JFrame jFrame; |
53 |
private static TreePanel panelGroup; |
54 |
|
55 |
/**
|
56 |
* <p>Test method for the Test3ButtonsPanel.</p>
|
57 |
*
|
58 |
* @param args optional arguments
|
59 |
*/
|
60 |
public static void main(String[] args) { |
61 |
try {
|
62 |
// Objects creation
|
63 |
jFrame = new JFrame(); |
64 |
|
65 |
PanelGroupManager manager = PanelGroupManager.getManager(); |
66 |
manager.setDefaultType(TreePanel.class); |
67 |
|
68 |
panelGroup = (TreePanel) manager.getPanelGroup(Sample_ExtensionPointsOfIPanels.REFERENCE1); |
69 |
|
70 |
PanelGroupLoaderFromList loader = new PanelGroupLoaderFromList(Sample_ExtensionPointsOfIPanels.EXTENSIONPOINTS1_CLASSES);
|
71 |
AbstractPanel[] panels = loader.loadPanels();
|
72 |
|
73 |
// Begin: Initialise sample classes
|
74 |
int i = 0; |
75 |
|
76 |
while (i < panels.length) {
|
77 |
panels[i].setPreferredSize(new Dimension(Sample_ExtensionPointsOfIPanels.PANELS_DEFAULT_WIDTH, Sample_ExtensionPointsOfIPanels.PANELS_DEFAULT_HEIGHT)); |
78 |
panels[i].setReference(Sample_ExtensionPointsOfIPanels.REFERENCE1); |
79 |
|
80 |
panels[i].setID(Sample_ExtensionPointsOfIPanels.PANELS1_IDS[i]); |
81 |
panels[i].setLabel(Sample_ExtensionPointsOfIPanels.PANELS1_LABELS[i]); |
82 |
panels[i].setLabelGroup(Sample_ExtensionPointsOfIPanels.PANELS1_LABELGROUPS[i]); |
83 |
|
84 |
panelGroup.addPanel(panels[i++]); |
85 |
} |
86 |
// End: Initialise sample classes
|
87 |
|
88 |
// Creates the IWindow
|
89 |
PanelGroupDialog panelGroupDialog = new PanelGroupDialog(Sample_ExtensionPointsOfIPanels.REFERENCE1_NAME, "Panel with Buttons", 800, 800, (byte)WindowInfo.RESIZABLE, panelGroup); |
90 |
|
91 |
// Some tests
|
92 |
// Test Removing a panel (case 3)
|
93 |
panelGroup.removePanel(panels[--i]); |
94 |
|
95 |
loader = new PanelGroupLoaderFromList(Sample_ExtensionPointsOfIPanels.OTHER_PANELS_CLASSES);
|
96 |
panels = loader.loadPanels(); |
97 |
|
98 |
// SamplePanelWithoutGroupLabel sample
|
99 |
AbstractPanel panel = panels[0];
|
100 |
panel.setPreferredSize(new Dimension(Sample_ExtensionPointsOfIPanels.PANELS_DEFAULT_WIDTH, Sample_ExtensionPointsOfIPanels.PANELS_DEFAULT_HEIGHT)); |
101 |
panel.setID(Sample_ExtensionPointsOfIPanels.PANELS3_IDS[0]);
|
102 |
panel.setLabel(Sample_ExtensionPointsOfIPanels.PANELS3_LABELS[0]);
|
103 |
panel.setLabelGroup(Sample_ExtensionPointsOfIPanels.PANELS3_LABELGROUPS[0]);
|
104 |
panelGroupDialog.addPanel(panel); |
105 |
|
106 |
// Test Removing a panel (case 1)
|
107 |
panelGroupDialog.removePanel(panel); |
108 |
|
109 |
// SamplePanelGroupLabelRepeated sample
|
110 |
panel = panels[1];
|
111 |
panel.setPreferredSize(new Dimension(Sample_ExtensionPointsOfIPanels.PANELS_DEFAULT_WIDTH, Sample_ExtensionPointsOfIPanels.PANELS_DEFAULT_HEIGHT)); |
112 |
panel.setID(Sample_ExtensionPointsOfIPanels.PANELS3_IDS[1]);
|
113 |
panel.setLabel(Sample_ExtensionPointsOfIPanels.PANELS3_LABELS[1]);
|
114 |
panel.setLabelGroup(Sample_ExtensionPointsOfIPanels.PANELS3_LABELGROUPS[1]);
|
115 |
panelGroupDialog.addPanel(panel); |
116 |
|
117 |
// Test Removing a panel (case 2)
|
118 |
panelGroupDialog.removePanel(panel); |
119 |
|
120 |
panelGroupDialog.addButtonPressedListener(new ButtonsPanelListener() {
|
121 |
/*
|
122 |
* @see org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener#actionButtonPressed(org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent)
|
123 |
*/
|
124 |
public void actionButtonPressed(ButtonsPanelEvent e) { |
125 |
switch (e.getButton()) {
|
126 |
case ButtonsPanel.BUTTON_ACCEPT:
|
127 |
System.out.println("Accept Button pressed."); |
128 |
hideJFrame(); |
129 |
System.exit(0); |
130 |
break;
|
131 |
case ButtonsPanel.BUTTON_CANCEL:
|
132 |
System.out.println("Cancel Button pressed."); |
133 |
hideJFrame(); |
134 |
System.exit(0); |
135 |
break;
|
136 |
case ButtonsPanel.BUTTON_APPLY:
|
137 |
System.out.println("Apply Button pressed."); |
138 |
break;
|
139 |
} |
140 |
} |
141 |
}); |
142 |
|
143 |
jFrame.setTitle("Test resizable PanelGroupDialog with tree and using PanelGroupLoaderFromList");
|
144 |
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
145 |
jFrame.setSize(panelGroupDialog.getPreferredSize()); |
146 |
jFrame.getContentPane().add(panelGroupDialog); |
147 |
// jFrame.pack();
|
148 |
jFrame.setVisible(true);
|
149 |
|
150 |
// Resize listenings
|
151 |
panelGroup.addComponentListener(new ComponentAdapter() { |
152 |
/*
|
153 |
* (non-Javadoc)
|
154 |
* @see java.awt.event.ComponentAdapter#componentResized(java.awt.event.ComponentEvent)
|
155 |
*/
|
156 |
public void componentResized(ComponentEvent e) { |
157 |
updateFrameSize(); |
158 |
} |
159 |
}); |
160 |
|
161 |
jFrame.addComponentListener(new ComponentAdapter() { |
162 |
/*
|
163 |
* (non-Javadoc)
|
164 |
* @see java.awt.event.ComponentAdapter#componentResized(java.awt.event.ComponentEvent)
|
165 |
*/
|
166 |
public void componentResized(ComponentEvent e) { |
167 |
panelGroup.setPreferredSize(jFrame.getSize()); |
168 |
} |
169 |
}); |
170 |
} catch (Exception e) { |
171 |
e.printStackTrace(); |
172 |
} |
173 |
} |
174 |
|
175 |
/**
|
176 |
* <p>Hides the {@link JFrame JFrame}, hiding the graphical interface.</p>
|
177 |
*/
|
178 |
private static void hideJFrame() { |
179 |
jFrame.setVisible(false);
|
180 |
} |
181 |
|
182 |
/**
|
183 |
* <p>Updates the test Frame when its components are resized.</p>
|
184 |
*/
|
185 |
private static void updateFrameSize() { |
186 |
jFrame.setSize(panelGroup.getPreferredSize()); |
187 |
} |
188 |
} |