Statistics
| Revision:

root / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / graphic / GraphicContainer.java @ 13978

History | View | Annotate | Download (6.27 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 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.gui.beans.graphic;
20

    
21
import java.awt.BorderLayout;
22
import java.awt.Color;
23
import java.awt.Dimension;
24
import java.util.ArrayList;
25
import java.util.Iterator;
26

    
27
import javax.swing.JComponent;
28
import javax.swing.JPanel;
29

    
30
import org.gvsig.gui.beans.doubleslider.DoubleSlider;
31
import org.gvsig.gui.beans.doubleslider.DoubleSliderEvent;
32
import org.gvsig.gui.beans.doubleslider.DoubleSliderListener;
33
import org.gvsig.gui.beans.textincreaser.TextIncreaserEvent;
34
import org.gvsig.gui.beans.textincreaser.TextIncreaserListener;
35
/**
36
 * Control para el manejo de un gr?fico.
37
 * 
38
 * @author Nacho Brodin (brodin_ign@gva.es)
39
 */
40
public class GraphicContainer extends JPanel implements DoubleSliderListener, TextIncreaserListener {
41
        private static final long serialVersionUID = -6230083498345786500L;
42
        private ArrayList actionCommandListeners = new ArrayList();
43

    
44
        private JPanel            pGeneral         = null;
45
        private GraphicChartPanel pGraphic         = null;
46
        private JPanel            panelSlider      = null;
47
        private BoxesPanel        pBoxes           = null;
48
        private DoubleSlider      doubleSlider     = null;
49

    
50
        private boolean           bDoCallListeners = true;
51
        static private int        eventId          = Integer.MIN_VALUE;
52

    
53
        public GraphicContainer() {
54
                initialize();
55
        }
56

    
57
        public GraphicContainer(boolean showSlider) {
58
                getPDoubleSlider().setVisible(showSlider);
59
                initialize();
60
        }
61

    
62

    
63
        private void initialize() {
64
                this.setLayout(new BorderLayout(0, 4));
65
                this.add(getPGraphic(), BorderLayout.CENTER);
66
                this.add(getPGeneral(), BorderLayout.SOUTH);
67
        }
68

    
69
        /**
70
         * This method initializes jPanel1        
71
         *         
72
         * @return javax.swing.JPanel        
73
         */
74
        private JPanel getPGeneral() {
75
                if (pGeneral == null) {
76
                        pGeneral = new JPanel();
77
                        pGeneral.setLayout(new BorderLayout(0, 2));
78
                        getPDoubleSlider().setPreferredSize(new Dimension(50, 25));
79
                        pGeneral.add(getPDoubleSlider(), BorderLayout.NORTH);
80
                        pGeneral.add(getPBoxes(), BorderLayout.SOUTH);
81
                }
82
                return pGeneral;
83
        }
84

    
85
        /**
86
         * This method initializes jPanel1        
87
         *         
88
         * @return javax.swing.JPanel        
89
         */
90
        public GraphicChartPanel getPGraphic() {
91
                if (pGraphic == null) {
92
                        pGraphic = new GraphicChartPanel();
93
                }
94
                return pGraphic;
95
        }
96

    
97
        /**
98
         * This method initializes jPanel1        
99
         *         
100
         * @return javax.swing.JPanel        
101
         */
102
        private JComponent getPDoubleSlider() {
103
                if (panelSlider == null) {
104
                        panelSlider = new JPanel();
105
                        panelSlider.setLayout(new BorderLayout());
106
                        panelSlider.add(getDoubleSlider(), BorderLayout.CENTER);
107
                }
108
                return panelSlider;
109
        }
110
        
111
        /**
112
         * Devuelve el componente DoubleSlider
113
         * @return
114
         */
115
        private DoubleSlider getDoubleSlider() {
116
                if (doubleSlider == null) {
117
                        doubleSlider = new DoubleSlider();
118
                        doubleSlider.addValueChangedListener(this);
119
                }
120
                return doubleSlider;
121
        }
122

    
123
        /**
124
         * This method initializes jPanel1        
125
         *         
126
         * @return javax.swing.JPanel        
127
         */
128
        private BoxesPanel getPBoxes() {
129
                if (pBoxes == null) {
130
                        pBoxes = new BoxesPanel();
131
                        pBoxes.getControlLeft().addValueChangedListener(this);
132
                        pBoxes.getControlRight().addValueChangedListener(this);
133
                }
134
                return pBoxes;
135
        }
136

    
137
        //****************************************************
138
        //M?TODOS DEL CONTROL
139

    
140
        public double getX1() {
141
                return getPBoxes().getControlLeft().getValue();
142
        }
143

    
144
        public double getX2() {
145
                return getPBoxes().getControlRight().getValue();
146
        }
147

    
148
        public void actionValueChanged(TextIncreaserEvent e) {
149
                if (e.getSource() == getPBoxes().getControlLeft()) {
150
                        if (getPBoxes().getControlLeft().getValue() > getPBoxes().getControlRight().getValue())
151
                                getPBoxes().getControlRight().setValue(getPBoxes().getControlLeft().getValue());
152
                }
153
                if (e.getSource() == getPBoxes().getControlRight()) {
154
                        if (getPBoxes().getControlRight().getValue() < getPBoxes().getControlLeft().getValue())
155
                                getPBoxes().getControlLeft().setValue(getPBoxes().getControlRight().getValue());
156
                }
157
                getDoubleSlider().setX1((int) getPBoxes().getControlLeft().getValue());
158
                getDoubleSlider().setX2((int) getPBoxes().getControlRight().getValue());
159
                callValueChangedListeners();
160
        }
161

    
162
        public void addValueChangedListener(GraphicListener listener) {
163
                if (!actionCommandListeners.contains(listener))
164
                        actionCommandListeners.add(listener);
165
        }
166

    
167
        public void removeValueChangedListener(GraphicListener listener) {
168
                actionCommandListeners.remove(listener);
169
        }
170

    
171
        private void callValueChangedListeners() {
172
                if (!bDoCallListeners)
173
                        return;
174
                Iterator acIterator = actionCommandListeners.iterator();
175
                while (acIterator.hasNext()) {
176
                        GraphicListener listener = (GraphicListener) acIterator.next();
177
                        listener.actionValueChanged(new GraphicEvent(this));
178
                }
179
                eventId++;
180
        }
181

    
182
        public void setBandVisible(int band, boolean visible) {
183
                getPGraphic().getChart().getChart().getXYPlot().getRenderer().setSeriesVisible(band, Boolean.valueOf(visible));
184
        }
185

    
186
        public void setBandColor(int band, Color color) {
187
                getPGraphic().getChart().getChart().getXYPlot().getRenderer().setSeriesPaint(band, color);
188
        }
189

    
190
        /*
191
         * (non-Javadoc)
192
         * @see org.gvsig.gui.beans.doubleslider.DoubleSliderListener#actionValueChanged(java.util.EventObject)
193
         */
194
        public void actionValueChanged(DoubleSliderEvent e) {
195
                getPBoxes().getControlLeft().setValue(((DoubleSlider) e.getSource()).getX1());
196
                getPBoxes().getControlRight().setValue(((DoubleSlider) e.getSource()).getX2());
197
                callValueChangedListeners();
198
        }
199

    
200
        /*
201
         * (non-Javadoc)
202
         * @see org.gvsig.gui.beans.doubleslider.DoubleSliderListener#actionValueDragged(java.util.EventObject)
203
         */
204
        public void actionValueDragged(DoubleSliderEvent e) {
205
                actionValueChanged(e);
206
        }
207
}