Revision 11116
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/histogram/HistogramPanelListener.java | ||
---|---|---|
22 | 22 |
import java.awt.Component; |
23 | 23 |
import java.awt.event.ActionEvent; |
24 | 24 |
import java.awt.event.ActionListener; |
25 |
import java.beans.PropertyChangeEvent; |
|
26 |
import java.beans.PropertyChangeListener; |
|
25 | 27 |
import java.io.File; |
26 | 28 |
import java.io.IOException; |
27 | 29 |
import java.io.RandomAccessFile; |
... | ... | |
33 | 35 |
import javax.swing.JComboBox; |
34 | 36 |
import javax.swing.JFileChooser; |
35 | 37 |
import javax.swing.JOptionPane; |
38 |
import javax.swing.table.DefaultTableModel; |
|
36 | 39 |
|
37 | 40 |
import org.gvsig.gui.beans.graphic.GraphicEvent; |
38 | 41 |
import org.gvsig.gui.beans.graphic.GraphicListener; |
... | ... | |
65 | 68 |
* @author Nacho Brodin (brodin_ign@gva.es) |
66 | 69 |
* @author Borja Sanchez Zamorano (borja.sanchez@iver.es) |
67 | 70 |
*/ |
68 |
public class HistogramPanelListener implements GraphicListener, ActionListener { |
|
71 |
public class HistogramPanelListener implements GraphicListener, ActionListener, PropertyChangeListener {
|
|
69 | 72 |
private HistogramPanel histogramPanel = null; |
70 | 73 |
private IncrementableTask incrementableTask = null; |
71 | 74 |
private HistogramProcess histogramProcess = null; |
... | ... | |
96 | 99 |
public HistogramPanelListener(HistogramPanel p){ |
97 | 100 |
histogramPanel = p; |
98 | 101 |
} |
99 |
|
|
102 |
|
|
103 |
public HistogramPanel getHistogramPanel() { |
|
104 |
return histogramPanel; |
|
105 |
} |
|
106 |
|
|
100 | 107 |
public void setControlListeners(){ |
101 |
histogramPanel.getGraphicContainer().addValueChangedListener(this);
|
|
108 |
getHistogramPanel().getGraphicContainer().addValueChangedListener(this);
|
|
102 | 109 |
} |
103 | 110 |
|
104 | 111 |
/** |
105 | 112 |
* Actualizar cuadro de estad?sticas |
106 | 113 |
*/ |
107 | 114 |
private void updateStatistic() { |
108 |
int first = (int) histogramPanel.getBoxesValues()[1];
|
|
109 |
int end = (int) histogramPanel.getBoxesValues()[0];
|
|
115 |
int first = (int) getHistogramPanel().getBoxesValues()[1];
|
|
116 |
int end = (int) getHistogramPanel().getBoxesValues()[0];
|
|
110 | 117 |
|
111 |
histogramPanel.setStatistic(getLastHistogram().getBasicStats((int) first, (int) end, showBands));
|
|
118 |
getHistogramPanel().setStatistic(getLastHistogram().getBasicStats((int) first, (int) end, showBands));
|
|
112 | 119 |
} |
113 | 120 |
|
114 | 121 |
/** |
... | ... | |
116 | 123 |
*/ |
117 | 124 |
public void actionPerformed(ActionEvent e) { |
118 | 125 |
if (!eventsEnabled) return; |
119 |
//-------------------------------------- |
|
120 |
//Cambiar las bandas en el combo |
|
121 |
JComboBox cbb = histogramPanel.getJComboBands(); |
|
122 |
if (e.getSource() == cbb) { |
|
123 |
if (cbb.getSelectedItem() == null) return; |
|
124 |
|
|
125 |
if (cbb.getSelectedIndex() == 0) |
|
126 |
for (int i = 0; i < showBands.length; i++) |
|
127 |
showBands[i] = true; |
|
128 |
if (cbb.getSelectedItem().equals("R")) addOrRemoveGraphicBand(0); |
|
129 |
if (cbb.getSelectedItem().equals("G")) addOrRemoveGraphicBand(1); |
|
130 |
if (cbb.getSelectedItem().equals("B")) addOrRemoveGraphicBand(2); |
|
131 |
for (int i = 0; i < showBands.length; i++) |
|
132 |
if (cbb.getSelectedItem().equals("Band " + i)) |
|
133 |
addOrRemoveGraphicBand(i); |
|
134 |
|
|
135 |
updateGraphic(); |
|
136 |
updateStatistic(); |
|
137 |
return; |
|
138 |
} |
|
139 | 126 |
|
140 |
//-------------------------------------- |
|
141 |
//Limpiar |
|
142 |
if (e.getSource() == histogramPanel.getJButtonClear()) { |
|
143 |
for (int i = 0; i < showBands.length; i++) |
|
144 |
showBands[i] = false; |
|
145 |
updateGraphic(); |
|
146 |
return; |
|
147 |
} |
|
148 |
|
|
149 | 127 |
//-------------------------------------- |
150 | 128 |
//Selecci?n de fuente de datos del histograma |
151 |
JComboBox cbo = histogramPanel.getJComboBoxOrigen();
|
|
129 |
JComboBox cbo = getHistogramPanel().getJComboBoxOrigen();
|
|
152 | 130 |
if (e.getSource() == cbo) { |
153 | 131 |
showHistogram(); |
154 | 132 |
return; |
... | ... | |
156 | 134 |
|
157 | 135 |
//-------------------------------------- |
158 | 136 |
//Selecci?n de histograma acumulado y no acumulado |
159 |
JComboBox cbt = histogramPanel.getJComboBoxTipo();
|
|
137 |
JComboBox cbt = getHistogramPanel().getJComboBoxTipo();
|
|
160 | 138 |
if (e.getSource() == cbt) { |
161 | 139 |
updateStatistic(); |
162 | 140 |
updateGraphic(); |
... | ... | |
165 | 143 |
|
166 | 144 |
//-------------------------------------- |
167 | 145 |
// Boton Crear Tabla |
168 |
JButton table = histogramPanel.getBCreateTable();
|
|
146 |
JButton table = getHistogramPanel().getBCreateTable();
|
|
169 | 147 |
if (e.getSource() == table) { |
170 | 148 |
try { |
171 | 149 |
// -------Mostrar un fileChooser------------------ |
... | ... | |
173 | 151 |
JFileChooser chooser = new JFileChooser(); |
174 | 152 |
chooser.setDialogTitle(PluginServices.getText(this, "guardar_tabla")); |
175 | 153 |
|
176 |
int returnVal = chooser.showOpenDialog(histogramPanel);
|
|
154 |
int returnVal = chooser.showOpenDialog(getHistogramPanel());
|
|
177 | 155 |
if (returnVal == JFileChooser.APPROVE_OPTION) { |
178 | 156 |
fName = chooser.getSelectedFile().toString(); |
179 | 157 |
if (!fName.endsWith(".dbf")) |
... | ... | |
241 | 219 |
PluginServices.getMDIManager().addWindow(t); |
242 | 220 |
} |
243 | 221 |
} catch (IOException e1) { |
244 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),histogramPanel.getName() + " " + PluginServices.getText(this,"table_not_create"));
|
|
222 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),getHistogramPanel().getName() + " " + PluginServices.getText(this,"table_not_create"));
|
|
245 | 223 |
} catch (DriverLoadException e1) { |
246 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),histogramPanel.getName() + " " + PluginServices.getText(this,"table_not_create"));
|
|
224 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),getHistogramPanel().getName() + " " + PluginServices.getText(this,"table_not_create"));
|
|
247 | 225 |
} catch (NoSuchTableException e1) { |
248 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),histogramPanel.getName() + " " + PluginServices.getText(this,"table_not_create"));
|
|
226 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),getHistogramPanel().getName() + " " + PluginServices.getText(this,"table_not_create"));
|
|
249 | 227 |
} catch (ReadDriverException e1) { |
250 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),histogramPanel.getName() + " " + PluginServices.getText(this,"table_not_create"));
|
|
228 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),getHistogramPanel().getName() + " " + PluginServices.getText(this,"table_not_create"));
|
|
251 | 229 |
} |
252 | 230 |
} |
253 | 231 |
} |
... | ... | |
256 | 234 |
* Actualizar la variable de las bandas visibles y su componente visual. |
257 | 235 |
*/ |
258 | 236 |
private void refreshBands() { |
259 |
histogramPanel.refreshBands();
|
|
237 |
getHistogramPanel().refreshBands();
|
|
260 | 238 |
showBands = new boolean[getLastHistogram().getNumBands()]; |
261 | 239 |
for (int i = 0; i < showBands.length; i++) |
262 | 240 |
showBands[i] = true; |
... | ... | |
267 | 245 |
* ventana de incremento |
268 | 246 |
*/ |
269 | 247 |
public void showHistogram() { |
270 |
if (histogramPanel.getJComboBoxOrigen().getSelectedIndex() < 0) return;
|
|
248 |
if (getHistogramPanel().getJComboBoxOrigen().getSelectedIndex() < 0) return;
|
|
271 | 249 |
|
272 |
IHistogramable iaux = (IHistogramable) ((ArrayList) histogramPanel.getComboSource().get(histogramPanel.getJComboBoxOrigen().getSelectedIndex())).get(0);
|
|
250 |
IHistogramable iaux = (IHistogramable) ((ArrayList) getHistogramPanel().getComboSource().get(getHistogramPanel().getJComboBoxOrigen().getSelectedIndex())).get(0);
|
|
273 | 251 |
histogramProcess = new HistogramProcess(iaux, this); |
274 | 252 |
incrementableTask = new IncrementableTask(histogramProcess); |
275 | 253 |
histogramProcess.setIncrementableTask(incrementableTask); |
... | ... | |
293 | 271 |
* Actualiza la grafica con los datos que ya teniamos del histograma. |
294 | 272 |
*/ |
295 | 273 |
private void updateGraphic() { |
296 |
long[][] auxHistogram = getLastHistogram().getHistogramByType(Histogram.getType(histogramPanel.getJComboBoxTipo().getSelectedIndex()));
|
|
274 |
long[][] auxHistogram = getLastHistogram().getHistogramByType(Histogram.getType(getHistogramPanel().getJComboBoxTipo().getSelectedIndex()));
|
|
297 | 275 |
if (auxHistogram == null) return; |
298 | 276 |
|
299 |
int first = (int) histogramPanel.getBoxesValues()[1];
|
|
300 |
int end = (int) histogramPanel.getBoxesValues()[0];
|
|
277 |
int first = (int) getHistogramPanel().getBoxesValues()[1];
|
|
278 |
int end = (int) getHistogramPanel().getBoxesValues()[0];
|
|
301 | 279 |
|
302 | 280 |
int bandCount = 0; |
303 | 281 |
for (int i = 0; i < showBands.length; i++) { |
... | ... | |
315 | 293 |
|
316 | 294 |
for (int j=first; j<end; j++) |
317 | 295 |
newHistogram[numBand][j-first] = (int) auxHistogram[iBand][j]; |
318 |
bandNames[numBand] = histogramPanel.getJComboBands().getItemAt(iBand + 1).toString();
|
|
296 |
bandNames[numBand] = (String) ((DefaultTableModel) getHistogramPanel().getJTableBands().getModel()).getValueAt(iBand, 1);
|
|
319 | 297 |
|
320 |
histogramPanel.getGraphicContainer().setBandColor(numBand, bandsColor[iBand % bandsColor.length]);
|
|
298 |
getHistogramPanel().getGraphicContainer().setBandColor(numBand, bandsColor[iBand % bandsColor.length]);
|
|
321 | 299 |
|
322 | 300 |
numBand++; |
323 | 301 |
} |
324 | 302 |
|
325 |
histogramPanel.getGraphicContainer().getPGraphic().setNewChart(newHistogram, bandNames);
|
|
303 |
getHistogramPanel().getGraphicContainer().getPGraphic().setNewChart(newHistogram, bandNames);
|
|
326 | 304 |
updateStatistic(); |
327 | 305 |
} |
328 | 306 |
|
... | ... | |
332 | 310 |
* @param histograma nuevo |
333 | 311 |
*/ |
334 | 312 |
public void setNewHistogram(Histogram value) { |
335 |
histogramPanel.panelInizialited = false;
|
|
313 |
getHistogramPanel().panelInizialited = false;
|
|
336 | 314 |
eventsEnabled = false; |
337 | 315 |
lastHistogram = value; |
338 | 316 |
refreshBands(); |
... | ... | |
343 | 321 |
|
344 | 322 |
// Activo la ejecucion de los eventos porque seguro que ya tenemos un histograma |
345 | 323 |
eventsEnabled = true; |
346 |
histogramPanel.panelInizialited = true;
|
|
324 |
getHistogramPanel().panelInizialited = true;
|
|
347 | 325 |
} |
348 | 326 |
|
349 | 327 |
/** |
... | ... | |
385 | 363 |
|
386 | 364 |
return channel; |
387 | 365 |
} |
366 |
|
|
367 |
public void propertyChange(PropertyChangeEvent evt) { |
|
368 |
if (!eventsEnabled) return; |
|
369 |
int countRow = ((DefaultTableModel) histogramPanel.getJTableBands().getModel()).getRowCount(); |
|
370 |
for (int i=0; i<countRow; i++) { |
|
371 |
showBands[i] = ((Boolean) ((DefaultTableModel) histogramPanel.getJTableBands().getModel()).getValueAt(i, 0)).booleanValue(); |
|
372 |
} |
|
373 |
updateGraphic(); |
|
374 |
updateStatistic(); |
|
375 |
} |
|
388 | 376 |
} |
Also available in: Unified diff