gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.swing / org.gvsig.tools.swing.impl / src / main / java / org / gvsig / tools / swing / impl / DefaultZoomDialog.java @ 1867
History | View | Annotate | Download (3.93 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.tools.swing.impl; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Component; |
28 |
import java.awt.Dialog; |
29 |
import java.awt.Dimension; |
30 |
import java.awt.GraphicsConfiguration; |
31 |
import java.awt.GraphicsDevice; |
32 |
import java.awt.Rectangle; |
33 |
import java.awt.Toolkit; |
34 |
import java.awt.Window; |
35 |
import java.awt.event.ActionEvent; |
36 |
import java.awt.event.ActionListener; |
37 |
|
38 |
import javax.swing.BorderFactory; |
39 |
import javax.swing.JButton; |
40 |
import javax.swing.JDialog; |
41 |
import javax.swing.JPanel; |
42 |
import javax.swing.JScrollPane; |
43 |
import javax.swing.JTextArea; |
44 |
|
45 |
public class DefaultZoomDialog extends JDialog { |
46 |
|
47 |
/**
|
48 |
*
|
49 |
*/
|
50 |
private static final long serialVersionUID = 7913363575200612492L; |
51 |
|
52 |
private String value = null; |
53 |
private JTextArea text = null; |
54 |
|
55 |
public DefaultZoomDialog(Component parent, String title) { |
56 |
super(getParentWindow(parent), title, ModalityType.DOCUMENT_MODAL);
|
57 |
} |
58 |
|
59 |
public DefaultZoomDialog(Component parent, String title, String value) { |
60 |
this(parent, title);
|
61 |
this.value = value;
|
62 |
initComponents(); |
63 |
|
64 |
} |
65 |
|
66 |
private static Window getParentWindow(Component c) { |
67 |
while( c!=null ) { |
68 |
if( c instanceof Window ) { |
69 |
return (Window) c; |
70 |
} |
71 |
c = c.getParent(); |
72 |
} |
73 |
return null; |
74 |
} |
75 |
|
76 |
public void setEditable(boolean editable) { |
77 |
this.text.setEditable(editable);
|
78 |
} |
79 |
|
80 |
private void initComponents() { |
81 |
|
82 |
JPanel panel = new JPanel(); |
83 |
panel.setLayout(new BorderLayout()); |
84 |
|
85 |
text = new JTextArea(); |
86 |
text.setText(value); |
87 |
text.setLineWrap(true);
|
88 |
JScrollPane scroll = new JScrollPane(text); |
89 |
panel.add(scroll, BorderLayout.CENTER);
|
90 |
panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
91 |
|
92 |
JPanel p = new JPanel(); |
93 |
|
94 |
JButton close = new JButton("Close"); |
95 |
close.addActionListener(new ActionListener() { |
96 |
@Override
|
97 |
public void actionPerformed(ActionEvent arg0) { |
98 |
value = text.getText(); |
99 |
setVisible(false);
|
100 |
} |
101 |
}); |
102 |
|
103 |
p.setLayout(new BorderLayout()); |
104 |
p.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); |
105 |
p.add(close, BorderLayout.LINE_END);
|
106 |
|
107 |
panel.add(p, BorderLayout.PAGE_END);
|
108 |
|
109 |
panel.setPreferredSize(new Dimension(600, 250)); |
110 |
|
111 |
this.setContentPane(panel);
|
112 |
|
113 |
this.center();
|
114 |
this.pack();
|
115 |
} |
116 |
|
117 |
public void center() { |
118 |
Dimension size = this.getPreferredSize(); |
119 |
|
120 |
// Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
|
121 |
// int x = (int) ((dimension.getWidth() - size.getWidth()) / 2);
|
122 |
// int y = (int) ((dimension.getHeight() - size.getHeight()) / 2);
|
123 |
|
124 |
Rectangle r = this.getGraphicsConfiguration().getBounds(); |
125 |
int x = (int) ((r.width - size.getWidth()) / 2) + r.x; |
126 |
int y = (int) ((r.height - size.getHeight()) / 2) + r.y ; |
127 |
|
128 |
this.setLocation(x, y);
|
129 |
} |
130 |
|
131 |
public String getText() { |
132 |
return this.value; |
133 |
} |
134 |
} |