Revision 2102 branches/gvSIG_03_SLD/applications/appgvSIG/src/com/iver/cit/gvsig/gui/thememanager/legendmanager/panels/edition/FValueCellEditor.java

View differences:

FValueCellEditor.java
1 1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2004 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
*/
2
 *
3
 * Copyright (C) 2004 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 41
package com.iver.cit.gvsig.gui.thememanager.legendmanager.panels.edition;
42
import java.awt.Component;
43
import java.awt.event.KeyEvent;
44
import java.awt.event.KeyListener;
45
import java.util.Date;
46 42

  
47
import javax.swing.AbstractCellEditor;
48
import javax.swing.JOptionPane;
49
import javax.swing.JTable;
50
import javax.swing.JTextField;
51
import javax.swing.table.TableCellEditor;
52

  
53 43
import com.hardcode.gdbms.engine.values.BooleanValue;
54 44
import com.hardcode.gdbms.engine.values.DateValue;
55 45
import com.hardcode.gdbms.engine.values.DoubleValue;
......
60 50
import com.hardcode.gdbms.engine.values.StringValue;
61 51
import com.hardcode.gdbms.engine.values.Value;
62 52
import com.hardcode.gdbms.engine.values.ValueFactory;
63
import com.iver.andami.PluginServices;
64 53

  
54
import java.awt.Component;
55
import java.awt.event.KeyEvent;
56
import java.awt.event.KeyListener;
65 57

  
58
import java.util.Date;
59

  
60
import javax.swing.AbstractCellEditor;
61
import javax.swing.JTable;
62
import javax.swing.JTextField;
63
import javax.swing.table.TableCellEditor;
64

  
65

  
66 66
/**
67 67
 * Cell Editor sobre los valores ?nicos.
68 68
 *
......
92 92
	public Component getTableCellEditorComponent(JTable table, Object value,
93 93
		boolean isSelected, int row, int column) {
94 94
		System.out.println(value.toString());
95
		this.value = (Value)value;
95
		this.value = (Value) value;
96 96
		button.setText(value.toString());
97

  
97 98
		return button;
98 99
	}
99 100

  
101
	/**
102
	 * DOCUMENT ME!
103
	 *
104
	 * @param e DOCUMENT ME!
105
	 */
100 106
	public void keyPressed(KeyEvent e) {
101 107
	}
108

  
109
	/**
110
	 * DOCUMENT ME!
111
	 *
112
	 * @param e DOCUMENT ME!
113
	 */
102 114
	public void keyReleased(KeyEvent e) {
103
		value = getValue(value,button.getText());
115
		if (value == null) {
116
			value = ValueFactory.createValue((double) 0);
117
		} else {
118
			value = getValue(value, button.getText());
119
		}
104 120
	}
121

  
122
	/**
123
	 * DOCUMENT ME!
124
	 *
125
	 * @param e DOCUMENT ME!
126
	 */
105 127
	public void keyTyped(KeyEvent e) {
106 128
	}
107
	private Value getValue(Value v,String s) {
108
		Value val=null;
109
			try{	
110
				if (v instanceof DoubleValue) {
111
					val = ValueFactory.createValue(Double.parseDouble(s));
112
				} else if (v instanceof StringValue) {
113
					val = ValueFactory.createValue(s);
114
				} else if (v instanceof LongValue) {
115
					val = ValueFactory.createValue(Long.parseLong(s));
116
				} else if (v instanceof IntValue) {
117
					val = ValueFactory.createValue(Integer.parseInt(s));
118
				} else if (v instanceof FloatValue) {
119
					val = ValueFactory.createValue(Float.parseFloat(s));
120
				} else if (v instanceof ShortValue) {
121
					val = ValueFactory.createValue(Short.parseShort(s));
122
				} else if (v instanceof BooleanValue) {
123
					val = ValueFactory.createValue(Boolean.getBoolean(s));
124
				} else if (v instanceof DateValue) {
125
					val = ValueFactory.createValue(Date.parse(s));
126
				}
127
			}catch (NumberFormatException e) {
128
				JOptionPane.showMessageDialog(null, PluginServices.getText(this,"Formato de n?mero erroneo")+".");
129

  
130
	/**
131
	 * DOCUMENT ME!
132
	 *
133
	 * @param v DOCUMENT ME!
134
	 * @param s DOCUMENT ME!
135
	 *
136
	 * @return DOCUMENT ME!
137
	 */
138
	private Value getValue(Value v, String s) {
139
		Value val = null;
140
		Value cero = null;
141

  
142
		try {
143
			if (v instanceof DoubleValue) {
144
				val = ValueFactory.createValue(Double.parseDouble(s));
145
				cero = ValueFactory.createValue((double) 0);
146
			} else if (v instanceof StringValue) {
147
				val = ValueFactory.createValue(s);
148
				cero = ValueFactory.createValue((String) "");
149
			} else if (v instanceof LongValue) {
150
				val = ValueFactory.createValue(Long.parseLong(s));
151
				cero = ValueFactory.createValue((long) 0);
152
			} else if (v instanceof IntValue) {
153
				val = ValueFactory.createValue(Integer.parseInt(s));
154
				cero = ValueFactory.createValue((int) 0);
155
			} else if (v instanceof FloatValue) {
156
				val = ValueFactory.createValue(Float.parseFloat(s));
157
				cero = ValueFactory.createValue((float) 0);
158
			} else if (v instanceof ShortValue) {
159
				val = ValueFactory.createValue(Short.parseShort(s));
160
				cero = ValueFactory.createValue((short) 0);
161
			} else if (v instanceof BooleanValue) {
162
				val = ValueFactory.createValue(Boolean.getBoolean(s));
163
				cero = ValueFactory.createValue((boolean) false);
164
			} else if (v instanceof DateValue) {
165
				val = ValueFactory.createValue(Date.parse(s));
166
				cero = ValueFactory.createValue((Date) new Date());
129 167
			}
168
		} catch (NumberFormatException e) {
169
			///JOptionPane.showMessageDialog(null, PluginServices.getText(this,"Formato de n?mero erroneo")+".");
170
			return cero;
171
		}
172

  
130 173
		return val;
131 174
	}
132 175
}

Also available in: Unified diff