root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / Panels / TextFieldEdit.java @ 5115
History | View | Annotate | Download (4.73 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.IEditableSource; |
29 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
30 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
31 |
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation; |
32 |
import com.iver.cit.gvsig.gui.View; |
33 |
|
34 |
|
35 |
/**
|
36 |
* DOCUMENT ME!
|
37 |
*
|
38 |
* @author Vicente Caballero Navarro
|
39 |
*/
|
40 |
public class TextFieldEdit extends JPopupMenu implements KeyListener { |
41 |
private JTextField txt = new JTextField(); |
42 |
private FLyrAnnotation lyr;
|
43 |
/**
|
44 |
* This is the default constructor
|
45 |
*/
|
46 |
public TextFieldEdit(FLyrAnnotation lyr) {
|
47 |
super();
|
48 |
this.lyr=lyr;
|
49 |
initialize(); |
50 |
} |
51 |
|
52 |
/**
|
53 |
* This method initializes this
|
54 |
*/
|
55 |
private void initialize() { |
56 |
this.setSize(100, 20); |
57 |
txt.setPreferredSize(new Dimension(100, 20)); |
58 |
txt.addActionListener(new java.awt.event.ActionListener() {
|
59 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
60 |
try {
|
61 |
VectorialEditableAdapter vea=(VectorialEditableAdapter)lyr.getSource(); |
62 |
int index=lyr.getInEdition();
|
63 |
IRowEdited row = vea.getRow(index); //.getAttribute(columnIndex);
|
64 |
Value[] values = row.getAttributes();
|
65 |
int columnText=lyr.getMapping().getColumnText();
|
66 |
int type=vea.getRecordset().getFieldType(columnText);
|
67 |
values[columnText] = 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", IEditableSource.GRAPHIC);
|
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 |
} catch (NumberFormatException e1) { |
91 |
NotificationManager.addError("no_es_de_tipo_numerico",e1);
|
92 |
} |
93 |
View view=(View)PluginServices.getMDIManager().getActiveView(); |
94 |
TextFieldEdit.this.show(false);
|
95 |
view.getMapControl().drawMap(true);
|
96 |
|
97 |
PluginServices.getMainFrame().enableControls(); |
98 |
} |
99 |
}); |
100 |
this.add(txt);
|
101 |
this.setBorderPainted(false); |
102 |
this.setBorder(BorderFactory.createEmptyBorder()); |
103 |
} |
104 |
|
105 |
/**
|
106 |
* DOCUMENT ME!
|
107 |
*
|
108 |
* @param p DOCUMENT ME!
|
109 |
* @param component DOCUMENT ME!
|
110 |
*/
|
111 |
public void show(Point2D p, JComponent component) { |
112 |
|
113 |
VectorialEditableAdapter vea=(VectorialEditableAdapter)lyr.getSource(); |
114 |
int index=lyr.getInEdition();
|
115 |
Value value=null;
|
116 |
try {
|
117 |
int columnText=lyr.getMapping().getColumnText();
|
118 |
value = vea.getRecordset().getFieldValue(index,columnText); |
119 |
txt.setText(value.toString()); |
120 |
} catch (DriverLoadException e) {
|
121 |
e.printStackTrace(); |
122 |
} catch (DriverException e) {
|
123 |
e.printStackTrace(); |
124 |
} |
125 |
|
126 |
this.show(component, (int)p.getX(), (int)p.getY()-20); |
127 |
FocusManager fm = FocusManager.getCurrentManager(); |
128 |
fm.focusPreviousComponent(txt); |
129 |
} |
130 |
|
131 |
public void keyPressed(KeyEvent arg0) { |
132 |
// TODO Auto-generated method stub
|
133 |
|
134 |
} |
135 |
|
136 |
public void keyReleased(KeyEvent arg0) { |
137 |
FocusManager fm = FocusManager.getCurrentManager(); |
138 |
fm.focusPreviousComponent(txt); |
139 |
} |
140 |
|
141 |
public void keyTyped(KeyEvent arg0) { |
142 |
// TODO Auto-generated method stub
|
143 |
|
144 |
} |
145 |
|
146 |
} |