Statistics
| Revision:

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

History | View | Annotate | Download (6.82 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.FlowLayout;
22
import java.awt.GridBagConstraints;
23
import java.awt.GridBagLayout;
24
import java.awt.event.ComponentEvent;
25
import java.awt.event.ComponentListener;
26

    
27
import javax.swing.JButton;
28
import javax.swing.JPanel;
29
import javax.swing.JTextField;
30

    
31
import org.gvsig.gui.beans.graphic.listeners.GraphicListener;
32

    
33
/**
34
 * Control para el manejo de un gr?fico.
35
 * 
36
 * @author Nacho Brodin (brodin_ign@gva.es)
37
 *
38
 */
39
public class GraphicContainer extends JPanel implements  ComponentListener {
40
        private static final long serialVersionUID = -6230083498345786500L;
41
        private static final int                INTERNAL_MARGIN = 4;
42
        private int                                                HEIGHT_DOUBLESLIDER = 25;
43
        private static final int                HEIGHT_BOXES = 30;
44
        
45
        private JPanel                                         pGeneral = null;
46
        private GraphicChartPanel                 pGraphic = null;
47
        private JPanel                                         pDoubleSlider = null;
48
        private BoxesPanel                                 pBoxes = null;
49
        private GraphicListener                 graphicListener = null;
50
        /**
51
         * Variable que estar? a true si se desea que se muestre el control de barra deslizadora
52
         */
53
        private        boolean                                 showSlider = true;
54

    
55
        public GraphicContainer() {
56
                graphicListener = new GraphicListener(this);
57
                initialize();
58
        }
59
        
60
        public GraphicContainer(boolean showSlider) {
61
                this.showSlider = showSlider;
62
                if (!showSlider)
63
                        HEIGHT_DOUBLESLIDER = 0;
64
                graphicListener = new GraphicListener(this);
65
                initialize();
66
        }
67
        
68

    
69
        private void initialize() {
70
                FlowLayout layout = new FlowLayout();
71
                layout.setHgap(0);
72
                layout.setVgap(0);
73
                this.setLayout(layout);
74
                this.add(getPGeneral(), null);
75
                this.addComponentListener(this);
76
        }
77
        
78
        /**
79
         * This method initializes jPanel1        
80
         *         
81
         * @return javax.swing.JPanel        
82
         */
83
        private JPanel getPGeneral() {
84
                if (pGeneral == null) {
85
                        GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
86
                        gridBagConstraints4.gridy = 2;
87
                        gridBagConstraints4.insets = new java.awt.Insets(2,0,0,0);
88
                        gridBagConstraints4.gridwidth = 0;
89
                        GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
90
                        gridBagConstraints3.gridy = 1;
91
                        gridBagConstraints3.insets = new java.awt.Insets(2,0,0,0);
92
                        gridBagConstraints3.gridx = 0;
93
                        GridBagConstraints gridBagConstraints = new GridBagConstraints();
94
                        gridBagConstraints.gridy = 0;
95
                        gridBagConstraints.insets = new java.awt.Insets(0,0,0,0);
96
                        gridBagConstraints.gridx = 0;
97
                        pGeneral = new JPanel();
98
                        pGeneral.setLayout(new GridBagLayout());
99
                        pGeneral.add(getPGraphic(), gridBagConstraints);
100
                        if(showSlider)
101
                                pGeneral.add(getPDoubleSlider(), gridBagConstraints3);
102
                        pGeneral.add(getPBoxes(), gridBagConstraints4);
103
                }
104
                return pGeneral;
105
        }
106

    
107
        /**
108
         * This method initializes jPanel1        
109
         *         
110
         * @return javax.swing.JPanel        
111
         */
112
        public GraphicChartPanel getPGraphic() {
113
                if (pGraphic == null) {
114
                        pGraphic = new GraphicChartPanel(this.getWidth() - INTERNAL_MARGIN, this.getHeight() - HEIGHT_BOXES - HEIGHT_DOUBLESLIDER);
115
                }
116
                return pGraphic;
117
        }
118

    
119
        /**
120
         * This method initializes jPanel1        
121
         *         
122
         * @return javax.swing.JPanel        
123
         */
124
        private JPanel getPDoubleSlider() {
125
                if (pDoubleSlider == null) {
126
                        pDoubleSlider = new DoubleSliderControlPanel(this.getWidth() - INTERNAL_MARGIN, HEIGHT_DOUBLESLIDER, graphicListener);
127
                }
128
                return pDoubleSlider;
129
        }
130

    
131
        /**
132
         * This method initializes jPanel1        
133
         *         
134
         * @return javax.swing.JPanel        
135
         */
136
        private BoxesPanel getPBoxes() {
137
                if (pBoxes == null) {
138
                        pBoxes = new BoxesPanel(this.getWidth() - INTERNAL_MARGIN, HEIGHT_BOXES);
139
                }
140
                return pBoxes;
141
        }
142
        
143
        /**
144
         * Asigna el tama?o del componente
145
         * @param w Nuevo ancho del componente padre
146
         * @param h Nuevo alto del componente padre
147
         */
148
        public void setComponentSize(int w, int h){
149
    setPreferredSize(new java.awt.Dimension(w, h));
150
                getPGraphic().setComponentSize(w - INTERNAL_MARGIN, h - HEIGHT_BOXES - HEIGHT_DOUBLESLIDER);
151
                if(this.showSlider){
152
                        getPDoubleSlider().setPreferredSize(new java.awt.Dimension(w - INTERNAL_MARGIN, HEIGHT_DOUBLESLIDER));
153
                }
154
                ((BoxesPanel)getPBoxes()).setComponentSize(w - INTERNAL_MARGIN, HEIGHT_BOXES);
155
                this.updateUI();
156
        }
157
        
158
        //****************************************************
159
        //M?TODOS DEL CONTROL
160

    
161
        /**
162
         * Obtiene el valor de los controles. 
163
         * @return Array con los valores de ambos controles. El primer valor del array es el control de la derecha
164
         * y el segundo el de la izquierda.  
165
         */
166
        public double[] getBoxesValues(){
167
                return getPBoxes().getBoxesValues();
168
        }
169
        
170
        /**
171
         * Obtiene el bot?n de incremento del control izquierdo
172
         * @return JButton. Bot?n de incremento del control izquierdo
173
         */
174
        public JButton getPlusButtonControlLeft(){
175
                return this.getPBoxes().getControlLeft().getBmas();
176
        }
177
        
178
        /**
179
         * Obtiene el bot?n de decremento del control izquierdo
180
         * @return JButton. Bot?n de decremento del control izquierdo
181
         */
182
        public JButton getLessButtonControlLeft(){
183
                return this.getPBoxes().getControlLeft().getBmenos();
184
        }
185
        
186
        /**
187
         * Obtiene el bot?n de incremento del control derecho
188
         * @return JButton. Bot?n de incremento del control derecho
189
         */
190
        public JButton getPlusButtonControlRight(){
191
                return this.getPBoxes().getControlRight().getBmas();
192
        }
193
        
194
        /**
195
         * Obtiene el bot?n de decremento del control derecho
196
         * @return JButton. Bot?n de decremento del control derecho
197
         */
198
        public JButton getLessButtonControlRight(){
199
                return this.getPBoxes().getControlRight().getBmenos();
200
        }
201
        
202
        /**
203
         * Obtiene el JTextField de control derecho
204
         * @return JTextField de control derecho
205
         */
206
        public JTextField getTextControlRight(){
207
                return this.getPBoxes().getControlRight().getTText();
208
        }
209
        
210
        /**
211
         * Obtiene el JTextField de control izquierdo
212
         * @return JTextField de control izquierdo
213
         */
214
        public JTextField getTextControlLeft(){
215
                return this.getPBoxes().getControlLeft().getTText();
216
        }
217

    
218
        public void componentResized(ComponentEvent e) {
219
                this.setComponentSize(this.getWidth(), this.getHeight());
220
        }
221

    
222
        public void componentHidden(ComponentEvent e) {
223
                // TODO Auto-generated method stub
224
        }
225

    
226
        public void componentMoved(ComponentEvent e) {
227
                // TODO Auto-generated method stub        
228
        }
229

    
230
        public void componentShown(ComponentEvent e) {
231
                // TODO Auto-generated method stub
232
        }
233
}