svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / properties / panels / TranspByPixelPanel.java @ 19601
History | View | Annotate | Download (12.1 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.properties.panels; |
20 |
|
21 |
import java.awt.BorderLayout; |
22 |
import java.awt.Color; |
23 |
import java.awt.Dimension; |
24 |
import java.awt.FlowLayout; |
25 |
import java.awt.GridBagConstraints; |
26 |
import java.awt.GridBagLayout; |
27 |
import java.util.ArrayList; |
28 |
import java.util.EventObject; |
29 |
import java.util.Iterator; |
30 |
|
31 |
import javax.swing.DefaultListModel; |
32 |
import javax.swing.JButton; |
33 |
import javax.swing.JCheckBox; |
34 |
import javax.swing.JList; |
35 |
import javax.swing.JPanel; |
36 |
import javax.swing.JScrollPane; |
37 |
import javax.swing.ListSelectionModel; |
38 |
|
39 |
import org.gvsig.raster.datastruct.TransparencyRange; |
40 |
import org.gvsig.raster.util.RasterToolsUtil; |
41 |
import org.gvsig.rastertools.properties.control.TranspByPixelEventListener; |
42 |
import org.gvsig.rastertools.properties.control.TranspByPixelListener; |
43 |
|
44 |
import com.iver.andami.PluginServices; |
45 |
/**
|
46 |
* Panel con los controles para la transparencia por pixel. Incluye los textbox
|
47 |
* para a?adir un RGB a la lista.
|
48 |
*
|
49 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
50 |
*/
|
51 |
public class TranspByPixelPanel extends JPanel { |
52 |
private static final long serialVersionUID = -1131297200332579683L; |
53 |
private boolean controlEnabled = false; |
54 |
private JCheckBox activeCheck = null; |
55 |
private JList jList = null; |
56 |
private JPanel pixelSelector = null; |
57 |
private JPanel activeControl = null; |
58 |
private JPanel pEast = null; |
59 |
private JPanel pCenter = null; |
60 |
private JPanel pButtons = null; |
61 |
private JButton bAdd = null; |
62 |
private JButton bRemove = null; |
63 |
private JButton bSelectColor = null; |
64 |
private JScrollPane jScrollList = null; |
65 |
private TranspByPixelRGBInputPanel pWest = null; |
66 |
private TranspByPixelAndOrSelectorPanel pOperation = null; |
67 |
private TranspByPixelListener listener = null; |
68 |
private ArrayList actionCommandListeners = new ArrayList(); |
69 |
|
70 |
/**
|
71 |
* This is the default constructor
|
72 |
*/
|
73 |
public TranspByPixelPanel() {
|
74 |
initialize(); |
75 |
// Inicializa el TranspByPixelListener
|
76 |
getListener(); |
77 |
setControlEnabled(false);
|
78 |
} |
79 |
|
80 |
/**
|
81 |
* This method initializes this
|
82 |
*/
|
83 |
private void initialize() { |
84 |
setLayout(new BorderLayout()); |
85 |
add(getActiveControl(), BorderLayout.NORTH);
|
86 |
add(getPixelSelector(), BorderLayout.CENTER);
|
87 |
} |
88 |
|
89 |
/**
|
90 |
* Obtiene el panel con los controles principales para introducir valores RGB
|
91 |
* en la lista
|
92 |
* @return JPanel
|
93 |
*/
|
94 |
private JPanel getPixelSelector() { |
95 |
if (pixelSelector == null) { |
96 |
|
97 |
pixelSelector = new JPanel(); |
98 |
pixelSelector.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 11, 5, 11)); |
99 |
|
100 |
pixelSelector.setLayout(new BorderLayout(5, 5)); |
101 |
|
102 |
JPanel jpanel1 = new JPanel(); |
103 |
jpanel1.setLayout(new BorderLayout(5, 5)); |
104 |
jpanel1.add(getPRGBInput(), BorderLayout.CENTER);
|
105 |
jpanel1.add(getPCenter(), BorderLayout.EAST);
|
106 |
|
107 |
pixelSelector.add(jpanel1, BorderLayout.CENTER);
|
108 |
pixelSelector.add(getPList(), BorderLayout.EAST);
|
109 |
} |
110 |
return pixelSelector;
|
111 |
} |
112 |
|
113 |
/**
|
114 |
* Obtiene el panel con el control de activaci?n
|
115 |
* @return JPanel
|
116 |
*/
|
117 |
private JPanel getActiveControl() { |
118 |
if (activeControl == null){ |
119 |
activeControl = new JPanel(); |
120 |
FlowLayout fl = new FlowLayout(); |
121 |
fl.setAlignment(FlowLayout.LEFT);
|
122 |
activeControl.setLayout(fl); |
123 |
activeControl.add(getActiveCheck()); |
124 |
} |
125 |
return activeControl;
|
126 |
} |
127 |
|
128 |
/**
|
129 |
* Obtiene el check que activa y desactiva la transparencia por pixel.
|
130 |
* @return JCheckBox
|
131 |
*/
|
132 |
public JCheckBox getActiveCheck() { |
133 |
if(activeCheck == null) { |
134 |
activeCheck = new JCheckBox(PluginServices.getText(this, "activar")); |
135 |
activeCheck.setSelected(false);
|
136 |
} |
137 |
return activeCheck;
|
138 |
} |
139 |
|
140 |
/**
|
141 |
* This method initializes jPanel
|
142 |
* @return
|
143 |
*/
|
144 |
public TranspByPixelRGBInputPanel getPRGBInput() {
|
145 |
if (pWest == null) { |
146 |
pWest = new TranspByPixelRGBInputPanel();
|
147 |
} |
148 |
return pWest;
|
149 |
} |
150 |
|
151 |
/**
|
152 |
* This method initializes jPanel1
|
153 |
* @return javax.swing.JPanel
|
154 |
*/
|
155 |
public JPanel getPList() { |
156 |
if (pEast == null) { |
157 |
GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); |
158 |
gridBagConstraints3.fill = java.awt.GridBagConstraints.BOTH; |
159 |
gridBagConstraints3.gridx = 0;
|
160 |
gridBagConstraints3.gridy = 0;
|
161 |
gridBagConstraints3.weightx = 1.0;
|
162 |
gridBagConstraints3.weighty = 1.0;
|
163 |
gridBagConstraints3.insets = new java.awt.Insets(0,0,0,0); |
164 |
pEast = new JPanel(); |
165 |
pEast.setLayout(new GridBagLayout()); |
166 |
pEast.add(getJScrollList(), gridBagConstraints3); |
167 |
} |
168 |
return pEast;
|
169 |
} |
170 |
|
171 |
/**
|
172 |
* This method initializes pCenter
|
173 |
* @return javax.swing.JPanel
|
174 |
*/
|
175 |
private JPanel getPCenter() { |
176 |
if (pCenter == null) { |
177 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
178 |
gridBagConstraints1.insets = new java.awt.Insets(0,0,0,0); |
179 |
gridBagConstraints1.gridy = 1;
|
180 |
gridBagConstraints1.gridx = 0;
|
181 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
182 |
gridBagConstraints.insets = new java.awt.Insets(0,0,0,0); |
183 |
gridBagConstraints.gridy = 0;
|
184 |
gridBagConstraints.gridx = 0;
|
185 |
pCenter = new JPanel(); |
186 |
pCenter.setLayout(new GridBagLayout()); |
187 |
pCenter.add(getPButtons(), gridBagConstraints); |
188 |
pCenter.add(getPOperation(), gridBagConstraints1); |
189 |
} |
190 |
return pCenter;
|
191 |
} |
192 |
|
193 |
|
194 |
/**
|
195 |
* Obtiene el bot?n de a?adir elemento de la lista en la transparencia
|
196 |
* por pixel.
|
197 |
*
|
198 |
* @return javax.swing.JButton
|
199 |
*/
|
200 |
public JButton getBAdd() { |
201 |
if (bAdd == null) { |
202 |
bAdd = new JButton("A?adir"); |
203 |
bAdd.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT); |
204 |
bAdd.setIcon(RasterToolsUtil.getIcon("forward-icon"));
|
205 |
} |
206 |
return bAdd;
|
207 |
} |
208 |
|
209 |
/**
|
210 |
* Obtiene el bot?n de eliminar elemento de la lista en la transparencia
|
211 |
* por pixel.
|
212 |
* @return javax.swing.JButton
|
213 |
*/
|
214 |
public JButton getBRemove() { |
215 |
if (bRemove == null) { |
216 |
bRemove = new JButton("Quitar"); |
217 |
bRemove.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); |
218 |
bRemove.setIcon(RasterToolsUtil.getIcon("backward-icon"));
|
219 |
bRemove.setEnabled(false);
|
220 |
} |
221 |
return bRemove;
|
222 |
} |
223 |
|
224 |
/**
|
225 |
* Obtiene el bot?n de color.
|
226 |
* @return JButton
|
227 |
*/
|
228 |
public JButton getBSelectColor() { |
229 |
if (bSelectColor == null) { |
230 |
bSelectColor = new JButton(); |
231 |
bSelectColor.setIcon(RasterToolsUtil.getIcon("selectrgb-icon"));
|
232 |
bSelectColor.setPreferredSize(new Dimension(26, 26)); |
233 |
bSelectColor.setToolTipText(RasterToolsUtil.getText(this, "select_rgb")); |
234 |
} |
235 |
return bSelectColor;
|
236 |
} |
237 |
|
238 |
/**
|
239 |
* Obtiene el panel con los botones
|
240 |
* @return javax.swing.JPanel
|
241 |
*/
|
242 |
private JPanel getPButtons() { |
243 |
if (pButtons == null) { |
244 |
pButtons = new JPanel(); |
245 |
pButtons.setLayout(new java.awt.GridBagLayout());
|
246 |
|
247 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
248 |
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); |
249 |
gridBagConstraints.gridy = 0;
|
250 |
gridBagConstraints.gridx = 0;
|
251 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
252 |
pButtons.add(getBAdd(), gridBagConstraints); |
253 |
|
254 |
gridBagConstraints = new GridBagConstraints(); |
255 |
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); |
256 |
gridBagConstraints.gridy = 1;
|
257 |
gridBagConstraints.gridx = 0;
|
258 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
259 |
pButtons.add(getBRemove(), gridBagConstraints); |
260 |
|
261 |
gridBagConstraints = new GridBagConstraints(); |
262 |
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); |
263 |
gridBagConstraints.gridy = 2;
|
264 |
gridBagConstraints.gridx = 0;
|
265 |
pButtons.add(getBSelectColor(), gridBagConstraints); |
266 |
} |
267 |
return pButtons;
|
268 |
} |
269 |
|
270 |
/**
|
271 |
* This method initializes jPanel1
|
272 |
*
|
273 |
* @return javax.swing.JPanel
|
274 |
*/
|
275 |
public TranspByPixelAndOrSelectorPanel getPOperation() {
|
276 |
if (pOperation == null) { |
277 |
pOperation = new TranspByPixelAndOrSelectorPanel();
|
278 |
pOperation.setPreferredSize(new java.awt.Dimension(60,60)); |
279 |
} |
280 |
return pOperation;
|
281 |
} |
282 |
|
283 |
/**
|
284 |
* This method initializes jList
|
285 |
*
|
286 |
* @return javax.swing.JList
|
287 |
*/
|
288 |
public JList getJList() { |
289 |
if (jList == null) { |
290 |
jList = new JList(new DefaultListModel()); |
291 |
jList.setFont(new java.awt.Font("Monospaced", java.awt.Font.PLAIN, 10)); |
292 |
jList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
293 |
} |
294 |
return jList;
|
295 |
} |
296 |
|
297 |
/**
|
298 |
* Inicializa el scroll para el jList
|
299 |
* @return
|
300 |
*/
|
301 |
public JScrollPane getJScrollList() { |
302 |
if (jScrollList == null) { |
303 |
jScrollList = new JScrollPane(); |
304 |
jScrollList.setViewportView(getJList()); |
305 |
jScrollList.setPreferredSize(new java.awt.Dimension(160,100)); |
306 |
} |
307 |
return jScrollList;
|
308 |
} |
309 |
|
310 |
/**
|
311 |
* Obtiene el ListModel de la lista
|
312 |
* @return DefaultListModel
|
313 |
*/
|
314 |
public DefaultListModel getListModel(){ |
315 |
return (DefaultListModel) getJList().getModel(); |
316 |
} |
317 |
|
318 |
/**
|
319 |
* Activa o desactiva el control
|
320 |
* @param enable True activa el control y false lo desactiva
|
321 |
*/
|
322 |
public void setControlEnabled(boolean enabled){ |
323 |
this.getActiveCheck().setSelected(enabled);
|
324 |
getJList().setEnabled(enabled); |
325 |
if (enabled)
|
326 |
getJList().setBackground(Color.WHITE);
|
327 |
else
|
328 |
getJList().setBackground(this.getBackground());
|
329 |
getPRGBInput().setControlEnabled(enabled); |
330 |
getBAdd().setEnabled(enabled); |
331 |
getBSelectColor().setEnabled(enabled); |
332 |
|
333 |
if (enabled)
|
334 |
getBRemove().setEnabled(getJList().getModel().getSize()>0);
|
335 |
else
|
336 |
getBRemove().setEnabled(false);
|
337 |
|
338 |
getPOperation().setControlEnabled(enabled); |
339 |
controlEnabled = enabled; |
340 |
} |
341 |
|
342 |
/**
|
343 |
* Obtiene true si el control est? activo y false si no lo est?
|
344 |
* @return
|
345 |
*/
|
346 |
public boolean isControlEnabled(){ |
347 |
return controlEnabled;
|
348 |
} |
349 |
|
350 |
/**
|
351 |
* Asigna el n?mero de bandas activas
|
352 |
* @param n N?mero de bandas
|
353 |
*/
|
354 |
public void setActiveBands(int n){ |
355 |
((TranspByPixelRGBInputPanel)getPRGBInput()).setActiveBands(n); |
356 |
} |
357 |
|
358 |
/**
|
359 |
* Obtiene el array de entradas de valores a?adidos a la lista
|
360 |
* @return ArrayList
|
361 |
*/
|
362 |
public ArrayList getEntries(){ |
363 |
return getListener().getEntries();
|
364 |
} |
365 |
|
366 |
/**
|
367 |
* Obtiene la clase manejadora de eventos asociada a esta
|
368 |
* @return TransparencyByPixelListener
|
369 |
*/
|
370 |
public TranspByPixelListener getListener() {
|
371 |
if (listener == null) { |
372 |
listener = new TranspByPixelListener(this); |
373 |
} |
374 |
return listener;
|
375 |
} |
376 |
|
377 |
/**
|
378 |
* A?ade una entrada a la tabla
|
379 |
* @param entry objeto TransparencyRange
|
380 |
*/
|
381 |
public void addStringElement(TransparencyRange entry){ |
382 |
getEntries().add(entry); |
383 |
getListModel().addElement(entry.getStrEntry()); |
384 |
getBRemove().setEnabled(true);
|
385 |
} |
386 |
|
387 |
/**
|
388 |
* Borra las entradas de la tabla
|
389 |
*/
|
390 |
public void clear(){ |
391 |
getPRGBInput().clear(); |
392 |
getListModel().clear(); |
393 |
getEntries().clear(); |
394 |
getBRemove().setEnabled(false);
|
395 |
} |
396 |
|
397 |
/**
|
398 |
* A?adir un listener a la lista de eventos
|
399 |
* @param listener
|
400 |
*/
|
401 |
public void addValueChangedListener(TranspByPixelEventListener listener) { |
402 |
if (!actionCommandListeners.contains(listener))
|
403 |
actionCommandListeners.add(listener); |
404 |
} |
405 |
|
406 |
/**
|
407 |
* Borrar un listener de la lista de eventos
|
408 |
* @param listener
|
409 |
*/
|
410 |
public void removeValueChangedListener(TranspByPixelEventListener listener) { |
411 |
actionCommandListeners.remove(listener); |
412 |
} |
413 |
|
414 |
/**
|
415 |
* Dispara todos los manejadores que estan apuntando a este evento
|
416 |
*/
|
417 |
public void callValueChanged() { |
418 |
Iterator acIterator = actionCommandListeners.iterator();
|
419 |
while (acIterator.hasNext()) {
|
420 |
TranspByPixelEventListener listener = (TranspByPixelEventListener) acIterator.next(); |
421 |
listener.actionPixelListChanged(new EventObject(this)); |
422 |
} |
423 |
} |
424 |
} |