gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / filter / regionalpha / RegionAlphaUI.java @ 2125
History | View | Annotate | Download (8.81 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.tools.app.basic.tool.filter.regionalpha; |
23 |
|
24 |
import java.awt.BorderLayout; |
25 |
import java.awt.Dimension; |
26 |
import java.util.ArrayList; |
27 |
import java.util.EventObject; |
28 |
import java.util.Iterator; |
29 |
import java.util.List; |
30 |
|
31 |
import javax.swing.JCheckBox; |
32 |
import javax.swing.JLabel; |
33 |
import javax.swing.JPanel; |
34 |
import javax.swing.event.ChangeEvent; |
35 |
import javax.swing.event.ChangeListener; |
36 |
import javax.swing.event.TableModelEvent; |
37 |
import javax.swing.event.TableModelListener; |
38 |
|
39 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
40 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
41 |
import org.gvsig.fmap.dal.coverage.exception.ROIException; |
42 |
import org.gvsig.fmap.dal.coverage.grid.FilterUIListener; |
43 |
import org.gvsig.fmap.dal.coverage.grid.RegistrableFilterListener; |
44 |
import org.gvsig.gui.beans.table.TableContainer; |
45 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
46 |
import org.gvsig.i18n.Messages; |
47 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
48 |
import org.gvsig.raster.roi.ROI; |
49 |
import org.gvsig.raster.tools.app.basic.RasterToolsUtil; |
50 |
/**
|
51 |
* Es el interfaz gr?fico que contiene el filtro de regiones de interes.
|
52 |
* En el se muestra una tabla con las posibles Rois a seleccionar y tambi?n
|
53 |
* un Checkbox para definir si la seleccion es normal o invertida.
|
54 |
*
|
55 |
* @version 17/01/2008
|
56 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
57 |
*/
|
58 |
public class RegionAlphaUI extends JPanel implements RegistrableFilterListener, TableModelListener, ChangeListener { |
59 |
private static final long serialVersionUID = 4525736825113598035L; |
60 |
private TableContainer tableContainer = null; |
61 |
private FLyrRaster layer = null; |
62 |
private JLabel warning = null; |
63 |
private ArrayList<ROI> rois = null; |
64 |
private JCheckBox negative = null; |
65 |
private boolean lastInv = false; |
66 |
protected Params params = null; |
67 |
private ArrayList<FilterUIListener> |
68 |
actionCommandListeners = new ArrayList<FilterUIListener>(); |
69 |
|
70 |
/**
|
71 |
* Constructor de un RegionAlphaUI
|
72 |
*/
|
73 |
public RegionAlphaUI() {
|
74 |
init(null);
|
75 |
} |
76 |
|
77 |
public void init(Object obj) { |
78 |
setLayout(new BorderLayout()); |
79 |
add(getTableContainer(), BorderLayout.CENTER);
|
80 |
add(getWarning(), BorderLayout.NORTH);
|
81 |
add(getInverse(), BorderLayout.SOUTH);
|
82 |
} |
83 |
|
84 |
/**
|
85 |
* Obtiene el contenedor con la tabla.
|
86 |
* @return
|
87 |
*/
|
88 |
private TableContainer getTableContainer() {
|
89 |
if (tableContainer == null) { |
90 |
String[] columnNames = {" ", "Nombre", ""}; |
91 |
int[] columnWidths = {22, 334, 0}; |
92 |
tableContainer = new TableContainer(columnNames, columnWidths);
|
93 |
tableContainer.setPreferredSize(new Dimension(0, 130)); |
94 |
tableContainer.setModel("CheckBoxModel");
|
95 |
tableContainer.initialize(); |
96 |
tableContainer.setControlVisible(false);
|
97 |
tableContainer.setMoveRowsButtonsVisible(false);
|
98 |
tableContainer.getTable().getJTable().getColumnModel().getColumn(0).setMinWidth(22); |
99 |
tableContainer.getTable().getJTable().getColumnModel().getColumn(0).setMaxWidth(22); |
100 |
tableContainer.getTable().getJTable().getColumnModel().getColumn(2).setMinWidth(0); |
101 |
tableContainer.getTable().getJTable().getColumnModel().getColumn(2).setMaxWidth(0); |
102 |
tableContainer.getModel().addTableModelListener(this);
|
103 |
} |
104 |
return tableContainer;
|
105 |
} |
106 |
|
107 |
/**
|
108 |
* Obtiene el checkbox que informa de si selecciona lo que contiene las Rois
|
109 |
* o su inversa.
|
110 |
* @return JCheckBox
|
111 |
*/
|
112 |
private JCheckBox getInverse() { |
113 |
if (negative == null) { |
114 |
negative = new JCheckBox(); |
115 |
negative.setText(RasterToolsUtil.getText(this, "inversa")); |
116 |
negative.addChangeListener(this);
|
117 |
} |
118 |
return negative;
|
119 |
} |
120 |
|
121 |
/**
|
122 |
* Obtiene el mensaje de aviso de que no hay rois en la lista. Esta etiqueta solo
|
123 |
* es mostrada en caso en que la capa no tenga ROIs asociadas.
|
124 |
* @return JLabel Etiqueta con el mensaje de aviso.
|
125 |
*/
|
126 |
public JLabel getWarning() { |
127 |
if(warning == null) { |
128 |
warning = new JLabel(RasterToolsUtil.getText(this, "rois_needed")); |
129 |
warning.setVisible(false);
|
130 |
} |
131 |
return warning;
|
132 |
} |
133 |
|
134 |
/**
|
135 |
* Asigna la lista de regiones de inter?s.
|
136 |
* @param rois Lista de ROIs
|
137 |
*/
|
138 |
public void setRois(ArrayList<ROI> rois) { |
139 |
this.rois = rois;
|
140 |
} |
141 |
|
142 |
/**
|
143 |
* Asigna la capa.
|
144 |
* @param layer
|
145 |
*/
|
146 |
public void setLayer(FLyrRaster layer) { |
147 |
this.layer = layer;
|
148 |
if (layer == null) |
149 |
return;
|
150 |
|
151 |
List<ROI> roisArray = null; |
152 |
try {
|
153 |
roisArray = ((FLyrRaster) layer).getRois(); |
154 |
} catch (ROIException e1) {
|
155 |
RasterToolsUtil.messageBoxError(Messages.getText("problems_loading_rois"), null); |
156 |
} |
157 |
|
158 |
if(roisArray == null || roisArray.size() == 0) |
159 |
getWarning().setVisible(true);
|
160 |
|
161 |
if (roisArray != null) { |
162 |
for (int i = 0; i < roisArray.size(); i++) { |
163 |
ROI roi = (ROI) roisArray.get(i); |
164 |
|
165 |
Object row[] = {"", "", ""}; |
166 |
|
167 |
boolean active = false; |
168 |
|
169 |
if (rois != null) { |
170 |
for (int r = 0; r < rois.size(); r++) { |
171 |
if (((ROI) rois.get(r)) == roi) {
|
172 |
active = true;
|
173 |
break;
|
174 |
} |
175 |
} |
176 |
} |
177 |
|
178 |
row[0] = new Boolean(active); |
179 |
row[1] = roi.getName();
|
180 |
row[2] = new Integer(i); |
181 |
try {
|
182 |
getTableContainer().addRow(row); |
183 |
} catch (NotInitializeException e) {
|
184 |
} |
185 |
} |
186 |
} |
187 |
} |
188 |
|
189 |
/**
|
190 |
* Obtiene la lista de ROIs seleccionadas
|
191 |
* @return ArrayList con la lista de ROIs
|
192 |
*/
|
193 |
private List<ROI> getSelectedROIs() { |
194 |
if (layer == null) |
195 |
return null; |
196 |
|
197 |
List<ROI> roisArray = null; |
198 |
try {
|
199 |
roisArray = ((FLyrRaster) layer).getRois(); |
200 |
} catch (ROIException e1) {
|
201 |
} |
202 |
List<ROI> selected = new ArrayList<ROI>(); |
203 |
if (roisArray != null) { |
204 |
for (int i = 0; i < roisArray.size(); i++) { |
205 |
try {
|
206 |
if (((Boolean) tableContainer.getModel().getValueAt(i, 0)).booleanValue()) { |
207 |
selected.add(roisArray.get(i)); |
208 |
} |
209 |
} catch (ArrayIndexOutOfBoundsException e) { |
210 |
//Entra aqu? si se han a?adido ROIs con el cuadro abierto. Pasamos de hacer nada
|
211 |
} |
212 |
} |
213 |
} |
214 |
return selected;
|
215 |
} |
216 |
|
217 |
/**
|
218 |
* Sobrecargamos el m?todo getParams para que siempre devuelva
|
219 |
* algo.
|
220 |
*/
|
221 |
public Params getParams() {
|
222 |
params = RasterLocator.getManager().createParams( |
223 |
"rois",
|
224 |
getSelectedROIs(), |
225 |
-1,
|
226 |
null);
|
227 |
params.setParam("inverse",
|
228 |
new Boolean(getInverse().isSelected()), |
229 |
-1,
|
230 |
null);
|
231 |
return params;
|
232 |
} |
233 |
|
234 |
/*
|
235 |
* (non-Javadoc)
|
236 |
* @see javax.swing.event.TableModelListener#tableChanged(javax.swing.event.TableModelEvent)
|
237 |
*/
|
238 |
public void tableChanged(TableModelEvent e) { |
239 |
callStateChanged(); |
240 |
} |
241 |
|
242 |
/**
|
243 |
* Cambio de estado para el check de inversa
|
244 |
* @param e
|
245 |
*/
|
246 |
public void stateChanged(ChangeEvent e) { |
247 |
if (e.getSource().equals(getInverse())) {
|
248 |
if (((JCheckBox) e.getSource()).isSelected() != lastInv) { |
249 |
callStateChanged(); |
250 |
lastInv = ((JCheckBox) e.getSource()).isSelected();
|
251 |
} |
252 |
} |
253 |
} |
254 |
|
255 |
|
256 |
/*
|
257 |
* (non-Javadoc)
|
258 |
* @see org.gvsig.fmap.dal.coverage.grid.RegistrableFilterListener#addFilterUIListener(org.gvsig.fmap.dal.coverage.grid.FilterUIListener)
|
259 |
*/
|
260 |
public void addFilterUIListener(FilterUIListener listener) { |
261 |
if (!actionCommandListeners.contains(listener))
|
262 |
actionCommandListeners.add(listener); |
263 |
} |
264 |
|
265 |
/*
|
266 |
* (non-Javadoc)
|
267 |
* @see org.gvsig.fmap.dal.coverage.grid.RegistrableFilterListener#callStateChanged()
|
268 |
*/
|
269 |
public void callStateChanged() { |
270 |
Iterator<FilterUIListener> acIterator = actionCommandListeners.iterator();
|
271 |
while (acIterator.hasNext()) {
|
272 |
FilterUIListener listener = (FilterUIListener) acIterator.next(); |
273 |
listener.actionValuesCompleted(new EventObject(this)); |
274 |
} |
275 |
} |
276 |
|
277 |
/*
|
278 |
* (non-Javadoc)
|
279 |
* @see org.gvsig.fmap.dal.coverage.grid.RegistrableFilterListener#removeStateChangedListener(org.gvsig.fmap.dal.coverage.grid.FilterUIListener)
|
280 |
*/
|
281 |
public void removeStateChangedListener(FilterUIListener listener) { |
282 |
actionCommandListeners.remove(listener); |
283 |
} |
284 |
} |