Statistics
| Revision:

root / trunk / libraries / libUIComponent_praster / src / org / gvsig / gui / beans / graphic / GraphicContainer.java @ 8026

History | View | Annotate | Download (7.06 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

    
25
import javax.swing.JButton;
26
import javax.swing.JPanel;
27
import javax.swing.JTextField;
28

    
29
import org.gvsig.gui.beans.BaseComponent;
30
import org.gvsig.gui.beans.graphic.listeners.GraphicListener;
31

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

    
57
        
58
        /**
59
     * Constructor
60
     * @param width Ancho del gr?fico en pixeles
61
     * @param height Alto del gr?fico en pixeles
62
     */
63
        public GraphicContainer(int width, int height) {
64
                this.width = width;
65
                this.height = height;
66
                graphicListener = new GraphicListener(this);
67
                initialize();
68
        }
69
                
70
        /**
71
     * Constructor
72
     * @param width Ancho del gr?fico en pixeles
73
     * @param height Alto del gr?fico en pixeles
74
     */
75
        public GraphicContainer(int width, int height, boolean showSlider) {
76
                this.showSlider = showSlider;
77
                if(!showSlider)
78
                        HEIGHT_DOUBLESLIDER = 0;
79
                this.width = width;
80
                this.height = height;
81
                graphicListener = new GraphicListener(this);
82
                initialize();
83
        }
84

    
85
        private void initialize() {
86
                FlowLayout layout = new FlowLayout();
87
                layout.setHgap(0);
88
                layout.setVgap(0);
89
        this.setLayout(layout);
90
        this.add(getPGeneral(), null);                        
91
        }
92
        
93
        /**
94
         * This method initializes jPanel1        
95
         *         
96
         * @return javax.swing.JPanel        
97
         */
98
        private JPanel getPGeneral() {
99
                if (pGeneral == null) {
100
                        GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
101
                        gridBagConstraints4.gridy = 2;
102
                        gridBagConstraints4.insets = new java.awt.Insets(2,0,0,0);
103
                        gridBagConstraints4.gridwidth = 0;
104
                        GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
105
                        gridBagConstraints3.gridy = 1;
106
                        gridBagConstraints3.insets = new java.awt.Insets(2,0,0,0);
107
                        gridBagConstraints3.gridx = 0;
108
                        GridBagConstraints gridBagConstraints = new GridBagConstraints();
109
                        gridBagConstraints.gridy = 0;
110
                        gridBagConstraints.insets = new java.awt.Insets(0,0,0,0);
111
                        gridBagConstraints.gridx = 0;
112
                        pGeneral = new JPanel();
113
                        //pGeneral.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
114
                        pGeneral.setLayout(new GridBagLayout());
115
                        pGeneral.add(getPGraphic(), gridBagConstraints);
116
                        if(showSlider)
117
                                pGeneral.add(getPDoubleSlider(), gridBagConstraints3);
118
                        pGeneral.add(getPBoxes(), gridBagConstraints4);
119
                }
120
                return pGeneral;
121
        }
122

    
123

    
124
        /**
125
         * This method initializes jPanel1        
126
         *         
127
         * @return javax.swing.JPanel        
128
         */
129
        public GraphicChartPanel getPGraphic() {
130
                if (pGraphic == null) {
131
                        pGraphic = new GraphicChartPanel(width - INTERNAL_MARGIN, height - HEIGHT_BOXES - HEIGHT_DOUBLESLIDER);
132
                }
133
                return pGraphic;
134
        }
135

    
136

    
137
        /**
138
         * This method initializes jPanel1        
139
         *         
140
         * @return javax.swing.JPanel        
141
         */
142
        private JPanel getPDoubleSlider() {
143
                if (pDoubleSlider == null) {
144
                        pDoubleSlider = new DoubleSliderControlPanel(width - INTERNAL_MARGIN, HEIGHT_DOUBLESLIDER, graphicListener);
145
                }
146
                return pDoubleSlider;
147
        }
148

    
149

    
150
        /**
151
         * This method initializes jPanel1        
152
         *         
153
         * @return javax.swing.JPanel        
154
         */
155
        private BoxesPanel getPBoxes() {
156
                if (pBoxes == null) {
157
                        pBoxes = new BoxesPanel(width - INTERNAL_MARGIN, HEIGHT_BOXES);
158
                }
159
                return pBoxes;
160
        }
161
        
162
        /**
163
         * Asigna el tama?o del componente
164
         * @param w Nuevo ancho del componente padre
165
         * @param h Nuevo alto del componente padre
166
         */
167
        public void setComponentSize(int w, int h){
168
                width = w;
169
                height = h;
170
        setPreferredSize(new java.awt.Dimension(w, h));
171
        //getPGeneral().setPreferredSize(new java.awt.Dimension(w, h));
172
                getPGraphic().setComponentSize(w - INTERNAL_MARGIN, h - HEIGHT_BOXES - HEIGHT_DOUBLESLIDER);
173
                if(this.showSlider){
174
                        //getPDoubleSlider().setSize(w - INTERNAL_MARGIN, HEIGHT_DOUBLESLIDER);
175
                        getPDoubleSlider().setPreferredSize(new java.awt.Dimension(w - INTERNAL_MARGIN, HEIGHT_DOUBLESLIDER));
176
                }
177
                ((BoxesPanel)getPBoxes()).setComponentSize(w - INTERNAL_MARGIN, HEIGHT_BOXES);
178
        }
179
        
180
        //****************************************************
181
        //M?TODOS DEL CONTROL
182

    
183
        /**
184
         * Obtiene el valor de los controles. 
185
         * @return Array con los valores de ambos controles. El primer valor del array es el control de la derecha
186
         * y el segundo el de la izquierda.  
187
         */
188
        public double[] getBoxesValues(){
189
                return getPBoxes().getBoxesValues();
190
        }
191
        
192
        /**
193
         * Obtiene el bot?n de incremento del control izquierdo
194
         * @return JButton. Bot?n de incremento del control izquierdo
195
         */
196
        public JButton getPlusButtonControlLeft(){
197
                return this.getPBoxes().getControlLeft().getBmas();
198
        }
199
        
200
        /**
201
         * Obtiene el bot?n de decremento del control izquierdo
202
         * @return JButton. Bot?n de decremento del control izquierdo
203
         */
204
        public JButton getLessButtonControlLeft(){
205
                return this.getPBoxes().getControlLeft().getBmenos();
206
        }
207
        
208
        /**
209
         * Obtiene el bot?n de incremento del control derecho
210
         * @return JButton. Bot?n de incremento del control derecho
211
         */
212
        public JButton getPlusButtonControlRight(){
213
                return this.getPBoxes().getControlRight().getBmas();
214
        }
215
        
216
        /**
217
         * Obtiene el bot?n de decremento del control derecho
218
         * @return JButton. Bot?n de decremento del control derecho
219
         */
220
        public JButton getLessButtonControlRight(){
221
                return this.getPBoxes().getControlRight().getBmenos();
222
        }
223
        
224
        /**
225
         * Obtiene el JTextField de control derecho
226
         * @return JTextField de control derecho
227
         */
228
        public JTextField getTextControlRight(){
229
                return this.getPBoxes().getControlRight().getTText();
230
        }
231
        
232
        /**
233
         * Obtiene el JTextField de control izquierdo
234
         * @return JTextField de control izquierdo
235
         */
236
        public JTextField getTextControlLeft(){
237
                return this.getPBoxes().getControlLeft().getTText();
238
        }
239
        
240
}