Revision 7317

View differences:

trunk/libraries/libUI/src/org/gvsig/gui/beans/swing/JNumericTextField.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 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
 * 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
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

  
42
/* CVS MESSAGES:
43
*
44
* $Id$
45
* $Log$
46
* Revision 1.1  2006-09-18 08:00:34  jaume
47
* *** empty log message ***
48
*
49
*
50
*/
51
package org.gvsig.gui.beans.swing;
52

  
53
import java.awt.event.KeyEvent;
54
import java.awt.event.KeyListener;
55

  
56
import javax.swing.JFrame;
57
import javax.swing.JTextField;
58

  
59
/**
60
 *
61
 * @author jaume dominguez faus - jaume.dominguez@iver.es
62
 *
63
 */
64
public class JNumericTextField extends JTextField {
65
	public static final int INTEGER_VALUES = 0;
66
	public static final int ONLY_POSITIVE_INTEGER_VALUES = 1;
67
	public static final int ONLY_NEGATIVE_INTEGER_VALUES = 2;
68
	public static final int ONLY_GREATHER_THAN_ZERO_INTEGER_VALUES = 3;
69
	public static final int ONLY_LESS_THAN_ZERO_INTEGER_VALUES = 4;
70

  
71
	public static final int SHORT_VALUES = 5;
72
	public static final int ONLY_POSITIVE_SHORT_VALUES = 6;
73
	public static final int ONLY_NEGATIVE_SHORT_VALUES = 7;
74
	public static final int ONLY_GREATHER_THAN_ZERO_SHORT_VALUES = 8;
75
	public static final int ONLY_LESS_THAN_ZERO_SHORT_VALUES = 9;
76

  
77
	public static final int FLOAT_VALUES = 10;
78
	public static final int ONLY_POSITIVE_FLOAT_VALUES = 11;
79
	public static final int ONLY_NEGATIVE_FLOAT_VALUES = 12;
80
	public static final int ONLY_GREATHER_THAN_ZERO_FLOAT_VALUES = 13;
81
	public static final int ONLY_LESS_THAN_ZERO_FLOAT_VALUES = 14;
82

  
83
	public static final int DOUBLE_VALUES = 15;
84
	public static final int ONLY_POSITIVE_DOUBLE_VALUES = 16;
85
	public static final int ONLY_NEGATIVE_DOUBLE_VALUES = 17;
86
	public static final int ONLY_GREATHER_THAN_ZERO_DOUBLE_VALUES = 18;
87
	public static final int ONLY_LESS_THAN_ZERO_DOUBLE_VALUES = 19;
88

  
89
	private int valueType = 15;
90
	private double defaultValue = 0D;
91

  
92
	private KeyListener checkNumericValue = new KeyListener() {
93
		public void keyPressed(KeyEvent e)  { }
94
		public void keyReleased(KeyEvent e) {
95
			JTextField component = (JTextField) e.getComponent();
96
			String text= component.getText();
97
			if (e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyCode() == KeyEvent.VK_TAB) {
98
				text = fitValue(text, valueType);
99
			} else if (!text.equals("")){
100
				try {
101
					switch (valueType) {
102
					case INTEGER_VALUES:
103
					case ONLY_POSITIVE_INTEGER_VALUES:
104
					case ONLY_NEGATIVE_INTEGER_VALUES:
105
					case ONLY_GREATHER_THAN_ZERO_INTEGER_VALUES:
106
					case ONLY_LESS_THAN_ZERO_INTEGER_VALUES:
107
						text = String.valueOf(	Integer.parseInt(text) );
108
						break;
109

  
110
					case SHORT_VALUES:
111
					case ONLY_POSITIVE_SHORT_VALUES:
112
					case ONLY_NEGATIVE_SHORT_VALUES:
113
					case ONLY_GREATHER_THAN_ZERO_SHORT_VALUES:
114
					case ONLY_LESS_THAN_ZERO_SHORT_VALUES:
115
						String.valueOf( Short.parseShort(text) );
116
						break;
117

  
118
					case FLOAT_VALUES:
119
					case ONLY_POSITIVE_FLOAT_VALUES:
120
					case ONLY_NEGATIVE_FLOAT_VALUES:
121
					case ONLY_GREATHER_THAN_ZERO_FLOAT_VALUES:
122
					case ONLY_LESS_THAN_ZERO_FLOAT_VALUES:
123
						String.valueOf( Float.parseFloat(text) );
124
						break;
125

  
126
					case DOUBLE_VALUES:
127
					case ONLY_POSITIVE_DOUBLE_VALUES:
128
					case ONLY_NEGATIVE_DOUBLE_VALUES:
129
					case ONLY_GREATHER_THAN_ZERO_DOUBLE_VALUES:
130
					case ONLY_LESS_THAN_ZERO_DOUBLE_VALUES:
131
						String.valueOf(	Double.parseDouble(text) );
132

  
133
						break;
134
					}
135

  
136
				} catch (Exception ex) {
137
					text = component.getText();
138
					text = (text.length() <= 1)? "0" : text.substring(0, text.length()-1);
139
					component.setText(text);
140
				}
141
			}
142

  
143

  
144
			component.setText(text);
145

  
146
		}
147
		public void keyTyped(KeyEvent e)    { }
148
	};
149

  
150
	public JNumericTextField() {
151
		super();
152
		addKeyListener(checkNumericValue);
153
	}
154

  
155
	private String fitValue(String text, int valueType) {
156
		switch (valueType) {
157
		case ONLY_POSITIVE_SHORT_VALUES:
158
		case ONLY_POSITIVE_INTEGER_VALUES:
159
			text = String.valueOf(Math.abs((int) Double.parseDouble(text)));
160
			break;
161
		case ONLY_POSITIVE_FLOAT_VALUES:
162
		case ONLY_POSITIVE_DOUBLE_VALUES:
163
			text = String.valueOf(Math.abs(Double.parseDouble(text)));
164
			break;
165

  
166
		case ONLY_NEGATIVE_INTEGER_VALUES:
167
		case ONLY_NEGATIVE_SHORT_VALUES:
168
			text = String.valueOf(-Math.abs((short) Double.parseDouble(text)));
169
			break;
170
		case ONLY_NEGATIVE_FLOAT_VALUES:
171
		case ONLY_NEGATIVE_DOUBLE_VALUES:
172
			text = String.valueOf(-Math.abs(Double.parseDouble(text)));
173
			break;
174

  
175
		case ONLY_GREATHER_THAN_ZERO_INTEGER_VALUES:
176
		case ONLY_GREATHER_THAN_ZERO_SHORT_VALUES:
177
			if ( !isGreatherThanZero(text) )
178
				text = String.valueOf((int) defaultValue);
179
			break;
180
		case ONLY_GREATHER_THAN_ZERO_FLOAT_VALUES:
181
		case ONLY_GREATHER_THAN_ZERO_DOUBLE_VALUES:
182
			if ( !isGreatherThanZero(text) )
183
				text = String.valueOf(defaultValue);
184
			break;
185

  
186
		case ONLY_LESS_THAN_ZERO_INTEGER_VALUES:
187
		case ONLY_LESS_THAN_ZERO_SHORT_VALUES:
188
			if ( !isLessThanZero(text) )
189
				text = String.valueOf((int) defaultValue);
190
			break;
191

  
192
		case ONLY_LESS_THAN_ZERO_FLOAT_VALUES:
193
		case ONLY_LESS_THAN_ZERO_DOUBLE_VALUES:
194
			if ( !isLessThanZero(text) )
195
				text = String.valueOf(defaultValue);
196
			break;
197
		}
198
		return text;
199
	}
200

  
201
	public JNumericTextField(int valueType) {
202
		super();
203
		setValueType(valueType);
204
		addKeyListener(checkNumericValue);
205
		setText(fitValue(String.valueOf(defaultValue), valueType));
206
	}
207

  
208
	public JNumericTextField(int valueType, double defaultValue) {
209
		super();
210
		setValueType(valueType);
211
		setDefaultValue(defaultValue);
212
		addKeyListener(checkNumericValue);
213
		setText(fitValue(String.valueOf(defaultValue), valueType));
214
	}
215

  
216
	public JNumericTextField(String text) {
217
		super(text);
218
		addKeyListener(checkNumericValue);
219
		setText(fitValue(text, valueType));
220
	}
221

  
222
	public JNumericTextField(String text, int valueType) {
223
		super(text);
224
		setValueType(valueType);
225
		addKeyListener(checkNumericValue);
226
		setText(fitValue(text, valueType));
227
	}
228

  
229
	public JNumericTextField(String text, int valueType, double defaultValue) {
230
		super(text);
231
		setValueType(valueType);
232
		setDefaultValue(defaultValue);
233
		addKeyListener(checkNumericValue);
234
		setText(fitValue(text, valueType));
235
	}
236

  
237
	private boolean isGreatherThanZero(String text) {
238
		return Double.parseDouble(text) > 0;
239
	}
240

  
241
	private boolean isLessThanZero(String text) {
242
		return Double.parseDouble(text) < 0;
243
	}
244

  
245
	public int getValueType() {
246
		return valueType;
247
	}
248

  
249
	public void setValueType(int valueType) {
250
		this.valueType = valueType;
251
	}
252

  
253
	public double getDefaultValue() {
254
		return defaultValue;
255
	}
256

  
257
	public void setDefaultValue(double value) {
258
		this.defaultValue = value;
259
	}
260

  
261
	public static void main(String args[]) {
262
		JFrame f = new JFrame("Test JNumericTextField");
263
		GridBagLayoutPanel contentPane = new GridBagLayoutPanel();
264
		JNumericTextField integerJTextField = new JNumericTextField(JNumericTextField.INTEGER_VALUES),
265
						  positiveIntegerJTextField = new JNumericTextField(JNumericTextField.ONLY_POSITIVE_INTEGER_VALUES),
266
						  negativeIntegerJTextField = new JNumericTextField(JNumericTextField.ONLY_NEGATIVE_INTEGER_VALUES, -1),
267
						  greatherThanZeroIntegerJTextField = new JNumericTextField(JNumericTextField.ONLY_GREATHER_THAN_ZERO_INTEGER_VALUES),
268
						  doubleJTextField = new JNumericTextField(JNumericTextField.DOUBLE_VALUES),
269
						  positiveDoubleJTextField = new JNumericTextField(JNumericTextField.ONLY_POSITIVE_DOUBLE_VALUES, 45),
270
						  negativeDoubleJTextField = new JNumericTextField(JNumericTextField.ONLY_NEGATIVE_DOUBLE_VALUES, -1),
271
						  greatherThanZeroDoubleJTextField = new JNumericTextField(JNumericTextField.ONLY_GREATHER_THAN_ZERO_DOUBLE_VALUES);
272

  
273
		contentPane.addComponent("Integer", integerJTextField);
274
		contentPane.addComponent("Positive Integer", positiveIntegerJTextField);
275
		contentPane.addComponent("Negative Integer", negativeIntegerJTextField);
276
		contentPane.addComponent("Greather than zero Integer", greatherThanZeroIntegerJTextField);
277
		contentPane.addComponent("Double", doubleJTextField);
278
		contentPane.addComponent("Positive Double", positiveDoubleJTextField);
279
		contentPane.addComponent("Negative Double", negativeDoubleJTextField);
280
		contentPane.addComponent("Greather than zero Double", greatherThanZeroDoubleJTextField);
281
		f.setContentPane(contentPane);
282
		f.pack();
283
		f.show();
284

  
285
	}
286
}
0 287

  
trunk/libraries/libUI/src/org/gvsig/gui/beans/swing/JTextPreview.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 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
 * 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
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

  
42
/* CVS MESSAGES:
43
*
44
* $Id$
45
* $Log$
46
* Revision 1.1  2006-09-18 08:00:34  jaume
47
* *** empty log message ***
48
*
49
*
50
*/
51
package org.gvsig.gui.beans.swing;
52

  
53
import java.awt.Font;
54
import java.util.Enumeration;
55

  
56
import javax.swing.JEditorPane;
57
import javax.swing.UIManager;
58
import javax.swing.plaf.FontUIResource;
59

  
60

  
61
import com.iver.andami.PluginServices;
62

  
63
public class JTextPreview extends JEditorPane {
64
	private String text = null;
65
	private Font font = null;
66
	private final String template=
67
	"{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang3082{\\fonttbl{\\f0\\fswiss\\fprq2\\fcharset0 Arial;}{\\f1\\fswiss\\fcharset0 #FONT#;}}\r\n" +
68
	"{\\*\\generator Msftedit 5.41.15.1507;}\\viewkind4\\uc1\\pard#BOLD##ITALIC##UNDERLINED#f0#FONT_SIZE# #TEXT##END_UNDERLINED##NONE##END_BOLD##END_ITALIC#\\f1\\par\r\n" +
69
	"}";
70

  
71

  
72
	public JTextPreview() {
73
		super();
74
		setEditable(false);
75
	}
76

  
77
	public void setText(String text) {
78
		if (text == null)
79
			text = PluginServices.getText(this, "text_preview_text");
80
		setContentType("text/rtf");
81
		this.text = text;
82
		if (font == null) {
83
			Enumeration keys = UIManager.getDefaults().keys();
84
			while (keys.hasMoreElements()) {
85
				Object key = keys.nextElement();
86
				Object value = UIManager.get (key);
87
				if (value instanceof FontUIResource) {
88
					FontUIResource fur = (FontUIResource) value;
89
					String fontName = fur.getFontName();
90
					font = new Font(fontName, Font.PLAIN, 10);
91
					break;
92
				}
93
			}
94
		}
95

  
96
		String theText =
97
			template.replaceAll("#FONT#", font.getName()).
98
					 replaceAll("#BOLD#", (font.isBold())? "\\b": "").
99
					 replaceAll("#END_BOLD#", (font.isBold())? "\\b0": "").
100
					 replaceAll("#ITALIC#", (font.isItalic())? "\\i": "").
101
					 replaceAll("#END_ITALIC#", (font.isItalic())? "\\i0": "").
102
					 replaceAll("#UNDERLINED#", (false/*font.isUnderlined()*/)? "\\ul": "").
103
					 replaceAll("#END_UNDERLINED#", (false/*font.isUnderlined()*/)? "\\ul": "").
104
					 replaceAll("#FONT_SIZE#", "\\\\fs"+font.getSize()*2).
105
					 replaceAll("#NONE#", ((font.isBold() || font.isItalic() /*||font.isUnderlined()*/)? "none":"")).
106
					 replaceAll("#TEXT#", text);
107
		super.setText(theText);
108
	}
109

  
110
	public void setFont(Font font) {
111
		this.font = font;
112
		setText(text);
113
	}
114

  
115
	public void setEditable(boolean b) {
116
		// avoided
117
	}
118
}
0 119

  
trunk/extensions/extGPS/.project
10 10
			<arguments>
11 11
			</arguments>
12 12
		</buildCommand>
13
		<buildCommand>
14
			<name>de.loskutov.FileSync.FSBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
13 18
	</buildSpec>
14 19
	<natures>
15 20
		<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
trunk/extensions/extGPS/src/org/gvsig/gps/tools/PointCalibrate.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.12  2006-09-14 07:06:00  jaume
46
* Revision 1.13  2006-09-18 08:02:46  jaume
47 47
* *** empty log message ***
48 48
*
49
* Revision 1.12  2006/09/14 07:06:00  jaume
50
* *** empty log message ***
51
*
49 52
* Revision 1.11  2006/08/29 11:52:17  jaume
50 53
* *** empty log message ***
51 54
*
......
96 99
import com.iver.cit.gvsig.fmap.tools.BehaviorException;
97 100
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent;
98 101
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener;
99
import com.iver.cit.gvsig.gui.View;
102
import com.iver.cit.gvsig.project.documents.view.gui.View;
100 103
import com.iver.utiles.XMLEntity;
101 104

  
102 105
public class PointCalibrate implements PointListener {
trunk/extensions/extGPS/src/org/gvsig/gps/GPSExtension.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.14  2006-09-14 07:06:00  jaume
46
* Revision 1.15  2006-09-18 08:02:46  jaume
47 47
* *** empty log message ***
48 48
*
49
* Revision 1.14  2006/09/14 07:06:00  jaume
50
* *** empty log message ***
51
*
49 52
* Revision 1.13  2006/08/29 11:52:17  jaume
50 53
* *** empty log message ***
51 54
*
......
111 114
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
112 115
import com.iver.cit.gvsig.fmap.layers.GraphicLayer;
113 116
import com.iver.cit.gvsig.fmap.rendering.FGraphic;
114
import com.iver.cit.gvsig.gui.View;
117
import com.iver.cit.gvsig.project.documents.view.gui.View;
115 118

  
116 119
public class GPSExtension extends Extension{
117 120

  
trunk/extensions/extGPS/src/org/gvsig/gps/panel/GPSConfigPanel.java
43 43
 *
44 44
 * $Id$
45 45
 * $Log$
46
 * Revision 1.15  2006-08-29 11:52:17  jaume
46
 * Revision 1.16  2006-09-18 08:02:46  jaume
47 47
 * *** empty log message ***
48 48
 *
49
 * Revision 1.15  2006/08/29 11:52:17  jaume
50
 * *** empty log message ***
51
 *
49 52
 * Revision 1.14  2006/08/29 07:45:35  jaume
50 53
 * *** empty log message ***
51 54
 *
......
111 114
import com.iver.andami.ui.mdiManager.WindowInfo;
112 115
import com.iver.cit.gvsig.fmap.MapControl;
113 116
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior;
114
import com.iver.cit.gvsig.gui.View;
117
import com.iver.cit.gvsig.project.documents.view.gui.View;
115 118
import com.iver.utiles.XMLEntity;
116 119

  
117 120
public class GPSConfigPanel extends JPanel implements SingletonWindow{

Also available in: Unified diff