Statistics
| Revision:

root / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / gridmath / gui / KeysPanel.java @ 13790

History | View | Annotate | Download (10.1 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Instituto de Desarrollo Regional 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
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
34
 *   Campus Universitario s/n
35
 *   02071 Alabacete
36
 *   Spain
37
 *
38
 *   +34 967 599 200
39
 */
40

    
41
package org.gvsig.remotesensing.gridmath.gui;
42

    
43
import info.clearthought.layout.TableLayout;
44

    
45
import java.awt.Dimension;
46
import java.awt.event.ActionEvent;
47
import java.awt.event.ActionListener;
48

    
49
import javax.swing.BorderFactory;
50
import javax.swing.JButton;
51
import javax.swing.JPanel;
52
import javax.swing.JTextArea;
53
import javax.swing.border.CompoundBorder;
54
import javax.swing.border.EmptyBorder;
55
import javax.swing.border.TitledBorder;
56

    
57
/**
58
 * Clase que implementa la el la interfaz de la calculadora 
59
 * @author Alejandro Mu?oz
60
 *
61
 */
62
public class KeysPanel extends JPanel implements ActionListener{
63
        
64
        private static final long serialVersionUID = 1L;
65
        private JButton jButtonMinus;
66
        private JButton jButtonDivide;
67
        private JButton jButton2;
68
        private JButton jButtonDot;
69
        private JButton jButtonBrackets;
70
        private JButton jButton0;
71
        private JButton jButton9;
72
        private JButton jButton8;
73
        private JButton jButton7;
74
        private JButton jButton6;
75
        private JButton jButton5;
76
        private JButton jButton4;
77
        private JButton jButton3;
78
        private JButton jButton1;
79
        private JButton jButtonMultiply;
80
        private JButton jButtonPlus;
81
        
82
        Dimension dButton;
83
        private JTextArea textExpression = null;
84
        
85
        
86
        public KeysPanel(JTextArea m_TextExpression) {
87
                super();
88
                textExpression=m_TextExpression;
89
                dButton=new Dimension();
90
                dButton=getJButtonBrackets().getPreferredSize();
91
                Inicializar();
92
                
93
        }
94
        
95
        /**Inicializacion del teclado de la calculadora */
96
        private void Inicializar(){
97
                
98
                TableLayout thisLayout = new TableLayout(new double[][] {
99
                                { TableLayout.PREFERRED,1.0, TableLayout.PREFERRED, TableLayout.PREFERRED,
100
                                                TableLayout.PREFERRED },
101
                                { TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED,
102
                                                TableLayout.PREFERRED } });
103
                //Establece la separaci?n entre los elementos
104
                thisLayout.setHGap(3);
105
                thisLayout.setVGap(3);
106
                //asignar el layout al panel actual(this)                
107
                this.setLayout(thisLayout);
108
                TitledBorder topBorder = BorderFactory.createTitledBorder("");
109
            topBorder.setTitlePosition(TitledBorder.TOP);
110
            this.setBorder(new CompoundBorder(topBorder,new EmptyBorder(1,1,1,1)));
111
                
112
                //a?adir los componentes al panel
113
                this.add(getJButtonPlus(),"0,0");
114
                this.add(getJButtonMinus(),"0,1");
115
                this.add(getJButtonMultiply(),"0,2");
116
                this.add(getJButtonDivide(),"0,3");
117
                this.add(getJButton7(),"2,0");
118
                this.add(getJButton4(),"2,1");
119
                this.add(getJButton1(),"2,2");
120
                this.add(getJButton0(),"2,3");
121
                this.add(getJButton8(),"3,0");
122
                this.add(getJButton5(),"3,1");
123
                this.add(getJButton2(),"3,2");
124
                this.add(getJButtonBrackets(),"3,3");
125
                this.add(getJButton9(),"4,0");
126
                this.add(getJButton6(),"4,1");
127
                this.add(getJButton3(),"4,2");
128
                this.add(getJButtonDot(),"4,3");
129
        }
130
        
131
        /**
132
         * Define todos los eventos de los botones de la calculadora
133
         */
134
        public void actionPerformed(ActionEvent e) {
135
                
136
                if (e.getSource().equals(jButton0))  {
137
                        // Completar con acciones de boton 0
138
                        textExpression.insert("0", textExpression.getCaretPosition());
139
                        
140
                }else if (e.getSource().equals(jButton1))  {
141
                        // Completar con acciones de boton 1
142
                        textExpression.insert("1", textExpression.getCaretPosition());
143
                }
144
                else if (e.getSource().equals(jButton2))  {
145
                        // Completar con acciones de boton 2
146
                        textExpression.insert("2", textExpression.getCaretPosition());        
147
                }
148
                else if (e.getSource().equals(jButton3))  {
149
                        // Completar con acciones de boton 3
150
                        textExpression.insert("3", textExpression.getCaretPosition());
151
                }
152
                else if (e.getSource().equals(jButton4))  {
153
                        // Completar con acciones de boton 4
154
                        textExpression.insert("4", textExpression.getCaretPosition());
155
                }
156
                else if (e.getSource().equals(jButton5))  {
157
                        // Completar con acciones de boton 5
158
                        textExpression.insert("5", textExpression.getCaretPosition());
159
                }
160
                else if (e.getSource().equals(jButton6))  {
161
                        // Completar con acciones de boton 6
162
                        textExpression.insert("6", textExpression.getCaretPosition());
163
                }
164
                else if (e.getSource().equals(jButton7))  {
165
                        // Completar con acciones de boton 7
166
                        textExpression.insert("7", textExpression.getCaretPosition());        
167
                }
168
                else if (e.getSource().equals(jButton8))  {
169
                        // Completar con acciones de boton 8
170
                        textExpression.insert("8", textExpression.getCaretPosition());
171
                }
172
                else if (e.getSource().equals(jButton9))  {
173
                        // Completar con acciones de boton 9
174
                        textExpression.insert("9", textExpression.getCaretPosition());
175
                }        
176
                else if (e.getSource().equals(jButtonPlus))  {
177
                        // Completar con acciones de boton +
178
                        textExpression.insert("+", textExpression.getCaretPosition());
179
                }
180
                else if (e.getSource().equals(jButtonMinus))  {
181
                        // Completar con acciones de boton -
182
                        textExpression.insert("-", textExpression.getCaretPosition());
183
                }
184
                else if (e.getSource().equals(jButtonMultiply))  {
185
                        // Completar con acciones de boton *
186
                        textExpression.insert("*", textExpression.getCaretPosition());
187
                }
188
                else if (e.getSource().equals(jButtonDot))  {
189
                        // Completar con acciones de boton .
190
                        textExpression.insert(".", textExpression.getCaretPosition());
191
                }
192
                else if (e.getSource().equals(jButtonDivide))  {
193
                        // Completar con acciones de boton /
194
                        textExpression.insert("/", textExpression.getCaretPosition());
195
                }
196
                else if (e.getSource().equals(jButtonBrackets))  {
197
                        // Completar con acciones de boton ()
198
                        textExpression.insert("()", textExpression.getCaretPosition());
199
                        //coloca le cursor en el centro de los dos par?ntesis
200
                        textExpression.setCaretPosition(textExpression.getCaretPosition() - 1);
201
                }
202
        }
203

    
204
        
205
        public JButton getJButton0() {
206
                if (jButton0==null){
207
                        jButton0=new JButton();
208
                        jButton0.setText("0");
209
                        jButton0.addActionListener(this);
210
                        jButton0.setPreferredSize(dButton);
211
                }
212
                return jButton0;
213
        }
214

    
215
        public JButton getJButton1() {
216
                if (jButton1==null){
217
                        jButton1=new JButton();
218
                        jButton1.setText("1");
219
                        jButton1.setPreferredSize(dButton);
220
                        jButton1.addActionListener(this);
221
                }
222
                return jButton1;
223
        }
224

    
225
        public JButton getJButton2() {
226
                if (jButton2==null){
227
                        jButton2=new JButton();
228
                        jButton2.setText("2");
229
                        jButton2.setPreferredSize(dButton);
230
                        jButton2.addActionListener(this);
231
                }
232
                return jButton2;
233
        }
234

    
235
        public JButton getJButton3() {
236
                
237
                if (jButton3==null){
238
                        jButton3=new JButton();
239
                        jButton3.setText("3");
240
                        jButton0.setPreferredSize(dButton);
241
                        jButton3.addActionListener(this);
242
                }        
243
                return jButton3;
244
        }
245

    
246
        public JButton getJButton4() {
247
                
248
                if (jButton4==null){
249
                        jButton4=new JButton();
250
                        jButton4.setText("4");
251
                        jButton4.setPreferredSize(dButton);
252
                        jButton4.addActionListener(this);
253
                }
254
                return jButton4;
255
        }
256

    
257
        public JButton getJButton5() {
258
                
259
                if (jButton5==null){
260
                        jButton5=new JButton();
261
                        jButton5.setText("5");
262
                        jButton5.setPreferredSize(dButton);
263
                        jButton5.addActionListener(this);
264
                }
265
                return jButton5;
266
        }
267

    
268
        public JButton getJButton6() {
269
                
270
                if (jButton6==null){
271
                        jButton6=new JButton();
272
                        jButton6.setText("6");
273
                        jButton6.setPreferredSize(dButton);
274
                        jButton6.addActionListener(this);
275
                }
276
                return jButton6;
277
        }
278

    
279
        public JButton getJButton7() {
280
                
281
                if (jButton7==null){
282
                        jButton7=new JButton();
283
                        jButton7.setText("7");
284
                        jButton7.setPreferredSize(dButton);
285
                        jButton7.addActionListener(this);
286
                }
287
                return jButton7;
288
        }
289

    
290
        public JButton getJButton8() {
291
                
292
                if (jButton8==null){
293
                        jButton8=new JButton();
294
                        jButton8.setText("8");
295
                        jButton8.setPreferredSize(dButton);
296
                        jButton8.addActionListener(this);
297
                }
298
                
299
                return jButton8;
300
        }
301

    
302
        public JButton getJButton9() {
303
                
304
                if (jButton9==null){
305
                        jButton9=new JButton();
306
                        jButton9.setText("9");
307
                        jButton9.setPreferredSize(dButton);
308
                        jButton9.addActionListener(this);
309
                }
310
                return jButton9;
311
        }
312

    
313
        public JButton getJButtonBrackets() {
314
                
315
                if (jButtonBrackets==null){
316
                        jButtonBrackets=new JButton();
317
                        jButtonBrackets.setText("( )");
318
                        jButtonBrackets.addActionListener(this);        
319
                }
320
                return jButtonBrackets;
321
        }
322

    
323
        public JButton getJButtonDivide() {
324
                
325
                if (jButtonDivide==null){
326
                        jButtonDivide=new JButton();
327
                        jButtonDivide.setText("/");
328
                        jButtonDivide.setPreferredSize(dButton);
329
                        jButtonDivide.addActionListener(this);
330
                }
331
                return jButtonDivide;
332
        }
333

    
334
        public JButton getJButtonDot() {
335
                
336
                if (jButtonDot==null){
337
                        jButtonDot=new JButton();
338
                        jButtonDot.setText(".");
339
                        jButtonDot.setPreferredSize(dButton);
340
                        jButtonDot.addActionListener(this);
341
                }
342
        
343
                return jButtonDot;
344
        }
345

    
346
        public JButton getJButtonMinus() {
347
                if (jButtonMinus==null){
348
                        jButtonMinus=new JButton();
349
                        jButtonMinus.setText("-");
350
                        jButtonMinus.setPreferredSize(dButton);
351
                        jButtonMinus.addActionListener(this);
352
                }
353
        
354
                return jButtonMinus;
355
        }
356

    
357
        public JButton getJButtonMultiply() {
358
                if (jButtonMultiply==null){
359
                        jButtonMultiply=new JButton();
360
                        jButtonMultiply.setText("*");
361
                        jButtonMultiply.setPreferredSize(dButton);
362
                        jButtonMultiply.addActionListener(this);
363
                }
364
        
365
                return jButtonMultiply;
366
        }
367

    
368
        
369
        public JButton getJButtonPlus() {
370
                
371
                if (jButtonPlus==null){
372
                        jButtonPlus=new JButton();
373
                        jButtonPlus.setText("+");
374
                        jButtonPlus.setPreferredSize(dButton);
375
                        jButtonPlus.addActionListener(this);
376
                }
377
                return jButtonPlus;
378
        }
379
        
380

    
381
}