Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / histogram / ui / HistogramPanelListener.java @ 10819

History | View | Annotate | Download (7.96 KB)

1
/* 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.ui;
20

    
21
import java.awt.event.ActionEvent;
22
import java.awt.event.ActionListener;
23
import java.awt.event.FocusEvent;
24
import java.awt.event.FocusListener;
25
import java.awt.event.KeyEvent;
26
import java.awt.event.KeyListener;
27
import java.awt.event.MouseEvent;
28
import java.awt.event.MouseListener;
29
import java.awt.event.MouseMotionListener;
30

    
31
import javax.swing.JLabel;
32
import javax.swing.event.TableModelEvent;
33

    
34
import org.gvsig.rastertools.histogram.Histogram;
35
/**
36
 * Listener para eventos del panel de histograma
37
 *
38
 * @version 20/03/2007
39
 * @author Nacho Brodin (brodin_ign@gva.es)
40
 * @author Borja Sanchez Zamorano (borja.sanchez@iver.es)
41
 */
42
public class HistogramPanelListener implements ActionListener, KeyListener, FocusListener {
43

    
44
        private HistogramPanel                        panel = null;
45
        /**
46
         * Objeto histograma para la gesti?n de procesos de histograma
47
         */
48
        private        Histogram                                histogram = null;
49
        /**
50
         * ?ltimo histograma visualizado en el gr?fico
51
         */
52
        private int[][]                                                lastHistogram = null;
53

    
54
        public static boolean                         comboEventEnable = true;
55
                
56
        public HistogramPanelListener(HistogramPanel p){
57
                panel = p;
58
        }
59
        
60
        public void setControlListeners(){
61
                panel.getGraphicContainer().getPlusButtonControlLeft().addActionListener(this);
62
                panel.getGraphicContainer().getPlusButtonControlRight().addActionListener(this);
63
                panel.getGraphicContainer().getLessButtonControlLeft().addActionListener(this);
64
                panel.getGraphicContainer().getLessButtonControlRight().addActionListener(this);
65
                panel.getGraphicContainer().getTextControlRight().addKeyListener(this);
66
                panel.getGraphicContainer().getTextControlLeft().addKeyListener(this);
67
                panel.getGraphicContainer().getTextControlRight().addFocusListener(this);
68
                panel.getGraphicContainer().getTextControlLeft().addFocusListener(this);
69
        }
70

    
71
        public void actionPerformed(ActionEvent e) {
72
/*                
73
                //--------------------------------------
74
                //Botones de m?s y menos
75
                if(        e.getSource() == panel.getPHistogram().getPlusButtonControlLeft() ||
76
                        e.getSource() == panel.getPHistogram().getLessButtonControlLeft() ||
77
                        e.getSource() == panel.getPHistogram().getPlusButtonControlRight() ||
78
                        e.getSource() == panel.getPHistogram().getLessButtonControlRight()){
79
                        panel.setStatistic(Statistic.getBasicStatsFromHistogram(panel.getLastHistogram(),
80
                                                                                                                                        (int)panel.getBoxesValues()[1], 
81
                                                                                                                                        (int)panel.getBoxesValues()[0],
82
                                                                                                                                        panel.showBands));
83
                        return;
84
                }
85
                        
86
                
87
                //--------------------------------------
88
                //Cambiar las bandas en el combo
89
                JComboBox cbb = panel.getJComboBands();
90
                if(comboEventEnable && e.getSource() == cbb){
91
                        if(cbb.getSelectedIndex() == 0){
92
                                boolean[] list = panel.getBandListShowInChart();
93
                                for(int i = 0; i < list.length; i++)
94
                                        list[i] = true;
95
                                panel.setBandListShowInChart(list);
96
                        }else if(cbb.getSelectedItem().equals("R") || cbb.getSelectedItem().equals("Band 0"))
97
                                panel.addOrRemoveGraphicBand(0);
98
                        else if(cbb.getSelectedItem().equals("G") || cbb.getSelectedItem().equals("Band 1"))
99
                                panel.addOrRemoveGraphicBand(1);
100
                        else if(cbb.getSelectedItem().equals("B") || cbb.getSelectedItem().equals("Band 2"))
101
                                panel.addOrRemoveGraphicBand(2);
102
                        else{
103
                                for(int i = 3; i < HistogramPanel.MAXBANDS; i++){
104
                                        if(cbb.getSelectedItem().equals("Band "+i))
105
                                                panel.addOrRemoveGraphicBand(i);
106
                                }
107
                        }
108
                }
109
                
110
                //--------------------------------------                
111
                //Limpiar
112
                JButton clean = panel.getJButtonClear();
113
                if(e.getSource() == clean){
114
                        panel.cleanChart();
115
                }
116
                
117
                //--------------------------------------
118
                //Selecci?n de fuente de datos del histograma
119
                JComboBox cbo = panel.getJComboBoxOrigen();
120
                if(comboEventEnable && e.getSource() == cbo){
121
                        panel.setHistogramDataSource(cbo.getSelectedIndex());
122
                        
123
                        //En caso de que el histograma se monte a partir de los datos de la vista ponemos RGB en el combo
124
                        if(cbo.getSelectedIndex() == 0)
125
                                panel.setRGBInBandList();
126
                        
127
                        //En caso de que el histograma se monte a partir de los datos reales ponemos el n?mero de bandas en el combo
128
                        if(cbo.getSelectedIndex() == 1 || cbo.getSelectedIndex() == 2)
129
                                panel.setBands(panel.getHistogram().getGrid().getBandCount());                        
130
                }
131
                                
132
                //--------------------------------------
133
                //Selecci?n de histograma acumulado y no acumulado
134
                JComboBox cbt = panel.getJComboBoxTipo();
135
                if(comboEventEnable && e.getSource() == cbt)
136
                        panel.setType(cbt.getSelectedIndex());
137
        
138
                if(comboEventEnable)
139
                        panel.showHistogram();
140
*/
141
        }
142

    
143
        /**
144
         * Obtiene el ?ltimo histograma visualizado
145
         * @return
146
         */
147
        public int[][] getLastHistogram() {
148
                return lastHistogram;
149
        }
150

    
151
        /**
152
         * Asigna el objeto histograma para la gesti?n de procesos de histograma
153
         * @param histogramObj
154
         */
155
        public void setHistogram(Histogram histogram) {
156
                this.histogram = histogram;
157
        }
158
        
159
        /**
160
         * M?todo que ejecuta el thread que comprueba cuando se ha acabado de generar
161
         * el histograma. Al finalizar, se lee el histograma de la imagen completa 
162
         * calculado y se muestra.
163
         */
164
        public void readFullHistogramFromThread(){
165
                if (panel.getType() == 0)
166
                        lastHistogram = getHistogram().getFullHistogram();
167
                else if(panel.getType() == 1)
168
                        lastHistogram = getHistogram().getFullAccumulatedHistogram();
169
                
170
/*                setStatistic(Statistic.getBasicStatsFromHistogram(        lastHistogram, 
171
                                                                                                                        (int)getBoxesValues()[1], 
172
                                                                                                                        (int)getBoxesValues()[0], 
173
                                                                                                                        showBands));
174
*/
175
                //Si el histograma es grande lo recortamos para mostrarlo porque jfreeChart se vuelve
176
                //inestable al poner muchos elementos en las X
177
                
178
/*
179

180
                 int pos = lastHistogram[0].length;
181
                int[][] newHistogram = lastHistogram;
182
                boolean elem = true;
183
                if(lastHistogram[0].length >= Utilities.MAX_SHORT_BIT_VALUE){
184
                        for(int i = (lastHistogram[0].length - 1); i >= 0; i--){
185
                                for(int iBand = 0; iBand < lastHistogram.length; iBand ++){
186
                                        if(lastHistogram[iBand][i] != 0)
187
                                                elem = false;
188
                                }
189
                                if(!elem){
190
                                        pos = i;
191
                                        break;
192
                                }
193
                        }
194
                        newHistogram = new int[lastHistogram.length][pos];
195
                        for(int iBand = 0; iBand < lastHistogram.length; iBand ++){
196
                                for(int i = 0; i < newHistogram[iBand].length; i ++){
197
                                        newHistogram[iBand][i] = lastHistogram[iBand][i];
198
                                }
199
                        }
200
                }
201
*/
202
/*
203
                GraphicChartPanel gcp = pHistogram.getPGraphic();
204
                
205
                String bandNames[] = new String[lastHistogram.length];
206
                for (int iBand = 0; iBand<lastHistogram.length; iBand++)
207
                        bandNames[iBand]=this.getJComboBands().getItemAt(iBand+1).toString();
208
                
209
                gcp.setNewChart(newHistogram, bandNames);
210
*/
211
        }
212

    
213
        /**
214
         * Obtiene el objeto histograma para la gesti?n de procesos de histograma
215
         * @return
216
         */
217
        public Histogram getHistogram() {
218
                return histogram;
219
        }
220
        
221
        public void keyPressed(KeyEvent e) {
222
/*                if(e.getKeyCode() == 10){
223
                        panel.setStatistic(Statistic.getBasicStatsFromHistogram(panel.getLastHistogram(),
224
                                                                                                                                        (int)panel.getBoxesValues()[1], 
225
                                                                                                                                        (int)panel.getBoxesValues()[0],
226
                                                                                                                                        panel.showBands));
227
                        
228
                }*/
229
        }
230

    
231
        public void keyReleased(KeyEvent e) {
232
                // TODO Auto-generated method stub
233
                
234
        }
235

    
236
        public void keyTyped(KeyEvent e) {
237
                // TODO Auto-generated method stub
238
                
239
        }
240

    
241
        public void focusGained(FocusEvent e) {
242
                // TODO Auto-generated method stub
243
                
244
        }
245

    
246
        public void focusLost(FocusEvent e) {
247
                // TODO Auto-generated method stub
248
                
249
        }
250
}