Revision 38607 branches/v2_0_0_prep/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/swing/dynfield/GeometryDynFieldComponent.java
GeometryDynFieldComponent.java | ||
---|---|---|
22 | 22 |
*/ |
23 | 23 |
package org.gvsig.fmap.mapcontrol.swing.dynfield; |
24 | 24 |
|
25 |
import java.awt.event.ActionEvent; |
|
26 |
import java.awt.event.ActionListener; |
|
27 |
|
|
28 |
import javax.swing.BoxLayout; |
|
29 |
import javax.swing.JCheckBox; |
|
25 | 30 |
import javax.swing.JComponent; |
26 |
import javax.swing.JLabel; |
|
31 |
import javax.swing.JPanel; |
|
32 |
import javax.swing.JTextField; |
|
27 | 33 |
|
34 |
import org.slf4j.Logger; |
|
35 |
import org.slf4j.LoggerFactory; |
|
36 |
|
|
28 | 37 |
import org.gvsig.fmap.geom.Geometry; |
29 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
30 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
|
31 | 38 |
import org.gvsig.i18n.Messages; |
32 | 39 |
import org.gvsig.tools.dynobject.DynField; |
33 | 40 |
import org.gvsig.tools.service.ServiceException; |
... | ... | |
45 | 52 |
* |
46 | 53 |
*/ |
47 | 54 |
public class GeometryDynFieldComponent extends |
48 |
AbstractJDynFieldComponent { |
|
55 |
AbstractJDynFieldComponent implements ActionListener {
|
|
49 | 56 |
|
50 |
private JLabel label = null; |
|
57 |
private static Logger logger = |
|
58 |
LoggerFactory.getLogger(GeometryDynFieldComponent.class); |
|
59 |
|
|
60 |
private JCheckBox wktCheckBox = null; |
|
61 |
private JTextField txtField = null; |
|
62 |
private JPanel panel = null; |
|
51 | 63 |
|
52 | 64 |
public GeometryDynFieldComponent( |
53 | 65 |
DynField definition, |
... | ... | |
69 | 81 |
} |
70 | 82 |
|
71 | 83 |
public JComponent asJComponent() { |
72 |
return label;
|
|
84 |
return panel;
|
|
73 | 85 |
} |
74 | 86 |
|
75 | 87 |
public Object getValue() { |
... | ... | |
84 | 96 |
|
85 | 97 |
protected void initData() { |
86 | 98 |
} |
87 |
|
|
88 |
protected void initUI() {
|
|
99 |
|
|
100 |
private String getValueText(boolean wkt) {
|
|
89 | 101 |
Object val = this.getFieldValue(); |
102 |
String txt = null; |
|
103 |
|
|
90 | 104 |
if (val == null || (!(val instanceof Geometry))) { |
91 |
label = new JLabel("[" + Messages.getText("_Null") + "]");
|
|
105 |
txt = "[" + Messages.getText("_Invalid_value") + "]";
|
|
92 | 106 |
} else { |
93 | 107 |
Geometry geom = (Geometry) val; |
94 |
label = new JLabel(geom.getGeometryType().getName()); |
|
108 |
if (wkt) { |
|
109 |
try { |
|
110 |
txt = geom.convertToWKT(); |
|
111 |
} catch (Exception e) { |
|
112 |
logger.info("Error while getting WKT: " + e.getMessage(), e); |
|
113 |
txt = "[" + Messages.getText("_Unable_to_show_value") + "]"; |
|
114 |
} |
|
115 |
} else { |
|
116 |
txt = geom.getGeometryType().getName(); |
|
117 |
} |
|
95 | 118 |
} |
119 |
return txt; |
|
96 | 120 |
} |
97 | 121 |
|
122 |
protected void initUI() { |
|
123 |
|
|
124 |
wktCheckBox = |
|
125 |
new JCheckBox(Messages.getText("_Show_as_text") + " "); |
|
126 |
wktCheckBox.setSelected(false); |
|
127 |
wktCheckBox.addActionListener(this); |
|
128 |
txtField = new JTextField(); |
|
129 |
// txtField.setEditable(false); |
|
130 |
txtField.setText(this.getValueText(wktCheckBox.isSelected())); |
|
131 |
txtField.setHorizontalAlignment(JTextField.LEFT); |
|
132 |
|
|
133 |
panel = new JPanel(); // new GridBagLayout()); |
|
134 |
panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS)); |
|
135 |
|
|
136 |
/* |
|
137 |
GridBagConstraints constr = new GridBagConstraints(); |
|
138 |
constr.insets = new Insets(3, 3, 3, 3); |
|
139 |
constr.gridx = 0; |
|
140 |
constr.gridy = 0; |
|
141 |
constr.fill = GridBagConstraints.NONE; |
|
142 |
*/ |
|
143 |
|
|
144 |
panel.add(wktCheckBox); // , constr); |
|
145 |
/* |
|
146 |
constr.gridx = 1; |
|
147 |
constr.fill = GridBagConstraints.HORIZONTAL; |
|
148 |
*/ |
|
149 |
panel.add(txtField); // , constr); |
|
150 |
} |
|
151 |
|
|
98 | 152 |
protected void setNonNullValue(Object value) { |
99 | 153 |
} |
100 | 154 |
|
... | ... | |
104 | 158 |
protected void setReadOnly() { |
105 | 159 |
} |
106 | 160 |
|
161 |
|
|
162 |
public void actionPerformed(ActionEvent e) { |
|
163 |
// update txt field when check box state changes |
|
164 |
if (txtField != null && wktCheckBox != null) { |
|
165 |
txtField.setText(this.getValueText(wktCheckBox.isSelected())); |
|
166 |
txtField.setHorizontalAlignment(JTextField.LEFT); |
|
167 |
} |
|
168 |
} |
|
169 |
|
|
107 | 170 |
} |
Also available in: Unified diff