Revision 11042 trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/HistogramPanelListener.java
HistogramPanelListener.java | ||
---|---|---|
36 | 36 |
|
37 | 37 |
import org.gvsig.gui.beans.graphic.GraphicEvent; |
38 | 38 |
import org.gvsig.gui.beans.graphic.GraphicListener; |
39 |
import org.gvsig.gui.beans.incrementabletask.IncrementableEvent; |
|
40 |
import org.gvsig.gui.beans.incrementabletask.IncrementableListener; |
|
41 | 39 |
import org.gvsig.gui.beans.incrementabletask.IncrementableTask; |
42 | 40 |
import org.gvsig.raster.util.Histogram; |
43 | 41 |
import org.gvsig.raster.util.IHistogramable; |
... | ... | |
67 | 65 |
* @author Nacho Brodin (brodin_ign@gva.es) |
68 | 66 |
* @author Borja Sanchez Zamorano (borja.sanchez@iver.es) |
69 | 67 |
*/ |
70 |
public class HistogramPanelListener implements IncrementableListener, GraphicListener, ActionListener {
|
|
68 |
public class HistogramPanelListener implements GraphicListener, ActionListener { |
|
71 | 69 |
private HistogramPanel histogramPanel = null; |
72 | 70 |
private IncrementableTask incrementableTask = null; |
73 | 71 |
private HistogramProcess histogramProcess = null; |
74 | 72 |
private Histogram lastHistogram = null; |
75 |
private int bandCount = 0; |
|
76 | 73 |
|
77 |
public boolean comboEventEnable = false;
|
|
74 |
public boolean eventsEnabled = false;
|
|
78 | 75 |
|
79 |
private boolean[] showBands = {true, true, true}; |
|
76 |
/** |
|
77 |
* Bandas que se est?n mostrando en el gr?fico. Se inicializa con las 3 bandas |
|
78 |
* RGB de la visualizaci?n. Este array puede tener m?s elementos ya que si las |
|
79 |
* bandas no son de visualizaci?n (bandas de la imagen en disco) tendr? un elemento |
|
80 |
* por cada una. |
|
81 |
*/ |
|
82 |
private boolean[] showBands = null; |
|
80 | 83 |
private Color[] bandsColor = { |
81 | 84 |
Color.red, |
82 | 85 |
Color.green, |
... | ... | |
96 | 99 |
public void setControlListeners(){ |
97 | 100 |
histogramPanel.getGraphicContainer().addValueChangedListener(this); |
98 | 101 |
} |
99 |
|
|
100 | 102 |
|
101 | 103 |
private void updateStatistic() { |
102 |
// long[][] auxHistogram = lastHistogram.getHistogramByType(Histogram.getType(histogramPanel.getJComboBoxTipo().getSelectedIndex()));
|
|
103 |
// long[][] auxHistogram = lastHistogram.getHistogram();
|
|
104 |
int first = (int) histogramPanel.getBoxesValues()[1];
|
|
105 |
int end = (int) histogramPanel.getBoxesValues()[0];
|
|
104 | 106 |
|
105 |
int first = (int) ((histogramPanel.getGraphicContainer().getX1()*(lastHistogram.getNumValues()-1))/100); |
|
106 |
int end = (int) ((histogramPanel.getGraphicContainer().getX2()*(lastHistogram.getNumValues()-1))/100); |
|
107 |
|
|
108 |
// first = histogramPanel.getGraphicContainer().getX1(); |
|
109 |
// end = histogramPanel.getGraphicContainer().getX2(); |
|
110 |
|
|
111 |
// Histogram aux = new Histogram(); |
|
112 |
// aux.setHistogram(auxHistogram); |
|
113 |
|
|
114 |
// histogramPanel.setStatistic(aux.getBasicStats(first, end, showBands)); |
|
115 | 107 |
histogramPanel.setStatistic(lastHistogram.getBasicStats((int) first, (int) end, showBands)); |
116 | 108 |
} |
117 | 109 |
|
118 | 110 |
public void actionPerformed(ActionEvent e) { |
111 |
if (!eventsEnabled) return; |
|
119 | 112 |
//-------------------------------------- |
120 | 113 |
//Cambiar las bandas en el combo |
121 | 114 |
JComboBox cbb = histogramPanel.getJComboBands(); |
122 |
if (comboEventEnable && (e.getSource() == cbb)) {
|
|
115 |
if (e.getSource() == cbb) {
|
|
123 | 116 |
if (cbb.getSelectedItem() == null) return; |
124 | 117 |
|
125 | 118 |
if (cbb.getSelectedIndex() == 0) |
... | ... | |
149 | 142 |
//-------------------------------------- |
150 | 143 |
//Selecci?n de fuente de datos del histograma |
151 | 144 |
JComboBox cbo = histogramPanel.getJComboBoxOrigen(); |
152 |
if (comboEventEnable && e.getSource() == cbo) { |
|
153 |
//En caso de que el histograma se monte a partir de los datos de la vista ponemos RGB en el combo |
|
154 |
if(cbo.getSelectedIndex() == 0) { |
|
155 |
histogramPanel.setRGBInBandList(); |
|
156 |
} |
|
157 |
|
|
158 |
//En caso de que el histograma se monte a partir de los datos reales ponemos el n?mero de bandas en el combo |
|
159 |
if (cbo.getSelectedIndex() == 1 || cbo.getSelectedIndex() == 2) { |
|
160 |
bandCount = lastHistogram.getNumBands(); |
|
161 |
histogramPanel.setBands(bandCount); |
|
162 |
showBands = new boolean[bandCount]; |
|
163 |
for (int i = 0; i < showBands.length; i++) |
|
164 |
showBands[i] = true; |
|
165 |
} |
|
145 |
if (e.getSource() == cbo) { |
|
166 | 146 |
showHistogram(); |
167 | 147 |
return; |
168 | 148 |
} |
... | ... | |
170 | 150 |
//-------------------------------------- |
171 | 151 |
//Selecci?n de histograma acumulado y no acumulado |
172 | 152 |
JComboBox cbt = histogramPanel.getJComboBoxTipo(); |
173 |
if (comboEventEnable && e.getSource() == cbt) { |
|
174 |
histogramPanel.setType(cbt.getSelectedIndex()); |
|
153 |
if (e.getSource() == cbt) { |
|
175 | 154 |
updateStatistic(); |
176 | 155 |
updateGraphic(); |
177 | 156 |
return; |
... | ... | |
266 | 245 |
} |
267 | 246 |
} |
268 | 247 |
|
248 |
private void refreshBands() { |
|
249 |
histogramPanel.refreshBands(); |
|
250 |
showBands = new boolean[getHistogram().getNumBands()]; |
|
251 |
for (int i = 0; i < showBands.length; i++) |
|
252 |
showBands[i] = true; |
|
253 |
} |
|
254 |
|
|
269 | 255 |
public void showHistogram() { |
270 | 256 |
if (histogramPanel.getJComboBoxOrigen().getSelectedIndex() < 0) return; |
271 |
closeHistogramProcess(); |
|
257 |
|
|
272 | 258 |
IHistogramable iaux = (IHistogramable) ((ArrayList) histogramPanel.getComboSource().get(histogramPanel.getJComboBoxOrigen().getSelectedIndex())).get(0); |
273 |
histogramProcess = new HistogramProcess(iaux); |
|
259 |
histogramProcess = new HistogramProcess(iaux, this);
|
|
274 | 260 |
incrementableTask = new IncrementableTask(histogramProcess); |
275 |
incrementableTask.addIncrementableListener(this);
|
|
261 |
histogramProcess.setIncrementableTask(incrementableTask);
|
|
276 | 262 |
incrementableTask.showWindow(); |
263 |
histogramProcess.start(); |
|
264 |
incrementableTask.start(); |
|
277 | 265 |
} |
278 | 266 |
|
279 | 267 |
/** |
... | ... | |
290 | 278 |
long[][] auxHistogram = lastHistogram.getHistogramByType(Histogram.getType(histogramPanel.getJComboBoxTipo().getSelectedIndex())); |
291 | 279 |
if (auxHistogram == null) return; |
292 | 280 |
|
293 |
int first = (int) ((histogramPanel.getGraphicContainer().getX1()*(auxHistogram[0].length-1))/100);
|
|
294 |
int end = (int) ((histogramPanel.getGraphicContainer().getX2()*(auxHistogram[0].length-1))/100);
|
|
281 |
int first = (int) histogramPanel.getBoxesValues()[1];
|
|
282 |
int end = (int) histogramPanel.getBoxesValues()[0];
|
|
295 | 283 |
|
296 | 284 |
int bandCount = 0; |
297 | 285 |
for (int i = 0; i < showBands.length; i++) { |
... | ... | |
304 | 292 |
bandCount = auxHistogram.length; |
305 | 293 |
|
306 | 294 |
int numBand = 0; |
307 |
for (int iBand = 0; iBand < showBands.length; iBand++) {
|
|
295 |
for (int iBand = 0; iBand < auxHistogram.length; iBand++) {
|
|
308 | 296 |
if (!showBands[iBand]) continue; |
309 | 297 |
|
310 | 298 |
for (int j=first; j<end; j++) |
... | ... | |
319 | 307 |
histogramPanel.getGraphicContainer().getPGraphic().setNewChart(newHistogram, bandNames); |
320 | 308 |
updateStatistic(); |
321 | 309 |
} |
322 |
private void closeHistogramProcess() { |
|
323 |
histogramProcess = null; |
|
324 |
incrementableTask = null; |
|
325 |
} |
|
326 | 310 |
|
327 |
public void actionCanceled(IncrementableEvent e) { |
|
328 |
// if (histogramProcess != null) histogramProcess.suspend(); |
|
329 |
closeHistogramProcess(); |
|
330 |
} |
|
331 |
|
|
332 |
public void actionClosed(IncrementableEvent e) { |
|
333 |
if (histogramProcess == null) return; |
|
334 |
lastHistogram = histogramProcess.getLastHistogram(); |
|
311 |
public void setNewHistogram(Histogram value) { |
|
312 |
histogramPanel.panelInizialited = false; |
|
313 |
eventsEnabled = false; |
|
314 |
lastHistogram = value; |
|
315 |
refreshBands(); |
|
335 | 316 |
updateGraphic(); |
336 |
closeHistogramProcess(); |
|
337 |
} |
|
317 |
|
|
318 |
incrementableTask = null; |
|
319 |
histogramProcess = null; |
|
338 | 320 |
|
339 |
public void actionResumed(IncrementableEvent e) {
|
|
340 |
if (histogramProcess == null) return;
|
|
341 |
histogramProcess.resume();
|
|
321 |
// Activo la ejecucion de los eventos porque seguro que ya tenemos un histograma
|
|
322 |
eventsEnabled = true;
|
|
323 |
histogramPanel.panelInizialited = true;
|
|
342 | 324 |
} |
343 | 325 |
|
344 |
public void actionSuspended(IncrementableEvent e) { |
|
345 |
if (histogramProcess == null) return; |
|
346 |
histogramProcess.suspend(); |
|
326 |
public Histogram getHistogram() { |
|
327 |
return lastHistogram; |
|
347 | 328 |
} |
348 | 329 |
|
349 | 330 |
public void actionValueChanged(GraphicEvent e) { |
... | ... | |
368 | 349 |
|
369 | 350 |
return channel; |
370 | 351 |
} |
371 |
|
|
372 | 352 |
} |
Also available in: Unified diff