Statistics
| Revision:

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

History | View | Annotate | Download (5.72 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.GridBagConstraints;
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
/**
37
 * Control para el manejo de un gr?fico.
38
 * 
39
 * @author Nacho Brodin (brodin_ign@gva.es)
40
 *
41
 */
42
public class GraphicContainer extends JPanel implements DoubleSliderListener, TextIncreaserListener {
43
        private static final long serialVersionUID = -6230083498345786500L;
44
        
45
        private JPanel                                         pGeneral = null;
46
        private GraphicChartPanel                 pGraphic = null;
47
        private JPanel                                         panelSlider = null;
48
        private BoxesPanel                                 pBoxes = null;
49
        private DoubleSlider multiSlider;
50
        
51
        private ArrayList actionCommandListeners = new ArrayList();
52
        private boolean bDoCallListeners = true;
53
        static private int eventId = Integer.MIN_VALUE;
54

    
55
        public GraphicContainer() {
56
                initialize();
57
        }
58
        
59
        public GraphicContainer(boolean showSlider) {
60
                getPDoubleSlider().setVisible(showSlider);
61
                initialize();
62
        }
63
        
64

    
65
        private void initialize() {
66
                this.setLayout(new BorderLayout(0, 4));
67
                this.add(getPGraphic(), BorderLayout.CENTER);
68
                this.add(getPGeneral(), BorderLayout.SOUTH);
69
        }
70
        
71
        /**
72
         * This method initializes jPanel1        
73
         *         
74
         * @return javax.swing.JPanel        
75
         */
76
        private JPanel getPGeneral() {
77
                if (pGeneral == null) {
78
                        pGeneral = new JPanel();
79
                        pGeneral.setLayout(new BorderLayout(0, 2));
80
                        pGeneral.add(getPDoubleSlider(), BorderLayout.NORTH);
81
                        pGeneral.add(getPBoxes(), BorderLayout.SOUTH);
82
                }
83
                return pGeneral;
84
        }
85

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

    
98
        /**
99
         * This method initializes jPanel1        
100
         *         
101
         * @return javax.swing.JPanel        
102
         */
103
        private JComponent getPDoubleSlider() {
104
                if (panelSlider == null) {
105
                        panelSlider = new JPanel();
106
                        multiSlider = new DoubleSlider();
107
                        multiSlider.addValueChangedListener(this);
108
                        panelSlider.setLayout(new BorderLayout());
109
                        panelSlider.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
110
                        panelSlider.add(multiSlider, BorderLayout.CENTER);
111
                }
112
                return panelSlider;
113
        }
114

    
115
        /**
116
         * This method initializes jPanel1        
117
         *         
118
         * @return javax.swing.JPanel        
119
         */
120
        private BoxesPanel getPBoxes() {
121
                if (pBoxes == null) {
122
                        pBoxes = new BoxesPanel();
123
                        pBoxes.getControlLeft().addValueChangedListener(this);
124
                        pBoxes.getControlRight().addValueChangedListener(this);
125
                }
126
                return pBoxes;
127
        }
128
        
129
        //****************************************************
130
        //M?TODOS DEL CONTROL
131

    
132
        public double getX1() {
133
                return getPBoxes().getControlLeft().getValue();
134
        }
135

    
136
        public double getX2() {
137
                return getPBoxes().getControlRight().getValue();
138
        }
139

    
140
        public void actionValueChanged(DoubleSliderEvent e) {
141
                getPBoxes().getControlLeft().setValue(((DoubleSlider) e.getSource()).getX1());
142
                getPBoxes().getControlRight().setValue(((DoubleSlider) e.getSource()).getX2());
143
                callValueChangedListeners();
144
        }
145

    
146
        public void actionValueChanged(TextIncreaserEvent e) {
147
                if (e.getSource() == getPBoxes().getControlLeft()) {
148
                        if (getPBoxes().getControlLeft().getValue() > getPBoxes().getControlRight().getValue())
149
                                getPBoxes().getControlRight().setValue(getPBoxes().getControlLeft().getValue());
150
                }
151
                if (e.getSource() == getPBoxes().getControlRight()) {
152
                        if (getPBoxes().getControlRight().getValue() < getPBoxes().getControlLeft().getValue())
153
                                getPBoxes().getControlLeft().setValue(getPBoxes().getControlRight().getValue());
154
                }
155
                multiSlider.setX1((int) getPBoxes().getControlLeft().getValue());
156
                multiSlider.setX2((int) getPBoxes().getControlRight().getValue());
157
                callValueChangedListeners();
158
        }
159
        
160
        public void addValueChangedListener(GraphicListener listener) {
161
                if (!actionCommandListeners.contains(listener))
162
                        actionCommandListeners.add(listener);
163
        }
164

    
165
        public void removeValueChangedListener(GraphicListener listener) {
166
                actionCommandListeners.remove(listener);
167
        }
168
        
169
        private void callValueChangedListeners() {
170
                if (!bDoCallListeners)
171
                        return;
172
                Iterator acIterator = actionCommandListeners.iterator();
173
                while (acIterator.hasNext()) {
174
                        GraphicListener listener = (GraphicListener) acIterator.next();
175
                        listener.actionValueChanged(new GraphicEvent(this));
176
                }
177
                eventId++;
178
        }
179
        
180
        public void setBandVisible(int band, boolean visible) {
181
                getPGraphic().getChart().getChart().getXYPlot().getRenderer().setSeriesVisible(band, Boolean.valueOf(visible));
182
        }
183
        
184
        public void setBandColor(int band, Color color) {
185
                getPGraphic().getChart().getChart().getXYPlot().getRenderer().setSeriesPaint(band, color);
186
        }
187
}