svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.utils / src / test / java / org / gvsig / utils / centerComponent / TestCenterComponent.java @ 40561
History | View | Annotate | Download (5.32 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.utils.centerComponent; |
25 |
|
26 |
import java.awt.Color; |
27 |
import java.awt.Dimension; |
28 |
import java.awt.Point; |
29 |
import java.awt.Rectangle; |
30 |
import java.awt.Toolkit; |
31 |
import java.awt.event.MouseAdapter; |
32 |
import java.awt.event.MouseEvent; |
33 |
|
34 |
import javax.swing.JDesktopPane; |
35 |
import javax.swing.JDialog; |
36 |
import javax.swing.JFrame; |
37 |
import javax.swing.JInternalFrame; |
38 |
import javax.swing.JPanel; |
39 |
|
40 |
import org.gvsig.utils.centerComponent.CenterComponent; |
41 |
|
42 |
|
43 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
44 |
*
|
45 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
46 |
*
|
47 |
* This program is free software; you can redistribute it and/or
|
48 |
* modify it under the terms of the GNU General Public License
|
49 |
* as published by the Free Software Foundation; either version 2
|
50 |
* of the License, or (at your option) any later version.
|
51 |
*
|
52 |
* This program is distributed in the hope that it will be useful,
|
53 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
54 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
55 |
* GNU General Public License for more details.
|
56 |
*
|
57 |
* You should have received a copy of the GNU General Public License
|
58 |
* along with this program; if not, write to the Free Software
|
59 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
60 |
*
|
61 |
* For more information, contact:
|
62 |
*
|
63 |
* Generalitat Valenciana
|
64 |
* Conselleria d'Infraestructures i Transport
|
65 |
* Av. Blasco Ib??ez, 50
|
66 |
* 46010 VALENCIA
|
67 |
* SPAIN
|
68 |
*
|
69 |
* +34 963862235
|
70 |
* gvsig@gva.es
|
71 |
* www.gvsig.gva.es
|
72 |
*
|
73 |
* or
|
74 |
*
|
75 |
* IVER T.I. S.A
|
76 |
* Salamanca 50
|
77 |
* 46005 Valencia
|
78 |
* Spain
|
79 |
*
|
80 |
* +34 963163400
|
81 |
* dac@iver.es
|
82 |
*/
|
83 |
|
84 |
/**
|
85 |
* Tests the 'centerJComponent' method of the CenterJComponent class
|
86 |
*
|
87 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
|
88 |
*/
|
89 |
public class TestCenterComponent { |
90 |
private static JFrame jFrame; |
91 |
private static JDesktopPane jDesktopPane; |
92 |
private static int i; |
93 |
|
94 |
/**
|
95 |
* Test method for the CenterJComponent
|
96 |
*
|
97 |
* @param args
|
98 |
*/
|
99 |
public static void main (String args[]) |
100 |
{ |
101 |
try {
|
102 |
// Creates the main JFrame and configures it for test. Adds a JDesktopPane
|
103 |
jFrame = new JFrame("JFrame: Tests 1, 2 y 3"); |
104 |
|
105 |
jDesktopPane = new JDesktopPane(); |
106 |
jDesktopPane.setPreferredSize(new Dimension(300, 300)); |
107 |
jDesktopPane.setSize(new Dimension(300, 300)); |
108 |
jDesktopPane.addMouseListener(new MouseAdapter() { |
109 |
|
110 |
/*
|
111 |
* (non-Javadoc)
|
112 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
113 |
*/
|
114 |
public void mouseClicked(MouseEvent e) { |
115 |
createComponentsForTest(); |
116 |
} |
117 |
}); |
118 |
|
119 |
jFrame.getContentPane().add(jDesktopPane); |
120 |
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
121 |
jFrame.pack(); |
122 |
jFrame.setVisible(true);
|
123 |
|
124 |
// By default: centers the JFrame in the screen
|
125 |
Point screenTopLeftCorner = new Point(0, 0); |
126 |
Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); |
127 |
Rectangle screenRectangle = new Rectangle(screenTopLeftCorner, screenDimension); |
128 |
CenterComponent.centerComponent(jFrame, screenRectangle); |
129 |
// jFrame.setLocationRelativeTo(null);
|
130 |
|
131 |
i = 0;
|
132 |
createComponentsForTest(); |
133 |
} |
134 |
catch(Exception e) { |
135 |
e.printStackTrace(); |
136 |
} |
137 |
|
138 |
} |
139 |
|
140 |
/**
|
141 |
* Creates some objects for test
|
142 |
*/
|
143 |
private static void createComponentsForTest() { |
144 |
|
145 |
// Creates a JInternalFrame with a JPanel, and adds it
|
146 |
JInternalFrame jInternalFrame1 = new JInternalFrame("JInternalFrame" + i, |
147 |
true, // resizable |
148 |
true, // closable |
149 |
true, // maximizable |
150 |
false); //iconizable |
151 |
jInternalFrame1.setPreferredSize(new Dimension(200, 200)); |
152 |
jInternalFrame1.setSize(new Dimension(200, 200)); |
153 |
|
154 |
JPanel jPanel1 = new JPanel(); |
155 |
jPanel1.setBackground(Color.BLUE);
|
156 |
jInternalFrame1.getContentPane().add(jPanel1); |
157 |
jInternalFrame1.setVisible(true);
|
158 |
jDesktopPane.add(jInternalFrame1); |
159 |
|
160 |
// Creates a JDialog with a JPanel, and adds it
|
161 |
JDialog jDialog = new JDialog(); |
162 |
jDialog.setTitle("JDialog " + i);
|
163 |
jDialog.setSize(new Dimension(100, 150)); |
164 |
JPanel jPanel2 = new JPanel(); |
165 |
jPanel2.setBackground(Color.GREEN);
|
166 |
jDialog.getContentPane().add(jPanel2); |
167 |
jDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
168 |
jDialog.setVisible(true);
|
169 |
|
170 |
// Centers the JInternalFrame
|
171 |
CenterComponent.centerComponent(jInternalFrame1, jDesktopPane.getBounds()); |
172 |
|
173 |
// Centers the JDialog
|
174 |
jDialog.setLocationRelativeTo(jFrame.getContentPane()); |
175 |
|
176 |
i++; |
177 |
} |
178 |
} |