root / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / gui / Panels / SelectPointsPanel.java @ 2962
History | View | Annotate | Download (14.1 KB)
1 |
package com.iver.cit.gvsig.gui.Panels; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
import java.awt.FlowLayout; |
5 |
import java.awt.GridBagConstraints; |
6 |
import java.awt.GridBagLayout; |
7 |
import java.awt.geom.Point2D; |
8 |
|
9 |
import javax.swing.JButton; |
10 |
import javax.swing.JComboBox; |
11 |
import javax.swing.JLabel; |
12 |
import javax.swing.JOptionPane; |
13 |
import javax.swing.JPanel; |
14 |
import javax.swing.JTextField; |
15 |
|
16 |
import com.iver.andami.PluginServices; |
17 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
18 |
import com.iver.cit.gvsig.fmap.layers.FLyrPoints; |
19 |
import com.iver.cit.gvsig.gui.View; |
20 |
|
21 |
public class SelectPointsPanel extends JPanel { |
22 |
|
23 |
private JPanel pGeneral = null; |
24 |
private JPanel pPointSelection = null; |
25 |
private JPanel pControlPoint = null; |
26 |
private JButton bPrev = null; |
27 |
private JComboBox cPoint = null; |
28 |
private JLabel lNumberOfPoints = null; |
29 |
private JLabel lPoint = null; |
30 |
private JButton bNext = null; |
31 |
private JButton bNew = null; |
32 |
private JPanel pInfoPoint = null; |
33 |
private JPanel pX = null; |
34 |
private JPanel pY = null; |
35 |
private JPanel pLatitud = null; |
36 |
private JPanel pLongitud = null; |
37 |
private JTextField tX = null; |
38 |
private JLabel lX = null; |
39 |
private JLabel lY = null; |
40 |
private JTextField tY = null; |
41 |
private JLabel lLatitud = null; |
42 |
private JLabel lLongitud = null; |
43 |
private JTextField tLatitud = null; |
44 |
private JTextField tLongitud = null; |
45 |
|
46 |
private JPanel pControls = null; |
47 |
private JPanel pSelectFromView = null; |
48 |
private JButton bSelectFromView = null; |
49 |
private FLyrPoints lyrPoints = null; |
50 |
|
51 |
/**
|
52 |
* This is the default constructor
|
53 |
*/
|
54 |
public SelectPointsPanel() {
|
55 |
super();
|
56 |
initialize(); |
57 |
} |
58 |
|
59 |
/**
|
60 |
* This method initializes this
|
61 |
*
|
62 |
* @return void
|
63 |
*/
|
64 |
private void initialize() { |
65 |
this.setPreferredSize(new java.awt.Dimension(400,240)); |
66 |
this.setSize(new java.awt.Dimension(400,240)); |
67 |
this.setLocation(new java.awt.Point(0,0)); |
68 |
this.add(getPGeneral(), null); |
69 |
} |
70 |
|
71 |
/**
|
72 |
* This method initializes pGeneral
|
73 |
*
|
74 |
* @return javax.swing.JPanel
|
75 |
*/
|
76 |
private JPanel getPGeneral() { |
77 |
if (pGeneral == null) { |
78 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
79 |
gridBagConstraints1.insets = new java.awt.Insets(5,0,0,0); |
80 |
gridBagConstraints1.gridy = 1;
|
81 |
gridBagConstraints1.gridx = 0;
|
82 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
83 |
gridBagConstraints.insets = new java.awt.Insets(0,0,4,0); |
84 |
gridBagConstraints.gridy = 0;
|
85 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; |
86 |
gridBagConstraints.gridheight = 1;
|
87 |
gridBagConstraints.gridx = 0;
|
88 |
pGeneral = new JPanel(); |
89 |
pGeneral.setLayout(new GridBagLayout()); |
90 |
pGeneral.setPreferredSize(new java.awt.Dimension(400,240)); |
91 |
pGeneral.add(getPPointSelection(), gridBagConstraints); |
92 |
pGeneral.add(getPControlPoint(), gridBagConstraints1); |
93 |
} |
94 |
return pGeneral;
|
95 |
} |
96 |
|
97 |
/**
|
98 |
* This method initializes pFileSelection
|
99 |
*
|
100 |
* @return javax.swing.JPanel
|
101 |
*/
|
102 |
private JPanel getPPointSelection() { |
103 |
if (pPointSelection == null) { |
104 |
lPoint = new JLabel(); |
105 |
lPoint.setText(PluginServices.getText(this, "punto")); |
106 |
lPoint.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
107 |
lPoint.setPreferredSize(new java.awt.Dimension(46,15)); |
108 |
lNumberOfPoints = new JLabel(); |
109 |
lNumberOfPoints.setText(PluginServices.getText(this, "de") + " 1"); |
110 |
lNumberOfPoints.setPreferredSize(new java.awt.Dimension(37,15)); |
111 |
FlowLayout flowLayout = new FlowLayout(); |
112 |
flowLayout.setVgap(8);
|
113 |
flowLayout.setAlignment(java.awt.FlowLayout.LEFT); |
114 |
pPointSelection = new JPanel(); |
115 |
pPointSelection.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", java.awt.Font.BOLD, 12), java.awt.Color.black)); |
116 |
pPointSelection.setLayout(flowLayout); |
117 |
pPointSelection.setPreferredSize(new java.awt.Dimension(380,50)); |
118 |
pPointSelection.add(getBPrev(), null);
|
119 |
pPointSelection.add(lPoint, null);
|
120 |
pPointSelection.add(getCPoint(), null);
|
121 |
pPointSelection.add(lNumberOfPoints, null);
|
122 |
pPointSelection.add(getBNext(), null);
|
123 |
pPointSelection.add(getBNew(), null);
|
124 |
} |
125 |
return pPointSelection;
|
126 |
} |
127 |
|
128 |
/**
|
129 |
* This method initializes pControls
|
130 |
*
|
131 |
*/
|
132 |
private JPanel getPControlPoint() { |
133 |
if (pControlPoint == null) { |
134 |
GridBagConstraints gridBagConstraints11 = new GridBagConstraints(); |
135 |
GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
136 |
gridBagConstraints2.gridx = 1;
|
137 |
gridBagConstraints2.insets = new java.awt.Insets(0,0,0,0); |
138 |
gridBagConstraints2.gridy = 0;
|
139 |
pControlPoint = new JPanel(); |
140 |
pControlPoint.setLayout(new GridBagLayout()); |
141 |
pControlPoint.setPreferredSize(new java.awt.Dimension(380,160)); |
142 |
pControlPoint.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,0,0,0)); |
143 |
gridBagConstraints11.gridy = 0;
|
144 |
gridBagConstraints11.gridx = 0;
|
145 |
pControlPoint.add(getPInfoPoint(), gridBagConstraints2); |
146 |
pControlPoint.add(getPControls(), gridBagConstraints11); |
147 |
} |
148 |
return pControlPoint;
|
149 |
} |
150 |
|
151 |
/**
|
152 |
* This method initializes bBefore
|
153 |
*
|
154 |
* @return javax.swing.JButton
|
155 |
*/
|
156 |
private JButton getBPrev() { |
157 |
if (bPrev == null) { |
158 |
bPrev = new JButton(); |
159 |
bPrev.setText("<<");
|
160 |
bPrev.addActionListener(new java.awt.event.ActionListener() {
|
161 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
162 |
|
163 |
} |
164 |
}); |
165 |
} |
166 |
return bPrev;
|
167 |
} |
168 |
|
169 |
/**
|
170 |
* Este m?todo inicializa el combo que contiene el n?mero de puntos.
|
171 |
*
|
172 |
* @return javax.swing.JComboBox
|
173 |
*/
|
174 |
public JComboBox getCPoint() { |
175 |
if (cPoint == null) { |
176 |
cPoint = new JComboBox(); |
177 |
} |
178 |
return cPoint;
|
179 |
} |
180 |
|
181 |
/**
|
182 |
* This method initializes bNext
|
183 |
*
|
184 |
* @return javax.swing.JButton
|
185 |
*/
|
186 |
private JButton getBNext() { |
187 |
if (bNext == null) { |
188 |
bNext = new JButton(); |
189 |
bNext.setText(">>");
|
190 |
bNext.addActionListener(new java.awt.event.ActionListener() {
|
191 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
192 |
|
193 |
} |
194 |
}); |
195 |
} |
196 |
return bNext;
|
197 |
} |
198 |
|
199 |
/**
|
200 |
* Obtiene una capa de puntos. Si no existe crea una.
|
201 |
* @return
|
202 |
*/
|
203 |
private FLyrPoints getLyrPoint(){
|
204 |
//Buscamos una capa FlyrPoint en la vista y si no la hay la creamos
|
205 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
206 |
|
207 |
//Si todavia no hay ninguna cargada la buscamos
|
208 |
if(lyrPoints == null){ |
209 |
for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){ |
210 |
FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i); |
211 |
if(lyr instanceof FLyrPoints) |
212 |
lyrPoints = (FLyrPoints)lyr; |
213 |
} |
214 |
} |
215 |
|
216 |
//Si no hemos encontrado ninguna la creamos
|
217 |
if(lyrPoints == null){ |
218 |
lyrPoints = new FLyrPoints();
|
219 |
lyrPoints.setName("layerPoints");
|
220 |
lyrPoints.setVisible(true);
|
221 |
theView.getMapControl().getMapContext().getLayers().addLayer(lyrPoints); |
222 |
} |
223 |
return lyrPoints;
|
224 |
} |
225 |
|
226 |
/**
|
227 |
* Este m?todo inicializa el bot?n que crea un nuevo punto de georreferenciaci?n.
|
228 |
*
|
229 |
* @return javax.swing.JButton
|
230 |
*/
|
231 |
private JButton getBNew() { |
232 |
if (bNew == null) { |
233 |
bNew = new JButton(); |
234 |
bNew.setText(PluginServices.getText(this, "nuevo")); |
235 |
bNew.addActionListener(new java.awt.event.ActionListener() {
|
236 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
237 |
getLyrPoint(); |
238 |
//Si hay alg?n punto en la lista se guarda en la capa
|
239 |
if(getCPoint().getSelectedIndex() != -1){ |
240 |
Point2D pixel = null, map = null; |
241 |
if( getTX().getText().equals("") || |
242 |
getTY().getText().equals("") ||
|
243 |
getLatitud().getText().equals("") ||
|
244 |
getLongitud().getText().equals("")){
|
245 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
246 |
PluginServices.getText(this, "coordenadas_vacias")); |
247 |
return;
|
248 |
} |
249 |
/*pixel = new Point2D.Double( Double.valueOf(getTX().getText()),
|
250 |
Double.valueOf(getTY().getText()));
|
251 |
map = new Point2D.Double( Double.valueOf(getLatitud().getText()),
|
252 |
Double.valueOf(getLongitud().getText()));*/
|
253 |
//lyrPoints.updatePoint()
|
254 |
} |
255 |
getLyrPoint(); |
256 |
getTX().setText("");
|
257 |
getTY().setText("");
|
258 |
getLatitud().setText("");
|
259 |
getLongitud().setText("");
|
260 |
getCPoint().addItem("" + (lyrPoints.getCountPoints() + 1)); |
261 |
} |
262 |
}); |
263 |
} |
264 |
return bNew;
|
265 |
} |
266 |
|
267 |
/**
|
268 |
* Este m?todo inicializa el bot?n seleccionar desde la vista.
|
269 |
*
|
270 |
* @return javax.swing.JButton
|
271 |
*/
|
272 |
private JButton getBSelectFromView() { |
273 |
if (bSelectFromView == null) { |
274 |
bSelectFromView = new JButton(); |
275 |
bSelectFromView.setText(PluginServices.getText(this, "seleccionar")); |
276 |
bSelectFromView.addActionListener(new java.awt.event.ActionListener() {
|
277 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
278 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
279 |
getLyrPoint(); |
280 |
lyrPoints.setLastTool(theView.getMapControl().getTool()); |
281 |
theView.getMapControl().setTool("pointLyrSelection");
|
282 |
} |
283 |
}); |
284 |
} |
285 |
return bSelectFromView;
|
286 |
} |
287 |
|
288 |
/**
|
289 |
* This method initializes pPoint
|
290 |
*
|
291 |
* @return javax.swing.JPanel
|
292 |
*/
|
293 |
private JPanel getPInfoPoint() { |
294 |
if (pInfoPoint == null) { |
295 |
GridBagConstraints gridBagConstraints6 = new GridBagConstraints(); |
296 |
gridBagConstraints6.insets = new java.awt.Insets(0,0,0,0); |
297 |
gridBagConstraints6.gridy = 3;
|
298 |
gridBagConstraints6.gridx = 0;
|
299 |
GridBagConstraints gridBagConstraints5 = new GridBagConstraints(); |
300 |
gridBagConstraints5.insets = new java.awt.Insets(0,0,0,0); |
301 |
gridBagConstraints5.gridy = 2;
|
302 |
gridBagConstraints5.weighty = 0.0D;
|
303 |
gridBagConstraints5.gridx = 0;
|
304 |
GridBagConstraints gridBagConstraints4 = new GridBagConstraints(); |
305 |
gridBagConstraints4.insets = new java.awt.Insets(0,0,0,0); |
306 |
gridBagConstraints4.gridy = 1;
|
307 |
gridBagConstraints4.weighty = 0.0D;
|
308 |
gridBagConstraints4.gridx = 0;
|
309 |
GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); |
310 |
gridBagConstraints3.insets = new java.awt.Insets(0,0,0,0); |
311 |
gridBagConstraints3.gridy = 0;
|
312 |
gridBagConstraints3.ipadx = 0;
|
313 |
gridBagConstraints3.gridx = 0;
|
314 |
pInfoPoint = new JPanel(); |
315 |
pInfoPoint.setLayout(new GridBagLayout()); |
316 |
pInfoPoint.setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this, "punto"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
317 |
pInfoPoint.setPreferredSize(new java.awt.Dimension(200,160)); |
318 |
pInfoPoint.add(getPX(), gridBagConstraints3); |
319 |
pInfoPoint.add(getPY(), gridBagConstraints4); |
320 |
pInfoPoint.add(getPLatitud(), gridBagConstraints5); |
321 |
pInfoPoint.add(getPLongitud(), gridBagConstraints6); |
322 |
} |
323 |
return pInfoPoint;
|
324 |
} |
325 |
|
326 |
/**
|
327 |
* This method initializes pX
|
328 |
*
|
329 |
* @return javax.swing.JPanel
|
330 |
*/
|
331 |
private JPanel getPX() { |
332 |
if (pX == null) { |
333 |
lX = new JLabel(); |
334 |
lX.setText("X: ");
|
335 |
FlowLayout flowLayout2 = new FlowLayout(); |
336 |
flowLayout2.setAlignment(java.awt.FlowLayout.RIGHT); |
337 |
pX = new JPanel(); |
338 |
pX.setLayout(flowLayout2); |
339 |
pX.setPreferredSize(new java.awt.Dimension(185,29)); |
340 |
pX.add(lX, null);
|
341 |
pX.add(getTX(), null);
|
342 |
} |
343 |
return pX;
|
344 |
} |
345 |
|
346 |
/**
|
347 |
* This method initializes pY
|
348 |
*
|
349 |
* @return javax.swing.JPanel
|
350 |
*/
|
351 |
private JPanel getPY() { |
352 |
if (pY == null) { |
353 |
lY = new JLabel(); |
354 |
lY.setText("Y:");
|
355 |
FlowLayout flowLayout1 = new FlowLayout(); |
356 |
flowLayout1.setAlignment(java.awt.FlowLayout.RIGHT); |
357 |
pY = new JPanel(); |
358 |
pY.setLayout(flowLayout1); |
359 |
pY.setPreferredSize(new java.awt.Dimension(185,29)); |
360 |
pY.add(lY, null);
|
361 |
pY.add(getTY(), null);
|
362 |
} |
363 |
return pY;
|
364 |
} |
365 |
|
366 |
/**
|
367 |
* This method initializes pLatitud
|
368 |
*
|
369 |
* @return javax.swing.JPanel
|
370 |
*/
|
371 |
private JPanel getPLatitud() { |
372 |
if (pLatitud == null) { |
373 |
lLatitud = new JLabel(); |
374 |
lLatitud.setText(PluginServices.getText(this,"latitud")+":"); |
375 |
FlowLayout flowLayout3 = new FlowLayout(); |
376 |
flowLayout3.setAlignment(java.awt.FlowLayout.RIGHT); |
377 |
pLatitud = new JPanel(); |
378 |
pLatitud.setLayout(flowLayout3); |
379 |
pLatitud.setPreferredSize(new java.awt.Dimension(185,29)); |
380 |
pLatitud.add(lLatitud, null);
|
381 |
pLatitud.add(getLatitud(), null);
|
382 |
} |
383 |
return pLatitud;
|
384 |
} |
385 |
|
386 |
/**
|
387 |
* This method initializes pLongitud
|
388 |
*
|
389 |
* @return javax.swing.JPanel
|
390 |
*/
|
391 |
private JPanel getPLongitud() { |
392 |
if (pLongitud == null) { |
393 |
lLongitud = new JLabel(); |
394 |
lLongitud.setText(PluginServices.getText(this, "longitud")+":"); |
395 |
FlowLayout flowLayout4 = new FlowLayout(); |
396 |
flowLayout4.setAlignment(java.awt.FlowLayout.RIGHT); |
397 |
pLongitud = new JPanel(); |
398 |
pLongitud.setLayout(flowLayout4); |
399 |
pLongitud.setPreferredSize(new java.awt.Dimension(185,29)); |
400 |
pLongitud.add(lLongitud, null);
|
401 |
pLongitud.add(getLongitud(), null);
|
402 |
} |
403 |
return pLongitud;
|
404 |
} |
405 |
|
406 |
/**
|
407 |
* This method initializes tX
|
408 |
*
|
409 |
* @return javax.swing.JTextField
|
410 |
*/
|
411 |
private JTextField getTX() { |
412 |
if (tX == null) { |
413 |
tX = new JTextField(); |
414 |
tX.setPreferredSize(new java.awt.Dimension(90,19)); |
415 |
} |
416 |
return tX;
|
417 |
} |
418 |
|
419 |
/**
|
420 |
* This method initializes jTextField
|
421 |
*
|
422 |
* @return javax.swing.JTextField
|
423 |
*/
|
424 |
private JTextField getTY() { |
425 |
if (tY == null) { |
426 |
tY = new JTextField(); |
427 |
tY.setPreferredSize(new java.awt.Dimension(90,19)); |
428 |
} |
429 |
return tY;
|
430 |
} |
431 |
|
432 |
/**
|
433 |
* This method initializes jTextField1
|
434 |
*
|
435 |
* @return javax.swing.JTextField
|
436 |
*/
|
437 |
private JTextField getLatitud() { |
438 |
if (tLatitud == null) { |
439 |
tLatitud = new JTextField(); |
440 |
tLatitud.setPreferredSize(new java.awt.Dimension(111,19)); |
441 |
} |
442 |
return tLatitud;
|
443 |
} |
444 |
|
445 |
/**
|
446 |
* This method initializes jTextField2
|
447 |
*
|
448 |
* @return javax.swing.JTextField
|
449 |
*/
|
450 |
private JTextField getLongitud() { |
451 |
if (tLongitud == null) { |
452 |
tLongitud = new JTextField(); |
453 |
tLongitud.setPreferredSize(new java.awt.Dimension(111,19)); |
454 |
} |
455 |
return tLongitud;
|
456 |
} |
457 |
|
458 |
/**
|
459 |
* This method initializes jPanel
|
460 |
*
|
461 |
* @return javax.swing.JPanel
|
462 |
*/
|
463 |
private JPanel getPControls() { |
464 |
if (pControls == null) { |
465 |
pControls = new JPanel(); |
466 |
pControls.setPreferredSize(new java.awt.Dimension(180,160)); |
467 |
pControls.add(getPSelectFromView(), null);
|
468 |
} |
469 |
return pControls;
|
470 |
} |
471 |
/**
|
472 |
* This method initializes jPanel
|
473 |
*
|
474 |
* @return javax.swing.JPanel
|
475 |
*/
|
476 |
private JPanel getPSelectFromView() { |
477 |
if (pSelectFromView == null) { |
478 |
pSelectFromView = new JPanel(); |
479 |
pSelectFromView.setPreferredSize(new java.awt.Dimension(150,35)); |
480 |
pSelectFromView.add(getBSelectFromView(), null);
|
481 |
} |
482 |
return pSelectFromView;
|
483 |
} |
484 |
|
485 |
} |