Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_Build_1014 / libraries / libCq_CMS_praster / src / org / cresques / ui / raster / listener / HistogramPanelListener.java @ 13593

History | View | Annotate | Download (6.47 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.cresques.ui.raster.listener;
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.JButton;
32
import javax.swing.JComboBox;
33
import javax.swing.JLabel;
34
import javax.swing.event.TableModelEvent;
35

    
36
import org.cresques.io.datastruct.Histogram;
37
import org.cresques.io.datastruct.Statistic;
38
import org.cresques.ui.raster.HistogramPanel;
39

    
40
/**
41
 * Listener para eventos del panel de histograma
42
 * @author Nacho Brodin <brodin_ign@gva.es>
43
 *
44
 */
45
public class HistogramPanelListener implements FocusListener, KeyListener, MouseListener, ActionListener, MouseMotionListener{
46

    
47
        private HistogramPanel                        panel = null;
48
        /**
49
         * Objeto histograma para la gesti?n de procesos de histograma
50
         */
51
        private        Histogram                                histogramObj = null;
52
        
53
        public static boolean                         comboEventEnable = true;
54
                
55
        public HistogramPanelListener(HistogramPanel p){
56
                panel = p;
57
        }
58
        
59
        public void setControlListeners(){
60
                panel.getPHistogram().getPlusButtonControlLeft().addActionListener(this);
61
                panel.getPHistogram().getPlusButtonControlRight().addActionListener(this);
62
                panel.getPHistogram().getLessButtonControlLeft().addActionListener(this);
63
                panel.getPHistogram().getLessButtonControlRight().addActionListener(this);
64
                panel.getPHistogram().getTextControlRight().addKeyListener(this);
65
                panel.getPHistogram().getTextControlLeft().addKeyListener(this);
66
                panel.getPHistogram().getTextControlRight().addFocusListener(this);
67
                panel.getPHistogram().getTextControlLeft().addFocusListener(this);
68
        }
69
        
70
        public void mouseDragged(MouseEvent e) {
71
                                
72
        }
73

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

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

    
90
        private void initialize(){
91

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

    
165
        public void tableChanged(TableModelEvent e) {
166
                                
167
        }
168

    
169
        public void mouseClicked(MouseEvent e) {
170
                
171
        }
172

    
173
        public void mouseEntered(MouseEvent e) {
174
                                
175
        }
176

    
177
        public void mouseExited(MouseEvent e) {
178
                                
179
        }
180

    
181
        /**
182
         * Asigna el objeto histograma para la gesti?n de procesos de histograma
183
         * @param histogramObj
184
         */
185
        public void setHistogram(Histogram histogramObj) {
186
                this.histogramObj = histogramObj;
187
        }
188

    
189
        public void keyPressed(KeyEvent e) {
190
                if(e.getKeyCode() == 10){
191
                        panel.setStatistic(Statistic.getBasicStatsFromHistogram(panel.getLastHistogram(),
192
                                                                                                                                        (int)panel.getBoxesValues()[1], 
193
                                                                                                                                        (int)panel.getBoxesValues()[0],
194
                                                                                                                                        panel.showBands));
195
                        
196
                }
197
        }
198

    
199
        public void keyReleased(KeyEvent e) {
200
                // TODO Auto-generated method stub
201
                
202
        }
203

    
204
        public void keyTyped(KeyEvent e) {
205
                // TODO Auto-generated method stub
206
                
207
        }
208

    
209
        public void focusGained(FocusEvent e) {
210
                // TODO Auto-generated method stub
211
                
212
        }
213

    
214
        public void focusLost(FocusEvent e) {
215
                // TODO Auto-generated method stub
216
                
217
        }
218

    
219
}