33 |
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 |
|
|
37 |
import com.iver.utiles.swing.threads.Cancellable;
|
36 |
38 |
/**
|
37 |
39 |
* Listener para eventos del panel de histograma
|
38 |
40 |
*
|
... | ... | |
44 |
46 |
private HistogramPanel histogramPanel = null;
|
45 |
47 |
private IncrementableTask incrementableTask = null;
|
46 |
48 |
private HistogramProcess histogramProcess = null;
|
47 |
|
private long[][] lastHistogram = null;
|
|
49 |
private Histogram lastHistogram = null;
|
|
50 |
private int bandCount = 0;
|
48 |
51 |
|
49 |
52 |
public boolean comboEventEnable = false;
|
50 |
53 |
|
... | ... | |
91 |
94 |
JComboBox cbb = histogramPanel.getJComboBands();
|
92 |
95 |
if (comboEventEnable && (e.getSource() == cbb)) {
|
93 |
96 |
if (cbb.getSelectedItem() == null) return;
|
|
97 |
updateGraphic();
|
|
98 |
/*
|
94 |
99 |
if(cbb.getSelectedIndex() == 0) {
|
95 |
100 |
boolean[] list = histogramPanel.getBandListShowInChart();
|
96 |
101 |
for (int i = 0; i < list.length; i++)
|
... | ... | |
114 |
119 |
if (cbb.getSelectedItem().equals("Band "+i))
|
115 |
120 |
histogramPanel.addOrRemoveGraphicBand(i);
|
116 |
121 |
}
|
|
122 |
*/
|
117 |
123 |
return;
|
118 |
124 |
}
|
119 |
125 |
|
... | ... | |
129 |
135 |
//Selecci?n de fuente de datos del histograma
|
130 |
136 |
JComboBox cbo = histogramPanel.getJComboBoxOrigen();
|
131 |
137 |
if (comboEventEnable && e.getSource() == cbo) {
|
132 |
|
showHistogram();
|
133 |
|
// panel.setHistogramDataSource(cbo.getSelectedIndex());
|
134 |
|
|
135 |
138 |
//En caso de que el histograma se monte a partir de los datos de la vista ponemos RGB en el combo
|
136 |
|
// if(cbo.getSelectedIndex() == 0)
|
137 |
|
// panel.setRGBInBandList();
|
|
139 |
if(cbo.getSelectedIndex() == 0) {
|
|
140 |
histogramPanel.setRGBInBandList();
|
|
141 |
}
|
138 |
142 |
|
139 |
143 |
//En caso de que el histograma se monte a partir de los datos reales ponemos el n?mero de bandas en el combo
|
140 |
|
// if (cbo.getSelectedIndex() == 1 || cbo.getSelectedIndex() == 2)
|
141 |
|
// panel.setBands(getHistogram().getGrid().getGrid().getBandCount());
|
|
144 |
if (cbo.getSelectedIndex() == 1 || cbo.getSelectedIndex() == 2) {
|
|
145 |
histogramPanel.setBands(bandCount);
|
|
146 |
}
|
|
147 |
showHistogram();
|
142 |
148 |
return;
|
143 |
149 |
}
|
144 |
150 |
|
... | ... | |
147 |
153 |
JComboBox cbt = histogramPanel.getJComboBoxTipo();
|
148 |
154 |
if (comboEventEnable && e.getSource() == cbt) {
|
149 |
155 |
histogramPanel.setType(cbt.getSelectedIndex());
|
150 |
|
showHistogram();
|
|
156 |
updateStatistic();
|
|
157 |
updateGraphic();
|
151 |
158 |
return;
|
152 |
159 |
}
|
153 |
160 |
}
|
154 |
161 |
|
155 |
162 |
public void showHistogram() {
|
156 |
163 |
if (histogramPanel.getJComboBoxOrigen().getSelectedIndex() < 0) return;
|
|
164 |
closeHistogramProcess();
|
157 |
165 |
IHistogramable iaux = (IHistogramable) ((ArrayList) histogramPanel.getComboSource().get(histogramPanel.getJComboBoxOrigen().getSelectedIndex())).get(0);
|
158 |
|
histogramProcess = new HistogramProcess(iaux, histogramPanel.getJComboBoxTipo().getSelectedIndex());
|
|
166 |
histogramProcess = new HistogramProcess(iaux);
|
159 |
167 |
incrementableTask = new IncrementableTask(histogramProcess);
|
160 |
168 |
incrementableTask.addIncrementableListener(this);
|
161 |
169 |
incrementableTask.showWindow();
|
... | ... | |
176 |
184 |
public void keyTyped(KeyEvent e) {
|
177 |
185 |
}
|
178 |
186 |
|
179 |
|
private void closeHistogramProcess() {
|
180 |
|
histogramProcess = null;
|
181 |
|
incrementableTask = null;
|
182 |
|
}
|
183 |
|
public void actionCanceled(IncrementableEvent e) {
|
184 |
|
closeHistogramProcess();
|
185 |
|
}
|
186 |
|
|
187 |
187 |
private void updateGraphic() {
|
188 |
|
if (lastHistogram == null) return;
|
|
188 |
long[][] auxHistogram = lastHistogram.getHistogramByType(Histogram.getType(histogramPanel.getJComboBoxTipo().getSelectedIndex()));
|
|
189 |
if (auxHistogram == null) return;
|
189 |
190 |
|
190 |
191 |
int first = 0;
|
191 |
|
int end = lastHistogram[0].length;
|
|
192 |
int end = auxHistogram[0].length;
|
192 |
193 |
|
193 |
|
first = (int) ((histogramPanel.getGraphicContainer().getBoxesValues()[1]*lastHistogram[0].length)/100);
|
194 |
|
end = (int) ((histogramPanel.getGraphicContainer().getBoxesValues()[0]*lastHistogram[0].length)/100);
|
|
194 |
first = (int) ((histogramPanel.getGraphicContainer().getBoxesValues()[1]*auxHistogram[0].length)/100);
|
|
195 |
end = (int) ((histogramPanel.getGraphicContainer().getBoxesValues()[0]*auxHistogram[0].length)/100);
|
195 |
196 |
|
196 |
|
int[][] newHistogram = new int[lastHistogram.length][end - first];
|
197 |
|
String[] bandNames = new String[lastHistogram.length];
|
|
197 |
int bands = (histogramPanel.getJComboBands().getSelectedIndex()==0?auxHistogram.length:1);
|
|
198 |
|
|
199 |
int[][] newHistogram = new int[bands][end - first];
|
|
200 |
String[] bandNames = new String[bands];
|
198 |
201 |
|
199 |
|
for (int iBand=0; iBand<lastHistogram.length; iBand++) {
|
|
202 |
bandCount = auxHistogram.length;
|
|
203 |
|
|
204 |
for (int iBand=0; iBand<bands; iBand++) {
|
200 |
205 |
for (int j=first; j<end; j++)
|
201 |
|
newHistogram[iBand][j-first] = (int) lastHistogram[iBand][j];
|
|
206 |
newHistogram[iBand][j-first] = (int) auxHistogram[(bands>1?iBand:histogramPanel.getJComboBands().getSelectedIndex()-1)][j];
|
202 |
207 |
bandNames[iBand] = iBand + "";
|
203 |
208 |
}
|
204 |
209 |
|
205 |
210 |
histogramPanel.getGraphicContainer().getPGraphic().cleanChart();
|
206 |
211 |
histogramPanel.getGraphicContainer().getPGraphic().setNewChart(newHistogram, bandNames);
|
207 |
212 |
}
|
|
213 |
|
|
214 |
private void closeHistogramProcess() {
|
|
215 |
histogramProcess = null;
|
|
216 |
incrementableTask = null;
|
|
217 |
}
|
|
218 |
|
|
219 |
public void actionCanceled(IncrementableEvent e) {
|
|
220 |
// if (histogramProcess != null) histogramProcess.suspend();
|
|
221 |
closeHistogramProcess();
|
|
222 |
}
|
208 |
223 |
|
209 |
224 |
public void actionClosed(IncrementableEvent e) {
|
|
225 |
if (histogramProcess == null) return;
|
210 |
226 |
lastHistogram = histogramProcess.getLastHistogram();
|
211 |
227 |
updateGraphic();
|
212 |
228 |
closeHistogramProcess();
|
213 |
229 |
}
|
214 |
230 |
|
215 |
231 |
public void actionResumed(IncrementableEvent e) {
|
|
232 |
if (histogramProcess == null) return;
|
216 |
233 |
histogramProcess.resume();
|
217 |
234 |
}
|
218 |
235 |
|
219 |
236 |
public void actionSuspended(IncrementableEvent e) {
|
|
237 |
if (histogramProcess == null) return;
|
220 |
238 |
histogramProcess.suspend();
|
221 |
239 |
}
|
222 |
240 |
}
|