Statistics
| Revision:

gvsig-catalog / org.gvsig.catalog / branches / org.gvsig.catalog-CSW2.0.2 / org.gvsig.catalog / org.gvsig.catalog.lib / src / main / java / org / gvsig / catalog / utils / Frames.java @ 55

History | View | Annotate | Download (3.13 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 org.gvsig.catalog.utils;
43
import java.awt.GraphicsEnvironment;
44
import java.awt.Point;
45

    
46
import javax.swing.JDialog;
47
import javax.swing.JFrame;
48

    
49
/**
50
 * 
51
 * 
52
 * 
53
 * @author Jorge Piera Llodra (piera_jor@gva.es)
54
 */
55
public class Frames {
56

    
57
/**
58
 * Sets a JFrame on the screen center
59
 * 
60
 * 
61
 * @param frame JFrams
62
 * @param width Frame width
63
 * @param height Frame height
64
 */
65
    public static void centerFrame(JFrame frame, int width, int height) {        
66
        Point p = getWindowCenter(width,height);
67
        frame.setBounds(p.x, p.y, width, height);
68
        frame.validate();
69
    } 
70

    
71
/**
72
 * Sets a JDialog on the screen center
73
 * 
74
 * 
75
 * @param dialog JDilog
76
 * @param width Dilaog width
77
 * @param height Dialog height
78
 */
79
    public static void centerFrame(JDialog dialog, int width, int height) {        
80
        Point p = getWindowCenter(width,height);
81
        dialog.setBounds(p.x, p.y, width, height);
82
        dialog.validate();
83
    } 
84

    
85
/**
86
 * Sets a JDialog on the upper rigth corner
87
 * 
88
 * 
89
 * @param dialog JDilog
90
 * @param width Dilaog width
91
 * @param height Dialog height
92
 */
93
    public static void searchDialogPosition(JDialog dialog, int width, int height) {        
94
        Point p = getWindowCenter(width,height);
95
        int x = new Double(p.x * 2).intValue();
96
        int y = new Double(p.y *         0.25).intValue();
97
        dialog.setBounds(x, y, width, height);
98
        dialog.validate();
99
    } 
100

    
101
/**
102
 * It returns the screen center
103
 * 
104
 * 
105
 * @return 
106
 */
107
    private static Point getCenter() {        
108
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
109
        return ge.getCenterPoint();
110
    } 
111

    
112
/**
113
 * It returns the point to center a frame
114
 * 
115
 * 
116
 * @return 
117
 * @param width Frame width
118
 * @param height Frame height
119
 */
120
    private static Point getWindowCenter(int width, int height) {        
121
        Point center = getCenter();
122
        center.x = center.x - (width / 2);
123
        center.y = center.y - (height / 2);
124
        return center;
125
    } 
126
 }