Statistics
| Revision:

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

History | View | Annotate | Download (4.02 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.KeyEvent;
6
import java.awt.event.KeyListener;
7
import java.io.IOException;
8
import java.text.ParseException;
9

    
10
import javax.swing.BorderFactory;
11
import javax.swing.FocusManager;
12
import javax.swing.JComponent;
13
import javax.swing.JPopupMenu;
14
import javax.swing.JTextField;
15

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

    
32

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

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

    
66
                                IRow newRow = null;
67

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

    
75

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

    
92
                                        PluginServices.getMainFrame().enableControls();
93
                }
94
        });
95
        this.add(txt);
96
        this.setBorderPainted(false);
97
        this.setBorder(BorderFactory.createEmptyBorder());
98
    }
99

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

    
112
        public void keyPressed(KeyEvent arg0) {
113
                // TODO Auto-generated method stub
114

    
115
        }
116

    
117
        public void keyReleased(KeyEvent arg0) {
118
                 FocusManager fm = FocusManager.getCurrentManager();
119
             fm.focusPreviousComponent(txt);
120
        }
121

    
122
        public void keyTyped(KeyEvent arg0) {
123
                // TODO Auto-generated method stub
124

    
125
        }
126

    
127
}