root / branches / gvSIG_03_SLD / applications / appgvSIG / src / com / iver / cit / gvsig / gui / thememanager / legendmanager / panels / edition / FValueCellEditor.java @ 2076
History | View | Annotate | Download (4.07 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.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 |
|
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 |
import com.hardcode.gdbms.engine.values.BooleanValue; |
54 |
import com.hardcode.gdbms.engine.values.DateValue; |
55 |
import com.hardcode.gdbms.engine.values.DoubleValue; |
56 |
import com.hardcode.gdbms.engine.values.FloatValue; |
57 |
import com.hardcode.gdbms.engine.values.IntValue; |
58 |
import com.hardcode.gdbms.engine.values.LongValue; |
59 |
import com.hardcode.gdbms.engine.values.ShortValue; |
60 |
import com.hardcode.gdbms.engine.values.StringValue; |
61 |
import com.hardcode.gdbms.engine.values.Value; |
62 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
63 |
import com.iver.andami.PluginServices; |
64 |
|
65 |
|
66 |
/**
|
67 |
* Cell Editor sobre los valores ?nicos.
|
68 |
*
|
69 |
* @author Vicente Caballero Navarro
|
70 |
*/
|
71 |
public class FValueCellEditor extends AbstractCellEditor |
72 |
implements TableCellEditor, KeyListener { |
73 |
protected static final String EDIT = "edit"; |
74 |
private Value value;
|
75 |
private JTextField button; |
76 |
|
77 |
/**
|
78 |
* Crea un nuevo FLabelCellEditor.
|
79 |
*/
|
80 |
public FValueCellEditor() {
|
81 |
button = new JTextField(); |
82 |
button.setActionCommand(EDIT); |
83 |
button.addKeyListener(this);
|
84 |
} |
85 |
|
86 |
//Implement the one CellEditor method that AbstractCellEditor doesn't.
|
87 |
public Object getCellEditorValue() { |
88 |
return value;
|
89 |
} |
90 |
|
91 |
//Implement the one method defined by TableCellEditor.
|
92 |
public Component getTableCellEditorComponent(JTable table, Object value, |
93 |
boolean isSelected, int row, int column) { |
94 |
System.out.println(value.toString());
|
95 |
this.value = (Value)value;
|
96 |
button.setText(value.toString()); |
97 |
return button;
|
98 |
} |
99 |
|
100 |
public void keyPressed(KeyEvent e) { |
101 |
} |
102 |
public void keyReleased(KeyEvent e) { |
103 |
value = getValue(value,button.getText()); |
104 |
} |
105 |
public void keyTyped(KeyEvent e) { |
106 |
} |
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 |
return val;
|
131 |
} |
132 |
} |