Statistics
| Revision:

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

History | View | Annotate | Download (8.34 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 FocusListener, KeyListener, MouseListener, ActionListener, MouseMotionListener{
43

    
44
        private HistogramPanel                        panel = null;
45
        /**
46
         * Objeto histograma para la gesti?n de procesos de histograma
47
         */
48
        private        Histogram                                histogramObj = 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 mouseDragged(MouseEvent e) {
72
                                
73
        }
74

    
75
        public void mousePressed(MouseEvent e) {
76
                
77
        }
78

    
79
        public void mouseReleased(MouseEvent e) {
80
                        
81
        }
82
        
83
        public void setLabels(JLabel left, JLabel right){
84
                  
85
        }
86
        
87
        public void mouseMoved(MouseEvent e) {
88
                        
89
        }
90

    
91
        private void initialize(){
92

    
93
        }
94
        
95
        public void actionPerformed(ActionEvent e) {
96
/*                
97
                //--------------------------------------
98
                //Botones de m?s y menos
99
                if(        e.getSource() == panel.getPHistogram().getPlusButtonControlLeft() ||
100
                        e.getSource() == panel.getPHistogram().getLessButtonControlLeft() ||
101
                        e.getSource() == panel.getPHistogram().getPlusButtonControlRight() ||
102
                        e.getSource() == panel.getPHistogram().getLessButtonControlRight()){
103
                        panel.setStatistic(Statistic.getBasicStatsFromHistogram(panel.getLastHistogram(),
104
                                                                                                                                        (int)panel.getBoxesValues()[1], 
105
                                                                                                                                        (int)panel.getBoxesValues()[0],
106
                                                                                                                                        panel.showBands));
107
                        return;
108
                }
109
                        
110
                
111
                //--------------------------------------
112
                //Cambiar las bandas en el combo
113
                JComboBox cbb = panel.getJComboBands();
114
                if(comboEventEnable && e.getSource() == cbb){
115
                        if(cbb.getSelectedIndex() == 0){
116
                                boolean[] list = panel.getBandListShowInChart();
117
                                for(int i = 0; i < list.length; i++)
118
                                        list[i] = true;
119
                                panel.setBandListShowInChart(list);
120
                        }else if(cbb.getSelectedItem().equals("R") || cbb.getSelectedItem().equals("Band 0"))
121
                                panel.addOrRemoveGraphicBand(0);
122
                        else if(cbb.getSelectedItem().equals("G") || cbb.getSelectedItem().equals("Band 1"))
123
                                panel.addOrRemoveGraphicBand(1);
124
                        else if(cbb.getSelectedItem().equals("B") || cbb.getSelectedItem().equals("Band 2"))
125
                                panel.addOrRemoveGraphicBand(2);
126
                        else{
127
                                for(int i = 3; i < HistogramPanel.MAXBANDS; i++){
128
                                        if(cbb.getSelectedItem().equals("Band "+i))
129
                                                panel.addOrRemoveGraphicBand(i);
130
                                }
131
                        }
132
                }
133
                
134
                //--------------------------------------                
135
                //Limpiar
136
                JButton clean = panel.getJButtonClear();
137
                if(e.getSource() == clean){
138
                        panel.cleanChart();
139
                }
140
                
141
                //--------------------------------------
142
                //Selecci?n de fuente de datos del histograma
143
                JComboBox cbo = panel.getJComboBoxOrigen();
144
                if(comboEventEnable && e.getSource() == cbo){
145
                        panel.setHistogramDataSource(cbo.getSelectedIndex());
146
                        
147
                        //En caso de que el histograma se monte a partir de los datos de la vista ponemos RGB en el combo
148
                        if(cbo.getSelectedIndex() == 0)
149
                                panel.setRGBInBandList();
150
                        
151
                        //En caso de que el histograma se monte a partir de los datos reales ponemos el n?mero de bandas en el combo
152
                        if(cbo.getSelectedIndex() == 1 || cbo.getSelectedIndex() == 2)
153
                                panel.setBands(panel.getHistogram().getGrid().getBandCount());                        
154
                }
155
                                
156
                //--------------------------------------
157
                //Selecci?n de histograma acumulado y no acumulado
158
                JComboBox cbt = panel.getJComboBoxTipo();
159
                if(comboEventEnable && e.getSource() == cbt)
160
                        panel.setType(cbt.getSelectedIndex());
161
        
162
                if(comboEventEnable)
163
                        panel.showHistogram();
164
*/
165
        }
166

    
167
        public void tableChanged(TableModelEvent e) {
168
                                
169
        }
170

    
171
        public void mouseClicked(MouseEvent e) {
172
                
173
        }
174

    
175
        public void mouseEntered(MouseEvent e) {
176
                                
177
        }
178

    
179
        public void mouseExited(MouseEvent e) {
180
                                
181
        }
182

    
183
        /**
184
         * Obtiene el ?ltimo histograma visualizado
185
         * @return
186
         */
187
        public int[][] getLastHistogram() {
188
                return lastHistogram;
189
        }
190

    
191
        /**
192
         * Asigna el objeto histograma para la gesti?n de procesos de histograma
193
         * @param histogramObj
194
         */
195
        public void setHistogram(Histogram histogramObj) {
196
                this.histogramObj = histogramObj;
197
        }
198
        
199
        /**
200
         * M?todo que ejecuta el thread que comprueba cuando se ha acabado de generar
201
         * el histograma. Al finalizar, se lee el histograma de la imagen completa 
202
         * calculado y se muestra.
203
         */
204
        public void readFullHistogramFromThread(){
205
                if (panel.getType() == 0)
206
                        lastHistogram = histogramObj.getFullHistogram();
207
                else if(panel.getType() == 1)
208
                        lastHistogram = histogramObj.getFullAccumulatedHistogram();
209
                
210
/*                setStatistic(Statistic.getBasicStatsFromHistogram(        lastHistogram, 
211
                                                                                                                        (int)getBoxesValues()[1], 
212
                                                                                                                        (int)getBoxesValues()[0], 
213
                                                                                                                        showBands));
214
*/
215
                //Si el histograma es grande lo recortamos para mostrarlo porque jfreeChart se vuelve
216
                //inestable al poner muchos elementos en las X
217
                
218
/*
219

220
                 int pos = lastHistogram[0].length;
221
                int[][] newHistogram = lastHistogram;
222
                boolean elem = true;
223
                if(lastHistogram[0].length >= Utilities.MAX_SHORT_BIT_VALUE){
224
                        for(int i = (lastHistogram[0].length - 1); i >= 0; i--){
225
                                for(int iBand = 0; iBand < lastHistogram.length; iBand ++){
226
                                        if(lastHistogram[iBand][i] != 0)
227
                                                elem = false;
228
                                }
229
                                if(!elem){
230
                                        pos = i;
231
                                        break;
232
                                }
233
                        }
234
                        newHistogram = new int[lastHistogram.length][pos];
235
                        for(int iBand = 0; iBand < lastHistogram.length; iBand ++){
236
                                for(int i = 0; i < newHistogram[iBand].length; i ++){
237
                                        newHistogram[iBand][i] = lastHistogram[iBand][i];
238
                                }
239
                        }
240
                }
241
*/
242
/*
243
                GraphicChartPanel gcp = pHistogram.getPGraphic();
244
                
245
                String bandNames[] = new String[lastHistogram.length];
246
                for (int iBand = 0; iBand<lastHistogram.length; iBand++)
247
                        bandNames[iBand]=this.getJComboBands().getItemAt(iBand+1).toString();
248
                
249
                gcp.setNewChart(newHistogram, bandNames);
250
*/
251
        }
252

    
253
        /**
254
         * Obtiene el objeto histograma para la gesti?n de procesos de histograma
255
         * @return
256
         */
257
        public Histogram getHistogram() {
258
                return histogramObj;
259
        }
260
        
261
        public void keyPressed(KeyEvent e) {
262
/*                if(e.getKeyCode() == 10){
263
                        panel.setStatistic(Statistic.getBasicStatsFromHistogram(panel.getLastHistogram(),
264
                                                                                                                                        (int)panel.getBoxesValues()[1], 
265
                                                                                                                                        (int)panel.getBoxesValues()[0],
266
                                                                                                                                        panel.showBands));
267
                        
268
                }*/
269
        }
270

    
271
        public void keyReleased(KeyEvent e) {
272
        }
273

    
274
        public void keyTyped(KeyEvent e) {
275
        }
276

    
277
        public void focusGained(FocusEvent e) {
278
        }
279

    
280
        public void focusLost(FocusEvent e) {
281
        }
282
}