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