svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / specificcaretposition / JTextFieldWithSCP.java @ 40561
History | View | Annotate | Download (5.94 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.io.Serializable; |
27 |
|
28 |
import javax.swing.JTextField; |
29 |
import javax.swing.text.Document; |
30 |
|
31 |
import org.gvsig.gui.awt.event.specificCaretPosition.ISpecificCaretPosition; |
32 |
import org.gvsig.gui.awt.event.specificCaretPosition.SpecificCaretPositionListeners; |
33 |
|
34 |
|
35 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
36 |
*
|
37 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
38 |
*
|
39 |
* This program is free software; you can redistribute it and/or
|
40 |
* modify it under the terms of the GNU General Public License
|
41 |
* as published by the Free Software Foundation; either version 2
|
42 |
* of the License, or (at your option) any later version.
|
43 |
*
|
44 |
* This program is distributed in the hope that it will be useful,
|
45 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
46 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
47 |
* GNU General Public License for more details.
|
48 |
*
|
49 |
* You should have received a copy of the GNU General Public License
|
50 |
* along with this program; if not, write to the Free Software
|
51 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
52 |
*
|
53 |
* For more information, contact:
|
54 |
*
|
55 |
* Generalitat Valenciana
|
56 |
* Conselleria d'Infraestructures i Transport
|
57 |
* Av. Blasco Ib??ez, 50
|
58 |
* 46010 VALENCIA
|
59 |
* SPAIN
|
60 |
*
|
61 |
* +34 963862235
|
62 |
* gvsig@gva.es
|
63 |
* www.gvsig.gva.es
|
64 |
*
|
65 |
* or
|
66 |
*
|
67 |
* IVER T.I. S.A
|
68 |
* Salamanca 50
|
69 |
* 46005 Valencia
|
70 |
* Spain
|
71 |
*
|
72 |
* +34 963163400
|
73 |
* dac@iver.es
|
74 |
*/
|
75 |
|
76 |
/**
|
77 |
* This class is a JTextField with two listeners that allow authomatically reset the caret
|
78 |
* position of this component to left (LEFT_POSITIONS), right (RIGHT_POSITIONS) or like JTextField (LIKE_JTEXTCOMPONENT) (do nothing).
|
79 |
* By default is to left.
|
80 |
*
|
81 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
82 |
*/
|
83 |
public class JTextFieldWithSCP extends JTextField implements ISpecificCaretPosition, Serializable { |
84 |
private static final long serialVersionUID = -7873719783491147038L; |
85 |
|
86 |
private int caretPositionMode; |
87 |
|
88 |
/**
|
89 |
* @see JTextField#JTextField()
|
90 |
*/
|
91 |
public JTextFieldWithSCP() {
|
92 |
super();
|
93 |
caretPositionMode = LEFT_POSITIONS; |
94 |
initialize(); |
95 |
} |
96 |
|
97 |
/**
|
98 |
* @see JTextField#JTextField(javax.swing.text.Document, java.lang.String, int)
|
99 |
*/
|
100 |
public JTextFieldWithSCP(Document doc, String text, int columns) { |
101 |
super(doc, text, columns);
|
102 |
caretPositionMode = LEFT_POSITIONS; |
103 |
initialize(); |
104 |
} |
105 |
|
106 |
/**
|
107 |
* @see JTextField#JTextField(int)
|
108 |
*/
|
109 |
public JTextFieldWithSCP(int columns) { |
110 |
super(columns);
|
111 |
caretPositionMode = LEFT_POSITIONS; |
112 |
initialize(); |
113 |
} |
114 |
|
115 |
/**
|
116 |
* @see JTextField#JTextField(java.lang.String)
|
117 |
*/
|
118 |
public JTextFieldWithSCP(String text) { |
119 |
super(text);
|
120 |
caretPositionMode = LEFT_POSITIONS; |
121 |
initialize(); |
122 |
} |
123 |
|
124 |
/**
|
125 |
* @see JTextField#JTextField(java.lang.String, int)
|
126 |
*/
|
127 |
public JTextFieldWithSCP(String text, int columns) { |
128 |
super(text, columns);
|
129 |
caretPositionMode = LEFT_POSITIONS; |
130 |
initialize(); |
131 |
} |
132 |
//
|
133 |
// /**
|
134 |
// * @see JTextField#JTextField()
|
135 |
// * @param position The position of text that will be seen (LEFT_POSITIONS, RIGHT_POSITIONS or LIKE_JTEXTCOMPONENT)
|
136 |
// */
|
137 |
// public JTextFieldWithSpecificCaretPosition(int position) {
|
138 |
// super();
|
139 |
// caretPositionMode = position;
|
140 |
// initialize();
|
141 |
// }
|
142 |
|
143 |
/**
|
144 |
* @see JTextField#JTextField(javax.swing.text.Document, java.lang.String, int)
|
145 |
* @param position The position of text that will be seen (LEFT_POSITIONS, RIGHT_POSITIONS or LIKE_JTEXTCOMPONENT)
|
146 |
*/
|
147 |
public JTextFieldWithSCP(Document doc, String text, int columns, int position) { |
148 |
super(doc, text, columns);
|
149 |
caretPositionMode = position; |
150 |
initialize(); |
151 |
} |
152 |
|
153 |
/**
|
154 |
* @see JTextField#JTextField(int)
|
155 |
* @param position The position of text that will be seen (LEFT_POSITIONS, RIGHT_POSITIONS or LIKE_JTEXTCOMPONENT)
|
156 |
*/
|
157 |
public JTextFieldWithSCP(int columns, int position) { |
158 |
super(columns);
|
159 |
caretPositionMode = position; |
160 |
initialize(); |
161 |
} |
162 |
|
163 |
/**
|
164 |
* @see JTextField#JTextField(java.lang.String)
|
165 |
* @param position The position of text that will be seen (LEFT_POSITIONS, RIGHT_POSITIONS or LIKE_JTEXTCOMPONENT)
|
166 |
*/
|
167 |
public JTextFieldWithSCP(int position, String text) { |
168 |
super(text);
|
169 |
caretPositionMode = position; |
170 |
initialize(); |
171 |
} |
172 |
|
173 |
/**
|
174 |
* @see JTextField#JTextField(java.lang.String, int)
|
175 |
* @param position The position of text that will be seen (LEFT_POSITIONS, RIGHT_POSITIONS or LIKE_JTEXTCOMPONENT)
|
176 |
*/
|
177 |
public JTextFieldWithSCP(String text, int columns, int position) { |
178 |
super(text, columns);
|
179 |
caretPositionMode = position; |
180 |
initialize(); |
181 |
} |
182 |
|
183 |
/**
|
184 |
* This method adds three listeners to this component:
|
185 |
*/
|
186 |
private void initialize() { |
187 |
SpecificCaretPositionListeners.setListeners(this);
|
188 |
} |
189 |
|
190 |
/*
|
191 |
* (non-Javadoc)
|
192 |
* @see org.gvsig.gui.awt.event.ISpecificCaretPosition#getCaretPositionMode()
|
193 |
*/
|
194 |
public int getCaretPositionMode() { |
195 |
return caretPositionMode;
|
196 |
} |
197 |
|
198 |
/*
|
199 |
* (non-Javadoc)
|
200 |
* @see org.gvsig.gui.awt.event.ISpecificCaretPosition#setCaretPositionMode(int)
|
201 |
*/
|
202 |
public void setCaretPositionMode(int caretPositionMode) { |
203 |
this.caretPositionMode = caretPositionMode;
|
204 |
} |
205 |
} |