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