root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / panels / TextFieldEdit.java @ 6117
History | View | Annotate | Download (4.86 KB)
1 |
package com.iver.cit.gvsig.gui.panels; |
---|---|
2 |
|
3 |
import java.awt.Dimension; |
4 |
import java.awt.event.KeyEvent; |
5 |
import java.awt.event.KeyListener; |
6 |
import java.awt.geom.Point2D; |
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.andami.messages.NotificationManager; |
22 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
23 |
import com.iver.cit.gvsig.fmap.core.DefaultRow; |
24 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
25 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
26 |
import com.iver.cit.gvsig.fmap.core.IRow; |
27 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
28 |
import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
29 |
import com.iver.cit.gvsig.fmap.edition.IEditableSource; |
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 columnText=lyr.getMapping().getColumnText();
|
67 |
int type=vea.getRecordset().getFieldType(columnText);
|
68 |
values[columnText] = ValueFactory.createValueByType(txt.getText(),type); |
69 |
|
70 |
IRow newRow = null;
|
71 |
|
72 |
if (row.getLinkedRow() instanceof IFeature) { |
73 |
IGeometry geometry = ((DefaultFeature) row.getLinkedRow()).getGeometry(); |
74 |
newRow = new DefaultFeature(geometry, values);
|
75 |
} else {
|
76 |
newRow = new DefaultRow(values);
|
77 |
} |
78 |
|
79 |
|
80 |
vea.modifyRow(index, newRow,"Editar valor de texto", EditionEvent.GRAPHIC);
|
81 |
} catch (IOException e1) { |
82 |
e1.printStackTrace(); |
83 |
} catch (DriverIOException e1) {
|
84 |
e1.printStackTrace(); |
85 |
} catch (DriverLoadException e1) {
|
86 |
e1.printStackTrace(); |
87 |
} catch (DriverException e1) {
|
88 |
e1.printStackTrace(); |
89 |
} catch (ParseException e1) { |
90 |
e1.printStackTrace(); |
91 |
} catch (NumberFormatException e1) { |
92 |
NotificationManager.addError("no_es_de_tipo_numerico",e1);
|
93 |
} |
94 |
View view=(View)PluginServices.getMDIManager().getActiveView(); |
95 |
TextFieldEdit.this.show(false);
|
96 |
// view.getMapControl().drawMap(true);
|
97 |
lyr.setDirty(true);
|
98 |
view.getMapControl().rePaintDirtyLayers(); |
99 |
|
100 |
PluginServices.getMainFrame().enableControls(); |
101 |
} |
102 |
}); |
103 |
this.add(txt);
|
104 |
this.setBorderPainted(false); |
105 |
this.setBorder(BorderFactory.createEmptyBorder()); |
106 |
} |
107 |
|
108 |
/**
|
109 |
* DOCUMENT ME!
|
110 |
*
|
111 |
* @param p DOCUMENT ME!
|
112 |
* @param component DOCUMENT ME!
|
113 |
*/
|
114 |
public void show(Point2D p, JComponent component) { |
115 |
|
116 |
VectorialEditableAdapter vea=(VectorialEditableAdapter)lyr.getSource(); |
117 |
int index=lyr.getInEdition();
|
118 |
Value value=null;
|
119 |
try {
|
120 |
int columnText=lyr.getMapping().getColumnText();
|
121 |
value = vea.getRecordset().getFieldValue(index,columnText); |
122 |
txt.setText(value.toString()); |
123 |
} catch (DriverLoadException e) {
|
124 |
e.printStackTrace(); |
125 |
} catch (DriverException e) {
|
126 |
e.printStackTrace(); |
127 |
} |
128 |
|
129 |
this.show(component, (int)p.getX(), (int)p.getY()-20); |
130 |
FocusManager fm = FocusManager.getCurrentManager(); |
131 |
fm.focusPreviousComponent(txt); |
132 |
} |
133 |
|
134 |
public void keyPressed(KeyEvent arg0) { |
135 |
// TODO Auto-generated method stub
|
136 |
|
137 |
} |
138 |
|
139 |
public void keyReleased(KeyEvent arg0) { |
140 |
FocusManager fm = FocusManager.getCurrentManager(); |
141 |
fm.focusPreviousComponent(txt); |
142 |
} |
143 |
|
144 |
public void keyTyped(KeyEvent arg0) { |
145 |
// TODO Auto-generated method stub
|
146 |
|
147 |
} |
148 |
|
149 |
} |