svn-gvsig-desktop / tags / Anotaciones_Build_1 / extensions / extAnnotations / src / com / iver / cit / gvsig / project / documents / gui / Annotation_ConfigureLabel.java @ 11599
History | View | Annotate | Download (12.6 KB)
1 |
package com.iver.cit.gvsig.project.documents.gui; |
---|---|
2 |
|
3 |
import com.iver.andami.PluginServices; |
4 |
|
5 |
import com.iver.cit.gvsig.fmap.DriverException; |
6 |
import com.iver.cit.gvsig.fmap.layers.Annotation_Layer; |
7 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
8 |
|
9 |
import jwizardcomponent.JWizardComponents; |
10 |
import jwizardcomponent.JWizardPanel; |
11 |
|
12 |
import java.awt.Dimension; |
13 |
import java.awt.Rectangle; |
14 |
import java.awt.event.ItemEvent; |
15 |
import java.awt.event.ItemListener; |
16 |
|
17 |
import java.sql.Types; |
18 |
|
19 |
import java.util.ArrayList; |
20 |
import java.util.Collection; |
21 |
import java.util.HashMap; |
22 |
import java.util.Iterator; |
23 |
|
24 |
import javax.swing.JComboBox; |
25 |
import javax.swing.JLabel; |
26 |
|
27 |
|
28 |
/**
|
29 |
* Configure annotation mapping.
|
30 |
*
|
31 |
* @author Vicente Caballero Navarro
|
32 |
*/
|
33 |
public class Annotation_ConfigureLabel extends JWizardPanel { |
34 |
public static final String TEXT_FOR_DEFAULT_VALUE = "- Default -"; |
35 |
private static final Rectangle lblDescriptionPosition = new Rectangle(4, 4, |
36 |
355, 60); |
37 |
private static final Rectangle lblStep1Position = new Rectangle(4, 90, 15, |
38 |
15);
|
39 |
private static final Rectangle lblAnglePosition = new Rectangle(30, 90, |
40 |
355, 30); |
41 |
private static final Rectangle cmbAnglePosition = new Rectangle(30, 124, |
42 |
170, 18); |
43 |
private static final Rectangle lblStep2Position = new Rectangle(4, 150, 15, |
44 |
15);
|
45 |
private static final Rectangle lblColorPosition = new Rectangle(30, 150, |
46 |
355, 30); |
47 |
private static final Rectangle cmbColorPosition = new Rectangle(30, 184, |
48 |
170, 18); |
49 |
private static final Rectangle lblStep3Position = new Rectangle(4, 210, 15, |
50 |
15);
|
51 |
private static final Rectangle lblSizePosition = new Rectangle(30, 210, |
52 |
355, 30); |
53 |
private static final Rectangle cmbSizePosition = new Rectangle(30, 244, |
54 |
170, 18); |
55 |
private static final Rectangle lblSizeUnitsPosition = new Rectangle(204, |
56 |
244, 80, 15); |
57 |
private static final Rectangle cmbSizeUnitsPosition = new Rectangle(305, |
58 |
244, 80, 18); |
59 |
private static final Rectangle lblStep4Position = new Rectangle(4, 270, 15, |
60 |
15);
|
61 |
private static final Rectangle lblFontPosition = new Rectangle(30, 270, |
62 |
355, 30); |
63 |
private static final Rectangle cmbFontPosition = new Rectangle(30, 304, |
64 |
170, 18); |
65 |
private Annotation_Layer layer;
|
66 |
private HashMap fieldsNames = new HashMap(); |
67 |
private JLabel lblDescription; |
68 |
private JLabel lblAngle; |
69 |
private JLabel lblColor; |
70 |
private JLabel lblSize; |
71 |
|
72 |
private JLabel lblSizeUnits; |
73 |
private JLabel lblFont; |
74 |
private JLabel lblStep1; |
75 |
private JLabel lblStep2; |
76 |
private JLabel lblStep3; |
77 |
private JLabel lblStep4; |
78 |
private JComboBox cmbAngle = null; |
79 |
private JComboBox cmbColor = null; |
80 |
private JComboBox cmbSize = null; |
81 |
|
82 |
private JComboBox cmbSizeUnits = null; |
83 |
private JComboBox cmbFont = null; |
84 |
private EventsListener eventsListener = new EventsListener(); |
85 |
private SelectableDataSource sds;
|
86 |
|
87 |
public Annotation_ConfigureLabel(JWizardComponents arg0,
|
88 |
Annotation_Layer layer) { |
89 |
super(arg0);
|
90 |
this.layer = layer;
|
91 |
try {
|
92 |
if (layer.getRecordset()!=null) |
93 |
sds=layer.getRecordset(); |
94 |
} catch (DriverException e) {
|
95 |
e.printStackTrace(); |
96 |
} |
97 |
this.initialize();
|
98 |
} |
99 |
|
100 |
private void updateButtonsState() { |
101 |
try {
|
102 |
if (getWizardComponents().getCurrentIndex()==1){ |
103 |
setBackButtonEnabled(true);
|
104 |
setNextButtonEnabled(false);
|
105 |
setFinishButtonEnabled(checkIsOkPanelData()); |
106 |
} |
107 |
} catch (Exception e) { |
108 |
e.printStackTrace(); |
109 |
} |
110 |
} |
111 |
|
112 |
protected boolean checkIsOkPanelData() { |
113 |
// if (!((String)this.getCmbSize().getSelectedItem()).equals(Annotation_ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
|
114 |
// return (((String)this.getCmbSizeUnits().getSelectedItem()).trim().length() > 0);
|
115 |
// }
|
116 |
return true; |
117 |
} |
118 |
|
119 |
protected void initialize() { |
120 |
this.setLayout(null); |
121 |
this.setSize(new Dimension(358, 263)); |
122 |
this.addLabels();
|
123 |
|
124 |
this.add(getCmbAngle(), null); |
125 |
this.add(getCmbColor(), null); |
126 |
this.add(getCmbSize(), null); |
127 |
|
128 |
this.add(getCmbSizeUnits(),null); |
129 |
this.add(getCmbFont(), null); |
130 |
|
131 |
checkIsOkPanelData(); |
132 |
} |
133 |
|
134 |
protected void addLabels() { |
135 |
this.lblDescription = new JLabel(); |
136 |
this.lblStep1 = new JLabel(); |
137 |
this.lblAngle = new JLabel(); |
138 |
this.lblStep2 = new JLabel(); |
139 |
this.lblColor = new JLabel(); |
140 |
this.lblStep3 = new JLabel(); |
141 |
this.lblSize = new JLabel(); |
142 |
|
143 |
this.lblSizeUnits= new JLabel(); |
144 |
this.lblStep4 = new JLabel(); |
145 |
this.lblFont = new JLabel(); |
146 |
|
147 |
this.lblDescription.setText(PluginServices.getText(this, |
148 |
"descripcion_de_configuracion_capa_de_anotaciones"));
|
149 |
this.lblStep1.setText("1."); |
150 |
this.lblAngle.setText(PluginServices.getText(this, |
151 |
"seleccione_el_campo_angulo_de_la_capa_de_anotaciones"));
|
152 |
this.lblStep2.setText("2."); |
153 |
this.lblColor.setText(PluginServices.getText(this, |
154 |
"seleccione_el_campo_color_de_la_capa_de_anotaciones"));
|
155 |
this.lblStep3.setText("3."); |
156 |
this.lblSize.setText(PluginServices.getText(this, |
157 |
"seleccione_el_campo_tamano_de_la_capa_de_anotaciones"));
|
158 |
|
159 |
this.lblSizeUnits.setText(PluginServices.getText(this,"en_unidades")); |
160 |
this.lblStep4.setText("4."); |
161 |
this.lblFont.setText(PluginServices.getText(this, |
162 |
"seleccione_el_campo_fuente_de_la_capa_de_anotaciones"));
|
163 |
|
164 |
//TODO: Posicionar
|
165 |
this.lblDescription.setBounds(lblDescriptionPosition);
|
166 |
this.lblStep1.setBounds(lblStep1Position);
|
167 |
this.lblAngle.setBounds(lblAnglePosition);
|
168 |
this.lblStep2.setBounds(lblStep2Position);
|
169 |
this.lblColor.setBounds(lblColorPosition);
|
170 |
this.lblStep3.setBounds(lblStep3Position);
|
171 |
this.lblSize.setBounds(lblSizePosition);
|
172 |
|
173 |
this.lblSizeUnits.setBounds(lblSizeUnitsPosition);
|
174 |
this.lblStep4.setBounds(lblStep4Position);
|
175 |
this.lblFont.setBounds(lblFontPosition);
|
176 |
|
177 |
this.add(lblDescription, null); |
178 |
this.add(lblStep1, null); |
179 |
this.add(lblAngle, null); |
180 |
this.add(lblStep2, null); |
181 |
this.add(lblColor, null); |
182 |
this.add(lblStep3, null); |
183 |
this.add(lblSize, null); |
184 |
|
185 |
this.add(lblSizeUnits,null); |
186 |
this.add(lblStep4, null); |
187 |
this.add(lblFont, null); |
188 |
} |
189 |
|
190 |
private void fillFieldsNames(JComboBox cmb, int[] types) { |
191 |
cmb.addItem(Annotation_ConfigureLabel.TEXT_FOR_DEFAULT_VALUE); |
192 |
|
193 |
Collection names;
|
194 |
|
195 |
if (types == null) { |
196 |
String[] allNames = (String[]) this.fieldsNames.get("ALL"); |
197 |
|
198 |
if (allNames == null) { |
199 |
try {
|
200 |
SelectableDataSource dataSource = this.layer.getRecordset();
|
201 |
|
202 |
allNames = dataSource.getFieldNames(); |
203 |
this.fieldsNames.put("ALL", allNames); |
204 |
} catch (DriverException e) {
|
205 |
e.printStackTrace(); |
206 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
207 |
e.printStackTrace(); |
208 |
} |
209 |
} |
210 |
|
211 |
for (int i = 0; i < allNames.length; i++) { |
212 |
cmb.addItem(allNames[i]); |
213 |
} |
214 |
|
215 |
return;
|
216 |
} |
217 |
|
218 |
Integer typeKey;
|
219 |
|
220 |
for (int i = 0; i < types.length; i++) { |
221 |
typeKey = new Integer(types[i]); |
222 |
|
223 |
if (!this.fieldsNames.containsKey(typeKey)) { |
224 |
names = this.getFieldsFromType(types[i]);
|
225 |
this.fieldsNames.put(typeKey, names);
|
226 |
} else {
|
227 |
names = (Collection) this.fieldsNames.get(typeKey); |
228 |
} |
229 |
|
230 |
if (names != null) { |
231 |
Iterator name = names.iterator();
|
232 |
|
233 |
while (name.hasNext()) {
|
234 |
cmb.addItem(name.next()); |
235 |
} |
236 |
} |
237 |
} |
238 |
} |
239 |
|
240 |
private Collection getFieldsFromType(int type) { |
241 |
ArrayList result = new ArrayList(); |
242 |
|
243 |
try {
|
244 |
SelectableDataSource dataSource = this.layer.getRecordset();
|
245 |
|
246 |
for (int i = 0; i < dataSource.getFieldCount(); i++) { |
247 |
if (dataSource.getFieldType(i) == type) {
|
248 |
result.add(dataSource.getFieldName(i)); |
249 |
} |
250 |
} |
251 |
} catch (DriverException e) {
|
252 |
// TODO Auto-generated catch block
|
253 |
e.printStackTrace(); |
254 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
255 |
// TODO Auto-generated catch block
|
256 |
e.printStackTrace(); |
257 |
} |
258 |
|
259 |
if (result.size() == 0) { |
260 |
return null; |
261 |
} |
262 |
|
263 |
return result;
|
264 |
} |
265 |
|
266 |
private JComboBox getCmbAngle() { |
267 |
if (this.cmbAngle == null) { |
268 |
this.cmbAngle = new JComboBox(); |
269 |
this.cmbAngle.setEditable(false); |
270 |
this.cmbAngle.setBounds(cmbAnglePosition);
|
271 |
this.fillFieldsNames(this.cmbAngle, |
272 |
new int[] { Types.INTEGER, Types.DOUBLE }); |
273 |
this.cmbAngle.addItemListener(this.eventsListener); |
274 |
|
275 |
if (sds!=null && layer.getAnnotatonMapping()!=null){ |
276 |
int index=layer.getAnnotatonMapping().getColumnRotate();
|
277 |
setSelectedItem(index,cmbAngle); |
278 |
updateButtonsState(); |
279 |
} |
280 |
} |
281 |
|
282 |
return this.cmbAngle; |
283 |
} |
284 |
|
285 |
public String getAngleFieldName() { |
286 |
return (String) this.getCmbAngle().getSelectedItem(); |
287 |
} |
288 |
|
289 |
private JComboBox getCmbColor() { |
290 |
if (this.cmbColor == null) { |
291 |
this.cmbColor = new JComboBox(); |
292 |
this.cmbColor.setEditable(false); |
293 |
this.cmbColor.setBounds(cmbColorPosition);
|
294 |
this.fillFieldsNames(this.cmbColor, new int[] { Types.INTEGER }); |
295 |
this.cmbColor.addItemListener(this.eventsListener); |
296 |
if (sds!=null && layer.getAnnotatonMapping()!=null){ |
297 |
int index=layer.getAnnotatonMapping().getColumnColor();
|
298 |
setSelectedItem(index,cmbColor); |
299 |
} |
300 |
} |
301 |
|
302 |
return this.cmbColor; |
303 |
} |
304 |
private void setSelectedItem(int index,JComboBox cmb){ |
305 |
if (sds!=null){ |
306 |
String field=null; |
307 |
try {
|
308 |
field = sds.getFieldName(index); |
309 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
310 |
e.printStackTrace(); |
311 |
} |
312 |
cmb.setSelectedItem(field); |
313 |
} |
314 |
} |
315 |
public String getColorFieldName() { |
316 |
return (String) this.getCmbColor().getSelectedItem(); |
317 |
} |
318 |
|
319 |
private JComboBox getCmbSize() { |
320 |
if (this.cmbSize == null) { |
321 |
this.cmbSize = new JComboBox(); |
322 |
this.cmbSize.setEditable(false); |
323 |
this.cmbSize.setBounds(cmbSizePosition);
|
324 |
this.fillFieldsNames(this.cmbSize, |
325 |
new int[] { Types.INTEGER, Types.DOUBLE }); |
326 |
this.cmbSize.addItemListener(this.eventsListener); |
327 |
if (sds!=null && layer.getAnnotatonMapping()!=null){ |
328 |
int index=layer.getAnnotatonMapping().getColumnHeight();
|
329 |
setSelectedItem(index,cmbSize); |
330 |
} |
331 |
} |
332 |
|
333 |
return this.cmbSize; |
334 |
} |
335 |
|
336 |
public String getSizeFieldName() { |
337 |
return (String) this.getCmbSize().getSelectedItem(); |
338 |
} |
339 |
|
340 |
private JComboBox getCmbSizeUnits() { |
341 |
if (this.cmbSizeUnits == null) { |
342 |
this.cmbSizeUnits= new JComboBox(); |
343 |
this.cmbSizeUnits.setEditable(false); |
344 |
this.cmbSizeUnits.setBounds(cmbSizeUnitsPosition);
|
345 |
this.cmbSizeUnits.addItem(PluginServices.getText(this,"pixels")); |
346 |
this.cmbSizeUnits.addItem(PluginServices.getText(this,"metros")); |
347 |
this.cmbSizeUnits.addItemListener(this.eventsListener); |
348 |
} |
349 |
return this.cmbSizeUnits; |
350 |
} |
351 |
public boolean sizeUnitsInPixels() { |
352 |
return (this.getCmbSizeUnits().getSelectedIndex() == 0); |
353 |
} |
354 |
|
355 |
private JComboBox getCmbFont() { |
356 |
if (this.cmbFont == null) { |
357 |
this.cmbFont = new JComboBox(); |
358 |
this.cmbFont.setEditable(false); |
359 |
this.cmbFont.setBounds(cmbFontPosition);
|
360 |
this.fillFieldsNames(this.cmbFont, |
361 |
new int[] { Types.VARCHAR, Types.LONGVARCHAR }); |
362 |
this.cmbFont.addItemListener(this.eventsListener); |
363 |
if (sds!=null && layer.getAnnotatonMapping()!=null){ |
364 |
int index=layer.getAnnotatonMapping().getColumnTypeFont();
|
365 |
setSelectedItem(index,cmbFont); |
366 |
} |
367 |
} |
368 |
|
369 |
return this.cmbFont; |
370 |
} |
371 |
|
372 |
public String getFontFieldName() { |
373 |
return (String) this.getCmbFont().getSelectedItem(); |
374 |
} |
375 |
|
376 |
private class EventsListener implements ItemListener { |
377 |
public void itemStateChanged(ItemEvent e) { |
378 |
updateButtonsState(); |
379 |
} |
380 |
} |
381 |
} |