root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / properties / panels / TranspByPixelPanel.java @ 10940
History | View | Annotate | Download (9.61 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 |
|
28 |
import javax.swing.DefaultListModel; |
29 |
import javax.swing.JCheckBox; |
30 |
import javax.swing.JList; |
31 |
import javax.swing.JPanel; |
32 |
|
33 |
import org.gvsig.raster.util.TransparencyRange; |
34 |
import org.gvsig.rastertools.properties.dialog.IResizable; |
35 |
|
36 |
import com.iver.andami.PluginServices; |
37 |
|
38 |
/**
|
39 |
* Panel con los controles para la transparencia por pixel. Incluye los
|
40 |
* textbox para a?adir un RGB a la lista.
|
41 |
*
|
42 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
43 |
*
|
44 |
*/
|
45 |
public class TranspByPixelPanel extends JPanel implements IResizable{ |
46 |
final private static long serialVersionUID = 0; |
47 |
private TranspByPixelRGBInputPanel pWest = null; |
48 |
private JPanel pEast = null; |
49 |
private JPanel pCenter = null; |
50 |
private TranspByPixelAddRemoveButtonsPanel pButtons = null; |
51 |
private TranspByPixelAndOrSelectorPanel pOperation = null; |
52 |
private JList jList = null; |
53 |
private TranspByPixelListener listener = null; |
54 |
private DefaultListModel listModel = null; |
55 |
private boolean controlEnabled = false; |
56 |
private JPanel pixelSelector = null; |
57 |
private JPanel activeControl = null; |
58 |
private JCheckBox activeCheck = null; |
59 |
|
60 |
/**
|
61 |
* This is the default constructor
|
62 |
*/
|
63 |
public TranspByPixelPanel() {
|
64 |
super();
|
65 |
initialize(); |
66 |
listener = new TranspByPixelListener(this); |
67 |
this.setControlEnabled(false); |
68 |
} |
69 |
|
70 |
/**
|
71 |
* This method initializes this
|
72 |
*
|
73 |
* @return void
|
74 |
*/
|
75 |
private void initialize() { |
76 |
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)); |
77 |
setLayout(new BorderLayout()); |
78 |
add(getActiveControl(), BorderLayout.NORTH);
|
79 |
add(getPixelSelector(), BorderLayout.CENTER);
|
80 |
} |
81 |
|
82 |
/**
|
83 |
* Obtiene el panel con los controles principales para introducir valores
|
84 |
* RGB en la lista
|
85 |
* @return JPanel
|
86 |
*/
|
87 |
private JPanel getPixelSelector(){ |
88 |
if(pixelSelector == null){ |
89 |
pixelSelector = new JPanel(); |
90 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
91 |
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 15); |
92 |
gridBagConstraints.gridx = 0;
|
93 |
gridBagConstraints.gridy = 0;
|
94 |
|
95 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
96 |
gridBagConstraints1.insets = new java.awt.Insets(0, 0, 0, 40); |
97 |
gridBagConstraints1.gridx = 1;
|
98 |
gridBagConstraints1.gridy = 0;
|
99 |
|
100 |
GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
101 |
gridBagConstraints1.gridx = 2;
|
102 |
gridBagConstraints1.gridy = 0;
|
103 |
|
104 |
pixelSelector.setLayout(new GridBagLayout()); |
105 |
//setMinimumSize(new Dimension(400, 185));
|
106 |
|
107 |
pixelSelector.add(getPRGBInput(), gridBagConstraints); |
108 |
pixelSelector.add(getPCenter(), gridBagConstraints1); |
109 |
pixelSelector.add(getPList(), gridBagConstraints2); |
110 |
} |
111 |
return pixelSelector;
|
112 |
} |
113 |
|
114 |
/**
|
115 |
* Obtiene el panel con el control de activaci?n
|
116 |
* @return JPanel
|
117 |
*/
|
118 |
private JPanel getActiveControl(){ |
119 |
if(activeControl == null){ |
120 |
activeControl = new JPanel(); |
121 |
FlowLayout fl = new FlowLayout(); |
122 |
fl.setAlignment(FlowLayout.LEFT);
|
123 |
activeControl.setLayout(fl); |
124 |
activeControl.add(getActiveCheck(), null);
|
125 |
} |
126 |
return activeControl;
|
127 |
} |
128 |
|
129 |
/**
|
130 |
* Obtiene el check que activa y desactiva la transparencia por pixel.
|
131 |
* @return JCheckBox
|
132 |
*/
|
133 |
public JCheckBox getActiveCheck(){ |
134 |
if(activeCheck == null){ |
135 |
activeCheck = new JCheckBox(PluginServices.getText(this, "activar")); |
136 |
activeCheck.setSelected(false);
|
137 |
} |
138 |
return activeCheck;
|
139 |
} |
140 |
|
141 |
/**
|
142 |
* This method initializes jPanel
|
143 |
*
|
144 |
* @return javax.swing.JPanel
|
145 |
*/
|
146 |
public TranspByPixelRGBInputPanel getPRGBInput() {
|
147 |
if (pWest == null) { |
148 |
FlowLayout flowLayout = new FlowLayout(); |
149 |
flowLayout.setHgap(1);
|
150 |
flowLayout.setAlignment(java.awt.FlowLayout.LEFT); |
151 |
flowLayout.setVgap(1);
|
152 |
pWest = new TranspByPixelRGBInputPanel();
|
153 |
pWest.setLayout(flowLayout); |
154 |
pWest.setPreferredSize(new java.awt.Dimension(120,90)); |
155 |
} |
156 |
return pWest;
|
157 |
} |
158 |
|
159 |
/**
|
160 |
* This method initializes jPanel1
|
161 |
*
|
162 |
* @return javax.swing.JPanel
|
163 |
*/
|
164 |
public JPanel getPList() { |
165 |
if (pEast == null) { |
166 |
GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); |
167 |
gridBagConstraints3.fill = java.awt.GridBagConstraints.BOTH; |
168 |
gridBagConstraints3.gridx = 0;
|
169 |
gridBagConstraints3.gridy = 0;
|
170 |
gridBagConstraints3.weightx = 1.0;
|
171 |
gridBagConstraints3.weighty = 1.0;
|
172 |
gridBagConstraints3.insets = new java.awt.Insets(0,0,0,0); |
173 |
pEast = new JPanel(); |
174 |
pEast.setLayout(new GridBagLayout()); |
175 |
pEast.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED)); |
176 |
pEast.add(getJList(), gridBagConstraints3); |
177 |
} |
178 |
return pEast;
|
179 |
} |
180 |
|
181 |
/**
|
182 |
* This method initializes jPanel2
|
183 |
*
|
184 |
* @return javax.swing.JPanel
|
185 |
*/
|
186 |
private JPanel getPCenter() { |
187 |
if (pCenter == null) { |
188 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
189 |
gridBagConstraints1.insets = new java.awt.Insets(0,0,0,0); |
190 |
gridBagConstraints1.gridy = 1;
|
191 |
gridBagConstraints1.gridx = 0;
|
192 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
193 |
gridBagConstraints.insets = new java.awt.Insets(0,0,0,0); |
194 |
gridBagConstraints.gridy = 0;
|
195 |
gridBagConstraints.gridx = 0;
|
196 |
pCenter = new JPanel(); |
197 |
pCenter.setLayout(new GridBagLayout()); |
198 |
pCenter.setPreferredSize(new java.awt.Dimension(65,118)); |
199 |
pCenter.add(getPButtons(), gridBagConstraints); |
200 |
pCenter.add(getPOperation(), gridBagConstraints1); |
201 |
} |
202 |
return pCenter;
|
203 |
} |
204 |
|
205 |
/**
|
206 |
* This method initializes jPanel
|
207 |
*
|
208 |
* @return javax.swing.JPanel
|
209 |
*/
|
210 |
public JPanel getPButtons() { |
211 |
if (pButtons == null) { |
212 |
pButtons = new TranspByPixelAddRemoveButtonsPanel();
|
213 |
pButtons.setPreferredSize(new java.awt.Dimension(60,50)); |
214 |
} |
215 |
return pButtons;
|
216 |
} |
217 |
|
218 |
/**
|
219 |
* This method initializes jPanel1
|
220 |
*
|
221 |
* @return javax.swing.JPanel
|
222 |
*/
|
223 |
public JPanel getPOperation() { |
224 |
if (pOperation == null) { |
225 |
pOperation = new TranspByPixelAndOrSelectorPanel();
|
226 |
pOperation.setPreferredSize(new java.awt.Dimension(60,60)); |
227 |
} |
228 |
return pOperation;
|
229 |
} |
230 |
|
231 |
/**
|
232 |
* This method initializes jList
|
233 |
*
|
234 |
* @return javax.swing.JList
|
235 |
*/
|
236 |
public JList getJList() { |
237 |
if (jList == null) { |
238 |
listModel = new DefaultListModel(); |
239 |
jList = new JList(listModel); |
240 |
jList.setPreferredSize(new java.awt.Dimension(140,100)); |
241 |
jList.setFont(new java.awt.Font("Monospaced", java.awt.Font.PLAIN, 10)); |
242 |
} |
243 |
return jList;
|
244 |
} |
245 |
|
246 |
/**
|
247 |
* Obtiene el ListModel de la lista
|
248 |
* @return DefaultListModel
|
249 |
*/
|
250 |
public DefaultListModel getListModel(){ |
251 |
return listModel;
|
252 |
} |
253 |
|
254 |
/**
|
255 |
* Asigna los tama?os de los componentes y el panel a partir del tama?o
|
256 |
* introducido.
|
257 |
* @param w
|
258 |
* @param h
|
259 |
*/
|
260 |
public void setComponentSize(int w, int h){ |
261 |
|
262 |
} |
263 |
|
264 |
|
265 |
/**
|
266 |
* Activa o desactiva el control
|
267 |
* @param enable True activa el control y false lo desactiva
|
268 |
*/
|
269 |
public void setControlEnabled(boolean enabled){ |
270 |
this.getActiveCheck().setSelected(enabled);
|
271 |
jList.setEnabled(enabled); |
272 |
if(enabled)
|
273 |
jList.setBackground(Color.WHITE);
|
274 |
else
|
275 |
jList.setBackground(this.getBackground());
|
276 |
pWest.setControlEnabled(enabled); |
277 |
pButtons.setControlEnabled(enabled); |
278 |
pOperation.setControlEnabled(enabled); |
279 |
controlEnabled = enabled; |
280 |
} |
281 |
|
282 |
/**
|
283 |
* Obtiene true si el control est? activo y false si no lo est?
|
284 |
* @return
|
285 |
*/
|
286 |
public boolean isControlEnabled(){ |
287 |
return controlEnabled;
|
288 |
} |
289 |
|
290 |
/**
|
291 |
* Asigna el n?mero de bandas activas
|
292 |
* @param n N?mero de bandas
|
293 |
*/
|
294 |
public void setActiveBands(int n){ |
295 |
((TranspByPixelRGBInputPanel)getPRGBInput()).setActiveBands(n); |
296 |
} |
297 |
|
298 |
/**
|
299 |
* Obtiene el array de entradas de valores a?adidos a la lista
|
300 |
* @return ArrayList
|
301 |
*/
|
302 |
public ArrayList getEntries(){ |
303 |
return listener.getEntries();
|
304 |
} |
305 |
|
306 |
/**
|
307 |
* Asigna el array de entradas de valores a?adidos a la lista
|
308 |
* @return ArrayList
|
309 |
*/
|
310 |
public void setEntries(ArrayList list){ |
311 |
this.listener.setEntries(list);
|
312 |
} |
313 |
|
314 |
/**
|
315 |
* Obtiene la clase manejadora de eventos asociada a esta
|
316 |
* @return TransparencyByPixelListener
|
317 |
*/
|
318 |
public TranspByPixelListener getListener() {
|
319 |
return listener;
|
320 |
} |
321 |
|
322 |
/**
|
323 |
* A?ade una entrada a la tabla
|
324 |
* @param entry Cadena en formato definido por TransparencyRange
|
325 |
*/
|
326 |
public void addStringElement(String entry){ |
327 |
getListModel().addElement(entry); |
328 |
getEntries().add(new TransparencyRange(entry));
|
329 |
} |
330 |
|
331 |
/**
|
332 |
* A?ade una entrada a la tabla
|
333 |
* @param entry objeto TransparencyRange
|
334 |
*/
|
335 |
public void addStringElement(TransparencyRange entry){ |
336 |
getListModel().addElement(entry.getStrEntry()); |
337 |
getEntries().add(entry); |
338 |
} |
339 |
|
340 |
/**
|
341 |
* Borra las entradas de la tabla
|
342 |
*/
|
343 |
public void clear(){ |
344 |
pWest.clear(); |
345 |
getListModel().clear(); |
346 |
getEntries().clear(); |
347 |
} |
348 |
} |