root / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / ui / launcher / FileSelectionPanel.java @ 19621
History | View | Annotate | Download (5.5 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.georeferencing.ui.launcher; |
20 |
|
21 |
import java.awt.BorderLayout; |
22 |
import java.awt.event.ActionEvent; |
23 |
import java.awt.event.ActionListener; |
24 |
import java.io.File; |
25 |
import java.util.ArrayList; |
26 |
|
27 |
import javax.swing.JButton; |
28 |
import javax.swing.JFileChooser; |
29 |
import javax.swing.JPanel; |
30 |
import javax.swing.JTextField; |
31 |
|
32 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
33 |
import org.gvsig.gui.beans.datainput.DataInputContainer; |
34 |
import org.gvsig.raster.dataset.RasterDataset; |
35 |
import org.gvsig.raster.util.ExtendedFileFilter; |
36 |
import org.gvsig.raster.util.RasterToolsUtil; |
37 |
import org.gvsig.raster.util.RasterUtilities; |
38 |
|
39 |
import com.iver.cit.gvsig.addlayer.fileopen.FileOpenWizard; |
40 |
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
41 |
|
42 |
/**
|
43 |
* Panel de selecci?n de fichero a georreferenciar.
|
44 |
*
|
45 |
* 10/01/2008
|
46 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
47 |
*/
|
48 |
public class FileSelectionPanel extends JPanel implements ActionListener { |
49 |
private static final long serialVersionUID = 1L; |
50 |
|
51 |
private JTextField fileName = null; |
52 |
private JButton bSelection = null; |
53 |
private FLyrRasterSE layer = null; |
54 |
private DataInputContainer yCellSize = null; |
55 |
private DataInputContainer xCellSize = null; |
56 |
|
57 |
/**
|
58 |
* Constructor. Asigna la lista de nombres de vistas para el selector.
|
59 |
* @param viewList
|
60 |
*/
|
61 |
public FileSelectionPanel(DataInputContainer xCellSize, DataInputContainer yCellSize) {
|
62 |
this.xCellSize = xCellSize;
|
63 |
this.yCellSize = yCellSize;
|
64 |
init(); |
65 |
} |
66 |
|
67 |
/**
|
68 |
* Acciones de inicializaci?n del panel
|
69 |
*/
|
70 |
public void init() { |
71 |
BorderLayout fl = new BorderLayout(); |
72 |
fl.setHgap(3);
|
73 |
fl.setVgap(0);
|
74 |
setLayout(fl); |
75 |
setBorder(javax.swing.BorderFactory.createTitledBorder(null, RasterToolsUtil.getText(this, "georef_file"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
76 |
add(getFileName(), BorderLayout.CENTER);
|
77 |
add(getSelectFileButton(), BorderLayout.EAST);
|
78 |
} |
79 |
|
80 |
/**
|
81 |
* Obtiene el campo con la ruta al ficheo a georreferenciar
|
82 |
* @return JFormattedTextField
|
83 |
*/
|
84 |
private JTextField getFileName() { |
85 |
if (fileName == null) { |
86 |
fileName = new JTextField(); |
87 |
fileName.setEditable(false);
|
88 |
} |
89 |
return fileName;
|
90 |
} |
91 |
|
92 |
/**
|
93 |
* Obtiene el bot?n de selecci?n de fichero
|
94 |
* @return JButton
|
95 |
*/
|
96 |
private JButton getSelectFileButton() { |
97 |
if(bSelection == null) { |
98 |
bSelection = new JButton(RasterToolsUtil.getText(this, "select")); |
99 |
bSelection.addActionListener(this);
|
100 |
} |
101 |
return bSelection;
|
102 |
} |
103 |
|
104 |
/**
|
105 |
* Gestiona el evento del bot?n de apertura de capa
|
106 |
*/
|
107 |
public void actionPerformed(ActionEvent e) { |
108 |
if(e.getSource() == getSelectFileButton()) {
|
109 |
loadRasterLayer(); |
110 |
if(getLayer() != null && xCellSize != null && yCellSize != null) { |
111 |
xCellSize.setValue(getLayer().getDataSource().getCellSize() + "");
|
112 |
yCellSize.setValue(getLayer().getDataSource().getCellSize() + "");
|
113 |
} |
114 |
} |
115 |
} |
116 |
|
117 |
/**
|
118 |
* Muestra el dialogo de selecci?n de fichero para la carga de la capa
|
119 |
* raster en los formatos definidos para georreferenciar.
|
120 |
* @return Capa raster cargada o null si no se consigue ninguna
|
121 |
*/
|
122 |
private FLyrRasterSE loadRasterLayer() {
|
123 |
String path = null; |
124 |
JFileChooser chooser = new JFileChooser(FileOpenWizard.getLastPath()); |
125 |
chooser.setAcceptAllFileFilterUsed(false);
|
126 |
ArrayList extensionsSupported = RasterDataset.getExtensionsSupported();
|
127 |
ExtendedFileFilter allFiles = new ExtendedFileFilter();
|
128 |
for (int i = 0; i < extensionsSupported.size(); i++) { |
129 |
ExtendedFileFilter fileFilter = new ExtendedFileFilter();
|
130 |
fileFilter.addExtension((String)extensionsSupported.get(i));
|
131 |
allFiles.addExtension((String)extensionsSupported.get(i));
|
132 |
chooser.addChoosableFileFilter(fileFilter); |
133 |
} |
134 |
allFiles.setDescription(RasterToolsUtil.getText(this, "todos_soportados")); |
135 |
chooser.addChoosableFileFilter(allFiles); |
136 |
|
137 |
int returnVal = chooser.showOpenDialog(null); |
138 |
if (returnVal == JFileChooser.APPROVE_OPTION) { |
139 |
path = chooser.getSelectedFile().getAbsolutePath(); |
140 |
try {
|
141 |
if (layer != null) |
142 |
layer.getDataSource().close(); |
143 |
layer = FLyrRasterSE.createLayer(RasterUtilities.getLastPart(path, File.separator), path, null); |
144 |
if (layer != null) |
145 |
getFileName().setText(path); |
146 |
return layer;
|
147 |
} catch (LoadLayerException e) {
|
148 |
} |
149 |
} |
150 |
RasterToolsUtil.messageBoxError(RasterToolsUtil.getText(this, "error_load_layer"), null); |
151 |
return null; |
152 |
} |
153 |
|
154 |
//-------Consulta de propiedades seleccionadas---------
|
155 |
|
156 |
/**
|
157 |
* Obtiene la capa que ha sido abierta por el usuario
|
158 |
* @return Obtiene la capa que ha sido abierta por el usuario o null si no
|
159 |
* hay abierta ninguna.
|
160 |
*/
|
161 |
public FLyrRasterSE getLayer() {
|
162 |
return layer;
|
163 |
} |
164 |
|
165 |
} |