01: /*
02: * Created on 14 août 2005
03: *
04: * Olivier BEDEL
05: * Bassin Versant du Jaudy-Guindy-Bizien,
06: * Laboratoire RESO UMR ESO 6590 CNRS, Université de Rennes 2
07: *
08: */
09:
10: package org.openjump.sigle.utilities.gui;
11:
12: import java.util.Iterator;
13: import java.util.LinkedList;
14: import java.util.List;
15:
16: import javax.swing.JComboBox;
17: import javax.swing.JLabel;
18:
19: import com.vividsolutions.jump.feature.AttributeType;
20: import com.vividsolutions.jump.feature.Feature;
21: import com.vividsolutions.jump.workbench.model.Layer;
22:
23: /**
24: * @author Olivier
25: * Classe utilitaire pour selectionner des champs à partir d'une couche
26: */
27:
28: public class DialogUtil {
29:
30: // renvoie la liste des champs de la table attributaire d'une couche
31: public static List getFieldsFromLayer(Layer l) {
32: List fields = new LinkedList();
33: for (int i = 0; i < l.getFeatureCollectionWrapper()
34: .getFeatureSchema().getAttributeCount(); i++) {
35: fields.add(l.getFeatureCollectionWrapper()
36: .getFeatureSchema().getAttributeName(i));
37: }
38: return fields;
39: }
40:
41: // met à jour la combo cb avec la liste des champs de la couche l
42: public static void updateFieldComboBox(JComboBox cb, Layer l) {
43: cb.removeAllItems();
44: for (Iterator i = getFieldsFromLayer(l).iterator(); i.hasNext();)
45: cb.addItem(i.next());
46: }
47:
48: // renvoie la liste des champs de la table attributaire d'une couche sans le champ geometry
49: public static List getFieldsFromLayerWithoutGeometry(Layer l) {
50: List fields = new LinkedList();
51: AttributeType type;
52: for (int i = 0; i < l.getFeatureCollectionWrapper()
53: .getFeatureSchema().getAttributeCount(); i++) {
54:
55: type = l.getFeatureCollectionWrapper().getFeatureSchema()
56: .getAttributeType(i);
57:
58: if (type == AttributeType.GEOMETRY) {
59:
60: } else {
61: fields.add(l.getFeatureCollectionWrapper()
62: .getFeatureSchema().getAttributeName(i));
63: }
64: }
65: return fields;
66: }
67:
68: // renvoie un objet Double créé a partir de la valeur de l'attibut attributeName de l'entite f
69: // si la valeur ne peut être interpretee comme une valeur double, renvoie NaN (Not a Number)
70: public static Double getDoubleFromAttribute(Feature f,
71: String attributeName) {
72: Double d = new Double(Double.NaN);
73: AttributeType type = f.getSchema().getAttributeType(
74: attributeName);
75: if (type == AttributeType.DOUBLE)
76: d = (Double) f.getAttribute(attributeName);
77: else if (type == AttributeType.INTEGER)
78: d = new Double(((Integer) f.getAttribute(attributeName))
79: .doubleValue());
80: else if (type == AttributeType.STRING)
81: d = Double.valueOf((String) f.getAttribute(attributeName));
82: return d;
83: }
84:
85: // met à jour un JLabel avec le format du champ sélectionné.
86: public static void updateFieldTypeLabel(JLabel label, Layer l,
87: String attributeName) {
88:
89: AttributeType nameType = l.getFeatureCollectionWrapper()
90: .getFeatureSchema().getAttributeType(attributeName);
91: label.setText(nameType.toString());
92:
93: }
94: }
|