Revision 10981 trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/HistogramPanelListener.java
HistogramPanelListener.java | ||
---|---|---|
30 | 30 |
import org.gvsig.gui.beans.incrementabletask.IncrementableEvent; |
31 | 31 |
import org.gvsig.gui.beans.incrementabletask.IncrementableListener; |
32 | 32 |
import org.gvsig.gui.beans.incrementabletask.IncrementableTask; |
33 |
import org.gvsig.raster.dataset.properties.DatasetStatistics;
|
|
33 |
import org.gvsig.raster.util.Histogram;
|
|
34 | 34 |
import org.gvsig.raster.util.IHistogramable; |
35 | 35 |
import org.gvsig.rastertools.histogram.ui.HistogramPanel; |
36 | 36 |
/** |
... | ... | |
41 | 41 |
* @author Borja Sanchez Zamorano (borja.sanchez@iver.es) |
42 | 42 |
*/ |
43 | 43 |
public class HistogramPanelListener implements ActionListener, KeyListener, IncrementableListener { |
44 |
private HistogramPanel histogramPanel = null; |
|
45 |
private IncrementableTask incrementableTask = null; |
|
46 |
private HistogramProcess histogramProcess = null; |
|
47 |
private long[][] lastHistogram = null; |
|
44 | 48 |
|
45 |
private HistogramPanel panel = null; |
|
46 |
|
|
47 |
private IncrementableTask incrementableTask = null; |
|
48 |
private HistogramProcess histogramProcess = null; |
|
49 |
/** |
|
50 |
* Objeto histograma para la gesti?n de procesos de histograma |
|
51 |
*/ |
|
52 |
// private Histogram histogram = null; |
|
53 |
/** |
|
54 |
* ?ltimo histograma visualizado en el gr?fico |
|
55 |
*/ |
|
56 |
private int[][] lastHistogram = null; |
|
57 |
|
|
58 |
public static boolean comboEventEnable = true; |
|
49 |
public boolean comboEventEnable = false; |
|
59 | 50 |
|
60 | 51 |
public HistogramPanelListener(HistogramPanel p){ |
61 |
panel = p;
|
|
52 |
histogramPanel = p;
|
|
62 | 53 |
} |
63 | 54 |
|
64 | 55 |
public void setControlListeners(){ |
65 |
panel.getGraphicContainer().getPlusButtonControlLeft().addActionListener(this);
|
|
66 |
panel.getGraphicContainer().getPlusButtonControlRight().addActionListener(this);
|
|
67 |
panel.getGraphicContainer().getLessButtonControlLeft().addActionListener(this);
|
|
68 |
panel.getGraphicContainer().getLessButtonControlRight().addActionListener(this);
|
|
69 |
panel.getGraphicContainer().getTextControlRight().addKeyListener(this);
|
|
70 |
panel.getGraphicContainer().getTextControlLeft().addKeyListener(this);
|
|
56 |
histogramPanel.getGraphicContainer().getPlusButtonControlLeft().addActionListener(this);
|
|
57 |
histogramPanel.getGraphicContainer().getPlusButtonControlRight().addActionListener(this);
|
|
58 |
histogramPanel.getGraphicContainer().getLessButtonControlLeft().addActionListener(this);
|
|
59 |
histogramPanel.getGraphicContainer().getLessButtonControlRight().addActionListener(this);
|
|
60 |
histogramPanel.getGraphicContainer().getTextControlRight().addKeyListener(this);
|
|
61 |
histogramPanel.getGraphicContainer().getTextControlLeft().addKeyListener(this);
|
|
71 | 62 |
} |
72 | 63 |
|
73 | 64 |
|
74 | 65 |
public void keyPressed(KeyEvent e) { |
75 | 66 |
if (e.getKeyCode() == 10) { |
76 | 67 |
updateStatistic(); |
68 |
updateGraphic(); |
|
77 | 69 |
} |
78 | 70 |
} |
79 | 71 |
|
80 | 72 |
private void updateStatistic() { |
81 |
// TODO Actualizar tabla de los histogramas.
|
|
82 |
panel.setStatistic(DatasetStatistics.getBasicStatsFromHistogram(getLastHistogram(), (int)panel.getBoxesValues()[1], (int)panel.getBoxesValues()[0], panel.showBands));
|
|
73 |
// TODO Actualizar tabla de los histogramas.
|
|
74 |
// histogramPanel.setStatistic(DatasetStatistics.getBasicStatsFromHistogram(getLastHistogram(), (int)panel.getBoxesValues()[1], (int)panel.getBoxesValues()[0], panel.showBands));
|
|
83 | 75 |
} |
84 | 76 |
|
77 |
|
|
85 | 78 |
public void actionPerformed(ActionEvent e) { |
86 | 79 |
//Botones de m?s y menos |
87 |
if (e.getSource() == panel.getGraphicContainer().getPlusButtonControlLeft() ||
|
|
88 |
e.getSource() == panel.getGraphicContainer().getLessButtonControlLeft() ||
|
|
89 |
e.getSource() == panel.getGraphicContainer().getPlusButtonControlRight() ||
|
|
90 |
e.getSource() == panel.getGraphicContainer().getLessButtonControlRight() ) {
|
|
80 |
if (e.getSource() == histogramPanel.getGraphicContainer().getPlusButtonControlLeft() ||
|
|
81 |
e.getSource() == histogramPanel.getGraphicContainer().getLessButtonControlLeft() ||
|
|
82 |
e.getSource() == histogramPanel.getGraphicContainer().getPlusButtonControlRight() ||
|
|
83 |
e.getSource() == histogramPanel.getGraphicContainer().getLessButtonControlRight() ) {
|
|
91 | 84 |
updateStatistic(); |
85 |
updateGraphic(); |
|
92 | 86 |
return; |
93 | 87 |
} |
94 | 88 |
|
95 | 89 |
//-------------------------------------- |
96 | 90 |
//Cambiar las bandas en el combo |
97 |
JComboBox cbb = panel.getJComboBands(); |
|
98 |
if (comboEventEnable && e.getSource() == cbb) { |
|
91 |
JComboBox cbb = histogramPanel.getJComboBands(); |
|
92 |
if (comboEventEnable && (e.getSource() == cbb)) { |
|
93 |
if (cbb.getSelectedItem() == null) return; |
|
99 | 94 |
if(cbb.getSelectedIndex() == 0) { |
100 |
boolean[] list = panel.getBandListShowInChart();
|
|
95 |
boolean[] list = histogramPanel.getBandListShowInChart();
|
|
101 | 96 |
for (int i = 0; i < list.length; i++) |
102 | 97 |
list[i] = true; |
103 |
panel.setBandListShowInChart(list); |
|
104 |
} else if(cbb.getSelectedItem().equals("R") || cbb.getSelectedItem().equals("Band 0")) |
|
105 |
panel.addOrRemoveGraphicBand(0); |
|
106 |
else if(cbb.getSelectedItem().equals("G") || cbb.getSelectedItem().equals("Band 1")) |
|
107 |
panel.addOrRemoveGraphicBand(1); |
|
108 |
else if(cbb.getSelectedItem().equals("B") || cbb.getSelectedItem().equals("Band 2")) |
|
109 |
panel.addOrRemoveGraphicBand(2); |
|
110 |
else { |
|
111 |
for (int i = 3; i < HistogramPanel.MAXBANDS; i++) { |
|
112 |
if (cbb.getSelectedItem().equals("Band "+i)) |
|
113 |
panel.addOrRemoveGraphicBand(i); |
|
114 |
} |
|
98 |
histogramPanel.setBandListShowInChart(list); |
|
99 |
return; |
|
115 | 100 |
} |
101 |
if (cbb.getSelectedItem().equals("R")) { |
|
102 |
histogramPanel.addOrRemoveGraphicBand(0); |
|
103 |
return; |
|
104 |
} |
|
105 |
if(cbb.getSelectedItem().equals("G")) { |
|
106 |
histogramPanel.addOrRemoveGraphicBand(1); |
|
107 |
return; |
|
108 |
} |
|
109 |
if(cbb.getSelectedItem().equals("B")) { |
|
110 |
histogramPanel.addOrRemoveGraphicBand(2); |
|
111 |
return; |
|
112 |
} |
|
113 |
for (int i = 0; i < HistogramPanel.MAXBANDS; i++) { |
|
114 |
if (cbb.getSelectedItem().equals("Band "+i)) |
|
115 |
histogramPanel.addOrRemoveGraphicBand(i); |
|
116 |
} |
|
116 | 117 |
return; |
117 | 118 |
} |
118 | 119 |
|
119 | 120 |
//-------------------------------------- |
120 | 121 |
//Limpiar |
121 |
JButton clean = panel.getJButtonClear();
|
|
122 |
JButton clean = histogramPanel.getJButtonClear();
|
|
122 | 123 |
if (e.getSource() == clean) { |
123 |
panel.cleanChart();
|
|
124 |
cleanChart(); |
|
124 | 125 |
return; |
125 | 126 |
} |
126 | 127 |
|
127 | 128 |
//-------------------------------------- |
128 | 129 |
//Selecci?n de fuente de datos del histograma |
129 |
JComboBox cbo = panel.getJComboBoxOrigen();
|
|
130 |
JComboBox cbo = histogramPanel.getJComboBoxOrigen();
|
|
130 | 131 |
if (comboEventEnable && e.getSource() == cbo) { |
131 |
// showHistogram();
|
|
132 |
showHistogram(); |
|
132 | 133 |
// panel.setHistogramDataSource(cbo.getSelectedIndex()); |
133 | 134 |
|
134 | 135 |
//En caso de que el histograma se monte a partir de los datos de la vista ponemos RGB en el combo |
... | ... | |
138 | 139 |
//En caso de que el histograma se monte a partir de los datos reales ponemos el n?mero de bandas en el combo |
139 | 140 |
// if (cbo.getSelectedIndex() == 1 || cbo.getSelectedIndex() == 2) |
140 | 141 |
// panel.setBands(getHistogram().getGrid().getGrid().getBandCount()); |
142 |
return; |
|
141 | 143 |
} |
142 | 144 |
|
143 | 145 |
//-------------------------------------- |
144 | 146 |
//Selecci?n de histograma acumulado y no acumulado |
145 |
JComboBox cbt = panel.getJComboBoxTipo();
|
|
147 |
JComboBox cbt = histogramPanel.getJComboBoxTipo();
|
|
146 | 148 |
if (comboEventEnable && e.getSource() == cbt) { |
147 |
panel.setType(cbt.getSelectedIndex()); |
|
149 |
histogramPanel.setType(cbt.getSelectedIndex()); |
|
150 |
showHistogram(); |
|
151 |
return; |
|
148 | 152 |
} |
149 |
|
|
150 |
// if(comboEventEnable) |
|
151 |
// panel.showHistogram(); |
|
152 |
|
|
153 | 153 |
} |
154 | 154 |
|
155 |
/** |
|
156 |
* Obtiene el ?ltimo histograma visualizado |
|
157 |
* @return |
|
158 |
*/ |
|
159 |
public int[][] getLastHistogram() { |
|
160 |
return lastHistogram; |
|
161 |
} |
|
162 |
|
|
163 |
/** |
|
164 |
* Asigna el objeto histograma para la gesti?n de procesos de histograma |
|
165 |
* @param histogramObj |
|
166 |
*/ |
|
167 |
/* |
|
168 |
public void setHistogram(Histogram histogram) { |
|
169 |
this.histogram = histogram; |
|
170 |
} |
|
171 |
*/ |
|
172 |
/** |
|
173 |
* M?todo que ejecuta el thread que comprueba cuando se ha acabado de generar |
|
174 |
* el histograma. Al finalizar, se lee el histograma de la imagen completa |
|
175 |
* calculado y se muestra. |
|
176 |
*/ |
|
177 |
/* |
|
178 |
public void readFullHistogramFromThread(){ |
|
179 |
if (panel.getType() == 0) |
|
180 |
lastHistogram = getHistogram().getFullHistogram(); |
|
181 |
else if(panel.getType() == 1) |
|
182 |
lastHistogram = getHistogram().getFullAccumulatedHistogram(); |
|
183 |
|
|
184 |
this.updateStatistic(); |
|
185 |
|
|
186 |
//Si el histograma es grande lo recortamos para mostrarlo porque jfreeChart se vuelve |
|
187 |
//inestable al poner muchos elementos en las X |
|
188 |
|
|
189 |
/* |
|
190 |
|
|
191 |
int pos = lastHistogram[0].length; |
|
192 |
int[][] newHistogram = lastHistogram; |
|
193 |
boolean elem = true; |
|
194 |
if(lastHistogram[0].length >= Utilities.MAX_SHORT_BIT_VALUE){ |
|
195 |
for(int i = (lastHistogram[0].length - 1); i >= 0; i--){ |
|
196 |
for(int iBand = 0; iBand < lastHistogram.length; iBand ++){ |
|
197 |
if(lastHistogram[iBand][i] != 0) |
|
198 |
elem = false; |
|
199 |
} |
|
200 |
if(!elem){ |
|
201 |
pos = i; |
|
202 |
break; |
|
203 |
} |
|
204 |
} |
|
205 |
newHistogram = new int[lastHistogram.length][pos]; |
|
206 |
for(int iBand = 0; iBand < lastHistogram.length; iBand ++){ |
|
207 |
for(int i = 0; i < newHistogram[iBand].length; i ++){ |
|
208 |
newHistogram[iBand][i] = lastHistogram[iBand][i]; |
|
209 |
} |
|
210 |
} |
|
211 |
} |
|
212 |
*/ |
|
213 |
/* |
|
214 |
GraphicChartPanel gcp = pHistogram.getPGraphic(); |
|
215 |
|
|
216 |
String bandNames[] = new String[lastHistogram.length]; |
|
217 |
for (int iBand = 0; iBand<lastHistogram.length; iBand++) |
|
218 |
bandNames[iBand]=this.getJComboBands().getItemAt(iBand+1).toString(); |
|
219 |
|
|
220 |
gcp.setNewChart(newHistogram, bandNames); |
|
221 |
*/ |
|
222 |
// } |
|
223 |
|
|
224 | 155 |
public void showHistogram() { |
225 |
IHistogramable iaux = (IHistogramable) ((ArrayList) panel.getComboSource().get(panel.getJComboBoxOrigen().getSelectedIndex())).get(0); |
|
226 |
histogramProcess = new HistogramProcess(iaux, panel.getJComboBoxTipo().getSelectedIndex()); |
|
156 |
if (histogramPanel.getJComboBoxOrigen().getSelectedIndex() < 0) return; |
|
157 |
IHistogramable iaux = (IHistogramable) ((ArrayList) histogramPanel.getComboSource().get(histogramPanel.getJComboBoxOrigen().getSelectedIndex())).get(0); |
|
158 |
histogramProcess = new HistogramProcess(iaux, histogramPanel.getJComboBoxTipo().getSelectedIndex()); |
|
227 | 159 |
incrementableTask = new IncrementableTask(histogramProcess); |
228 | 160 |
incrementableTask.addIncrementableListener(this); |
229 | 161 |
incrementableTask.showWindow(); |
230 | 162 |
} |
231 |
/* |
|
232 |
public void showHistogram(){ |
|
233 |
// Tipo noacumulado = 0, acumulado = 1 |
|
234 |
switch (panel.getType()) { |
|
235 |
case 0: |
|
236 |
// Fte de datos vista = 0, extent = 1, completo = 2 |
|
237 |
switch (panel.getHistogramDataSource()) { |
|
238 |
case 0: |
|
239 |
requestDataType = RasterBuf.TYPE_BYTE; |
|
240 |
calcHistogramFromView(panel.showBands); |
|
241 |
break; |
|
242 |
case 1: |
|
243 |
if(this.getHistogram().getGrid().getDataType() == RasterBuf.TYPE_SHORT) |
|
244 |
requestDataType = RasterBuf.TYPE_SHORT; |
|
245 |
else |
|
246 |
requestDataType = RasterBuf.TYPE_BYTE; |
|
247 |
calcHistogramFromDataSourceAndExtentView(panel.showBands); |
|
248 |
break; |
|
249 |
case 2: |
|
250 |
if(this.getHistogram().getGrid().getDataType() == RasterBuf.TYPE_SHORT) |
|
251 |
requestDataType = RasterBuf.TYPE_SHORT; |
|
252 |
else |
|
253 |
requestDataType = RasterBuf.TYPE_BYTE; |
|
254 |
calcFullHistogramFromDataSource(panel.showBands); |
|
255 |
break; |
|
256 |
} |
|
257 |
break; |
|
258 |
case 1: |
|
259 |
// Fte de datos vista = 0, extent = 1, completo = 2 |
|
260 |
switch (panel.getHistogramDataSource()) { |
|
261 |
case 0: |
|
262 |
requestDataType = RasterBuf.TYPE_BYTE; |
|
263 |
calcAccumulatedHistogramFromView(panel.showBands); |
|
264 |
break; |
|
265 |
case 1: |
|
266 |
if(this.getHistogram().getGrid().getDataType() == RasterBuf.TYPE_SHORT) |
|
267 |
requestDataType = RasterBuf.TYPE_SHORT; |
|
268 |
else |
|
269 |
requestDataType = RasterBuf.TYPE_BYTE; |
|
270 |
calcHistogramFromDataSourceAndExtentView(panel.showBands); |
|
271 |
break; |
|
272 |
case 2: |
|
273 |
if(this.getHistogram().getGrid().getDataType() == RasterBuf.TYPE_SHORT) |
|
274 |
requestDataType = RasterBuf.TYPE_SHORT; |
|
275 |
else |
|
276 |
requestDataType = RasterBuf.TYPE_BYTE; |
|
277 |
calcFullAccumulatedHistogramFromDataSource(panel.showBands); |
|
278 |
break; |
|
279 |
} |
|
280 |
break; |
|
281 |
} |
|
282 |
} |
|
283 |
*/ |
|
163 |
|
|
284 | 164 |
/** |
285 |
* Obtiene el objeto histograma para la gesti?n de procesos de histograma |
|
286 |
* @return |
|
165 |
* Limpia la gr?fica |
|
287 | 166 |
*/ |
288 |
/* |
|
289 |
public Histogram getHistogram() { |
|
290 |
return histogram; |
|
167 |
public void cleanChart(){ |
|
168 |
histogramPanel.cleanChart(); |
|
169 |
for(int i = 0; i < histogramPanel.showBands.length; i++) |
|
170 |
histogramPanel.showBands[i] = false; |
|
291 | 171 |
} |
292 |
*/ |
|
293 |
|
|
172 |
|
|
294 | 173 |
public void keyReleased(KeyEvent e) { |
295 | 174 |
} |
296 | 175 |
|
... | ... | |
298 | 177 |
} |
299 | 178 |
|
300 | 179 |
private void closeHistogramProcess() { |
301 |
histogramProcess.suspend(); |
|
302 | 180 |
histogramProcess = null; |
303 | 181 |
incrementableTask = null; |
304 | 182 |
} |
... | ... | |
306 | 184 |
closeHistogramProcess(); |
307 | 185 |
} |
308 | 186 |
|
187 |
private void updateGraphic() { |
|
188 |
if (lastHistogram == null) return; |
|
189 |
|
|
190 |
int first = 0; |
|
191 |
int end = lastHistogram[0].length; |
|
192 |
|
|
193 |
first = (int) ((histogramPanel.getGraphicContainer().getBoxesValues()[1]*lastHistogram[0].length)/100); |
|
194 |
end = (int) ((histogramPanel.getGraphicContainer().getBoxesValues()[0]*lastHistogram[0].length)/100); |
|
195 |
|
|
196 |
int[][] newHistogram = new int[lastHistogram.length][end - first]; |
|
197 |
String[] bandNames = new String[lastHistogram.length]; |
|
198 |
|
|
199 |
for (int iBand=0; iBand<lastHistogram.length; iBand++) { |
|
200 |
for (int j=first; j<end; j++) |
|
201 |
newHistogram[iBand][j-first] = (int) lastHistogram[iBand][j]; |
|
202 |
bandNames[iBand] = iBand + ""; |
|
203 |
} |
|
204 |
|
|
205 |
histogramPanel.getGraphicContainer().getPGraphic().cleanChart(); |
|
206 |
histogramPanel.getGraphicContainer().getPGraphic().setNewChart(newHistogram, bandNames); |
|
207 |
} |
|
208 |
|
|
309 | 209 |
public void actionClosed(IncrementableEvent e) { |
310 |
//histogramProcess. |
|
311 |
panel.getGraphicContainer().getPGraphic().cleanChart(); |
|
312 |
//panel.getGraphicContainer().getPGraphic().setNewChart(histogramProcess.getLastHistogram(), null); |
|
210 |
lastHistogram = histogramProcess.getLastHistogram(); |
|
211 |
updateGraphic(); |
|
313 | 212 |
closeHistogramProcess(); |
314 | 213 |
} |
315 | 214 |
|
... | ... | |
320 | 219 |
public void actionSuspended(IncrementableEvent e) { |
321 | 220 |
histogramProcess.suspend(); |
322 | 221 |
} |
323 |
|
|
324 |
/** |
|
325 |
* Calcula el histograma completo |
|
326 |
* @param bandas que se desean visualizar. Cada elemento del vector es una banda y el boolean, si |
|
327 |
* est? a true se visualizar? esa banda y si est? a false no se visualizar? |
|
328 |
*/ |
|
329 |
/* |
|
330 |
private void calcFullHistogramFromDataSource(boolean[] bands){ |
|
331 |
if (histogram != null){ |
|
332 |
histogram.calcFullHistogram(bands); |
|
333 |
incrementPanel = new HistogramIncrement(this); |
|
334 |
incrementPanel.showWindow(); |
|
335 |
} |
|
336 |
} |
|
337 |
*/ |
|
338 |
|
|
339 |
/** |
|
340 |
* Calcula el histograma de la vista y solo con los datos de visualizaci?n |
|
341 |
* de las bandas R, G o B solicitadas |
|
342 |
* @param bandas que se desean visualizar. Cada elemento del vector es una banda y el boolean, si |
|
343 |
* est? a true se visualizar? esa banda y si est? a false no se visualizar? |
|
344 |
*/ |
|
345 |
/* |
|
346 |
private void calcHistogramFromView(boolean[] bands){ |
|
347 |
if(histogram != null){ |
|
348 |
lastHistogram = histogram.calcHistogramFromView(bands); |
|
349 |
panel.showBands = bands; |
|
350 |
updateStatistic(); |
|
351 |
|
|
352 |
GraphicChartPanel gcp = panel.getGraphicContainer().getPGraphic(); |
|
353 |
|
|
354 |
String bandNames[] = new String[bands.length]; |
|
355 |
for (int iBand = 0; iBand<bands.length; iBand++) |
|
356 |
bandNames[iBand] = panel.getJComboBands().getItemAt(iBand+1).toString(); |
|
357 |
|
|
358 |
gcp.setNewChart(lastHistogram, bandNames); |
|
359 |
} |
|
360 |
} |
|
361 |
*/ |
|
362 | 222 |
} |
Also available in: Unified diff