gvsig-raster / org.gvsig.raster.tools / branches / org.gvsig.raster.tools_dataaccess_refactoring / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / filter / regionalpha / RegionAlphaUI.java @ 2328
History | View | Annotate | Download (7.89 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.grid.FilterUIListener; |
42 |
import org.gvsig.fmap.dal.coverage.grid.RegistrableFilterListener; |
43 |
import org.gvsig.gui.beans.table.TableContainer; |
44 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
45 |
import org.gvsig.i18n.Messages; |
46 |
import org.gvsig.raster.roi.ROI; |
47 |
/**
|
48 |
* Es el interfaz gr?fico que contiene el filtro de regiones de interes.
|
49 |
* En el se muestra una tabla con las posibles Rois a seleccionar y tambi?n
|
50 |
* un Checkbox para definir si la seleccion es normal o invertida.
|
51 |
*
|
52 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
53 |
*/
|
54 |
public class RegionAlphaUI extends JPanel implements RegistrableFilterListener, TableModelListener, ChangeListener { |
55 |
private static final long serialVersionUID = 4525736825113598035L; |
56 |
private TableContainer tableContainer = null; |
57 |
private JLabel warning = null; |
58 |
private List<ROI> roiList = null; |
59 |
private JCheckBox negative = null; |
60 |
private boolean lastInv = false; |
61 |
protected Params params = null; |
62 |
private ArrayList<FilterUIListener> |
63 |
actionCommandListeners = new ArrayList<FilterUIListener>(); |
64 |
|
65 |
/**
|
66 |
* Constructor de un RegionAlphaUI
|
67 |
*/
|
68 |
public RegionAlphaUI() {
|
69 |
init(null);
|
70 |
} |
71 |
|
72 |
public void init(Object obj) { |
73 |
setLayout(new BorderLayout()); |
74 |
add(getTableContainer(), BorderLayout.CENTER);
|
75 |
add(getWarning(), BorderLayout.NORTH);
|
76 |
add(getInverse(), BorderLayout.SOUTH);
|
77 |
} |
78 |
|
79 |
/**
|
80 |
* Obtiene el contenedor con la tabla.
|
81 |
* @return
|
82 |
*/
|
83 |
private TableContainer getTableContainer() {
|
84 |
if (tableContainer == null) { |
85 |
String[] columnNames = {" ", "Nombre", ""}; |
86 |
int[] columnWidths = {22, 334, 0}; |
87 |
tableContainer = new TableContainer(columnNames, columnWidths);
|
88 |
tableContainer.setPreferredSize(new Dimension(0, 130)); |
89 |
tableContainer.setModel("CheckBoxModel");
|
90 |
tableContainer.initialize(); |
91 |
tableContainer.setControlVisible(false);
|
92 |
tableContainer.setMoveRowsButtonsVisible(false);
|
93 |
tableContainer.getTable().getJTable().getColumnModel().getColumn(0).setMinWidth(22); |
94 |
tableContainer.getTable().getJTable().getColumnModel().getColumn(0).setMaxWidth(22); |
95 |
tableContainer.getTable().getJTable().getColumnModel().getColumn(2).setMinWidth(0); |
96 |
tableContainer.getTable().getJTable().getColumnModel().getColumn(2).setMaxWidth(0); |
97 |
tableContainer.getModel().addTableModelListener(this);
|
98 |
} |
99 |
return tableContainer;
|
100 |
} |
101 |
|
102 |
/**
|
103 |
* Obtiene el checkbox que informa de si selecciona lo que contiene las Rois
|
104 |
* o su inversa.
|
105 |
* @return JCheckBox
|
106 |
*/
|
107 |
private JCheckBox getInverse() { |
108 |
if (negative == null) { |
109 |
negative = new JCheckBox(); |
110 |
negative.setText(Messages.getText("inversa"));
|
111 |
negative.addChangeListener(this);
|
112 |
} |
113 |
return negative;
|
114 |
} |
115 |
|
116 |
/**
|
117 |
* Obtiene el mensaje de aviso de que no hay rois en la lista. Esta etiqueta solo
|
118 |
* es mostrada en caso en que la capa no tenga ROIs asociadas.
|
119 |
* @return JLabel Etiqueta con el mensaje de aviso.
|
120 |
*/
|
121 |
public JLabel getWarning() { |
122 |
if(warning == null) { |
123 |
warning = new JLabel(Messages.getText("rois_needed")); |
124 |
warning.setVisible(false);
|
125 |
} |
126 |
return warning;
|
127 |
} |
128 |
|
129 |
/**
|
130 |
* Asigna la capa.
|
131 |
* @param layer
|
132 |
*/
|
133 |
public void setROIList(List<ROI> roiList) { |
134 |
this.roiList = roiList;
|
135 |
if(roiList == null || roiList.size() == 0) |
136 |
getWarning().setVisible(true);
|
137 |
|
138 |
if (roiList != null) { |
139 |
for (int i = 0; i < roiList.size(); i++) { |
140 |
ROI roi = (ROI) roiList.get(i); |
141 |
|
142 |
Object row[] = {"", "", ""}; |
143 |
|
144 |
boolean active = false; |
145 |
|
146 |
if (roiList != null) { |
147 |
for (int r = 0; r < roiList.size(); r++) { |
148 |
if (((ROI) roiList.get(r)) == roi) {
|
149 |
active = true;
|
150 |
break;
|
151 |
} |
152 |
} |
153 |
} |
154 |
|
155 |
row[0] = new Boolean(active); |
156 |
row[1] = roi.getName();
|
157 |
row[2] = new Integer(i); |
158 |
try {
|
159 |
getTableContainer().addRow(row); |
160 |
} catch (NotInitializeException e) {
|
161 |
} |
162 |
} |
163 |
} |
164 |
} |
165 |
|
166 |
/**
|
167 |
* Obtiene la lista de ROIs seleccionadas
|
168 |
* @return ArrayList con la lista de ROIs
|
169 |
*/
|
170 |
private List<ROI> getSelectedROIs() { |
171 |
List<ROI> selected = new ArrayList<ROI>(); |
172 |
if (roiList != null) { |
173 |
for (int i = 0; i < roiList.size(); i++) { |
174 |
try {
|
175 |
if (((Boolean) tableContainer.getModel().getValueAt(i, 0)).booleanValue()) { |
176 |
selected.add(roiList.get(i)); |
177 |
} |
178 |
} catch (ArrayIndexOutOfBoundsException e) { |
179 |
//Entra aqu? si se han a?adido ROIs con el cuadro abierto. Pasamos de hacer nada
|
180 |
} |
181 |
} |
182 |
} |
183 |
return selected;
|
184 |
} |
185 |
|
186 |
private boolean[] getPositionSelectedROIs() { |
187 |
boolean[] selectedROIs = new boolean[tableContainer.getModel().getRowCount()]; |
188 |
|
189 |
for (int i = 0; i < tableContainer.getModel().getRowCount(); i++) { |
190 |
try {
|
191 |
selectedROIs[i] = ((Boolean) tableContainer.getModel().getValueAt(i, 0)).booleanValue(); |
192 |
} catch (ArrayIndexOutOfBoundsException e) { |
193 |
//Entra aqu? si se han a?adido ROIs con el cuadro abierto. Pasamos de hacer nada
|
194 |
} |
195 |
} |
196 |
|
197 |
return selectedROIs;
|
198 |
} |
199 |
|
200 |
/**
|
201 |
* Sobrecargamos el m?todo getParams para que siempre devuelva
|
202 |
* algo.
|
203 |
*/
|
204 |
public Params getParams() {
|
205 |
params = RasterLocator.getManager().createParams( |
206 |
"rois_selected",
|
207 |
getPositionSelectedROIs(), |
208 |
-1,
|
209 |
null);
|
210 |
params.setParam("inverse",
|
211 |
new Boolean(getInverse().isSelected()), |
212 |
-1,
|
213 |
null);
|
214 |
return params;
|
215 |
} |
216 |
|
217 |
public void tableChanged(TableModelEvent e) { |
218 |
callStateChanged(); |
219 |
} |
220 |
|
221 |
/**
|
222 |
* Cambio de estado para el check de inversa
|
223 |
* @param e
|
224 |
*/
|
225 |
public void stateChanged(ChangeEvent e) { |
226 |
if (e.getSource().equals(getInverse())) {
|
227 |
if (((JCheckBox) e.getSource()).isSelected() != lastInv) { |
228 |
callStateChanged(); |
229 |
lastInv = ((JCheckBox) e.getSource()).isSelected();
|
230 |
} |
231 |
} |
232 |
} |
233 |
|
234 |
public void addFilterUIListener(FilterUIListener listener) { |
235 |
if (!actionCommandListeners.contains(listener))
|
236 |
actionCommandListeners.add(listener); |
237 |
} |
238 |
|
239 |
public void callStateChanged() { |
240 |
Iterator<FilterUIListener> acIterator = actionCommandListeners.iterator();
|
241 |
while (acIterator.hasNext()) {
|
242 |
FilterUIListener listener = (FilterUIListener) acIterator.next(); |
243 |
listener.actionValuesCompleted(new EventObject(this)); |
244 |
} |
245 |
} |
246 |
|
247 |
public void removeStateChangedListener(FilterUIListener listener) { |
248 |
actionCommandListeners.remove(listener); |
249 |
} |
250 |
} |