Statistics
| Revision:

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

History | View | Annotate | Download (4.42 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
import java.awt.event.ComponentEvent;
25
import java.awt.event.ComponentListener;
26

    
27
import javax.swing.event.ChangeEvent;
28
import javax.swing.event.ChangeListener;
29

    
30
import org.gvsig.raster.beans.canvas.layers.GraphicHistogram;
31

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

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

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

    
129
        public void componentHidden(ComponentEvent e) {
130
        }
131

    
132
        public void componentMoved(ComponentEvent e) {
133
        }
134

    
135
        public void componentResized(ComponentEvent e) {
136
                panel.getGraphicBorder().assignVisibleSize();
137
        }
138

    
139
        public void componentShown(ComponentEvent e) {
140
        }
141
        
142
}