Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / test / java / org / gvsig / gui / beans / specificcaretposition / TestJTextFieldWithSCP.java @ 40561

History | View | Annotate | Download (5.28 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.gui.beans.specificcaretposition;
25

    
26
import java.awt.Dimension;
27
import java.awt.event.MouseAdapter;
28
import java.awt.event.MouseEvent;
29

    
30
import javax.swing.JButton;
31
import javax.swing.JFrame;
32
import javax.swing.JPanel;
33

    
34
import org.gvsig.gui.awt.event.specificCaretPosition.ISpecificCaretPosition;
35
import org.gvsig.gui.beans.Messages;
36

    
37
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
38
 *
39
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
40
 *
41
 * This program is free software; you can redistribute it and/or
42
 * modify it under the terms of the GNU General Public License
43
 * as published by the Free Software Foundation; either version 2
44
 * of the License, or (at your option) any later version.
45
 *
46
 * This program is distributed in the hope that it will be useful,
47
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
48
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
49
 * GNU General Public License for more details.
50
 *
51
 * You should have received a copy of the GNU General Public License
52
 * along with this program; if not, write to the Free Software
53
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
54
 *
55
 * For more information, contact:
56
 *
57
 *  Generalitat Valenciana
58
 *   Conselleria d'Infraestructures i Transport
59
 *   Av. Blasco Ib??ez, 50
60
 *   46010 VALENCIA
61
 *   SPAIN
62
 *
63
 *      +34 963862235
64
 *   gvsig@gva.es
65
 *      www.gvsig.gva.es
66
 *
67
 *    or
68
 *
69
 *   IVER T.I. S.A
70
 *   Salamanca 50
71
 *   46005 Valencia
72
 *   Spain
73
 *
74
 *   +34 963163400
75
 *   dac@iver.es
76
 */
77

    
78
/**
79
 * Tests for JTextFieldWithSpecificCaretPosition
80
 * 
81
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
82
 */
83
public class TestJTextFieldWithSCP {
84
        private static JTextFieldWithSCP jTF1;
85
        private static JTextFieldWithSCP jTF2;
86
        private static JTextFieldWithSCP jTF3;
87
        private static JTextFieldWithSCP jTF4;
88
        
89
        /**
90
         * Test method for the TestJCalendarCDatePanel class
91
         * @param args
92
         */
93
        public static void main(String[] args)
94
        {
95
                final int height = 60;
96
                final int width = 300;
97
                
98
                final int heightTF = 25;
99
                final int widthTF = 40;
100
                
101
                final int heightJB = 25;
102
                final int widthJB = 100;
103
                
104
                // Objects creation
105
                JFrame jF = new JFrame();                
106

    
107
                JPanel jP = new JPanel();
108
                jP.setPreferredSize(new Dimension(width, height));
109
                
110
                jTF1 = new JTextFieldWithSCP();
111
                jTF1.setPreferredSize(new Dimension(widthTF, heightTF));
112
                jTF1.setToolTipText(Messages.getText("Default"));
113
                
114
                jTF2 = new JTextFieldWithSCP();
115
                jTF2.setCaretPositionMode(ISpecificCaretPosition.RIGHT_POSITIONS);
116
                jTF2.setPreferredSize(new Dimension(widthTF, heightTF));
117
                jTF2.setToolTipText(Messages.getText("Right"));
118

    
119
                jTF3 = new JTextFieldWithSCP();
120
                jTF3.setCaretPositionMode(ISpecificCaretPosition.LEFT_POSITIONS);
121
                jTF3.setPreferredSize(new Dimension(widthTF, heightTF));
122
                jTF3.setToolTipText(Messages.getText("Left"));
123

    
124
                jTF4 = new JTextFieldWithSCP();
125
                jTF4.setCaretPositionMode(ISpecificCaretPosition.LIKE_JTEXTCOMPONENT);
126
                jTF4.setPreferredSize(new Dimension(widthTF, heightTF));
127
                jTF4.setToolTipText(Messages.getText("Like_JTextField"));
128
                
129
                JButton jButton = new JButton();
130
                jButton.setToolTipText("Enable/Disable");
131
                jButton.setText("En./Dis.");
132
                jButton.setPreferredSize(new Dimension(widthJB, heightJB));
133
                jButton.addMouseListener(new MouseAdapter() {
134
                        /*
135
                         *  (non-Javadoc)
136
                         * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
137
                         */
138
                        public void mouseClicked(MouseEvent e) {
139
                                enableOrDisableJTextFields();
140
                        }                        
141
                });
142

    
143
            
144
                jP.add(jTF1);
145
                jP.add(jTF2);
146
                jP.add(jTF3);
147
                jP.add(jTF4);
148
                jP.add(jButton);
149

    
150
//                jF.setVisible(false);                
151
            // Test adding text to text fields
152

    
153
            // Set properties
154
                jF.setTitle("Test JTextFieldWithSpecificCaretPosition");
155
            jF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
156
            jF.setSize(jP.getPreferredSize());
157
            jF.getContentPane().add(jP);        
158
            
159
                jF.setVisible(true);
160
                
161
            jTF1.setEnabled(false);
162
            jTF1.setText("+123456.78901234141241");
163
            jTF2.setEnabled(false);
164
            jTF2.setText("-0917429817.10934712");
165
            jTF3.setEnabled(false);
166
            jTF3.setText("-184091.3095174");
167
            jTF4.setEnabled(false);
168
            jTF4.setText("+128947.09345734");
169

    
170
        }
171
        
172
        private static void enableOrDisableJTextFields() {
173
                jTF1.setEnabled(!jTF1.isEnabled());
174
                jTF2.setEnabled(!jTF2.isEnabled());
175
                jTF3.setEnabled(!jTF3.isEnabled());
176
                jTF4.setEnabled(!jTF4.isEnabled());
177
        }
178
}