Statistics
| Revision:

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

History | View | Annotate | Download (5.68 KB)

1 10741 nacho
/* 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 11004 bsanchez
import java.awt.BorderLayout;
22 11033 bsanchez
import java.awt.Color;
23 11004 bsanchez
import java.util.ArrayList;
24
import java.util.Iterator;
25 10741 nacho
26 11004 bsanchez
import javax.swing.JComponent;
27 10741 nacho
import javax.swing.JPanel;
28
29 11004 bsanchez
import org.gvsig.gui.beans.doubleslider.DoubleSlider;
30
import org.gvsig.gui.beans.doubleslider.DoubleSliderEvent;
31
import org.gvsig.gui.beans.doubleslider.DoubleSliderListener;
32
import org.gvsig.gui.beans.textincreaser.TextIncreaserEvent;
33
import org.gvsig.gui.beans.textincreaser.TextIncreaserListener;
34 10741 nacho
35
/**
36
 * Control para el manejo de un gr?fico.
37
 *
38
 * @author Nacho Brodin (brodin_ign@gva.es)
39
 *
40
 */
41 11004 bsanchez
public class GraphicContainer extends JPanel implements DoubleSliderListener, TextIncreaserListener {
42 10885 bsanchez
        private static final long serialVersionUID = -6230083498345786500L;
43 10741 nacho
44
        private JPanel                                         pGeneral = null;
45
        private GraphicChartPanel                 pGraphic = null;
46 11004 bsanchez
        private JPanel                                         panelSlider = null;
47 10741 nacho
        private BoxesPanel                                 pBoxes = null;
48 11004 bsanchez
        private DoubleSlider multiSlider;
49
50
        private ArrayList actionCommandListeners = new ArrayList();
51
        private boolean bDoCallListeners = true;
52
        static private int eventId = Integer.MIN_VALUE;
53 10741 nacho
54 10779 bsanchez
        public GraphicContainer() {
55 10741 nacho
                initialize();
56
        }
57 10779 bsanchez
58
        public GraphicContainer(boolean showSlider) {
59 11004 bsanchez
                getPDoubleSlider().setVisible(showSlider);
60 10741 nacho
                initialize();
61
        }
62 10779 bsanchez
63 10741 nacho
64
        private void initialize() {
65 11004 bsanchez
                this.setLayout(new BorderLayout(0, 4));
66
                this.add(getPGraphic(), BorderLayout.CENTER);
67
                this.add(getPGeneral(), BorderLayout.SOUTH);
68 10741 nacho
        }
69
70
        /**
71
         * This method initializes jPanel1
72
         *
73
         * @return javax.swing.JPanel
74
         */
75
        private JPanel getPGeneral() {
76
                if (pGeneral == null) {
77
                        pGeneral = new JPanel();
78 11004 bsanchez
                        pGeneral.setLayout(new BorderLayout(0, 2));
79
                        pGeneral.add(getPDoubleSlider(), BorderLayout.NORTH);
80
                        pGeneral.add(getPBoxes(), BorderLayout.SOUTH);
81 10741 nacho
                }
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 11004 bsanchez
                        pGraphic = new GraphicChartPanel();
93 10741 nacho
                }
94
                return pGraphic;
95
        }
96
97
        /**
98
         * This method initializes jPanel1
99
         *
100
         * @return javax.swing.JPanel
101
         */
102 11004 bsanchez
        private JComponent getPDoubleSlider() {
103
                if (panelSlider == null) {
104
                        panelSlider = new JPanel();
105
                        multiSlider = new DoubleSlider();
106
                        multiSlider.addValueChangedListener(this);
107
                        panelSlider.setLayout(new BorderLayout());
108
                        panelSlider.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
109
                        panelSlider.add(multiSlider, BorderLayout.CENTER);
110 10741 nacho
                }
111 11004 bsanchez
                return panelSlider;
112 10741 nacho
        }
113
114
        /**
115
         * This method initializes jPanel1
116
         *
117
         * @return javax.swing.JPanel
118
         */
119
        private BoxesPanel getPBoxes() {
120
                if (pBoxes == null) {
121 11004 bsanchez
                        pBoxes = new BoxesPanel();
122
                        pBoxes.getControlLeft().addValueChangedListener(this);
123
                        pBoxes.getControlRight().addValueChangedListener(this);
124 10741 nacho
                }
125
                return pBoxes;
126
        }
127
128
        //****************************************************
129
        //M?TODOS DEL CONTROL
130
131 11004 bsanchez
        public double getX1() {
132
                return getPBoxes().getControlLeft().getValue();
133 10741 nacho
        }
134 10779 bsanchez
135 11004 bsanchez
        public double getX2() {
136
                return getPBoxes().getControlRight().getValue();
137 10962 bsanchez
        }
138
139 11004 bsanchez
        public void actionValueChanged(DoubleSliderEvent e) {
140
                getPBoxes().getControlLeft().setValue(((DoubleSlider) e.getSource()).getX1());
141
                getPBoxes().getControlRight().setValue(((DoubleSlider) e.getSource()).getX2());
142
                callValueChangedListeners();
143 10779 bsanchez
        }
144
145 11004 bsanchez
        public void actionValueChanged(TextIncreaserEvent e) {
146
                if (e.getSource() == getPBoxes().getControlLeft()) {
147
                        if (getPBoxes().getControlLeft().getValue() > getPBoxes().getControlRight().getValue())
148
                                getPBoxes().getControlRight().setValue(getPBoxes().getControlLeft().getValue());
149
                }
150
                if (e.getSource() == getPBoxes().getControlRight()) {
151
                        if (getPBoxes().getControlRight().getValue() < getPBoxes().getControlLeft().getValue())
152
                                getPBoxes().getControlLeft().setValue(getPBoxes().getControlRight().getValue());
153
                }
154
                multiSlider.setX1((int) getPBoxes().getControlLeft().getValue());
155
                multiSlider.setX2((int) getPBoxes().getControlRight().getValue());
156
                callValueChangedListeners();
157 10779 bsanchez
        }
158 11004 bsanchez
159
        public void addValueChangedListener(GraphicListener listener) {
160
                if (!actionCommandListeners.contains(listener))
161
                        actionCommandListeners.add(listener);
162
        }
163 10779 bsanchez
164 11004 bsanchez
        public void removeValueChangedListener(GraphicListener listener) {
165
                actionCommandListeners.remove(listener);
166 10779 bsanchez
        }
167 11004 bsanchez
168
        private void callValueChangedListeners() {
169
                if (!bDoCallListeners)
170
                        return;
171
                Iterator acIterator = actionCommandListeners.iterator();
172
                while (acIterator.hasNext()) {
173
                        GraphicListener listener = (GraphicListener) acIterator.next();
174
                        listener.actionValueChanged(new GraphicEvent(this));
175
                }
176
                eventId++;
177
        }
178
179 11033 bsanchez
        public void setBandVisible(int band, boolean visible) {
180
                getPGraphic().getChart().getChart().getXYPlot().getRenderer().setSeriesVisible(band, Boolean.valueOf(visible));
181
        }
182
183
        public void setBandColor(int band, Color color) {
184
                getPGraphic().getChart().getChart().getXYPlot().getRenderer().setSeriesPaint(band, color);
185
        }
186 10779 bsanchez
}