svn-gvsig-desktop / tags / v10_RC2c / libraries / libIverUtiles / src / com / iver / utiles / swing / WindowUtils.java @ 8745
History | View | Annotate | Download (2.54 KB)
1 |
|
---|---|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 |
*
|
4 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
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 2
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* Generalitat Valenciana
|
23 |
* Conselleria d'Infraestructures i Transport
|
24 |
* Av. Blasco Ib??ez, 50
|
25 |
* 46010 VALENCIA
|
26 |
* SPAIN
|
27 |
*
|
28 |
* +34 963862235
|
29 |
* gvsig@gva.es
|
30 |
* www.gvsig.gva.es
|
31 |
*
|
32 |
* or
|
33 |
*
|
34 |
* IVER T.I. S.A
|
35 |
* Salamanca 50
|
36 |
* 46005 Valencia
|
37 |
* Spain
|
38 |
*
|
39 |
* +34 963163400
|
40 |
* dac@iver.es
|
41 |
*/
|
42 |
package com.iver.utiles.swing; |
43 |
import java.awt.GraphicsEnvironment; |
44 |
import java.awt.Point; |
45 |
import java.awt.Window; |
46 |
|
47 |
import javax.swing.JDialog; |
48 |
import javax.swing.JFrame; |
49 |
|
50 |
/**
|
51 |
*
|
52 |
*
|
53 |
*
|
54 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
55 |
*/
|
56 |
public class WindowUtils { |
57 |
|
58 |
/**
|
59 |
* Sets a Window on the screen center
|
60 |
* @param window
|
61 |
* Window
|
62 |
* @param width
|
63 |
* Window width
|
64 |
* @param height
|
65 |
* Window height
|
66 |
*/
|
67 |
public static void centerWindow(Window window, int width, int height) { |
68 |
Point p = getWindowCenter(width,height);
|
69 |
window.setBounds(p.x, p.y, width, height); |
70 |
window.validate(); |
71 |
} |
72 |
|
73 |
/**
|
74 |
* Sets a Window on the screen center
|
75 |
* @param window
|
76 |
* Window
|
77 |
*/
|
78 |
public static void centerWindow(Window window) { |
79 |
centerWindow(window,window.getWidth(),window.getHeight()); |
80 |
} |
81 |
|
82 |
/**
|
83 |
* It returns the screen center
|
84 |
*
|
85 |
*
|
86 |
* @return
|
87 |
*/
|
88 |
private static Point getCenter() { |
89 |
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); |
90 |
return ge.getCenterPoint();
|
91 |
} |
92 |
|
93 |
/**
|
94 |
* It returns the window center point
|
95 |
*
|
96 |
* @return
|
97 |
* @param width
|
98 |
* Window width
|
99 |
* @param height
|
100 |
* Window height
|
101 |
*/
|
102 |
private static Point getWindowCenter(int width, int height) { |
103 |
Point center = getCenter();
|
104 |
center.x = center.x - (width / 2);
|
105 |
center.y = center.y - (height / 2);
|
106 |
return center;
|
107 |
} |
108 |
} |