svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / ui / launcher / OutFileSelectionPanel.java @ 25681
History | View | Annotate | Download (4.47 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 |
|
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.raster.RasterLibrary; |
32 |
import org.gvsig.raster.util.RasterToolsUtil; |
33 |
|
34 |
import com.iver.cit.gvsig.addlayer.fileopen.FileOpenWizard; |
35 |
|
36 |
/**
|
37 |
* Panel de selecci?n de fichero de salida.
|
38 |
*
|
39 |
* 10/01/2008
|
40 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
41 |
*/
|
42 |
public class OutFileSelectionPanel extends JPanel implements ActionListener { |
43 |
private static final long serialVersionUID = 1L; |
44 |
private JTextField fileName = null; |
45 |
private JButton bSelection = null; |
46 |
|
47 |
/**
|
48 |
* Constructor. Asigna la lista de nombres de vistas para el selector.
|
49 |
* @param viewList
|
50 |
*/
|
51 |
public OutFileSelectionPanel() {
|
52 |
init(); |
53 |
} |
54 |
|
55 |
/**
|
56 |
* Acciones de inicializaci?n del panel
|
57 |
*/
|
58 |
public void init() { |
59 |
BorderLayout fl = new BorderLayout(); |
60 |
fl.setHgap(3);
|
61 |
fl.setVgap(0);
|
62 |
setLayout(fl); |
63 |
setBorder(javax.swing.BorderFactory.createTitledBorder(null, RasterToolsUtil.getText(this, "output_file"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
64 |
add(getFileName(), BorderLayout.CENTER);
|
65 |
add(getSelectFileButton(), BorderLayout.EAST);
|
66 |
} |
67 |
|
68 |
/**
|
69 |
* Obtiene el campo con la ruta al ficheo a georreferenciar
|
70 |
* @return JFormattedTextField
|
71 |
*/
|
72 |
private JTextField getFileName() { |
73 |
if (fileName == null) { |
74 |
String path = FileOpenWizard.getLastPath();
|
75 |
if(path == null) |
76 |
path = System.getProperty("user.home"); |
77 |
fileName = new JTextField(path + File.separator + RasterLibrary.usesOnlyLayerName() + ".tif"); |
78 |
fileName.setEditable(true);
|
79 |
} |
80 |
return fileName;
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* Obtiene el bot?n de selecci?n de fichero
|
85 |
* @return JButton
|
86 |
*/
|
87 |
private JButton getSelectFileButton() { |
88 |
if(bSelection == null) { |
89 |
bSelection = new JButton(RasterToolsUtil.getText(this, "select")); |
90 |
bSelection.addActionListener(this);
|
91 |
} |
92 |
return bSelection;
|
93 |
} |
94 |
|
95 |
public void actionPerformed(ActionEvent e) { |
96 |
if(e.getSource() == getSelectFileButton()) {
|
97 |
selectDirectory(); |
98 |
} |
99 |
} |
100 |
|
101 |
/**
|
102 |
* Muestra el dialogo de selecci?n de fichero para la carga de la capa
|
103 |
* raster en los formatos definidos para georreferenciar.
|
104 |
* @return Capa raster cargada o null si no se consigue ninguna
|
105 |
*/
|
106 |
private void selectDirectory() { |
107 |
JFileChooser chooser = new JFileChooser(FileOpenWizard.getLastPath()); |
108 |
chooser.setAcceptAllFileFilterUsed(false);
|
109 |
chooser.isDirectorySelectionEnabled(); |
110 |
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
111 |
|
112 |
int returnVal = chooser.showOpenDialog(null); |
113 |
if (returnVal == JFileChooser.APPROVE_OPTION) { |
114 |
String outPath = chooser.getSelectedFile().getAbsolutePath();
|
115 |
String fileName = RasterLibrary.getOnlyLayerName() + ".tif"; |
116 |
int index = getFileName().getText().lastIndexOf(File.separator); |
117 |
if(index != -1) |
118 |
fileName = getFileName().getText().substring(index + 1);
|
119 |
if(outPath.compareTo(File.separator) == 0) |
120 |
getFileName().setText(outPath + fileName); |
121 |
else
|
122 |
getFileName().setText(outPath + File.separator + fileName);
|
123 |
FileOpenWizard.setLastPath(outPath); |
124 |
} |
125 |
return;
|
126 |
} |
127 |
|
128 |
//-------Consulta de propiedades seleccionadas---------
|
129 |
|
130 |
/**
|
131 |
* Obtiene el fichero seleccionado
|
132 |
* @return String con el nombre del fichero seleccionado
|
133 |
*/
|
134 |
public String getOutFile() { |
135 |
return getFileName().getText();
|
136 |
} |
137 |
|
138 |
/**
|
139 |
* Asigna el fichero de salida
|
140 |
* @param file
|
141 |
*/
|
142 |
public void setOutFile(String file) { |
143 |
getFileName().setText(file); |
144 |
} |
145 |
|
146 |
} |