Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / Panels / TextFieldEdit.java @ 4258

History | View | Annotate | Download (4.15 KB)

1
package com.iver.cit.gvsig.gui.Panels;
2

    
3
import java.awt.Dimension;
4
import java.awt.Point;
5
import java.awt.event.FocusEvent;
6
import java.awt.event.FocusListener;
7
import java.awt.event.KeyEvent;
8
import java.awt.event.KeyListener;
9
import java.io.IOException;
10
import java.text.ParseException;
11

    
12
import javax.swing.BorderFactory;
13
import javax.swing.FocusManager;
14
import javax.swing.JComponent;
15
import javax.swing.JPopupMenu;
16
import javax.swing.JTextField;
17

    
18
import com.hardcode.driverManager.DriverLoadException;
19
import com.hardcode.gdbms.engine.data.driver.DriverException;
20
import com.hardcode.gdbms.engine.instruction.SemanticException;
21
import com.hardcode.gdbms.engine.values.Value;
22
import com.hardcode.gdbms.engine.values.ValueFactory;
23
import com.iver.andami.PluginServices;
24
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
25
import com.iver.cit.gvsig.fmap.core.DefaultRow;
26
import com.iver.cit.gvsig.fmap.core.IFeature;
27
import com.iver.cit.gvsig.fmap.core.IGeometry;
28
import com.iver.cit.gvsig.fmap.core.IRow;
29
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
30
import com.iver.cit.gvsig.fmap.edition.IRowEdited;
31
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
32
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation;
33
import com.iver.cit.gvsig.gui.View;
34

    
35

    
36
/**
37
 * DOCUMENT ME!
38
 *
39
 * @author Vicente Caballero Navarro
40
 */
41
public class TextFieldEdit extends JPopupMenu implements KeyListener {
42
    private JTextField txt = new JTextField();
43
    private FLyrAnnotation lyr;
44
    /**
45
     * This is the default constructor
46
     */
47
    public TextFieldEdit(FLyrAnnotation lyr) {
48
        super();
49
        this.lyr=lyr;
50
        initialize();
51
    }
52

    
53
    /**
54
     * This method initializes this
55
     */
56
    private void initialize() {
57
        this.setSize(100, 20);
58
        txt.setPreferredSize(new Dimension(100, 20));
59
        txt.addActionListener(new java.awt.event.ActionListener() {
60
                public void actionPerformed(java.awt.event.ActionEvent e) {
61
                         try {
62
                                        VectorialEditableAdapter vea=(VectorialEditableAdapter)lyr.getSource();
63
                                        int index=lyr.getInEdition();
64
                                        IRowEdited row = vea.getRow(index); //.getAttribute(columnIndex);
65
                                Value[] values = row.getAttributes();
66
                                int type=vea.getRecordset().getFieldType(lyr.getMapping()[0]);
67
                                values[lyr.getMapping()[0]] = ValueFactory.createValueByType(txt.getText(),type);
68

    
69
                                IRow newRow = null;
70

    
71
                                if (row.getLinkedRow() instanceof IFeature) {
72
                                    IGeometry geometry = ((DefaultFeature) row.getLinkedRow()).getGeometry();
73
                                    newRow = new DefaultFeature(geometry, values);
74
                                } else {
75
                                    newRow = new DefaultRow(values);
76
                                }
77

    
78

    
79
                                                vea.modifyRow(index, newRow,"Editar valor de texto");
80
                                        } catch (IOException e1) {
81
                                                e1.printStackTrace();
82
                                        } catch (DriverIOException e1) {
83
                                                e1.printStackTrace();
84
                                        } catch (DriverLoadException e1) {
85
                                                e1.printStackTrace();
86
                                        } catch (DriverException e1) {
87
                                                e1.printStackTrace();
88
                                        }  catch (ParseException e1) {
89
                                                        e1.printStackTrace();
90
                                                }
91
                                        View view=(View)PluginServices.getMDIManager().getActiveView();
92
                                        TextFieldEdit.this.show(false);
93
                                        view.getMapControl().drawMap(true);
94

    
95
                                        PluginServices.getMainFrame().enableControls();
96
                }
97
        });
98
        this.add(txt);
99
        this.setBorderPainted(false);
100
        this.setBorder(BorderFactory.createEmptyBorder());
101
    }
102

    
103
    /**
104
     * DOCUMENT ME!
105
     *
106
     * @param p DOCUMENT ME!
107
     * @param component DOCUMENT ME!
108
     */
109
    public void show(Point p, JComponent component) {
110
        this.show(component, p.x, p.y);
111
        FocusManager fm = FocusManager.getCurrentManager();
112
        fm.focusPreviousComponent(txt);
113
    }
114

    
115
        public void keyPressed(KeyEvent arg0) {
116
                // TODO Auto-generated method stub
117

    
118
        }
119

    
120
        public void keyReleased(KeyEvent arg0) {
121
                 FocusManager fm = FocusManager.getCurrentManager();
122
             fm.focusPreviousComponent(txt);
123
        }
124

    
125
        public void keyTyped(KeyEvent arg0) {
126
                // TODO Auto-generated method stub
127

    
128
        }
129

    
130
}