root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / edition / gui / ValueCellEditor.java @ 21359
History | View | Annotate | Download (6.36 KB)
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 |
*/
|
41 |
package com.iver.cit.gvsig.project.documents.view.legend.edition.gui; |
42 |
|
43 |
import java.awt.Component; |
44 |
import java.awt.event.KeyAdapter; |
45 |
import java.awt.event.KeyEvent; |
46 |
import java.sql.Types; |
47 |
import java.text.ParseException; |
48 |
import java.util.ArrayList; |
49 |
import java.util.EventObject; |
50 |
|
51 |
import javax.swing.JTable; |
52 |
import javax.swing.JTextField; |
53 |
import javax.swing.event.CellEditorListener; |
54 |
import javax.swing.event.ChangeEvent; |
55 |
import javax.swing.table.TableCellEditor; |
56 |
|
57 |
/**
|
58 |
* Cell Editor sobre los valores ?nicos.
|
59 |
*
|
60 |
* @author Vicente Caballero Navarro
|
61 |
*/
|
62 |
public class ValueCellEditor extends JTextField implements TableCellEditor { |
63 |
private ArrayList listeners = new ArrayList(); |
64 |
//private Value initialValue;
|
65 |
|
66 |
/**
|
67 |
* Crea un nuevo FLabelCellEditor.
|
68 |
*/
|
69 |
public ValueCellEditor() {
|
70 |
addKeyListener(new KeyAdapter() { |
71 |
public void keyReleased(KeyEvent e) { |
72 |
if (e.getKeyCode() == KeyEvent.VK_ENTER) { |
73 |
stopCellEditing(); |
74 |
} else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { |
75 |
cancelCellEditing(); |
76 |
} |
77 |
} |
78 |
}); |
79 |
} |
80 |
|
81 |
//Implement the one CellEditor method that AbstractCellEditor doesn't.
|
82 |
public Object getCellEditorValue() { |
83 |
return getValue(getText());
|
84 |
} |
85 |
|
86 |
//Implement the one method defined by TableCellEditor.
|
87 |
public Component getTableCellEditorComponent(JTable table, Object value, |
88 |
boolean isSelected, int row, int column) { |
89 |
//initialValue=(Value)value;
|
90 |
if (value == null) { |
91 |
setText("");
|
92 |
} else {
|
93 |
setText(value.toString()); |
94 |
} |
95 |
|
96 |
return this; |
97 |
} |
98 |
|
99 |
/**
|
100 |
* @see javax.swing.CellEditor#cancelCellEditing()
|
101 |
*/
|
102 |
public void cancelCellEditing() { |
103 |
//if (initialValue != null) {
|
104 |
// setText(initialValue.toString());
|
105 |
//}
|
106 |
|
107 |
for (int i = 0; i < listeners.size(); i++) { |
108 |
CellEditorListener l = (CellEditorListener) listeners.get(i); |
109 |
ChangeEvent evt = new ChangeEvent(this); |
110 |
l.editingCanceled(evt); |
111 |
} |
112 |
} |
113 |
|
114 |
/**
|
115 |
* @see javax.swing.CellEditor#stopCellEditing()
|
116 |
*/
|
117 |
public boolean stopCellEditing() { |
118 |
for (int i = 0; i < listeners.size(); i++) { |
119 |
CellEditorListener l = (CellEditorListener) listeners.get(i); |
120 |
ChangeEvent evt = new ChangeEvent(this); |
121 |
l.editingStopped(evt); |
122 |
} |
123 |
|
124 |
return true; |
125 |
} |
126 |
|
127 |
/**
|
128 |
* @see javax.swing.CellEditor#isCellEditable(java.util.EventObject)
|
129 |
*/
|
130 |
public boolean isCellEditable(EventObject anEvent) { |
131 |
return true; |
132 |
} |
133 |
|
134 |
/**
|
135 |
* @see javax.swing.CellEditor#shouldSelectCell(java.util.EventObject)
|
136 |
*/
|
137 |
public boolean shouldSelectCell(EventObject anEvent) { |
138 |
return true; |
139 |
} |
140 |
|
141 |
/**
|
142 |
* @see javax.swing.CellEditor#addCellEditorListener(javax.swing.event.CellEditorListener)
|
143 |
*/
|
144 |
public void addCellEditorListener(CellEditorListener l) { |
145 |
listeners.add(l); |
146 |
} |
147 |
|
148 |
/**
|
149 |
* @see javax.swing.CellEditor#removeCellEditorListener(javax.swing.event.CellEditorListener)
|
150 |
*/
|
151 |
public void removeCellEditorListener(CellEditorListener l) { |
152 |
listeners.remove(l); |
153 |
} |
154 |
|
155 |
/**
|
156 |
* DOCUMENT ME!
|
157 |
*
|
158 |
* @param s DOCUMENT ME!
|
159 |
*
|
160 |
* @return DOCUMENT ME!
|
161 |
*/
|
162 |
private Object getValue(String s) { |
163 |
Object val = null; |
164 |
//Value cero = null;
|
165 |
|
166 |
// try {
|
167 |
try {
|
168 |
val = new Integer(s);//ValueFactory.createValueByType(s, Types.INTEGER); |
169 |
|
170 |
return val;
|
171 |
} catch (NumberFormatException e) { |
172 |
} |
173 |
|
174 |
try {
|
175 |
val = new Long(s);//ValueFactory.createValueByType(s, Types.BIGINT); |
176 |
|
177 |
return val;
|
178 |
} catch (NumberFormatException e) { |
179 |
} |
180 |
|
181 |
try {
|
182 |
val = new Float(s);//ValueFactory.createValueByType(s, Types.FLOAT); |
183 |
|
184 |
return val;
|
185 |
} catch (NumberFormatException e) { |
186 |
} |
187 |
|
188 |
try {
|
189 |
val = new Double(s);//ValueFactory.createValueByType(s, Types.DOUBLE); |
190 |
|
191 |
return val;
|
192 |
} catch (NumberFormatException e) { |
193 |
} |
194 |
|
195 |
val = s;//ValueFactory.createValueByType(s, Types.LONGVARCHAR);
|
196 |
// } catch (ParseException e) {
|
197 |
// e.printStackTrace();
|
198 |
// }
|
199 |
|
200 |
/*try {
|
201 |
if (v instanceof DoubleValue) {
|
202 |
val = ValueFactory.createValue(Double.parseDouble(s));
|
203 |
cero = ValueFactory.createValue((double) 0);
|
204 |
} else if (v instanceof StringValue) {
|
205 |
val = ValueFactory.createValue(s);
|
206 |
cero = ValueFactory.createValue((String) "");
|
207 |
} else if (v instanceof LongValue) {
|
208 |
val = ValueFactory.createValue(Long.parseLong(s));
|
209 |
cero = ValueFactory.createValue((long) 0);
|
210 |
} else if (v instanceof IntValue) {
|
211 |
val = ValueFactory.createValue(Integer.parseInt(s));
|
212 |
cero = ValueFactory.createValue((int) 0);
|
213 |
} else if (v instanceof FloatValue) {
|
214 |
val = ValueFactory.createValue(Float.parseFloat(s));
|
215 |
cero = ValueFactory.createValue((float) 0);
|
216 |
} else if (v instanceof ShortValue) {
|
217 |
val = ValueFactory.createValue(Short.parseShort(s));
|
218 |
cero = ValueFactory.createValue((short) 0);
|
219 |
} else if (v instanceof BooleanValue) {
|
220 |
val = ValueFactory.createValue(Boolean.getBoolean(s));
|
221 |
cero = ValueFactory.createValue((boolean) false);
|
222 |
} else if (v instanceof DateValue) {
|
223 |
val = ValueFactory.createValue(Date.parse(s));
|
224 |
cero = ValueFactory.createValue((Date) new Date());
|
225 |
}
|
226 |
} catch (NumberFormatException e) {
|
227 |
///JOptionPane.showMessageDialog(null, PluginServices...getText(this,"Formato de n?mero erroneo")+".");
|
228 |
return cero;
|
229 |
}
|
230 |
*/
|
231 |
return val;
|
232 |
} |
233 |
} |