Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extRasterTools-SE / src / org / gvsig / rastertools / histogram / HistogramPanelListener.java @ 27490

History | View | Annotate | Download (16.4 KB)

1 10950 bsanchez
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
*/
19
package org.gvsig.rastertools.histogram;
20
21 11033 bsanchez
import java.awt.Color;
22 10950 bsanchez
import java.awt.event.ActionEvent;
23
import java.awt.event.ActionListener;
24 11116 bsanchez
import java.beans.PropertyChangeEvent;
25
import java.beans.PropertyChangeListener;
26 11033 bsanchez
import java.io.File;
27
import java.io.IOException;
28
import java.io.RandomAccessFile;
29
import java.nio.channels.WritableByteChannel;
30 10963 bsanchez
import java.util.ArrayList;
31 10950 bsanchez
32
import javax.swing.JComboBox;
33 11116 bsanchez
import javax.swing.table.DefaultTableModel;
34 10950 bsanchez
35 13942 nacho
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
36 11004 bsanchez
import org.gvsig.gui.beans.graphic.GraphicEvent;
37
import org.gvsig.gui.beans.graphic.GraphicListener;
38 18538 nbrodin
import org.gvsig.raster.IProcessActions;
39 12383 nacho
import org.gvsig.raster.datastruct.Histogram;
40
import org.gvsig.raster.datastruct.HistogramClass;
41
import org.gvsig.raster.datastruct.HistogramException;
42
import org.gvsig.raster.hierarchy.IHistogramable;
43 13622 bsanchez
import org.gvsig.raster.util.RasterToolsUtil;
44 10950 bsanchez
import org.gvsig.rastertools.histogram.ui.HistogramPanel;
45 17719 bsanchez
import org.gvsig.rastertools.statistics.StatisticsProcess;
46 10950 bsanchez
/**
47
 * Listener para eventos del panel de histograma
48
 *
49
 * @version 20/03/2007
50
 * @author Nacho Brodin (brodin_ign@gva.es)
51 12369 bsanchez
 * @author BorSanZa - Borja Sanchez Zamorano (borja.sanchez@iver.es)
52 10950 bsanchez
 */
53 17719 bsanchez
public class HistogramPanelListener implements GraphicListener, ActionListener, PropertyChangeListener, IProcessActions {
54 14439 bsanchez
        private HistogramPanel histogramPanel    = null;
55 17506 bsanchez
56 14439 bsanchez
        /**
57
         * Variable que apunta a uno de los dos histogramas posibles: Real o RGB
58
         */
59
        private Histogram      lastHistogram     = null;
60 17506 bsanchez
61 14439 bsanchez
        /**
62
         * Histograma original sin convertir a RGB
63
         */
64
        private Histogram      lastHistogramReal = null;
65 10950 bsanchez
66 14439 bsanchez
        /**
67
         * Histograma convertido a rango RGB
68
         */
69
        private Histogram      lastHistogramRGB  = null;
70 12369 bsanchez
71 14439 bsanchez
        public boolean         eventsEnabled     = false;
72
73 11042 bsanchez
        /**
74 17506 bsanchez
         * Bandas que se est?n mostrando en el gr?fico. Se inicializa con las 3 bandas
75
         * RGB de la visualizaci?n. Este array puede tener m?s elementos ya que si las
76
         * bandas no son de visualizaci?n (bandas de la imagen en disco) tendr? un
77
         * elemento por cada una.
78
         */
79 14439 bsanchez
        private boolean[]      showBands         = null;
80 17506 bsanchez
        private FLyrRasterSE   lyr               = null;
81 11070 bsanchez
82 14439 bsanchez
        private Color[]                                                bandsColor     = {
83 12369 bsanchez
                        Color.red,
84
                        Color.green,
85
                        Color.blue,
86
                        Color.cyan,
87
                        Color.black,
88
                        Color.darkGray,
89
                        Color.gray,
90
                        Color.magenta,
91
                        Color.yellow,
92
                        Color.orange};
93 11068 bsanchez
94 13942 nacho
        /**
95 17719 bsanchez
         * Guardamos el histogramable para hacer el histogramProcess
96
         */
97
        IHistogramable histogramable = null;
98
99
        /**
100 13942 nacho
         * Constructor. Asigna el panel del histograma
101
         * @param p Panel
102
         */
103 14397 bsanchez
        public HistogramPanelListener(HistogramPanel histogramPanel) {
104
                this.histogramPanel = histogramPanel;
105 10950 bsanchez
        }
106 12369 bsanchez
107 13942 nacho
        /**
108
         * Obtiene el panel del histograma
109
         * @return HistogramPanel
110
         */
111 14397 bsanchez
        private HistogramPanel getHistogramPanel() {
112 11116 bsanchez
                return histogramPanel;
113
        }
114 12369 bsanchez
115 13942 nacho
        /**
116 17506 bsanchez
         * Asigna la capa para obtener las fuentes de datos tanto del
117 13942 nacho
         * datasource como de la visualizaci?n.
118
         * @param lyr Capa
119
         */
120
        public void setLayer(FLyrRasterSE lyr) {
121
                this.lyr = lyr;
122
        }
123 17506 bsanchez
124 13949 nacho
        public void setControlListeners() {
125 11116 bsanchez
                getHistogramPanel().getGraphicContainer().addValueChangedListener(this);
126 10950 bsanchez
        }
127 11068 bsanchez
128
        /**
129
         * Actualizar cuadro de estad?sticas
130
         */
131 10950 bsanchez
        private void updateStatistic() {
132 20455 bsanchez
                if (getLastHistogram() == null) {
133
                        getHistogramPanel().setStatistic(null);
134 14397 bsanchez
                        return;
135 20455 bsanchez
                }
136 14397 bsanchez
137 13646 bsanchez
                double first = getHistogramPanel().getGraphicContainer().getX1();
138
                double end = getHistogramPanel().getGraphicContainer().getX2();
139 11033 bsanchez
140 13646 bsanchez
                getHistogramPanel().setStatistic(getLastHistogram().getBasicStats(first, end, showBands));
141 10950 bsanchez
        }
142
143 11068 bsanchez
        /**
144
         * Tratamiento de todos los eventos visuales.
145
         */
146 10950 bsanchez
        public void actionPerformed(ActionEvent e) {
147 11042 bsanchez
                if (!eventsEnabled) return;
148 12369 bsanchez
149 11444 bsanchez
                // Boton de desmarcar todas las bandas
150 11228 bsanchez
                if (e.getSource() == getHistogramPanel().getButtonClean()) {
151 11441 bsanchez
                        getHistogramPanel().refreshBands(false);
152 11202 bsanchez
                        for (int i = 0; i < showBands.length; i++)
153
                                showBands[i] = false;
154
                        updateStatistic();
155
                        updateGraphic();
156
                        return;
157
                }
158
159 11444 bsanchez
                // Boton de marcar todas las bandas
160 11228 bsanchez
                if (e.getSource() == getHistogramPanel().getButtonShowAll()) {
161 11441 bsanchez
                        getHistogramPanel().refreshBands(true);
162 11202 bsanchez
                        for (int i = 0; i < showBands.length; i++)
163
                                showBands[i] = true;
164
                        updateStatistic();
165
                        updateGraphic();
166
                        return;
167
                }
168
169 10950 bsanchez
                //--------------------------------------
170
                //Selecci?n de fuente de datos del histograma
171 11228 bsanchez
                JComboBox cbo = getHistogramPanel().getComboBoxSource();
172 11042 bsanchez
                if (e.getSource() == cbo) {
173 14397 bsanchez
                        ArrayList comboSource = getHistogramPanel().getComboSource();
174 13942 nacho
                        for (int i = 0; i < comboSource.size(); i++) {
175 20455 bsanchez
                                String name = (String) ((ArrayList) comboSource.get(i)).get(1);
176 20646 nbrodin
                                if (name.compareTo(RasterToolsUtil.getText(this, "datos_visualizados")) == 0) {
177 20455 bsanchez
                                        ((ArrayList) comboSource.get(i)).remove(0);
178
                                        ((ArrayList) comboSource.get(i)).add(0, ((FLyrRasterSE) lyr).getRender().getLastRenderBuffer());
179 13942 nacho
                                }
180 20646 nbrodin
                                if (name.compareTo(RasterToolsUtil.getText(this, "imagen_completa")) == 0) {
181 20455 bsanchez
                                        ((ArrayList) comboSource.get(i)).remove(0);
182
                                        ((ArrayList) comboSource.get(i)).add(0, ((FLyrRasterSE) lyr).getDataSource());
183 13942 nacho
                                }
184
                        }
185 10997 bsanchez
                        showHistogram();
186 10981 bsanchez
                        return;
187 10950 bsanchez
                }
188 12369 bsanchez
189 11444 bsanchez
                // Checkbox de eliminas extremos
190 14439 bsanchez
                if (e.getSource() == getHistogramPanel().getCheckBoxDeleteEdges()) {
191 11443 bsanchez
                        updateGraphic();
192
                        return;
193
                }
194 12369 bsanchez
195 14439 bsanchez
                // Checkbox de RGB
196
                if (e.getSource() == getHistogramPanel().getCheckBoxRGB()) {
197
                        selectHistogram();
198 20481 bsanchez
                        updateStatistic();
199 14439 bsanchez
                        updateGraphic();
200
                        return;
201
                }
202
203 10950 bsanchez
                //--------------------------------------
204
                //Selecci?n de histograma acumulado y no acumulado
205 11228 bsanchez
                JComboBox cbt = getHistogramPanel().getComboBoxType();
206 11042 bsanchez
                if (e.getSource() == cbt) {
207 21307 bsanchez
                        getHistogramPanel().getGraphicContainer().getPGraphic().setViewType(getHistogramPanel().getComboBoxType().getSelectedIndex());
208 10981 bsanchez
                        return;
209 10950 bsanchez
                }
210 12369 bsanchez
211 11033 bsanchez
                //--------------------------------------
212
                // Boton Crear Tabla
213 26368 nbrodin
//                JButton table = getHistogramPanel().getBCreateTable();
214
//                if (e.getSource() == table) {
215
//                        try {
216
////                        -------Mostrar un fileChooser------------------
217
//                                String fName;
218
//                                JFileChooser chooser = new JFileChooser();
219
//                                chooser.setDialogTitle(RasterToolsUtil.getText(this, "guardar_tabla"));
220
//
221
//                                int returnVal = chooser.showOpenDialog(getHistogramPanel());
222
//                                if (returnVal == JFileChooser.APPROVE_OPTION) {
223
//                                        fName = chooser.getSelectedFile().toString();
224
//                                        if (!fName.endsWith(".dbf"))
225
//                                                fName += ".dbf";
226
//
227
//                                        //-------------Crear el dbf----------------------
228
//
229
//                                        DbaseFileWriterNIO dbfWrite = null;
230
//                                        DbaseFileHeaderNIO myHeader;
231
//                                        Value[] record;
232
//
233
//                                        HistogramClass[][] histogram = getLastHistogram().getHistogram();
234
//                                        int numBands = histogram.length;
235
//                                        int numRecors = histogram[0].length;
236
//
237
//                                        File file = new File(fName);
238
//
239
//                                        String names[] = new String[numBands+1];
240
//                                        int types[] = new int [numBands+1];
241
//                                        int lengths[] = new int [numBands+1];
242
//
243
//                                        names[0]="Value";
244
//                                        types[0]=4;
245
//                                        lengths[0]=15;
246
//                                        for (int band = 0; band < numBands; band++){
247
//                                                names[band+1]="Band"+band;
248
//                                                types[band+1]=4;
249
//                                                lengths[band+1]=15;
250
//                                        }
251
//
252
//                                        myHeader = DbaseFileHeaderNIO.createDbaseHeader(names,types,lengths);
253
//
254
//                                        myHeader.setNumRecords(numRecors);
255
//                                        dbfWrite = new DbaseFileWriterNIO(myHeader, (FileChannel) getWriteChannel(file.getPath()));
256
//                                        record = new Value[numBands+1];
257
//
258
//                                        for (int j = 0; j < numRecors; j++) {
259
//                                                record[0] = ValueFactory.createValue(j);
260
//                                                for (int r = 0; r < numBands; r++) {
261
//                                                        record[r+1] = ValueFactory.createValue(histogram[r][j].getValue());
262
//                                                }
263
//
264
//                                                dbfWrite.write(record);
265
//                                        }
266
//
267
//                                        dbfWrite.close();
268
//
269
//                                        //------------A?adir el dbf al proyecto--------------
270
//                                        ProjectExtension ext = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
271
//                                        String name = file.getName();
272
//                                        LayerFactory.getDataSourceFactory().addFileDataSource("gdbms dbf driver", name, fName);
273
//                                        DataSource dataSource;
274
//                                        dataSource = LayerFactory.getDataSourceFactory().createRandomDataSource(name, DataSourceFactory.AUTOMATIC_OPENING);
275
//
276
//                                        SelectableDataSource sds = new SelectableDataSource(dataSource);
277
//                                        EditableAdapter auxea=new EditableAdapter();
278
//                                        auxea.setOriginalDataSource(sds);
279
//                                        ProjectTable projectTable = ProjectFactory.createTable(name, auxea);
280
//                                        //ext.getProject().addTable(projectTable);
281
//                                        ext.getProject().addDocument(projectTable);
282
//
283
//                                        Table t = new Table();
284
//                                        t.setModel(projectTable);
285
//                                        //projectTable.setAndamiWindow(t);
286
//                                        RasterToolsUtil.addWindow(t);
287
//                                }
288
//                        } catch (IOException e1) {
289
//                                JOptionPane.showMessageDialog(null, getHistogramPanel().getName() + " " + RasterToolsUtil.getText(this,"table_not_create"));
290
//                        } catch (DriverLoadException e1) {
291
//                                JOptionPane.showMessageDialog(null, getHistogramPanel().getName() + " " + RasterToolsUtil.getText(this,"table_not_create"));
292
//                        } catch (NoSuchTableException e1) {
293
//                                JOptionPane.showMessageDialog(null, getHistogramPanel().getName() + " " + RasterToolsUtil.getText(this,"table_not_create"));
294
//                        } catch (ReadDriverException e1) {
295
//                                JOptionPane.showMessageDialog(null, getHistogramPanel().getName() + " " + RasterToolsUtil.getText(this,"table_not_create"));
296
//                        }
297
//                }
298 10950 bsanchez
        }
299
300 11068 bsanchez
        /**
301
         * Actualizar la variable de las bandas visibles y su componente visual.
302
         */
303 11042 bsanchez
        private void refreshBands() {
304 11441 bsanchez
                getHistogramPanel().refreshBands(true);
305 20455 bsanchez
                if (getLastHistogram() == null)
306
                        showBands = new boolean[0];
307
                else
308
                        showBands = new boolean[getLastHistogram().getNumBands()];
309 11042 bsanchez
                for (int i = 0; i < showBands.length; i++)
310
                        showBands[i] = true;
311
        }
312 12369 bsanchez
313 11068 bsanchez
        /**
314
         * Lanza los dos threads para procesar el histograma y visualizar la
315
         * ventana de incremento
316
         */
317 10950 bsanchez
        public void showHistogram() {
318 12369 bsanchez
                if (getHistogramPanel().getComboBoxSource().getSelectedIndex() < 0)
319 12307 nacho
                        return;
320 11042 bsanchez
321 12307 nacho
                int dataSrc = getHistogramPanel().getComboBoxSource().getSelectedIndex();
322 17719 bsanchez
                histogramable = (IHistogramable) ((ArrayList) getHistogramPanel().getComboSource().get(dataSrc)).get(0);
323 11441 bsanchez
324 14397 bsanchez
                if (getLastHistogram() == null) {
325 11441 bsanchez
                        try {
326 20455 bsanchez
                                if (histogramable != null)
327
                                        setNewHistogram(histogramable.getHistogram());
328
                                else
329
                                        setNewHistogram(null);
330 11441 bsanchez
                        } catch (HistogramException e) {
331 14397 bsanchez
                                RasterToolsUtil.messageBoxError("histogram_error", getHistogramPanel(), e);
332 13932 nacho
                                return;
333 13409 nacho
                        } catch (InterruptedException e) {
334 17506 bsanchez
335 11441 bsanchez
                        }
336
                        return;
337
                }
338 12369 bsanchez
339 17719 bsanchez
                // Calculo las estadisticas para luego hacer el proceso del histograma.
340
                // El parametro object es el que se le pasara al siguiente proceso
341
                // Mirar el metodo end()
342
                StatisticsProcess statisticsProcess = new StatisticsProcess();
343
                statisticsProcess.setActions(this);
344 17772 bsanchez
                statisticsProcess.addParam("layer", lyr);
345 17719 bsanchez
                statisticsProcess.addParam("force", Boolean.FALSE);
346
                statisticsProcess.start();
347 10950 bsanchez
        }
348 17719 bsanchez
349
        /*
350
         * (non-Javadoc)
351
         * @see org.gvsig.rastertools.IProcessActions#end(java.lang.Object)
352
         */
353
        public void end(Object object) {
354
                // Si tenemos un histograma en el parametro, es que ya ha finalizado el proceso
355
                if (object instanceof Histogram) {
356
                        setNewHistogram((Histogram) object);
357
                        return;
358
                }
359 11068 bsanchez
360 23666 bsanchez
                // Si no tenemos un histograma, osease, tenemos un layer,
361
                // es que aun necesitamos calcularlo
362
                if (object instanceof FLyrRasterSE) {
363 20455 bsanchez
                        if (histogramable != null) {
364
                                HistogramProcess histogramProcess = new HistogramProcess();
365
                                histogramProcess.setActions(this);
366
                                histogramProcess.addParam("histogramable", histogramable);
367
                                histogramProcess.start();
368
                        } else {
369
                                setNewHistogram(null);
370
                        }
371 17719 bsanchez
                }
372
        }
373
374 10950 bsanchez
        /**
375 11068 bsanchez
         * Actualiza la grafica con los datos que ya teniamos del histograma.
376
         */
377 10981 bsanchez
        private void updateGraphic() {
378 20455 bsanchez
                if (getLastHistogram() == null) {
379
                        getHistogramPanel().getGraphicContainer().getPGraphic().cleanChart();
380 14360 bsanchez
                        return;
381 20455 bsanchez
                }
382 14360 bsanchez
383 21307 bsanchez
                HistogramClass[][] histogramClass = getLastHistogram().getHistogram();
384 14360 bsanchez
                if (histogramClass == null)
385
                        return;
386 10981 bsanchez
387 11151 bsanchez
                double[][][] datos = new double[histogramClass.length][histogramClass[0].length][2];
388 14360 bsanchez
                for (int iBand = 0; iBand < histogramClass.length; iBand++) {
389
                        for (int i = 0; i < histogramClass[iBand].length; i++) {
390 11151 bsanchez
                                datos[iBand][i][0] = histogramClass[iBand][i].getMin();
391 11180 bsanchez
                                datos[iBand][i][1] = histogramClass[iBand][i].getValue();
392 11151 bsanchez
                        }
393
                }
394
395 11441 bsanchez
                // Definimos el principio y final de la grafica, sirve para descartar valores.
396 14439 bsanchez
                int first = (int) getHistogramPanel().getBoxValueX1();
397
                int end = (int) getHistogramPanel().getBoxValueX2();
398
                //first = 0;
399
                //end = 100;
400 17506 bsanchez
401 14439 bsanchez
                int min = 0;
402
                int max = histogramClass[0].length - 1;
403 17506 bsanchez
404 14439 bsanchez
                first = min + ((first * (max - min))/ 100);
405
                end = min + ((end * (max - min))/ 100);
406 10981 bsanchez
407 11441 bsanchez
                // Si hay que eliminar los limites, quitamos el ultimo y primer valor de la grafica
408 14439 bsanchez
                if (getHistogramPanel().getCheckBoxDeleteEdges().isSelected()) {
409 11443 bsanchez
                        if ((first + 1) <= end)
410
                                first++;
411
                        if ((end - 1) >= first)
412
                                end--;
413
                }
414 11441 bsanchez
415 11004 bsanchez
                int bandCount = 0;
416 13949 nacho
                for (int i = 0; i < showBands.length; i++)
417 14360 bsanchez
                        if (showBands[i])
418
                                bandCount++;
419 10997 bsanchez
420 13942 nacho
                double[][][] newHistogram = new double[bandCount][end - first + 1][2];
421 11004 bsanchez
                String[] bandNames = new String[bandCount];
422 12369 bsanchez
423 11004 bsanchez
                int numBand = 0;
424 14360 bsanchez
                for (int iBand = 0; iBand < showBands.length; iBand++) {
425 13942 nacho
                        if (!showBands[iBand])
426
                                continue;
427
                        for (int j = first; j <= end; j++) {
428 13948 nacho
                                try {
429 14360 bsanchez
                                        newHistogram[numBand][j - first][0] = datos[iBand][j][0];
430
                                        newHistogram[numBand][j - first][1] = datos[iBand][j][1];
431 13948 nacho
                                } catch (ArrayIndexOutOfBoundsException e) {
432 22529 bsanchez
                                        RasterToolsUtil.messageBoxError("Error al crear el array del histograma. DataType: " + getHistogramPanel().getDataType() + " Posici?n: " + j, this, e);
433 13948 nacho
                                }
434 11151 bsanchez
                        }
435 11116 bsanchez
                        bandNames[numBand] = (String) ((DefaultTableModel) getHistogramPanel().getJTableBands().getModel()).getValueAt(iBand, 1);
436 11004 bsanchez
437 11116 bsanchez
                        getHistogramPanel().getGraphicContainer().setBandColor(numBand, bandsColor[iBand % bandsColor.length]);
438 11033 bsanchez
439 11004 bsanchez
                        numBand++;
440 10981 bsanchez
                }
441
442 11116 bsanchez
                getHistogramPanel().getGraphicContainer().getPGraphic().setNewChart(newHistogram, bandNames);
443 10981 bsanchez
        }
444 10997 bsanchez
445 17506 bsanchez
446 14439 bsanchez
        public void selectHistogram() {
447
                if (getHistogramPanel().getCheckBoxRGB().isSelected())
448
                        lastHistogram = lastHistogramRGB;
449
                else
450
                        lastHistogram = lastHistogramReal;
451
        }
452 14397 bsanchez
        /**
453 11068 bsanchez
         * Definir el nuevo histograma, metodo pu?blico para ser invocado desde
454
         * histogramProcess
455
         * @param histograma nuevo
456
         */
457 14397 bsanchez
        public void setNewHistogram(Histogram histogram) {
458 11116 bsanchez
                getHistogramPanel().panelInizialited = false;
459 11042 bsanchez
                eventsEnabled = false;
460 17506 bsanchez
461 14439 bsanchez
                this.lastHistogramReal = histogram;;
462 19454 nbrodin
                this.lastHistogramRGB = Histogram.convertHistogramToRGB(histogram);
463 14439 bsanchez
                selectHistogram();
464
465 11042 bsanchez
                refreshBands();
466 20455 bsanchez
                updateStatistic();
467 10981 bsanchez
                updateGraphic();
468 10970 bsanchez
469 11042 bsanchez
                // Activo la ejecucion de los eventos porque seguro que ya tenemos un histograma
470
                eventsEnabled = true;
471 11116 bsanchez
                getHistogramPanel().panelInizialited = true;
472 10970 bsanchez
        }
473
474 11068 bsanchez
        /**
475
         * Obtener ?ltimo histograma
476
         * @return Histogram
477
         */
478
        public Histogram getLastHistogram() {
479 11042 bsanchez
                return lastHistogram;
480 10970 bsanchez
        }
481 11004 bsanchez
482 11068 bsanchez
        /**
483
         * Eventos de los BoxValues
484
         */
485 11004 bsanchez
        public void actionValueChanged(GraphicEvent e) {
486 20481 bsanchez
                updateStatistic();
487 14439 bsanchez
                updateGraphic();
488 11004 bsanchez
        }
489 12369 bsanchez
490 11068 bsanchez
        /**
491
         * Proceso para guardar una estadistica en un fichero.
492
         * @param path
493
         * @return
494
         * @throws IOException
495
         */
496
        private WritableByteChannel getWriteChannel(String path) throws IOException {
497 11033 bsanchez
                WritableByteChannel channel;
498 12369 bsanchez
499 11033 bsanchez
                File f = new File(path);
500 12369 bsanchez
501 11033 bsanchez
                if (!f.exists()) {
502
                        if (!f.createNewFile()) {
503
                                throw new IOException("Cannot create file " + f);
504
                        }
505
                }
506 12369 bsanchez
507 11033 bsanchez
                RandomAccessFile raf = new RandomAccessFile(f, "rw");
508
                channel = raf.getChannel();
509 12369 bsanchez
510 11033 bsanchez
                return channel;
511
        }
512 11116 bsanchez
513 11444 bsanchez
        /**
514
         *  Cuando se selecciona/deselecciona una banda
515
         */
516 11116 bsanchez
        public void propertyChange(PropertyChangeEvent evt) {
517 14397 bsanchez
                if (!eventsEnabled)
518
                        return;
519
                int countRow = ((DefaultTableModel) getHistogramPanel().getJTableBands().getModel()).getRowCount();
520
                for (int i = 0; i < countRow; i++)
521
                        showBands[i] = ((Boolean) ((DefaultTableModel) getHistogramPanel().getJTableBands().getModel()).getValueAt(i, 0)).booleanValue();
522
523 20481 bsanchez
                updateStatistic();
524 11116 bsanchez
                updateGraphic();
525
        }
526 17719 bsanchez
527
        public void interrupted() {}
528 10950 bsanchez
}