root / trunk / applications / appgvSIG / src-test / com / iver / cit / gvsig / panelGroup / Test7ButtonsPanel.java @ 15734
History | View | Annotate | Download (6.7 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.Color; |
23 |
import java.awt.Dimension; |
24 |
import java.awt.event.ComponentAdapter; |
25 |
import java.awt.event.ComponentEvent; |
26 |
|
27 |
import javax.swing.JFrame; |
28 |
|
29 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
30 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent; |
31 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener; |
32 |
import org.gvsig.gui.beans.panelGroup.PanelGroupManager; |
33 |
import org.gvsig.gui.beans.panelGroup.loaders.PanelGroupLoaderFromList; |
34 |
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel; |
35 |
import org.gvsig.gui.beans.panelGroup.treePanel.TreePanel; |
36 |
|
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 the G.U.I. behaviour adding panels with different dimensions, to a non resizable {@link PanelGroupDialog PanelGroupDialog}
|
43 |
* with a {@link TreePanel TreePanel}.</p>
|
44 |
*
|
45 |
* @version 22/10/2007
|
46 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
47 |
*/
|
48 |
public class Test7ButtonsPanel { |
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 Test7ButtonsPanel.</p>
|
57 |
*
|
58 |
* @param args optional arguments
|
59 |
*/
|
60 |
public static void main(String[] args) { |
61 |
try {
|
62 |
jFrame = new JFrame(); |
63 |
|
64 |
PanelGroupManager manager = PanelGroupManager.getManager(); |
65 |
manager.setDefaultType(TreePanel.class); |
66 |
|
67 |
panelGroup = (TreePanel) manager.getPanelGroup(Sample_ExtensionPointsOfIPanels.REFERENCE1); |
68 |
|
69 |
PanelGroupLoaderFromList loader = new PanelGroupLoaderFromList(Sample_ExtensionPointsOfIPanels.EXTENSIONPOINTS1_CLASSES);
|
70 |
AbstractPanel[] panels = loader.loadPanels();
|
71 |
|
72 |
AbstractPanel panel; |
73 |
|
74 |
// Creates the IWindow
|
75 |
PanelGroupDialog panelGroupDialog = new PanelGroupDialog(Sample_ExtensionPointsOfIPanels.REFERENCE1_NAME, "Panel with Buttons", 800, 800, (byte)0, panelGroup); |
76 |
|
77 |
// First panel
|
78 |
panel = panels[0];
|
79 |
panel.setPreferredSize(new Dimension(Sample_ExtensionPointsOfIPanels.PANELS_DEFAULT_WIDTH, Sample_ExtensionPointsOfIPanels.PANELS_DEFAULT_HEIGHT)); |
80 |
panel.setReference(Sample_ExtensionPointsOfIPanels.REFERENCE1); |
81 |
panel.setID(Sample_ExtensionPointsOfIPanels.PANELS1_IDS[0]);
|
82 |
panel.setLabel(Sample_ExtensionPointsOfIPanels.PANELS1_LABELS[0]);
|
83 |
panel.setLabelGroup(Sample_ExtensionPointsOfIPanels.PANELS1_LABELGROUPS[0]);
|
84 |
panel.setBackground(Color.GRAY);
|
85 |
panelGroupDialog.addPanel(panel); |
86 |
|
87 |
// Second panel
|
88 |
panel = panels[1];
|
89 |
panel.setPreferredSize(new Dimension(200, 200)); |
90 |
panel.setReference(Sample_ExtensionPointsOfIPanels.REFERENCE1); |
91 |
panel.setID(Sample_ExtensionPointsOfIPanels.PANELS1_IDS[1]);
|
92 |
panel.setLabel(Sample_ExtensionPointsOfIPanels.PANELS1_LABELS[1]);
|
93 |
panel.setLabelGroup(Sample_ExtensionPointsOfIPanels.PANELS1_LABELGROUPS[1]);
|
94 |
panel.setBackground(Color.GRAY);
|
95 |
panelGroupDialog.addPanel(panel); |
96 |
|
97 |
// Third panel
|
98 |
panel = panels[2];
|
99 |
panel.setPreferredSize(new Dimension(600, 500)); |
100 |
panel.setReference(Sample_ExtensionPointsOfIPanels.REFERENCE1); |
101 |
panel.setID(Sample_ExtensionPointsOfIPanels.PANELS1_IDS[2]);
|
102 |
panel.setLabel(Sample_ExtensionPointsOfIPanels.PANELS1_LABELS[2]);
|
103 |
panel.setLabelGroup(Sample_ExtensionPointsOfIPanels.PANELS1_LABELGROUPS[2]);
|
104 |
panel.setBackground(Color.GRAY);
|
105 |
panelGroupDialog.addPanel(panel); |
106 |
|
107 |
// Fourth panel
|
108 |
panel = panels[3];
|
109 |
panel.setPreferredSize(new Dimension(300, 400)); |
110 |
panel.setReference(Sample_ExtensionPointsOfIPanels.REFERENCE1); |
111 |
panel.setID(Sample_ExtensionPointsOfIPanels.PANELS1_IDS[3]);
|
112 |
panel.setLabel(Sample_ExtensionPointsOfIPanels.PANELS1_LABELS[3]);
|
113 |
panel.setLabelGroup(Sample_ExtensionPointsOfIPanels.PANELS1_LABELGROUPS[3]);
|
114 |
panel.setBackground(Color.GRAY);
|
115 |
panelGroupDialog.addPanel(panel); |
116 |
|
117 |
panelGroupDialog.addButtonPressedListener(new ButtonsPanelListener() {
|
118 |
/*
|
119 |
* @see org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener#actionButtonPressed(org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent)
|
120 |
*/
|
121 |
public void actionButtonPressed(ButtonsPanelEvent e) { |
122 |
switch (e.getButton()) {
|
123 |
case ButtonsPanel.BUTTON_ACCEPT:
|
124 |
System.out.println("Accept Button pressed."); |
125 |
hideJFrame(); |
126 |
System.exit(0); |
127 |
break;
|
128 |
case ButtonsPanel.BUTTON_CANCEL:
|
129 |
System.out.println("Cancel Button pressed."); |
130 |
hideJFrame(); |
131 |
System.exit(0); |
132 |
break;
|
133 |
case ButtonsPanel.BUTTON_APPLY:
|
134 |
System.out.println("Apply Button pressed."); |
135 |
break;
|
136 |
} |
137 |
} |
138 |
}); |
139 |
|
140 |
jFrame.setTitle("Test non resizable PanelGroupDialog with a tree and using PanelGroupLoaderFromList");
|
141 |
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
142 |
jFrame.setSize(panelGroupDialog.getPreferredSize()); |
143 |
jFrame.getContentPane().add(panelGroupDialog); |
144 |
|
145 |
jFrame.setResizable(false);
|
146 |
jFrame.setVisible(true);
|
147 |
|
148 |
// Resize listenings
|
149 |
panelGroup.addComponentListener(new ComponentAdapter() { |
150 |
/*
|
151 |
* (non-Javadoc)
|
152 |
* @see java.awt.event.ComponentAdapter#componentResized(java.awt.event.ComponentEvent)
|
153 |
*/
|
154 |
public void componentResized(ComponentEvent e) { |
155 |
updateFrameSize(); |
156 |
} |
157 |
}); |
158 |
|
159 |
jFrame.addComponentListener(new ComponentAdapter() { |
160 |
/*
|
161 |
* (non-Javadoc)
|
162 |
* @see java.awt.event.ComponentAdapter#componentResized(java.awt.event.ComponentEvent)
|
163 |
*/
|
164 |
public void componentResized(ComponentEvent e) { |
165 |
panelGroup.setPreferredSize(jFrame.getSize()); |
166 |
} |
167 |
}); |
168 |
} catch (Exception e) { |
169 |
e.printStackTrace(); |
170 |
} |
171 |
} |
172 |
|
173 |
/**
|
174 |
* <p>Hides the {@link JFrame JFrame}, hiding the graphical interface.</p>
|
175 |
*/
|
176 |
private static void hideJFrame() { |
177 |
jFrame.setVisible(false);
|
178 |
} |
179 |
|
180 |
/**
|
181 |
* <p>Updates the test Frame when its components are resized.</p>
|
182 |
*/
|
183 |
private static void updateFrameSize() { |
184 |
jFrame.setSize(panelGroup.getPreferredSize()); |
185 |
} |
186 |
} |