svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / panels / TextFieldEdit.java @ 10626
History | View | Annotate | Download (5.05 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.text.ParseException; |
8 |
|
9 |
import javax.swing.BorderFactory; |
10 |
import javax.swing.FocusManager; |
11 |
import javax.swing.JComponent; |
12 |
import javax.swing.JPopupMenu; |
13 |
import javax.swing.JTextField; |
14 |
|
15 |
import com.hardcode.driverManager.DriverLoadException; |
16 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
17 |
import com.hardcode.gdbms.engine.values.Value; |
18 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
19 |
import com.iver.andami.PluginServices; |
20 |
import com.iver.andami.messages.NotificationManager; |
21 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
22 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileWriteException; |
23 |
import com.iver.cit.gvsig.exceptions.validate.ValidateRowException; |
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.edition.EditionEvent; |
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.project.documents.view.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 (DriverLoadException e1) {
|
82 |
e1.printStackTrace(); |
83 |
} catch (ReadDriverException e1) {
|
84 |
e1.printStackTrace(); |
85 |
} catch (ParseException e1) { |
86 |
e1.printStackTrace(); |
87 |
} catch (NumberFormatException e1) { |
88 |
NotificationManager.addError("no_es_de_tipo_numerico",e1);
|
89 |
} catch (ValidateRowException e1) {
|
90 |
e1.printStackTrace(); |
91 |
} catch (ExpansionFileWriteException e1) {
|
92 |
e1.printStackTrace(); |
93 |
} catch (ExpansionFileReadException e1) {
|
94 |
e1.printStackTrace(); |
95 |
} |
96 |
View view=(View)PluginServices.getMDIManager().getActiveWindow(); |
97 |
TextFieldEdit.this.show(false);
|
98 |
// view.getMapControl().drawMap(true);
|
99 |
lyr.setDirty(true);
|
100 |
view.getMapControl().rePaintDirtyLayers(); |
101 |
|
102 |
PluginServices.getMainFrame().enableControls(); |
103 |
} |
104 |
}); |
105 |
this.add(txt);
|
106 |
this.setBorderPainted(false); |
107 |
this.setBorder(BorderFactory.createEmptyBorder()); |
108 |
} |
109 |
|
110 |
/**
|
111 |
* DOCUMENT ME!
|
112 |
*
|
113 |
* @param p DOCUMENT ME!
|
114 |
* @param component DOCUMENT ME!
|
115 |
*/
|
116 |
public void show(Point2D p, JComponent component) { |
117 |
|
118 |
VectorialEditableAdapter vea=(VectorialEditableAdapter)lyr.getSource(); |
119 |
int index=lyr.getInEdition();
|
120 |
Value value=null;
|
121 |
try {
|
122 |
int columnText=lyr.getMapping().getColumnText();
|
123 |
value = vea.getRecordset().getFieldValue(index,columnText); |
124 |
txt.setText(value.toString()); |
125 |
} catch (DriverLoadException e) {
|
126 |
e.printStackTrace(); |
127 |
} catch (ReadDriverException e) {
|
128 |
e.printStackTrace(); |
129 |
} |
130 |
|
131 |
this.show(component, (int)p.getX(), (int)p.getY()-20); |
132 |
FocusManager fm = FocusManager.getCurrentManager(); |
133 |
fm.focusPreviousComponent(txt); |
134 |
} |
135 |
|
136 |
public void keyPressed(KeyEvent arg0) { |
137 |
// TODO Auto-generated method stub
|
138 |
|
139 |
} |
140 |
|
141 |
public void keyReleased(KeyEvent arg0) { |
142 |
FocusManager fm = FocusManager.getCurrentManager(); |
143 |
fm.focusPreviousComponent(txt); |
144 |
} |
145 |
|
146 |
public void keyTyped(KeyEvent arg0) { |
147 |
// TODO Auto-generated method stub
|
148 |
|
149 |
} |
150 |
|
151 |
} |