Statistics
| Revision:

root / trunk / libraries / libUIComponent / src-test-ui / org / gvsig / gui / beans / swing / jFormattedTextWithSpecificCaretPosition / TestJFormattedTextFieldWithSpecificCaretPosition.java @ 13136

History | View | Annotate | Download (4.75 KB)

1
package org.gvsig.gui.beans.swing.jFormattedTextWithSpecificCaretPosition;
2

    
3
import java.awt.Dimension;
4
import java.awt.event.MouseAdapter;
5
import java.awt.event.MouseEvent;
6

    
7
import javax.swing.JButton;
8
import javax.swing.JFrame;
9
import javax.swing.JPanel;
10

    
11
import org.gvsig.gui.awt.event.specificCaretPosition.ISpecificCaretPosition;
12
import org.gvsig.gui.beans.Messages;
13
import org.gvsig.gui.beans.swing.jFormattedTextFieldWithSpecificCaretPosition.JFormattedTextFieldWithSpecificCaretPosition;
14

    
15
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
16
 *
17
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
18
 *
19
 * This program is free software; you can redistribute it and/or
20
 * modify it under the terms of the GNU General Public License
21
 * as published by the Free Software Foundation; either version 2
22
 * of the License, or (at your option) any later version.
23
 *
24
 * This program is distributed in the hope that it will be useful,
25
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
 * GNU General Public License for more details.
28
 *
29
 * You should have received a copy of the GNU General Public License
30
 * along with this program; if not, write to the Free Software
31
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
32
 *
33
 * For more information, contact:
34
 *
35
 *  Generalitat Valenciana
36
 *   Conselleria d'Infraestructures i Transport
37
 *   Av. Blasco Ib??ez, 50
38
 *   46010 VALENCIA
39
 *   SPAIN
40
 *
41
 *      +34 963862235
42
 *   gvsig@gva.es
43
 *      www.gvsig.gva.es
44
 *
45
 *    or
46
 *
47
 *   IVER T.I. S.A
48
 *   Salamanca 50
49
 *   46005 Valencia
50
 *   Spain
51
 *
52
 *   +34 963163400
53
 *   dac@iver.es
54
 */
55

    
56
/**
57
 * Tests for JFormattedTextFieldWithSpecificCaretPosition
58
 * 
59
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
60
 */
61
public class TestJFormattedTextFieldWithSpecificCaretPosition {
62
        private static JFormattedTextFieldWithSpecificCaretPosition jTF1;
63
        private static JFormattedTextFieldWithSpecificCaretPosition jTF2;
64
        private static JFormattedTextFieldWithSpecificCaretPosition jTF3;
65
        private static JFormattedTextFieldWithSpecificCaretPosition jTF4;
66
        
67
        /**
68
         * Test method for the TestJCalendarCDatePanel class
69
         * @param args
70
         */
71
        public static void main(String[] args)
72
        {
73
                final int height = 60;
74
                final int width = 300;
75
                
76
                final int heightTF = 25;
77
                final int widthTF = 40;
78
                
79
                final int heightJB = 25;
80
                final int widthJB = 100;
81
                
82
                // Objects creation
83
                JFrame jF = new JFrame();                
84

    
85
                JPanel jP = new JPanel();
86
                jP.setPreferredSize(new Dimension(width, height));
87
                
88
                jTF1 = new JFormattedTextFieldWithSpecificCaretPosition();
89
                jTF1.setPreferredSize(new Dimension(widthTF, heightTF));
90
                jTF1.setToolTipText(Messages.getText("default"));
91
                
92
                jTF2 = new JFormattedTextFieldWithSpecificCaretPosition();
93
                jTF2.setCaretPositionMode(ISpecificCaretPosition.RIGHT_POSITIONS);
94
                jTF2.setPreferredSize(new Dimension(widthTF, heightTF));
95
                jTF2.setToolTipText(Messages.getText("right"));
96

    
97
                jTF3 = new JFormattedTextFieldWithSpecificCaretPosition();
98
                jTF3.setCaretPositionMode(ISpecificCaretPosition.LEFT_POSITIONS);
99
                jTF3.setPreferredSize(new Dimension(widthTF, heightTF));
100
                jTF3.setToolTipText(Messages.getText("left"));
101

    
102
                jTF4 = new JFormattedTextFieldWithSpecificCaretPosition();
103
                jTF4.setCaretPositionMode(ISpecificCaretPosition.LIKE_JTEXTCOMPONENT);
104
                jTF4.setPreferredSize(new Dimension(widthTF, heightTF));
105
                jTF4.setToolTipText(Messages.getText("like_JTextField"));
106
                
107
                JButton jButton = new JButton();
108
                jButton.setToolTipText(Messages.getText("enable/Disable"));
109
                jButton.setText("En./Dis.");
110
                jButton.setPreferredSize(new Dimension(widthJB, heightJB));
111
                jButton.addMouseListener(new MouseAdapter() {
112
                        /*
113
                         *  (non-Javadoc)
114
                         * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
115
                         */
116
                        public void mouseClicked(MouseEvent e) {
117
                                enableOrDisableJTextFields();
118
                        }                        
119
                });
120

    
121
            
122
                jP.add(jTF1);
123
                jP.add(jTF2);
124
                jP.add(jTF3);
125
                jP.add(jTF4);
126
                jP.add(jButton);
127

    
128
//                jF.setVisible(false);                
129
            // Test adding text to text fields
130

    
131
            // Set properties
132
                jF.setTitle("Test JFormattedTextFieldWithSpecificCaretPosition");
133
            jF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
134
            jF.setSize(jP.getPreferredSize());
135
            jF.getContentPane().add(jP);        
136
            
137
                jF.setVisible(true);
138
                
139
            jTF1.setEnabled(false);
140
            jTF1.setText("+123456.78901234141241");
141
            jTF2.setEnabled(false);
142
            jTF2.setText("-0917429817.10934712");
143
            jTF3.setEnabled(false);
144
            jTF3.setText("-184091.3095174");
145
            jTF4.setEnabled(false);
146
            jTF4.setText("+128947.09345734");
147

    
148
        }
149
        
150
        private static void enableOrDisableJTextFields() {
151
                jTF1.setEnabled(!jTF1.isEnabled());
152
                jTF2.setEnabled(!jTF2.isEnabled());
153
                jTF3.setEnabled(!jTF3.isEnabled());
154
                jTF4.setEnabled(!jTF4.isEnabled());
155
        }
156
}