Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src-test-ui / org / gvsig / rastertools / enhanced / graphics / panels / EcualizationHistogramListener.java @ 19535

History | View | Annotate | Download (4.04 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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.enhanced.graphics.panels;
20

    
21
import java.awt.Color;
22
import java.awt.event.ActionEvent;
23
import java.awt.event.ActionListener;
24

    
25
import javax.swing.event.ChangeEvent;
26
import javax.swing.event.ChangeListener;
27

    
28
import org.gvsig.raster.beans.canvas.layers.GraphicHistogram;
29

    
30
/**
31
 * Listener para el panel EnhancedGraphic. Gestiona los eventos de todos los
32
 * componentes de este panel.
33
 * 
34
 * 14-oct-2007
35
 * @author Nacho Brodin (nachobrodin@gmail.com)
36
 */
37
public class EcualizationHistogramListener  implements ActionListener, ChangeListener {
38

    
39
        private EcualizationHistogram             panel = null;
40
        
41
        /**
42
         * Constructor
43
         * @param panel
44
         */
45
        public EcualizationHistogramListener(EcualizationHistogram panel) {
46
                this.panel = panel;
47
                panel.getLineType().addActionListener(this);
48
                panel.getHistogramBand().addActionListener(this);
49
                panel.getGraphicType().addActionListener(this);
50
                panel.getSlider().addChangeListener(this);
51
                panel.getMinValue().addActionListener(this);
52
                panel.getMaxValue().addActionListener(this);
53
        }
54
        
55
        public void actionPerformed(ActionEvent e) {
56
                if(e.getSource() == panel.getMinValue()) {
57
                        try {
58
//                                panel.getMinMaxLines().setMin(Double.valueOf(panel.getMinValue().getText()).doubleValue());
59
                        }catch (NumberFormatException ex) {
60
                                
61
                        }
62
                }
63
                
64
                if(e.getSource() == panel.getMaxValue()) {
65
                        try {
66
//                                panel.getMinMaxLines().setMax(Double.valueOf(panel.getMaxValue().getText()).doubleValue());
67
                        }catch (NumberFormatException ex) {
68
                                
69
                        }
70
                }
71
                
72
                if(e.getSource() == panel.getLineType()) {
73
                        
74
                }
75
                
76
                if(e.getSource() == panel.getHistogramBand()) {
77
                        //Eliminamos el histograma que hay y a?adimos el nuevo
78
                        for (int i = 0; i < panel.getDrawableElementsCount(); i++) {
79
                                if(panel.getDrawableElement(i) instanceof GraphicHistogram) {
80
                                        Object value = panel.getHistogramBand().getSelectedItem();
81
                                        if(value instanceof String) {
82
                                                double[] hist = panel.getHistogram((String)value);
83
                                                Color colorH = Color.RED;
84
                                                if(value.equals("G"))
85
                                                        colorH = Color.GREEN;
86
                                                if(value.equals("B"))
87
                                                        colorH = Color.BLUE;
88
                                                GraphicHistogram gHist = new GraphicHistogram(hist, colorH);
89
                                                gHist.setCanvas(panel.getCanvas());
90
                                                int lineType = GraphicHistogram.TYPE_LINE;
91
                                                if(panel.getGraphicType().getSelectedItem().equals("Fill"))
92
                                                        lineType = GraphicHistogram.TYPE_FILL;
93
                                                gHist.setType(lineType);
94
                                                panel.getDrawableElements().remove(i);
95
                                                panel.getDrawableElements().add(i, gHist);
96
                                                panel.getCanvas().repaint();
97
                                        }
98
                                        
99
                                }
100
                        }
101
                        
102
                }
103
                
104
                if(e.getSource() == panel.getGraphicType()) {
105
                        for (int i = 0; i < panel.getDrawableElementsCount(); i++) {
106
                                if(panel.getDrawableElement(i) instanceof GraphicHistogram) {
107
                                        Object value = panel.getGraphicType().getSelectedItem();
108
                                        if(value instanceof String) {
109
                                                if(value.equals("Line"))
110
                                                        ((GraphicHistogram)panel.getDrawableElement(i)).setType(GraphicHistogram.TYPE_LINE);
111
                                                if(value.equals("Fill"))
112
                                                        ((GraphicHistogram)panel.getDrawableElement(i)).setType(GraphicHistogram.TYPE_FILL);
113
                                                panel.getCanvas().repaint();
114
                                        }
115
                                }
116
                        }
117
                }
118
        }
119

    
120
        /**
121
         * Acciones que se ejecutan al variar el slider de la gr?fica
122
         */
123
        public void stateChanged(ChangeEvent e) {
124
        }
125
}