svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / coordinatespanel / CoordinatesPanel.java @ 40561
History | View | Annotate | Download (10.4 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.gui.beans.coordinatespanel; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Font; |
28 |
import java.awt.GridBagConstraints; |
29 |
import java.awt.GridBagLayout; |
30 |
import java.awt.Insets; |
31 |
import java.net.URL; |
32 |
import java.util.ArrayList; |
33 |
import java.util.EventObject; |
34 |
import java.util.Iterator; |
35 |
|
36 |
import javax.swing.BorderFactory; |
37 |
import javax.swing.ImageIcon; |
38 |
import javax.swing.JLabel; |
39 |
import javax.swing.JPanel; |
40 |
import javax.swing.border.TitledBorder; |
41 |
|
42 |
import org.gvsig.gui.beans.datainput.DataInputContainer; |
43 |
import org.gvsig.gui.beans.datainput.DataInputContainerListener; |
44 |
/**
|
45 |
*
|
46 |
* @version 06/09/2007
|
47 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
48 |
*/
|
49 |
@SuppressWarnings("unchecked") |
50 |
public class CoordinatesPanel extends JPanel implements DataInputContainerListener { |
51 |
private static final long serialVersionUID = 3336324382874763427L; |
52 |
private String pathToImages = "images/"; |
53 |
private ArrayList actionChangedListeners = new ArrayList(); |
54 |
|
55 |
private JPanel pCoord = null; |
56 |
private JLabel lTitulo1 = null; |
57 |
private JLabel lTitulo2 = null; |
58 |
private DataInputContainer dataInputContainer11 = null; |
59 |
private DataInputContainer dataInputContainer12 = null; |
60 |
private DataInputContainer dataInputContainer21 = null; |
61 |
private DataInputContainer dataInputContainer22 = null; |
62 |
private int maximumFractionDigits = 3; |
63 |
|
64 |
/**
|
65 |
* This is the default constructor
|
66 |
*/
|
67 |
public CoordinatesPanel(int maximumFractionDigits) { |
68 |
this.maximumFractionDigits = maximumFractionDigits;
|
69 |
initialize(); |
70 |
} |
71 |
|
72 |
/**
|
73 |
* This is the default constructor
|
74 |
*/
|
75 |
public CoordinatesPanel() {
|
76 |
initialize(); |
77 |
} |
78 |
|
79 |
/**
|
80 |
* This method initializes this
|
81 |
*
|
82 |
* @return void
|
83 |
*/
|
84 |
private void initialize() { |
85 |
setLayout(new BorderLayout()); |
86 |
add(getPCoord(), BorderLayout.CENTER);
|
87 |
} |
88 |
|
89 |
/**
|
90 |
* This method initializes jPanel
|
91 |
*
|
92 |
* @return javax.swing.JPanel
|
93 |
*/
|
94 |
private JPanel getPCoord() { |
95 |
if (pCoord == null) { |
96 |
GridBagConstraints gridBagConstraints;
|
97 |
pCoord = new JPanel(); |
98 |
pCoord.setLayout(new GridBagLayout()); |
99 |
|
100 |
int y = 0; |
101 |
gridBagConstraints = new GridBagConstraints(); |
102 |
gridBagConstraints.gridx = 0;
|
103 |
gridBagConstraints.gridy = y; |
104 |
gridBagConstraints.insets = new Insets(5, 5, 2, 2); |
105 |
pCoord.add(getLTitulo1(), gridBagConstraints); |
106 |
|
107 |
gridBagConstraints = new GridBagConstraints(); |
108 |
gridBagConstraints.gridx = 1;
|
109 |
gridBagConstraints.gridy = y; |
110 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
111 |
gridBagConstraints.weightx = 1.0;
|
112 |
gridBagConstraints.insets = new Insets(5, 2, 2, 2); |
113 |
pCoord.add(getDataInputContainer11(), gridBagConstraints); |
114 |
|
115 |
gridBagConstraints = new GridBagConstraints(); |
116 |
gridBagConstraints.gridx = 2;
|
117 |
gridBagConstraints.gridy = y; |
118 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
119 |
gridBagConstraints.weightx = 1.0;
|
120 |
gridBagConstraints.insets = new Insets(5, 2, 2, 5); |
121 |
pCoord.add(getDataInputContainer12(), gridBagConstraints); |
122 |
|
123 |
y++; |
124 |
gridBagConstraints = new GridBagConstraints(); |
125 |
gridBagConstraints.gridx = 0;
|
126 |
gridBagConstraints.gridy = y; |
127 |
gridBagConstraints.insets = new Insets(2, 5, 5, 2); |
128 |
pCoord.add(getLTitulo2(), gridBagConstraints); |
129 |
|
130 |
gridBagConstraints = new GridBagConstraints(); |
131 |
gridBagConstraints.gridx = 1;
|
132 |
gridBagConstraints.gridy = y; |
133 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
134 |
gridBagConstraints.weightx = 1.0;
|
135 |
gridBagConstraints.insets = new Insets(2, 2, 5, 2); |
136 |
pCoord.add(getDataInputContainer21(), gridBagConstraints); |
137 |
|
138 |
|
139 |
gridBagConstraints = new GridBagConstraints(); |
140 |
gridBagConstraints.gridx = 2;
|
141 |
gridBagConstraints.gridy = y; |
142 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
143 |
gridBagConstraints.weightx = 1.0;
|
144 |
gridBagConstraints.insets = new Insets(2, 2, 5, 5); |
145 |
pCoord.add(getDataInputContainer22(), gridBagConstraints); |
146 |
} |
147 |
return pCoord;
|
148 |
} |
149 |
|
150 |
private JLabel getLTitulo1(){ |
151 |
if (lTitulo1 == null){ |
152 |
URL resource = getClass().getResource(pathToImages + "upleft.png"); |
153 |
if(resource != null) { |
154 |
ImageIcon icon = new ImageIcon(resource); |
155 |
lTitulo1 = new JLabel(icon); |
156 |
} else
|
157 |
lTitulo1 = new JLabel(); |
158 |
} |
159 |
return lTitulo1;
|
160 |
} |
161 |
|
162 |
private JLabel getLTitulo2() { |
163 |
if (lTitulo2 == null){ |
164 |
if (lTitulo2 == null){ |
165 |
URL resource = getClass().getResource(pathToImages + "downright.png"); |
166 |
if(resource != null) { |
167 |
ImageIcon icon = new ImageIcon(resource); |
168 |
lTitulo2 = new JLabel(icon); |
169 |
} else
|
170 |
lTitulo2 = new JLabel(); |
171 |
} |
172 |
} |
173 |
return lTitulo2;
|
174 |
} |
175 |
|
176 |
/**
|
177 |
* This method initializes jPanel
|
178 |
*
|
179 |
* @return javax.swing.JPanel
|
180 |
*/
|
181 |
public DataInputContainer getDataInputContainer11() {
|
182 |
if (dataInputContainer11 == null) { |
183 |
dataInputContainer11 = new DataInputContainer(maximumFractionDigits);
|
184 |
dataInputContainer11.setLabelText("X");
|
185 |
dataInputContainer11.addValueChangedListener(this);
|
186 |
} |
187 |
return dataInputContainer11;
|
188 |
} |
189 |
|
190 |
/**
|
191 |
* This method initializes jPanel1
|
192 |
*
|
193 |
* @return javax.swing.JPanel
|
194 |
*/
|
195 |
public DataInputContainer getDataInputContainer12() {
|
196 |
if (dataInputContainer12 == null) { |
197 |
dataInputContainer12 = new DataInputContainer(maximumFractionDigits);
|
198 |
dataInputContainer12.setLabelText("Y");
|
199 |
dataInputContainer12.addValueChangedListener(this);
|
200 |
} |
201 |
return dataInputContainer12;
|
202 |
} |
203 |
|
204 |
/**
|
205 |
* This method initializes jPanel2
|
206 |
*
|
207 |
* @return javax.swing.JPanel
|
208 |
*/
|
209 |
public DataInputContainer getDataInputContainer21() {
|
210 |
if (dataInputContainer21 == null) { |
211 |
dataInputContainer21 = new DataInputContainer(maximumFractionDigits);
|
212 |
dataInputContainer21.setLabelText("X");
|
213 |
dataInputContainer21.addValueChangedListener(this);
|
214 |
} |
215 |
return dataInputContainer21;
|
216 |
} |
217 |
|
218 |
/**
|
219 |
* This method initializes jPanel3
|
220 |
*
|
221 |
* @return javax.swing.JPanel
|
222 |
*/
|
223 |
public DataInputContainer getDataInputContainer22() {
|
224 |
if (dataInputContainer22 == null) { |
225 |
dataInputContainer22 = new DataInputContainer(maximumFractionDigits);
|
226 |
dataInputContainer22.setLabelText("Y");
|
227 |
dataInputContainer22.addValueChangedListener(this);
|
228 |
} |
229 |
return dataInputContainer22;
|
230 |
} |
231 |
|
232 |
/**
|
233 |
* M?todo para poner un titulo al panel.
|
234 |
*
|
235 |
* @param titlePanel
|
236 |
*/
|
237 |
public void setTitlePanel(String titlePanel) { |
238 |
getPCoord().setBorder(BorderFactory.createTitledBorder(null, titlePanel, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.PLAIN, 12), null)); |
239 |
} |
240 |
|
241 |
/**
|
242 |
* Devuelve los valores del panel por orden de izquierda a derecha
|
243 |
* y de arriba a bajo.
|
244 |
* @return
|
245 |
*/
|
246 |
public String[] getValues(){ |
247 |
String[] values = { |
248 |
getDataInputContainer11().getValue(), |
249 |
getDataInputContainer12().getValue(), |
250 |
getDataInputContainer21().getValue(), |
251 |
getDataInputContainer22().getValue() |
252 |
}; |
253 |
return values;
|
254 |
} |
255 |
|
256 |
/**
|
257 |
* Asigna los valores del panel por orden de izquierda a derecha
|
258 |
* y de arriba a bajo.
|
259 |
* @return
|
260 |
*/
|
261 |
public void setValues(String[] values){ |
262 |
getDataInputContainer11().setValue(values[0]);
|
263 |
getDataInputContainer12().setValue(values[1]);
|
264 |
getDataInputContainer21().setValue(values[2]);
|
265 |
getDataInputContainer22().setValue(values[3]);
|
266 |
} |
267 |
|
268 |
/**
|
269 |
* A?adir un listener a la lista de eventos
|
270 |
* @param listener
|
271 |
*/
|
272 |
public void addValueChangedListener(CoordinatesListener listener) { |
273 |
if (!actionChangedListeners.contains(listener))
|
274 |
actionChangedListeners.add(listener); |
275 |
} |
276 |
|
277 |
/**
|
278 |
* Borrar un listener de la lista de eventos
|
279 |
* @param listener
|
280 |
*/
|
281 |
public void removeValueChangedListener(CoordinatesListener listener) { |
282 |
actionChangedListeners.remove(listener); |
283 |
} |
284 |
|
285 |
/**
|
286 |
* Invocar a los eventos asociados al componente
|
287 |
*/
|
288 |
private void callValueChangedListeners(String component) { |
289 |
Iterator acIterator = actionChangedListeners.iterator();
|
290 |
while (acIterator.hasNext()) {
|
291 |
CoordinatesListener listener = (CoordinatesListener) acIterator.next(); |
292 |
listener.actionValueChanged(new CoordinatesEvent(this, component)); |
293 |
} |
294 |
} |
295 |
|
296 |
public void actionValueChanged(EventObject e) { |
297 |
if (e.getSource() == getDataInputContainer11().getDataInputField()) {
|
298 |
callValueChangedListeners("11");
|
299 |
return;
|
300 |
} |
301 |
if (e.getSource() == getDataInputContainer12().getDataInputField()) {
|
302 |
callValueChangedListeners("12");
|
303 |
return;
|
304 |
} |
305 |
if (e.getSource() == getDataInputContainer21().getDataInputField()) {
|
306 |
callValueChangedListeners("21");
|
307 |
return;
|
308 |
} |
309 |
if (e.getSource() == getDataInputContainer22().getDataInputField()) {
|
310 |
callValueChangedListeners("22");
|
311 |
return;
|
312 |
} |
313 |
} |
314 |
|
315 |
public String getValue11() { |
316 |
return getDataInputContainer11().getValue();
|
317 |
} |
318 |
|
319 |
public String getValue12() { |
320 |
return getDataInputContainer12().getValue();
|
321 |
} |
322 |
|
323 |
public String getValue21() { |
324 |
return getDataInputContainer21().getValue();
|
325 |
} |
326 |
|
327 |
public String getValue22() { |
328 |
return getDataInputContainer22().getValue();
|
329 |
} |
330 |
|
331 |
public void setValue11(String value) { |
332 |
getDataInputContainer11().setValue(value); |
333 |
} |
334 |
|
335 |
public void setValue12(String value) { |
336 |
getDataInputContainer12().setValue(value); |
337 |
} |
338 |
|
339 |
public void setValue21(String value) { |
340 |
getDataInputContainer21().setValue(value); |
341 |
} |
342 |
|
343 |
public void setValue22(String value) { |
344 |
getDataInputContainer22().setValue(value); |
345 |
} |
346 |
|
347 |
/*
|
348 |
* (non-Javadoc)
|
349 |
* @see javax.swing.JComponent#setEnabled(boolean)
|
350 |
*/
|
351 |
public void setEnabled(boolean enabled) { |
352 |
super.setEnabled(enabled);
|
353 |
getPCoord().setEnabled(enabled); |
354 |
getLTitulo1().setEnabled(enabled); |
355 |
getLTitulo2().setEnabled(enabled); |
356 |
getDataInputContainer11().setControlEnabled(enabled); |
357 |
getDataInputContainer12().setControlEnabled(enabled); |
358 |
getDataInputContainer21().setControlEnabled(enabled); |
359 |
getDataInputContainer22().setControlEnabled(enabled); |
360 |
} |
361 |
} |