Statistics
| Revision:

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

History | View | Annotate | Download (4.83 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

    
43
import com.hardcode.gdbms.engine.values.BooleanValue;
44
import com.hardcode.gdbms.engine.values.DateValue;
45
import com.hardcode.gdbms.engine.values.DoubleValue;
46
import com.hardcode.gdbms.engine.values.FloatValue;
47
import com.hardcode.gdbms.engine.values.IntValue;
48
import com.hardcode.gdbms.engine.values.LongValue;
49
import com.hardcode.gdbms.engine.values.ShortValue;
50
import com.hardcode.gdbms.engine.values.StringValue;
51
import com.hardcode.gdbms.engine.values.Value;
52
import com.hardcode.gdbms.engine.values.ValueFactory;
53

    
54
import java.awt.Component;
55
import java.awt.event.KeyEvent;
56
import java.awt.event.KeyListener;
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
/**
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

    
98
                return button;
99
        }
100

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

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

    
122
        /**
123
         * DOCUMENT ME!
124
         *
125
         * @param e DOCUMENT ME!
126
         */
127
        public void keyTyped(KeyEvent e) {
128
        }
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());
167
                        }
168
                } catch (NumberFormatException e) {
169
                        ///JOptionPane.showMessageDialog(null, PluginServices.getText(this,"Formato de n?mero erroneo")+".");
170
                        return cero;
171
                }
172

    
173
                return val;
174
        }
175
}