svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / clipping / panels / ClippingOptionsPanel.java @ 18962
History | View | Annotate | Download (9.68 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 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.clipping.panels; |
20 |
|
21 |
import java.awt.Dimension; |
22 |
import java.awt.GridBagConstraints; |
23 |
import java.awt.GridBagLayout; |
24 |
import java.awt.Insets; |
25 |
import java.awt.event.ActionEvent; |
26 |
import java.awt.event.ActionListener; |
27 |
import java.awt.event.ItemEvent; |
28 |
import java.awt.event.ItemListener; |
29 |
import java.io.File; |
30 |
|
31 |
import javax.swing.JButton; |
32 |
import javax.swing.JCheckBox; |
33 |
import javax.swing.JLabel; |
34 |
import javax.swing.JPanel; |
35 |
import javax.swing.JTextField; |
36 |
|
37 |
import org.gvsig.gui.beans.swing.JFileChooser; |
38 |
import org.gvsig.raster.RasterLibrary; |
39 |
import org.gvsig.raster.util.PropertyEvent; |
40 |
import org.gvsig.raster.util.PropertyListener; |
41 |
|
42 |
import com.iver.andami.PluginServices; |
43 |
/**
|
44 |
*
|
45 |
* @version 25/09/2007
|
46 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
47 |
*/
|
48 |
public class ClippingOptionsPanel extends JPanel implements PropertyListener, ItemListener, ActionListener { |
49 |
private static final long serialVersionUID = 7299254074235648334L; |
50 |
private JPanel jPNameFile = null; |
51 |
private JPanel jPNameDirectory = null; |
52 |
private JCheckBox jCheckBox = null; |
53 |
private JCheckBox jCheckLoadLayerInToc = null; |
54 |
private JButton jBChooseDirectory = null; |
55 |
private JLabel jLabelDirectory = null; |
56 |
private JCheckBox jCheckSaveFile = null; |
57 |
private JTextField filenameTextField = null; |
58 |
private JTextField directoryTextField = null; |
59 |
|
60 |
public ClippingOptionsPanel() {
|
61 |
initialize(); |
62 |
} |
63 |
|
64 |
private void initialize() { |
65 |
GridBagConstraints gridBagConstraints = null; |
66 |
|
67 |
setLayout(new GridBagLayout()); |
68 |
|
69 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
70 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
71 |
gridBagConstraints.weightx = 1.0;
|
72 |
gridBagConstraints.insets = new java.awt.Insets(5, 5, 2, 5); |
73 |
add(getJPNameFile(), gridBagConstraints); |
74 |
|
75 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
76 |
gridBagConstraints.gridx = 0;
|
77 |
gridBagConstraints.gridy = 1;
|
78 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
79 |
gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 5); |
80 |
add(getCbOneLyrPerBand(), gridBagConstraints); |
81 |
|
82 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
83 |
gridBagConstraints.gridx = 0;
|
84 |
gridBagConstraints.gridy = 2;
|
85 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
86 |
gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 5); |
87 |
//Preguntamos al acabar para que no nos peten la aplicaci?n
|
88 |
//add(getCbLoadLayerInToc(), gridBagConstraints);
|
89 |
|
90 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
91 |
gridBagConstraints.gridx = 0;
|
92 |
gridBagConstraints.gridy = 3;
|
93 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
94 |
gridBagConstraints.insets = new java.awt.Insets(2, 5, 2, 5); |
95 |
add(getCbSaveFile(), gridBagConstraints); |
96 |
|
97 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
98 |
gridBagConstraints.gridx = 0;
|
99 |
gridBagConstraints.gridy = 4;
|
100 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
101 |
gridBagConstraints.insets = new java.awt.Insets(2, 5, 5, 5); |
102 |
add(getJPNameDirectory(), gridBagConstraints); |
103 |
|
104 |
updateNewLayerText(); |
105 |
} |
106 |
|
107 |
/**
|
108 |
* This method initializes jPNameFile
|
109 |
* @return javax.swing.JPanel
|
110 |
*/
|
111 |
private JPanel getJPNameFile() { |
112 |
if (jPNameFile == null) { |
113 |
jPNameFile = new JPanel(); |
114 |
jPNameFile.add(new JLabel(PluginServices.getText(this, "nombre_capas") + ":")); |
115 |
jPNameFile.add(getFilenameTextField()); |
116 |
} |
117 |
return jPNameFile;
|
118 |
} |
119 |
|
120 |
/**
|
121 |
* This method initializes jPNameFile
|
122 |
* @return javax.swing.JPanel
|
123 |
*/
|
124 |
private JPanel getJPNameDirectory() { |
125 |
if (jPNameDirectory == null) { |
126 |
GridBagConstraints gridBagConstraints = null; |
127 |
jPNameDirectory = new JPanel(); |
128 |
|
129 |
jPNameDirectory.setLayout(new GridBagLayout()); |
130 |
|
131 |
gridBagConstraints = new GridBagConstraints(); |
132 |
gridBagConstraints.insets = new Insets(2, 5, 5, 2); |
133 |
jPNameDirectory.add(getJLabelDirectory(), gridBagConstraints); |
134 |
|
135 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
136 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
137 |
gridBagConstraints.weightx = 1.0;
|
138 |
gridBagConstraints.insets = new java.awt.Insets(2, 2, 5, 2); |
139 |
jPNameDirectory.add(getDirectoryTextField(), gridBagConstraints); |
140 |
|
141 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
142 |
gridBagConstraints.insets = new java.awt.Insets(2, 2, 5, 5); |
143 |
jPNameDirectory.add(getJBChooseDirectory(), gridBagConstraints); |
144 |
|
145 |
getJBChooseDirectory().addActionListener(this);
|
146 |
} |
147 |
return jPNameDirectory;
|
148 |
} |
149 |
|
150 |
/**
|
151 |
* This method initializes jCheckLoadLayerInToc
|
152 |
* @return javax.swing.JCheckBox
|
153 |
*/
|
154 |
public JCheckBox getCbLoadLayerInToc() { |
155 |
if (jCheckLoadLayerInToc == null) { |
156 |
jCheckLoadLayerInToc = new JCheckBox(); |
157 |
jCheckLoadLayerInToc.setText(PluginServices.getText(this, "cargar_en_toc")); |
158 |
jCheckLoadLayerInToc.setSelected(true);
|
159 |
jCheckLoadLayerInToc.setEnabled(false);
|
160 |
jCheckLoadLayerInToc.addItemListener(this);
|
161 |
} |
162 |
return jCheckLoadLayerInToc;
|
163 |
} |
164 |
|
165 |
/**
|
166 |
* This method initializes jCheckBox
|
167 |
* @return javax.swing.JCheckBox
|
168 |
*/
|
169 |
public JCheckBox getCbOneLyrPerBand() { |
170 |
if (jCheckBox == null) { |
171 |
jCheckBox = new JCheckBox(); |
172 |
jCheckBox.setText(PluginServices.getText(this, "crear_1_capa_por_banda")); |
173 |
} |
174 |
return jCheckBox;
|
175 |
} |
176 |
|
177 |
/**
|
178 |
* Cada vez que cambia un checkbox de cargar en toc o guardar en fichero, nos
|
179 |
* aseguramos de que no pueden estar las dos opciones desmarcadas
|
180 |
*/
|
181 |
public void itemStateChanged(ItemEvent e) { |
182 |
getCbLoadLayerInToc().setEnabled(true);
|
183 |
getCbSaveFile().setEnabled(true);
|
184 |
if (getCbLoadLayerInToc().isSelected() && !getCbSaveFile().isSelected())
|
185 |
getCbLoadLayerInToc().setEnabled(false);
|
186 |
if (!getCbLoadLayerInToc().isSelected() && getCbSaveFile().isSelected())
|
187 |
getCbSaveFile().setEnabled(false);
|
188 |
|
189 |
getJBChooseDirectory().setEnabled(getCbSaveFile().isSelected()); |
190 |
getDirectoryTextField().setEnabled(getCbSaveFile().isSelected()); |
191 |
getJLabelDirectory().setEnabled(getCbSaveFile().isSelected()); |
192 |
} |
193 |
|
194 |
private JButton getJBChooseDirectory() { |
195 |
if (jBChooseDirectory == null) { |
196 |
jBChooseDirectory = new JButton(PluginServices.getText(this, "cambiar_ruta")); |
197 |
jBChooseDirectory.setEnabled(false);
|
198 |
} |
199 |
return jBChooseDirectory;
|
200 |
} |
201 |
|
202 |
private JLabel getJLabelDirectory() { |
203 |
if (jLabelDirectory == null) { |
204 |
jLabelDirectory = new JLabel(PluginServices.getText(this, "ruta") + ":"); |
205 |
jLabelDirectory.setEnabled(false);
|
206 |
} |
207 |
return jLabelDirectory;
|
208 |
} |
209 |
|
210 |
/**
|
211 |
* This method initializes jCheckSaveFile
|
212 |
*
|
213 |
* @return javax.swing.JCheckBox
|
214 |
*/
|
215 |
public JCheckBox getCbSaveFile() { |
216 |
if (jCheckSaveFile == null) { |
217 |
jCheckSaveFile = new JCheckBox(); |
218 |
jCheckSaveFile.setText(PluginServices.getText(this, "guardar_en_disco")); |
219 |
jCheckSaveFile.addItemListener(this);
|
220 |
} |
221 |
return jCheckSaveFile;
|
222 |
} |
223 |
|
224 |
/**
|
225 |
* This method initializes filenameTextField
|
226 |
*
|
227 |
* @return javax.swing.JTextField
|
228 |
*/
|
229 |
public JTextField getFilenameTextField() { |
230 |
if (filenameTextField == null) { |
231 |
filenameTextField = new JTextField(); |
232 |
filenameTextField.setPreferredSize(new Dimension(150, filenameTextField.getPreferredSize().height)); |
233 |
RasterLibrary.addOnlyLayerNameListener(this);
|
234 |
} |
235 |
return filenameTextField;
|
236 |
} |
237 |
|
238 |
/**
|
239 |
* This method initializes filenameTextField
|
240 |
*
|
241 |
* @return javax.swing.JTextField
|
242 |
*/
|
243 |
public JTextField getDirectoryTextField() { |
244 |
if (directoryTextField == null) { |
245 |
directoryTextField = new JTextField(); |
246 |
directoryTextField.setText(JFileChooser.getLastPath(this.getClass().getName(), (File) null).toString()); |
247 |
directoryTextField.setEditable(false);
|
248 |
directoryTextField.setEnabled(false);
|
249 |
directoryTextField.setPreferredSize(new Dimension(200, directoryTextField.getPreferredSize().height)); |
250 |
} |
251 |
return directoryTextField;
|
252 |
} |
253 |
|
254 |
/**
|
255 |
* Accion que sucede cuando se pulsa el boton de cambiar directorio
|
256 |
*/
|
257 |
public void actionPerformed(ActionEvent e) { |
258 |
JFileChooser chooser = new JFileChooser(this.getClass().getName(), new File(getDirectoryTextField().getText())); |
259 |
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
260 |
chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_directorio")); |
261 |
|
262 |
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) |
263 |
getDirectoryTextField().setText(chooser.getSelectedFile().toString()); |
264 |
else
|
265 |
chooser.setLastPath(new File(getDirectoryTextField().getText())); |
266 |
} |
267 |
|
268 |
/**
|
269 |
* Especificar el nombre de la nueva capa para el recuadro de texto asign?ndo
|
270 |
* en cada llamada un nombre consecutivo.
|
271 |
*/
|
272 |
public void updateNewLayerText() { |
273 |
filenameTextField.setText(RasterLibrary.getOnlyLayerName()); |
274 |
} |
275 |
|
276 |
/**
|
277 |
* Cuando alguien ha cambiado la propiedad del nombre de la
|
278 |
* capa se actualiza autom?ticamente
|
279 |
*/
|
280 |
public void actionValueChanged(PropertyEvent e) { |
281 |
updateNewLayerText(); |
282 |
} |
283 |
} |