root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / cutting / ui / CuttingPanel.java @ 13569
History | View | Annotate | Download (26.4 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.rastertools.cutting.ui; |
20 |
|
21 |
import java.awt.BorderLayout; |
22 |
import java.awt.Dimension; |
23 |
import java.awt.GridBagConstraints; |
24 |
import java.awt.GridBagLayout; |
25 |
import java.awt.Insets; |
26 |
import java.awt.event.ActionEvent; |
27 |
import java.awt.event.ActionListener; |
28 |
import java.awt.event.ItemEvent; |
29 |
import java.awt.event.ItemListener; |
30 |
import java.io.File; |
31 |
import java.util.ArrayList; |
32 |
|
33 |
import javax.swing.JButton; |
34 |
import javax.swing.JCheckBox; |
35 |
import javax.swing.JFileChooser; |
36 |
import javax.swing.JLabel; |
37 |
import javax.swing.JPanel; |
38 |
import javax.swing.JTabbedPane; |
39 |
import javax.swing.JTextField; |
40 |
|
41 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
42 |
import org.gvsig.gui.beans.buttonbar.ButtonBarContainer; |
43 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
44 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent; |
45 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener; |
46 |
import org.gvsig.gui.beans.coordinatespanel.CoordinatesPanel; |
47 |
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel; |
48 |
import org.gvsig.gui.beans.table.TableContainer; |
49 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
50 |
import org.gvsig.raster.dataset.IRasterDataSource; |
51 |
import org.gvsig.raster.hierarchy.IRasterGeoOperations; |
52 |
import org.gvsig.raster.hierarchy.IRasterOperations; |
53 |
import org.gvsig.rastertools.RasterModule; |
54 |
import org.gvsig.rastertools.RasterToolsUtil; |
55 |
import org.gvsig.rastertools.cutting.ui.listener.CuttingMouseViewListener; |
56 |
import org.gvsig.rastertools.cutting.ui.listener.CuttingPanelListener; |
57 |
|
58 |
import com.iver.andami.PluginServices; |
59 |
import com.iver.andami.messages.NotificationManager; |
60 |
import com.iver.andami.ui.mdiManager.IWindow; |
61 |
import com.iver.cit.gvsig.fmap.MapControl; |
62 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
63 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
64 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior; |
65 |
import com.iver.cit.gvsig.fmap.tools.Behavior.RectangleBehavior; |
66 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
67 |
import com.iver.cit.gvsig.project.documents.view.toolListeners.StatusBarListener; |
68 |
/**
|
69 |
* <code>CuttingPanel</code>. Interfaz de usuario para el recorte de rasters.
|
70 |
*
|
71 |
* @version 17/04/2007
|
72 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
73 |
*/
|
74 |
public class CuttingPanel extends DefaultButtonsPanel implements ButtonsPanelListener, ItemListener, ActionListener { |
75 |
private static final long serialVersionUID = 3078196473228467834L; |
76 |
|
77 |
private int wPanel = 400; |
78 |
|
79 |
private CuttingDialog cuttingDialog = null; |
80 |
|
81 |
private CoordinatesPanel coordinatesPixel = null; |
82 |
private CoordinatesPanel coordinatesReales = null; |
83 |
private ButtonBarContainer buttonBarContainer = null; |
84 |
private JPanel pSelection = null; |
85 |
private JPanel jOptions = null; |
86 |
private JPanel jPNameFile = null; |
87 |
private TableContainer tSelection = null; |
88 |
private ResolutionPanel pResolution = null; |
89 |
private JCheckBox jCheckBox = null; |
90 |
private JCheckBox jCheckLoadLayerInToc = null; |
91 |
private JCheckBox jCheckSaveFile = null; |
92 |
private JTextField filenameTextField = null; |
93 |
private JTabbedPane jTabbedPane1 = null; |
94 |
private JPanel jPNameDirectory = null; |
95 |
private JTextField directoryTextField = null; |
96 |
private JButton jBChooseDirectory = null; |
97 |
private JLabel jLabelDirectory = null; |
98 |
|
99 |
private FLayer fLayer = null; |
100 |
|
101 |
/**
|
102 |
* Valores reales para el ancho, alto y tama?o de celda. Esto es necesario
|
103 |
* porque en la caja de texto se guardan con decimales recortados y cuando se
|
104 |
* pide el valor se devuelven completos.
|
105 |
*/
|
106 |
private double realWidth, realHeight; |
107 |
|
108 |
/**
|
109 |
* Relaci?n entre el ancho y alto en pixeles de la imagen
|
110 |
*/
|
111 |
private double relWidthHeight = 0; |
112 |
|
113 |
/**
|
114 |
* Valores reales para el tama?o de la ventana. Esto es necesario porque en la
|
115 |
* caja de texto se guardan con decimales recortados y cuando se pide el valor
|
116 |
* se devuelven completos.
|
117 |
*/
|
118 |
private double wcUlx, wcUly, wcLrx, wcLry; |
119 |
private double pxMinX, pxMinY, pxMaxX, pxMaxY; |
120 |
|
121 |
private CuttingPanelListener cuttingPanelListener = null; |
122 |
|
123 |
/**
|
124 |
* Herramienta seleccionada en el momento de la apertura del dialogo
|
125 |
*/
|
126 |
private String lastTool = null; |
127 |
private MapControl mapControl = null; |
128 |
private String viewName = null; |
129 |
|
130 |
/**
|
131 |
* Crea un nuevo <code>CuttingPanel</code>
|
132 |
* @param cuttingDialog
|
133 |
*/
|
134 |
public CuttingPanel(CuttingDialog cuttingDialog) {
|
135 |
super(ButtonsPanel.BUTTONS_ACCEPTCANCELAPPLY);
|
136 |
|
137 |
this.cuttingDialog = cuttingDialog;
|
138 |
initialize(); |
139 |
cuttingPanelListener = new CuttingPanelListener(this); |
140 |
|
141 |
getCoordinatesPixel().addValueChangedListener(cuttingPanelListener); |
142 |
getCoordinatesReales().addValueChangedListener(cuttingPanelListener); |
143 |
|
144 |
getPResolution().getCCellSize().addValueChangedListener(cuttingPanelListener); |
145 |
getPResolution().getCWidth().addValueChangedListener(cuttingPanelListener); |
146 |
getPResolution().getCHeight().addValueChangedListener(cuttingPanelListener); |
147 |
|
148 |
getButtonBarContainer().getButton(0).addActionListener(cuttingPanelListener);
|
149 |
getButtonBarContainer().getButton(1).addActionListener(cuttingPanelListener);
|
150 |
|
151 |
this.addButtonPressedListener(cuttingPanelListener);
|
152 |
} |
153 |
|
154 |
/**
|
155 |
* Obtener el <code>CuttingDialog</code> asociado a este objeto.
|
156 |
* @return CuttingDialog
|
157 |
*/
|
158 |
public CuttingDialog getCuttingDialog() {
|
159 |
return cuttingDialog;
|
160 |
} |
161 |
|
162 |
/**
|
163 |
* Especificar el nombre de la nueva capa para el recuadro de texto asign?ndo
|
164 |
* en cada llamada un nombre consecutivo.
|
165 |
*/
|
166 |
public void setNewLayerText() { |
167 |
filenameTextField.setText("NewLayer_" + RasterModule.layerCount);
|
168 |
RasterModule.layerCount++; |
169 |
} |
170 |
|
171 |
/**
|
172 |
* Obtener la capa de un raster.
|
173 |
* @return
|
174 |
*/
|
175 |
public FLayer getFLayer() {
|
176 |
return fLayer;
|
177 |
} |
178 |
|
179 |
/**
|
180 |
* Establecer la capa para usarla en el recorte
|
181 |
* @param fLayer
|
182 |
*/
|
183 |
public void setLayer(FLayer fLayer) { |
184 |
this.fLayer = fLayer;
|
185 |
View view = (View) PluginServices.getMDIManager().getActiveWindow(); |
186 |
viewName = PluginServices.getMDIManager().getWindowInfo(view).getTitle(); |
187 |
mapControl = view.getMapControl(); |
188 |
|
189 |
lastTool = mapControl.getCurrentTool(); |
190 |
|
191 |
// Listener de eventos de movimiento que pone las coordenadas del rat?n en
|
192 |
// la barra de estado
|
193 |
StatusBarListener sbl = new StatusBarListener(mapControl);
|
194 |
|
195 |
// Cortar Raster
|
196 |
CuttingMouseViewListener cuttingMouseListener = new CuttingMouseViewListener(mapControl, this); |
197 |
mapControl.addMapTool("cutRaster", new Behavior[] { |
198 |
new RectangleBehavior(cuttingMouseListener), new MouseMovementBehavior(sbl) |
199 |
} |
200 |
); |
201 |
|
202 |
// Rellenar el arbol de bandas
|
203 |
IRasterDataSource mDataset = ((FLyrRasterSE) fLayer).getDataSource(); |
204 |
for (int i = 0; i < mDataset.getDatasetCount(); i++) { |
205 |
String fName = mDataset.getDataset(i)[0].getFName(); |
206 |
String bandName = new File(fName).getName(); |
207 |
|
208 |
if (mDataset.getDataset(i)[0].getBandCount() > 1) { |
209 |
for (int b = 0; b < mDataset.getDataset(i)[0].getBandCount(); b++) { |
210 |
Object row[] = { new Boolean(true), |
211 |
new String("B" + (b + 1) + " - " + bandName) }; |
212 |
try {
|
213 |
getTSelection().addRow(row); |
214 |
} catch (NotInitializeException e) {
|
215 |
NotificationManager.addError("Error a?adiendo fila a la tabla.", e);
|
216 |
} |
217 |
} |
218 |
} else {
|
219 |
Object row[] = { new Boolean(true), new String("B - " + bandName) }; |
220 |
try {
|
221 |
getTSelection().addRow(row); |
222 |
} catch (NotInitializeException e) {
|
223 |
NotificationManager.addError("Error a?adiendo fila a la tabla.", e);
|
224 |
} |
225 |
} |
226 |
} |
227 |
|
228 |
// Obtener la extension completa de la capa
|
229 |
|
230 |
if(fLayer instanceof IRasterGeoOperations && fLayer instanceof IRasterOperations) { |
231 |
cuttingPanelListener.setAffineTransform(((IRasterGeoOperations)fLayer).getAffineTransform()); |
232 |
cuttingPanelListener.setDimension(new Dimension((int)((IRasterOperations)fLayer).getPxWidth(), (int)((IRasterOperations)fLayer).getPxHeight())); |
233 |
} else {
|
234 |
RasterToolsUtil.messageBoxError("Error obteniendo el extent.", this); |
235 |
return;
|
236 |
} |
237 |
|
238 |
// Definir el ancho y el alto de la vista en pixeles.
|
239 |
ArrayList attr = ((FLyrRasterSE) fLayer).getAttributes();
|
240 |
for (int i = 0; i < attr.size(); i++) { |
241 |
Object[] a = (Object[]) attr.get(i); |
242 |
if (a[0].toString().equals("Width")) |
243 |
cuttingPanelListener.setWidthPx(((Integer) a[1]).intValue()); |
244 |
if (a[0].toString().equals("Height")) |
245 |
cuttingPanelListener.setHeightPx(((Integer) a[1]).intValue()); |
246 |
} |
247 |
} |
248 |
|
249 |
/**
|
250 |
* Acciones que se realizan para seleccionar la tool CutRaster
|
251 |
*/
|
252 |
public void selectToolButton() { |
253 |
// seleccionamos la vista de gvSIG
|
254 |
com.iver.cit.gvsig.project.documents.view.gui.View theView = null;
|
255 |
try {
|
256 |
IWindow[] allViews = PluginServices.getMDIManager().getAllWindows();
|
257 |
for (int i = 0; i < allViews.length; i++) { |
258 |
if (allViews[i] instanceof com.iver.cit.gvsig.project.documents.view.gui.View |
259 |
&& PluginServices.getMDIManager().getWindowInfo((View) allViews[i])
|
260 |
.getTitle().equals(viewName)) |
261 |
theView = (com.iver.cit.gvsig.project.documents.view.gui.View) allViews[i]; |
262 |
} |
263 |
if (theView == null) |
264 |
return;
|
265 |
} catch (ClassCastException ex) { |
266 |
// logger.error(PluginServices.getText(this, "cant_get_view "), ex);
|
267 |
return;
|
268 |
} |
269 |
MapControl m_MapControl = theView.getMapControl(); |
270 |
|
271 |
// Listener de eventos de movimiento que pone las coordenadas del rat?n en
|
272 |
// la barra de estado
|
273 |
StatusBarListener sbl = new StatusBarListener(m_MapControl);
|
274 |
|
275 |
// Cortar Raster
|
276 |
CuttingMouseViewListener cuttingMouseListener = new CuttingMouseViewListener(m_MapControl, this); |
277 |
m_MapControl.addMapTool("cutRaster", new Behavior[] { |
278 |
new RectangleBehavior(cuttingMouseListener), new MouseMovementBehavior(sbl) |
279 |
} |
280 |
); |
281 |
|
282 |
m_MapControl.setTool("cutRaster");
|
283 |
} |
284 |
|
285 |
/**
|
286 |
* This method initializes this
|
287 |
*/
|
288 |
private void initialize() { |
289 |
jTabbedPane1 = new JTabbedPane(); |
290 |
|
291 |
JPanel jpanel1 = new JPanel(); |
292 |
jpanel1.setLayout(new GridBagLayout()); |
293 |
|
294 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
295 |
gridBagConstraints.gridx = 0;
|
296 |
gridBagConstraints.gridy = 0;
|
297 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
298 |
gridBagConstraints.weightx = 1.0;
|
299 |
gridBagConstraints.insets = new java.awt.Insets(5, 5, 2, 5); |
300 |
jpanel1.add(getCoordinatesPixel(), gridBagConstraints); |
301 |
|
302 |
gridBagConstraints = new GridBagConstraints(); |
303 |
gridBagConstraints.gridx = 0;
|
304 |
gridBagConstraints.gridy = 1;
|
305 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
306 |
gridBagConstraints.weightx = 1.0;
|
307 |
gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 5); |
308 |
jpanel1.add(getCoordinatesReales(), gridBagConstraints); |
309 |
|
310 |
gridBagConstraints = new GridBagConstraints(); |
311 |
gridBagConstraints.gridx = 0;
|
312 |
gridBagConstraints.gridy = 2;
|
313 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; |
314 |
gridBagConstraints.insets = new java.awt.Insets(2, 5, 5, 5); |
315 |
jpanel1.add(getButtonBarContainer(), gridBagConstraints); |
316 |
|
317 |
jTabbedPane1.addTab(PluginServices.getText(this, "coordenadas_recorte"), jpanel1); |
318 |
jTabbedPane1.addTab(PluginServices.getText(this, "resolucion_espacial"), getPResolution()); |
319 |
jTabbedPane1.addTab(PluginServices.getText(this, "seleccion_bandas"), getPSelection()); |
320 |
jTabbedPane1.addTab(PluginServices.getText(this, "otras_opciones"), getJOptions()); |
321 |
|
322 |
setLayout(new BorderLayout()); |
323 |
add(jTabbedPane1, BorderLayout.CENTER);
|
324 |
|
325 |
setNewLayerText(); |
326 |
} |
327 |
|
328 |
/*
|
329 |
* (non-Javadoc)
|
330 |
* @see org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener#actionButtonPressed(org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent)
|
331 |
*/
|
332 |
public void actionButtonPressed(ButtonsPanelEvent e) { |
333 |
} |
334 |
|
335 |
/**
|
336 |
* This method initializes jPanel
|
337 |
*
|
338 |
* @return javax.swing.JPanel
|
339 |
*/
|
340 |
public CoordinatesPanel getCoordinatesPixel() {
|
341 |
if (coordinatesPixel == null) { |
342 |
coordinatesPixel = new CoordinatesPanel();
|
343 |
coordinatesPixel.setParameters( PluginServices.getText(this, "coordenadas_pixel"), |
344 |
PluginServices.getText(this, "sup_izq"), |
345 |
"X" ,"Y", |
346 |
PluginServices.getText(this, "inf_der"), |
347 |
"X", "Y"); |
348 |
} |
349 |
return coordinatesPixel;
|
350 |
} |
351 |
|
352 |
/**
|
353 |
* This method initializes jPanel1
|
354 |
*
|
355 |
* @return javax.swing.JPanel
|
356 |
*/
|
357 |
public CoordinatesPanel getCoordinatesReales() {
|
358 |
if (coordinatesReales == null) { |
359 |
coordinatesReales = new CoordinatesPanel();
|
360 |
coordinatesReales.setParameters( PluginServices.getText(this, "coordenadas_reales"), |
361 |
PluginServices.getText(this, "sup_izq"), |
362 |
"X" ,"Y", |
363 |
PluginServices.getText(this, "inf_der"), |
364 |
"X", "Y"); |
365 |
} |
366 |
return coordinatesReales;
|
367 |
} |
368 |
|
369 |
/**
|
370 |
* This method initializes jButton
|
371 |
*
|
372 |
* @return javax.swing.JButton
|
373 |
*/
|
374 |
public ButtonBarContainer getButtonBarContainer() {
|
375 |
if (buttonBarContainer == null) { |
376 |
buttonBarContainer = new ButtonBarContainer();
|
377 |
buttonBarContainer.setPreferredSize(new java.awt.Dimension(wPanel - 4, 32)); |
378 |
buttonBarContainer.addButton("fullExtent.png", PluginServices.getText(this, "fullExtent"), 0); |
379 |
buttonBarContainer.addButton("selectTool.png", PluginServices.getText(this, "select_tool"), 1); |
380 |
buttonBarContainer.setButtonAlignment("right");
|
381 |
buttonBarContainer.setComponentBorder(false);
|
382 |
} |
383 |
return buttonBarContainer;
|
384 |
} |
385 |
|
386 |
/**
|
387 |
* This method initializes jPanel
|
388 |
*
|
389 |
* @return javax.swing.JPanel
|
390 |
*/
|
391 |
public ResolutionPanel getPResolution() {
|
392 |
if (pResolution == null) { |
393 |
pResolution = new ResolutionPanel();
|
394 |
pResolution.setPreferredSize(new java.awt.Dimension(wPanel, 120)); |
395 |
pResolution.validate(); |
396 |
} |
397 |
return pResolution;
|
398 |
} |
399 |
|
400 |
/**
|
401 |
* This method initializes jPanel1
|
402 |
*
|
403 |
* @return javax.swing.JPanel
|
404 |
*/
|
405 |
private JPanel getPSelection() { |
406 |
if (pSelection == null) { |
407 |
pSelection = new JPanel(); |
408 |
pSelection.setLayout(new BorderLayout()); |
409 |
pSelection.setPreferredSize(new java.awt.Dimension(wPanel, 120)); |
410 |
pSelection.add(getTSelection(), BorderLayout.CENTER);
|
411 |
|
412 |
} |
413 |
return pSelection;
|
414 |
} |
415 |
|
416 |
/**
|
417 |
* Obtiene la tabla de selecci?n de bandas
|
418 |
* @return Tabla de selecci?n de bandas
|
419 |
*/
|
420 |
public TableContainer getTSelection() {
|
421 |
if (tSelection == null) { |
422 |
String[] columnNames = {PluginServices.getText(this, "bandas"), PluginServices.getText(this, "nombre")}; |
423 |
int[] columnWidths = {75, 305}; |
424 |
tSelection = new TableContainer(columnNames, columnWidths);
|
425 |
tSelection.setModel("CheckBoxModel");
|
426 |
tSelection.setControlVisible(false);
|
427 |
tSelection.initialize(); |
428 |
} |
429 |
|
430 |
return tSelection;
|
431 |
} |
432 |
|
433 |
/**
|
434 |
* This method initializes jOptions
|
435 |
*
|
436 |
* @return javax.swing.JPanel
|
437 |
*/
|
438 |
private JPanel getJOptions() { |
439 |
if (jOptions == null) { |
440 |
jOptions = new JPanel(); |
441 |
jOptions.setLayout(new GridBagLayout()); |
442 |
jOptions.add(getJPNameFile(), new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, |
443 |
GridBagConstraints.CENTER, GridBagConstraints.BOTH, |
444 |
new Insets(0, 0, 5, 5), 0, 0)); |
445 |
jOptions.add(getCbOneLyrPerBand(), new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, |
446 |
GridBagConstraints.CENTER, GridBagConstraints.BOTH, |
447 |
new Insets(0, 0, 5, 5), 0, 0)); |
448 |
jOptions.add(getCbLoadLayerInToc(), new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, |
449 |
GridBagConstraints.CENTER, GridBagConstraints.BOTH, |
450 |
new Insets(0, 0, 5, 5), 0, 0)); |
451 |
jOptions.add(getCbSaveFile(), new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, |
452 |
GridBagConstraints.CENTER, GridBagConstraints.BOTH, |
453 |
new Insets(0, 0, 5, 5), 0, 0)); |
454 |
jOptions.add(getJPNameDirectory(), new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, |
455 |
GridBagConstraints.CENTER, GridBagConstraints.BOTH, |
456 |
new Insets(0, 0, 5, 5), 0, 0)); |
457 |
jOptions.setPreferredSize(new java.awt.Dimension(wPanel, 135)); |
458 |
} |
459 |
return jOptions;
|
460 |
} |
461 |
|
462 |
/**
|
463 |
* This method initializes jPNameFile
|
464 |
*
|
465 |
* @return javax.swing.JPanel
|
466 |
*/
|
467 |
private JPanel getJPNameFile() { |
468 |
if (jPNameFile == null) { |
469 |
jPNameFile = new JPanel(); |
470 |
jPNameFile.add(new JLabel(PluginServices.getText(this, "nombre_capas") + ":")); |
471 |
jPNameFile.add(getFilenameTextField()); |
472 |
} |
473 |
return jPNameFile;
|
474 |
} |
475 |
|
476 |
private JButton getJBChooseDirectory() { |
477 |
if (jBChooseDirectory == null) { |
478 |
jBChooseDirectory = new JButton(PluginServices.getText(this, "cambiar_ruta")); |
479 |
jBChooseDirectory.setEnabled(false);
|
480 |
} |
481 |
return jBChooseDirectory;
|
482 |
} |
483 |
/**
|
484 |
* This method initializes jPNameFile
|
485 |
*
|
486 |
* @return javax.swing.JPanel
|
487 |
*/
|
488 |
private JPanel getJPNameDirectory() { |
489 |
if (jPNameDirectory == null) { |
490 |
jPNameDirectory = new JPanel(); |
491 |
jPNameDirectory.add(getJLabelDirectory()); |
492 |
jPNameDirectory.add(getDirectoryTextField()); |
493 |
jPNameDirectory.add(getJBChooseDirectory()); |
494 |
getJBChooseDirectory().addActionListener(this);
|
495 |
} |
496 |
return jPNameDirectory;
|
497 |
} |
498 |
|
499 |
private JLabel getJLabelDirectory() { |
500 |
if (jLabelDirectory == null) { |
501 |
jLabelDirectory = new JLabel(PluginServices.getText(this, "ruta") + ":"); |
502 |
jLabelDirectory.setEnabled(false);
|
503 |
} |
504 |
return jLabelDirectory;
|
505 |
} |
506 |
|
507 |
/**
|
508 |
* This method initializes filenameTextField
|
509 |
*
|
510 |
* @return javax.swing.JTextField
|
511 |
*/
|
512 |
public JTextField getFilenameTextField() { |
513 |
if (filenameTextField == null) { |
514 |
filenameTextField = new JTextField(); |
515 |
filenameTextField.setPreferredSize(new Dimension(150, filenameTextField.getPreferredSize().height)); |
516 |
} |
517 |
return filenameTextField;
|
518 |
} |
519 |
|
520 |
/**
|
521 |
* This method initializes filenameTextField
|
522 |
*
|
523 |
* @return javax.swing.JTextField
|
524 |
*/
|
525 |
public JTextField getDirectoryTextField() { |
526 |
if (directoryTextField == null) { |
527 |
directoryTextField = new JTextField(); |
528 |
directoryTextField.setText(RasterModule.getPath()); |
529 |
directoryTextField.setEditable(false);
|
530 |
directoryTextField.setEnabled(false);
|
531 |
directoryTextField.setPreferredSize(new Dimension(200, directoryTextField.getPreferredSize().height)); |
532 |
} |
533 |
return directoryTextField;
|
534 |
} |
535 |
|
536 |
/**
|
537 |
* This method initializes jCheckSaveFile
|
538 |
*
|
539 |
* @return javax.swing.JCheckBox
|
540 |
*/
|
541 |
public JCheckBox getCbSaveFile() { |
542 |
if (jCheckSaveFile == null) { |
543 |
jCheckSaveFile = new JCheckBox(); |
544 |
jCheckSaveFile.setText(PluginServices.getText(this, "guardar_en_disco")); |
545 |
jCheckSaveFile.addItemListener(this);
|
546 |
} |
547 |
return jCheckSaveFile;
|
548 |
} |
549 |
|
550 |
/**
|
551 |
* This method initializes jCheckBox
|
552 |
*
|
553 |
* @return javax.swing.JCheckBox
|
554 |
*/
|
555 |
public JCheckBox getCbOneLyrPerBand() { |
556 |
if (jCheckBox == null) { |
557 |
jCheckBox = new JCheckBox(); |
558 |
jCheckBox.setText(PluginServices.getText(this, "crear_1_capa_por_banda")); |
559 |
} |
560 |
return jCheckBox;
|
561 |
} |
562 |
|
563 |
/**
|
564 |
* This method initializes jCheckLoadLayerInToc
|
565 |
*
|
566 |
* @return javax.swing.JCheckBox
|
567 |
*/
|
568 |
public JCheckBox getCbLoadLayerInToc() { |
569 |
if (jCheckLoadLayerInToc == null) { |
570 |
jCheckLoadLayerInToc = new JCheckBox(); |
571 |
jCheckLoadLayerInToc.setText(PluginServices.getText(this, "cargar_en_toc")); |
572 |
jCheckLoadLayerInToc.setSelected(true);
|
573 |
jCheckLoadLayerInToc.setEnabled(false);
|
574 |
jCheckLoadLayerInToc.addItemListener(this);
|
575 |
} |
576 |
return jCheckLoadLayerInToc;
|
577 |
} |
578 |
|
579 |
/**
|
580 |
* Asigna el valor del campo "Ancho" a partir del double que lo representa
|
581 |
* y con el n?mero de decimales que se especifica en el par?metro dec
|
582 |
* @param width Ancho
|
583 |
* @param dec N?mero de decimales
|
584 |
*/
|
585 |
public void setWidthText(double width, int dec) { |
586 |
realWidth = width; |
587 |
getPResolution().setWidthText(width, dec); |
588 |
} |
589 |
|
590 |
/**
|
591 |
* Obtiene la relaci?n entre el ancho y alto de la imagen
|
592 |
* @return
|
593 |
*/
|
594 |
public double getRelWidthHeight() { |
595 |
return relWidthHeight;
|
596 |
} |
597 |
|
598 |
/**
|
599 |
* Asigna el valor del campo "Alto" a partir del double que lo representa
|
600 |
* y con el n?mero de decimales que se especifica en el par?metro dec
|
601 |
* @param height Alto
|
602 |
* @param dec N?mero de decimales
|
603 |
*/
|
604 |
public void setHeightText(double height, int dec) { |
605 |
realHeight = height; |
606 |
getPResolution().setHeightText(height, dec); |
607 |
} |
608 |
|
609 |
/**
|
610 |
* Asigna el valor del campo "tama?o de celda" a partir del double que lo representa
|
611 |
* y con el n?mero de decimales que se especifica en el par?metro dec
|
612 |
* @param cellSize Tama?o de celda en double
|
613 |
* @param dec N?mero de decimales
|
614 |
*/
|
615 |
public void setCellSizeText(double cellSize, int dec) { |
616 |
getPResolution().setCellSizeText(cellSize, dec); |
617 |
} |
618 |
|
619 |
/**
|
620 |
* Asigna las coordenadas del mundo real a partir de n?meros en coma flotante.
|
621 |
* @param minx coordenada m?nima de X
|
622 |
* @param miny coordenada m?nima de Y
|
623 |
* @param maxx coordenada m?xima de X
|
624 |
* @param maxy coordenada m?xima de Y
|
625 |
* @param dec N?mero de decimales a mostrar en la caja de texto
|
626 |
*/
|
627 |
public void setCoorRealFromDouble(double ulx, double uly, double lrx, double lry, int dec) { |
628 |
wcUlx = ulx; |
629 |
wcUly = uly; |
630 |
wcLrx = lrx; |
631 |
wcLry = lry; |
632 |
setCoordReal(getCoord(ulx, uly, lrx, lry, dec)); |
633 |
} |
634 |
|
635 |
/**
|
636 |
* Obtiene un texto con las coordenadas a partir de n?meros en coma flotante.
|
637 |
* @param minx coordenada m?nima de X
|
638 |
* @param miny coordenada m?nima de Y
|
639 |
* @param maxx coordenada m?xima de X
|
640 |
* @param maxy coordenada m?xima de Y
|
641 |
* @param dec N?mero de decimales a mostrar en la caja de texto
|
642 |
*/
|
643 |
private String[] getCoord(double minx, double miny, double maxx, double maxy, int dec) { |
644 |
String[] coordPx = new String[4]; |
645 |
int indexPoint = String.valueOf(minx).indexOf('.'); |
646 |
try {
|
647 |
coordPx[0] = String.valueOf(minx).substring(0, indexPoint + dec); |
648 |
} catch (StringIndexOutOfBoundsException ex) { |
649 |
coordPx[0] = String.valueOf(minx); |
650 |
} |
651 |
indexPoint = String.valueOf(miny).indexOf('.'); |
652 |
try {
|
653 |
coordPx[1] = String.valueOf(miny).substring(0, indexPoint + dec); |
654 |
} catch (StringIndexOutOfBoundsException ex) { |
655 |
coordPx[1] = String.valueOf(miny); |
656 |
} |
657 |
indexPoint = String.valueOf(maxx).indexOf('.'); |
658 |
try {
|
659 |
coordPx[2] = String.valueOf(maxx).substring(0, indexPoint + dec); |
660 |
} catch (StringIndexOutOfBoundsException ex) { |
661 |
coordPx[2] = String.valueOf(maxx); |
662 |
} |
663 |
indexPoint = String.valueOf(maxy).indexOf('.'); |
664 |
try {
|
665 |
coordPx[3] = String.valueOf(maxy).substring(0, indexPoint + dec); |
666 |
} catch (StringIndexOutOfBoundsException ex) { |
667 |
coordPx[3] = String.valueOf(maxy); |
668 |
} |
669 |
return coordPx;
|
670 |
} |
671 |
|
672 |
/**
|
673 |
* Asigna los valores de las coordenadas reales.
|
674 |
* @param values
|
675 |
*/
|
676 |
private void setCoordReal(String[] values) { |
677 |
getCoordinatesReales().setValues(values); |
678 |
} |
679 |
|
680 |
/**
|
681 |
* Asigna las coordenadas pixel a partir de n?meros en coma flotante.
|
682 |
* @param minx coordenada m?nima de X
|
683 |
* @param miny coordenada m?nima de Y
|
684 |
* @param maxx coordenada m?xima de X
|
685 |
* @param maxy coordenada m?xima de Y
|
686 |
* @param dec N?mero de decimales a mostrar en la caja de texto
|
687 |
*/
|
688 |
public void setCoorPixelFromDouble(double minx, double miny, double maxx, double maxy, int dec) { |
689 |
pxMinX = minx; |
690 |
pxMinY = miny; |
691 |
pxMaxX = maxx; |
692 |
pxMaxY = maxy; |
693 |
setCoordPixel(getCoord(minx, miny, maxx, maxy, dec)); |
694 |
} |
695 |
|
696 |
/**
|
697 |
* Asigna los valores de las coordenadas p?xel.
|
698 |
* @return
|
699 |
*/
|
700 |
private void setCoordPixel(String[] values) { |
701 |
getCoordinatesPixel().setValues(values); |
702 |
} |
703 |
|
704 |
/**
|
705 |
* Asigna la relaci?n entre el ancho y alto de la imagen de salida
|
706 |
* @param rel
|
707 |
*/
|
708 |
public void setRelWidthHeight(double rel) { |
709 |
relWidthHeight = rel; |
710 |
} |
711 |
|
712 |
/**
|
713 |
* Obtiene la coordenada de m?xima X en pixel.
|
714 |
* @return Coordenada de m?xima X en pixel
|
715 |
*/
|
716 |
public double getPxMaxX() { |
717 |
return pxMaxX;
|
718 |
} |
719 |
|
720 |
/**
|
721 |
* Obtiene la coordenada de m?xima Y en pixel.
|
722 |
* @return Coordenada de m?xima Y en pixel
|
723 |
*/
|
724 |
public double getPxMaxY() { |
725 |
return pxMaxY;
|
726 |
} |
727 |
|
728 |
/**
|
729 |
* Obtiene la coordenada de m?nima X en pixel.
|
730 |
* @return Coordenada de m?nima X en pixel
|
731 |
*/
|
732 |
public double getPxMinX() { |
733 |
return pxMinX;
|
734 |
} |
735 |
|
736 |
/**
|
737 |
* Obtiene la coordenada de m?nima Y en pixel.
|
738 |
* @return Coordenada de m?nima Y en pixel
|
739 |
*/
|
740 |
public double getPxMinY() { |
741 |
return pxMinY;
|
742 |
} |
743 |
|
744 |
/**
|
745 |
* Obtiene la coordenada de m?xima X real.
|
746 |
* @return Coordenada de m?xima X real.
|
747 |
*/
|
748 |
public double getULX() { |
749 |
return wcUlx;
|
750 |
} |
751 |
|
752 |
/**
|
753 |
* Obtiene la coordenada de m?xima Y real.
|
754 |
* @return Coordenada de m?xima Y real
|
755 |
*/
|
756 |
public double getULY() { |
757 |
return wcUly;
|
758 |
} |
759 |
|
760 |
/**
|
761 |
* Obtiene la coordenada de m?nima X real.
|
762 |
* @return Coordenada de m?nima X real
|
763 |
*/
|
764 |
public double getLRX() { |
765 |
return wcLrx;
|
766 |
} |
767 |
|
768 |
/**
|
769 |
* Obtiene la coordenada de m?nima Y real.
|
770 |
* @return Coordenada de m?nima Y real
|
771 |
*/
|
772 |
public double getLRY() { |
773 |
return wcLry;
|
774 |
} |
775 |
|
776 |
/**
|
777 |
* Obtiene el <code>MapControl</code> de gvSIG
|
778 |
* @return <code>MapControl</code>
|
779 |
*/
|
780 |
public MapControl getMapControl() {
|
781 |
return mapControl;
|
782 |
} |
783 |
|
784 |
/**
|
785 |
* Obtiene la ultima herramienta seleccionada antes de cargar el recorte
|
786 |
* @return
|
787 |
*/
|
788 |
public String getLastTool() { |
789 |
return lastTool;
|
790 |
} |
791 |
|
792 |
/**
|
793 |
* Obtiene el nombre de la vista
|
794 |
* @return
|
795 |
*/
|
796 |
public String getViewName() { |
797 |
return viewName;
|
798 |
} |
799 |
|
800 |
/**
|
801 |
* Devuelve el valor del campo "tama?o de celda"
|
802 |
* @return
|
803 |
*/
|
804 |
public double getWidthText() { |
805 |
return realWidth;
|
806 |
} |
807 |
|
808 |
/**
|
809 |
* Devuelve el valor del campo "tama?o de celda"
|
810 |
* @return
|
811 |
*/
|
812 |
public double getHeightText() { |
813 |
return realHeight;
|
814 |
} |
815 |
|
816 |
/**
|
817 |
* Cada vez que cambia un checkbox de cargar en toc o guardar en fichero, nos
|
818 |
* aseguramos de que no pueden estar las dos opciones desmarcadas
|
819 |
*/
|
820 |
public void itemStateChanged(ItemEvent e) { |
821 |
getCbLoadLayerInToc().setEnabled(true);
|
822 |
getCbSaveFile().setEnabled(true);
|
823 |
if (getCbLoadLayerInToc().isSelected() && !getCbSaveFile().isSelected())
|
824 |
getCbLoadLayerInToc().setEnabled(false);
|
825 |
if (!getCbLoadLayerInToc().isSelected() && getCbSaveFile().isSelected())
|
826 |
getCbSaveFile().setEnabled(false);
|
827 |
|
828 |
getJBChooseDirectory().setEnabled(getCbSaveFile().isSelected()); |
829 |
getDirectoryTextField().setEnabled(getCbSaveFile().isSelected()); |
830 |
getJLabelDirectory().setEnabled(getCbSaveFile().isSelected()); |
831 |
} |
832 |
|
833 |
/**
|
834 |
* Accion que sucede cuando se pulsa el boton de cambiar directorio
|
835 |
*/
|
836 |
public void actionPerformed(ActionEvent e) { |
837 |
|
838 |
JFileChooser chooser = new JFileChooser(RasterModule.getPath()); |
839 |
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
840 |
chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_directorio")); |
841 |
|
842 |
if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) |
843 |
return;
|
844 |
String path = chooser.getSelectedFile().toString();
|
845 |
RasterModule.setPath(path); |
846 |
getDirectoryTextField().setText(path); |
847 |
} |
848 |
} |