Revision 4258 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/Panels/TextFieldEdit.java

View differences:

TextFieldEdit.java
7 7
import java.awt.event.KeyEvent;
8 8
import java.awt.event.KeyListener;
9 9
import java.io.IOException;
10
import java.text.ParseException;
10 11

  
11 12
import javax.swing.BorderFactory;
12 13
import javax.swing.FocusManager;
......
19 20
import com.hardcode.gdbms.engine.instruction.SemanticException;
20 21
import com.hardcode.gdbms.engine.values.Value;
21 22
import com.hardcode.gdbms.engine.values.ValueFactory;
23
import com.iver.andami.PluginServices;
22 24
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
23 25
import com.iver.cit.gvsig.fmap.core.DefaultRow;
24 26
import com.iver.cit.gvsig.fmap.core.IFeature;
......
28 30
import com.iver.cit.gvsig.fmap.edition.IRowEdited;
29 31
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
30 32
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation;
33
import com.iver.cit.gvsig.gui.View;
31 34

  
32 35

  
33 36
/**
......
35 38
 *
36 39
 * @author Vicente Caballero Navarro
37 40
 */
38
public class TextFieldEdit extends JPopupMenu implements KeyListener,FocusListener {
41
public class TextFieldEdit extends JPopupMenu implements KeyListener {
39 42
    private JTextField txt = new JTextField();
40 43
    private FLyrAnnotation lyr;
41 44
    /**
......
53 56
    private void initialize() {
54 57
        this.setSize(100, 20);
55 58
        txt.setPreferredSize(new Dimension(100, 20));
56
        txt.addKeyListener(this);
57
        this.addFocusListener(this);
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
        });
58 98
        this.add(txt);
59 99
        this.setBorderPainted(false);
60 100
        this.setBorder(BorderFactory.createEmptyBorder());
......
67 107
     * @param component DOCUMENT ME!
68 108
     */
69 109
    public void show(Point p, JComponent component) {
70
        this.show(component, p.x + 100, p.y);
71

  
110
        this.show(component, p.x, p.y);
72 111
        FocusManager fm = FocusManager.getCurrentManager();
73 112
        fm.focusPreviousComponent(txt);
74 113
    }
......
79 118
	}
80 119

  
81 120
	public void keyReleased(KeyEvent arg0) {
82
		// TODO Auto-generated method stub
83

  
121
		 FocusManager fm = FocusManager.getCurrentManager();
122
	     fm.focusPreviousComponent(txt);
84 123
	}
85 124

  
86 125
	public void keyTyped(KeyEvent arg0) {
......
88 127

  
89 128
	}
90 129

  
91
	public void focusGained(FocusEvent arg0) {
92
		// TODO Auto-generated method stub
93

  
94
	}
95

  
96
	public void focusLost(FocusEvent arg0) {
97
		 try {
98
		VectorialEditableAdapter vea=(VectorialEditableAdapter)lyr.getSource();
99
		int index=lyr.getInEdition();
100
		IRowEdited row = vea.getRow(index); //.getAttribute(columnIndex);
101
        Value[] values = row.getAttributes();
102
        int type=vea.getRecordset().getFieldType(lyr.getMapping()[0]);
103
        values[lyr.getMapping()[0]] = ValueFactory.createValue(txt.getText(),type);
104

  
105
        IRow newRow = null;
106

  
107
        if (row.getLinkedRow() instanceof IFeature) {
108
            IGeometry geometry = ((DefaultFeature) row.getLinkedRow()).getGeometry();
109
            newRow = new DefaultFeature(geometry, values);
110
        } else {
111
            newRow = new DefaultRow(values);
112
        }
113

  
114

  
115
			vea.modifyRow(index, newRow,"Editar valor de texto");
116
		} catch (IOException e) {
117
			// TODO Auto-generated catch block
118
			e.printStackTrace();
119
		} catch (DriverIOException e) {
120
			// TODO Auto-generated catch block
121
			e.printStackTrace();
122
		} catch (DriverLoadException e) {
123
			// TODO Auto-generated catch block
124
			e.printStackTrace();
125
		} catch (DriverException e) {
126
			// TODO Auto-generated catch block
127
			e.printStackTrace();
128
		} catch (SemanticException e) {
129
			// TODO Auto-generated catch block
130
			e.printStackTrace();
131
		}
132

  
133
	}
134 130
}

Also available in: Unified diff