Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / graphic / GraphicContainer.java @ 40561

History | View | Annotate | Download (6.55 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.gui.beans.graphic;
25

    
26
import java.awt.BorderLayout;
27
import java.awt.Color;
28
import java.awt.Dimension;
29
import java.util.ArrayList;
30
import java.util.Iterator;
31

    
32
import javax.swing.JComponent;
33
import javax.swing.JPanel;
34

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

    
49
        private JPanel            pGeneral         = null;
50
        private GraphicChartPanel pGraphic         = null;
51
        private JPanel            panelSlider      = null;
52
        private BoxesPanel        pBoxes           = null;
53
        private DoubleSlider      doubleSlider     = null;
54

    
55
        private boolean           bDoCallListeners = true;
56
        static private int        eventId          = Integer.MIN_VALUE;
57

    
58
        public GraphicContainer() {
59
                initialize();
60
        }
61

    
62
        public GraphicContainer(boolean showSlider) {
63
                getPDoubleSlider().setVisible(showSlider);
64
                initialize();
65
        }
66

    
67

    
68
        private void initialize() {
69
                this.setLayout(new BorderLayout(0, 4));
70
                this.add(getPGraphic(), BorderLayout.CENTER);
71
                this.add(getPGeneral(), BorderLayout.SOUTH);
72
        }
73

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

    
90
        /**
91
         * This method initializes jPanel1        
92
         *         
93
         * @return javax.swing.JPanel        
94
         */
95
        public GraphicChartPanel getPGraphic() {
96
                if (pGraphic == null) {
97
                        pGraphic = new GraphicChartPanel();
98
                }
99
                return pGraphic;
100
        }
101

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

    
128
        /**
129
         * This method initializes jPanel1        
130
         *         
131
         * @return javax.swing.JPanel        
132
         */
133
        private BoxesPanel getPBoxes() {
134
                if (pBoxes == null) {
135
                        pBoxes = new BoxesPanel();
136
                        pBoxes.getControlLeft().addValueChangedListener(this);
137
                        pBoxes.getControlRight().addValueChangedListener(this);
138
                }
139
                return pBoxes;
140
        }
141

    
142
        //****************************************************
143
        //M?TODOS DEL CONTROL
144

    
145
        public double getX1() {
146
                double value = getPBoxes().getControlLeft().getValue();
147
                
148
                if (value > 100)
149
                        value = 100;
150

    
151
                if (value < 0)
152
                        value = 0;
153

    
154
                return value;
155
        }
156

    
157
        public double getX2() {
158
                double value = getPBoxes().getControlRight().getValue();
159

    
160
                if (value > 100)
161
                        value = 100;
162

    
163
                if (value < 0)
164
                        value = 0;
165

    
166
                return value;
167
        }
168

    
169
        public void actionValueChanged(TextIncreaserEvent e) {
170
                if (e.getSource() == getPBoxes().getControlLeft()) {
171
                        if (getPBoxes().getControlLeft().getValue() > getPBoxes().getControlRight().getValue())
172
                                getPBoxes().getControlRight().setValue(getPBoxes().getControlLeft().getValue());
173
                }
174
                if (e.getSource() == getPBoxes().getControlRight()) {
175
                        if (getPBoxes().getControlRight().getValue() < getPBoxes().getControlLeft().getValue())
176
                                getPBoxes().getControlLeft().setValue(getPBoxes().getControlRight().getValue());
177
                }
178
                getDoubleSlider().setX1((int) getPBoxes().getControlLeft().getValue());
179
                getDoubleSlider().setX2((int) getPBoxes().getControlRight().getValue());
180
                callValueChangedListeners();
181
        }
182

    
183
        public void addValueChangedListener(GraphicListener listener) {
184
                if (!actionCommandListeners.contains(listener))
185
                        actionCommandListeners.add(listener);
186
        }
187

    
188
        public void removeValueChangedListener(GraphicListener listener) {
189
                actionCommandListeners.remove(listener);
190
        }
191

    
192
        private void callValueChangedListeners() {
193
                if (!bDoCallListeners)
194
                        return;
195
                Iterator acIterator = actionCommandListeners.iterator();
196
                while (acIterator.hasNext()) {
197
                        GraphicListener listener = (GraphicListener) acIterator.next();
198
                        listener.actionValueChanged(new GraphicEvent(this));
199
                }
200
                eventId++;
201
        }
202

    
203
        public void setBandVisible(int band, boolean visible) {
204
                getPGraphic().getChart().getChart().getXYPlot().getRenderer().setSeriesVisible(band, Boolean.valueOf(visible));
205
        }
206

    
207
        public void setBandColor(int band, Color color) {
208
                getPGraphic().getChart().getChart().getXYPlot().getRenderer().setSeriesPaint(band, color);
209
        }
210

    
211
        /*
212
         * (non-Javadoc)
213
         * @see org.gvsig.gui.beans.doubleslider.DoubleSliderListener#actionValueChanged(java.util.EventObject)
214
         */
215
        public void actionValueChanged(DoubleSliderEvent e) {
216
                getPBoxes().getControlLeft().setValue(((DoubleSlider) e.getSource()).getX1());
217
                getPBoxes().getControlRight().setValue(((DoubleSlider) e.getSource()).getX2());
218
                callValueChangedListeners();
219
        }
220

    
221
        /*
222
         * (non-Javadoc)
223
         * @see org.gvsig.gui.beans.doubleslider.DoubleSliderListener#actionValueDragged(java.util.EventObject)
224
         */
225
        public void actionValueDragged(DoubleSliderEvent e) {
226
                actionValueChanged(e);
227
        }
228
}