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