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