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