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