Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.spi / src / main / java / org / gvsig / exportto / swing / spi / panels / SelectGeometryTypePanel.java @ 43920

History | View | Annotate | Download (8.78 KB)

1
package org.gvsig.exportto.swing.spi.panels;
2

    
3
import java.util.ArrayList;
4
import java.util.Comparator;
5
import java.util.HashMap;
6
import java.util.List;
7
import java.util.Map;
8
import javax.swing.DefaultComboBoxModel;
9
import javax.swing.JComponent;
10
import org.apache.commons.lang3.ArrayUtils;
11
import org.gvsig.exportto.swing.spi.ExporttoPanelValidationException;
12
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderPanel;
13
import org.gvsig.exportto.swing.spi.options.ExportGeometryOptions;
14
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
15
import org.gvsig.fmap.dal.feature.FeatureType;
16
import org.gvsig.fmap.geom.Geometry;
17
import org.gvsig.fmap.geom.type.GeometryType;
18
import org.gvsig.tools.ToolsLocator;
19
import org.gvsig.tools.i18n.I18nManager;
20
import org.gvsig.tools.swing.api.ListElement;
21
import org.gvsig.tools.swing.api.ToolsSwingLocator;
22
import org.gvsig.tools.swing.api.ToolsSwingManager;
23

    
24
/**
25
 *
26
 * @author jjdelcerro
27
 */
28
public class SelectGeometryTypePanel 
29
        extends SelectGeometryTypePanelView 
30
        implements ExporttoSwingProviderPanel 
31
    {
32

    
33
    private final ExportGeometryOptions options;
34
    private int[] geometryTypes;
35
    private int[] geometrySubtypes;
36
    private final Map<Integer, String> geometryTypeNames;
37
    private final Map<Integer, String> geometrySubtypeNames;
38
    private boolean updateComponents;
39

    
40
            
41
    public SelectGeometryTypePanel(ExportGeometryOptions options) {
42
        this(options,null,null);
43
    }
44

    
45
    public SelectGeometryTypePanel(ExportGeometryOptions options, int[] geometryTypes, int[] geometrySubtypes) {
46
        this.geometryTypeNames = new HashMap<>();
47
        this.geometrySubtypeNames = new HashMap<>();
48
        this.options = options;
49
        this.geometryTypes = geometryTypes;
50
        this.geometrySubtypes = geometrySubtypes;
51
        this.initData();
52
        this.initComponents();
53
    }
54

    
55
    private void initData() {
56
        FeatureType ft = this.options.getSourceFeatureType();
57
        FeatureAttributeDescriptor geomDescriptor = ft.getDefaultGeometryAttribute();
58
        
59
        if( geomDescriptor == null ) {
60
            this.options.setGeometryType(Geometry.TYPES.GEOMETRY);
61
            this.options.setGeometrySubtype(Geometry.SUBTYPES.GEOM2D);
62
        } else {
63
            GeometryType gt = geomDescriptor.getGeomType();
64
            this.options.setGeometryType(gt.getType());
65
            this.options.setGeometrySubtype(gt.getSubType());
66
        }
67
        
68
        if( ArrayUtils.isEmpty(this.geometryTypes) ) {
69
            this.geometryTypes = new int[] {
70
                Geometry.TYPES.GEOMETRY,
71
                Geometry.TYPES.POINT,
72
                Geometry.TYPES.CURVE,
73
                Geometry.TYPES.SURFACE,
74
                Geometry.TYPES.SOLID,
75
                Geometry.TYPES.AGGREGATE,
76
                Geometry.TYPES.MULTIPOINT,
77
                Geometry.TYPES.MULTICURVE,
78
                Geometry.TYPES.MULTISURFACE,
79
                Geometry.TYPES.MULTISOLID,
80
                Geometry.TYPES.CIRCLE,
81
                Geometry.TYPES.ARC,
82
                Geometry.TYPES.ELLIPSE,
83
                Geometry.TYPES.SPLINE,
84
                Geometry.TYPES.ELLIPTICARC,
85
                Geometry.TYPES.COMPLEX,
86
                Geometry.TYPES.LINE,
87
                Geometry.TYPES.POLYGON,
88
                //Geometry.TYPES.RING,
89
                Geometry.TYPES.MULTILINE,
90
                Geometry.TYPES.MULTIPOLYGON,
91
                Geometry.TYPES.CIRCUMFERENCE,
92
                Geometry.TYPES.PERIELLIPSE,
93
                Geometry.TYPES.FILLEDSPLINE
94
            };                    
95
        }
96
        if( ArrayUtils.isEmpty(this.geometrySubtypes) ) {
97
            this.geometrySubtypes = new int[] {
98
                Geometry.SUBTYPES.GEOM2D,
99
                Geometry.SUBTYPES.GEOM2DM,
100
                Geometry.SUBTYPES.GEOM3D,
101
                Geometry.SUBTYPES.GEOM3DM
102
            };
103
        }
104
        this.geometryTypeNames.put(Geometry.TYPES.GEOMETRY,"GEOMETRY");
105
        this.geometryTypeNames.put(Geometry.TYPES.POINT,"POINT");
106
        this.geometryTypeNames.put(Geometry.TYPES.CURVE,"CURVE");
107
        this.geometryTypeNames.put(Geometry.TYPES.SURFACE,"SURFACE");
108
        this.geometryTypeNames.put(Geometry.TYPES.SOLID,"SOLID");
109
        this.geometryTypeNames.put(Geometry.TYPES.AGGREGATE,"AGGREGATE");
110
        this.geometryTypeNames.put(Geometry.TYPES.MULTIPOINT,"MULTIPOINT");
111
        this.geometryTypeNames.put(Geometry.TYPES.MULTICURVE,"MULTICURVE");
112
        this.geometryTypeNames.put(Geometry.TYPES.MULTISURFACE,"MULTISURFACE");
113
        this.geometryTypeNames.put(Geometry.TYPES.MULTISOLID,"MULTISOLID");
114
        this.geometryTypeNames.put(Geometry.TYPES.CIRCLE,"CIRCLE");
115
        this.geometryTypeNames.put(Geometry.TYPES.ARC,"ARC");
116
        this.geometryTypeNames.put(Geometry.TYPES.ELLIPSE,"ELLIPSE");
117
        this.geometryTypeNames.put(Geometry.TYPES.SPLINE,"SPLINE");
118
        this.geometryTypeNames.put(Geometry.TYPES.ELLIPTICARC,"ELLIPTICARC");
119
        this.geometryTypeNames.put(Geometry.TYPES.COMPLEX,"COMPLEX");
120
        this.geometryTypeNames.put(Geometry.TYPES.LINE,"LINE");
121
        this.geometryTypeNames.put(Geometry.TYPES.POLYGON,"POLYGON");
122
        this.geometryTypeNames.put(Geometry.TYPES.NULL,"NULL");
123
        this.geometryTypeNames.put(Geometry.TYPES.RING,"RING");
124
        this.geometryTypeNames.put(Geometry.TYPES.MULTILINE,"MULTILINE");
125
        this.geometryTypeNames.put(Geometry.TYPES.MULTIPOLYGON,"MULTIPOLYGON");
126
        this.geometryTypeNames.put(Geometry.TYPES.CIRCUMFERENCE,"CIRCUMFERENCE");
127
        this.geometryTypeNames.put(Geometry.TYPES.PERIELLIPSE,"PERIELLIPSE");
128
        this.geometryTypeNames.put(Geometry.TYPES.FILLEDSPLINE,"FILLEDSPLINE");
129
        this.geometrySubtypeNames.put(Geometry.SUBTYPES.GEOM2D,"2D");
130
        this.geometrySubtypeNames.put(Geometry.SUBTYPES.GEOM2DM,"2DM");
131
        this.geometrySubtypeNames.put(Geometry.SUBTYPES.GEOM3D,"3D");
132
        this.geometrySubtypeNames.put(Geometry.SUBTYPES.GEOM3DM,"3DM");
133
        this.geometrySubtypeNames.put(Geometry.SUBTYPES.UNKNOWN,"UNKNOWN");
134
    }
135
    
136
    private void initComponents() {
137
        List<ListElement<Integer>> items;
138

    
139
        items = new ArrayList<>();
140
        for (int geometryType : this.geometryTypes) {
141
            items.add(new ListElement<>(
142
                    this.geometryTypeNames.getOrDefault(geometryType, "unknown ("+geometryType+")"),
143
                    geometryType
144
                )
145
            );
146
        }
147
        items.sort(new Comparator<ListElement<Integer>>() {
148
            @Override
149
            public int compare(ListElement<Integer> o1, ListElement<Integer> o2) {
150
                return o1.toString().compareToIgnoreCase(o2.toString());
151
            }
152
        });
153
        DefaultComboBoxModel model1 = new DefaultComboBoxModel();
154
        for (ListElement<Integer> item : items) {
155
            model1.addElement(item);
156
        }
157
        this.cboType.setModel(model1);
158

    
159

    
160
        items = new ArrayList<>();
161
        for (int geometrySubtype : this.geometrySubtypes) {
162
            items.add(new ListElement<>(
163
                    this.geometrySubtypeNames.getOrDefault(geometrySubtype, "unknown ("+geometrySubtype+")"),
164
                    geometrySubtype
165
                )
166
            );
167
        }
168
        items.sort(new Comparator<ListElement<Integer>>() {
169
            @Override
170
            public int compare(ListElement<Integer> o1, ListElement<Integer> o2) {
171
                return o1.toString().compareToIgnoreCase(o2.toString());
172
            }
173
        });
174
        model1 = new DefaultComboBoxModel();
175
        for (ListElement<Integer> item : items) {
176
            model1.addElement(item);
177
        }
178
        this.cboSubtype.setModel(model1);
179
        this.updateComponents=true;
180
        this.translate();
181
    }
182
    
183
    private void translate() {
184
        ToolsSwingManager i18nc = ToolsSwingLocator.getToolsSwingManager();
185
        i18nc.translate(this.lblSelectTargetGeometryType);
186
        i18nc.translate(this.lblSubtype);
187
        i18nc.translate(this.lblType);
188
    }
189

    
190
    @Override
191
    public String getPanelTitle() {
192
        I18nManager i18nManager = ToolsLocator.getI18nManager();
193
        return i18nManager.getTranslation("_Select_geometry_type");    
194
    }
195

    
196
    @Override
197
    public boolean isValidPanel() throws ExporttoPanelValidationException {
198
        Integer n = (Integer) ListElement.getSelected(cboType);
199
        if( n!=null ) {
200
            this.options.setGeometryType(n);
201
        }
202
        n = (Integer) ListElement.getSelected(cboSubtype);
203
        if( n!=null ) {
204
            this.options.setGeometrySubtype(n);
205
        }
206
        return true;
207
    }
208

    
209
    @Override
210
    public void enterPanel() {
211
        if( this.updateComponents ) {
212
            ListElement.setSelected(cboType, this.options.getGeometryTypeAsInt());
213
            ListElement.setSelected(cboSubtype, this.options.getGeometrySubtype());
214
        }
215
        this.updateComponents=false;
216
    }
217

    
218
    @Override
219
    public JComponent asJComponent() {
220
        return this;
221
    }
222

    
223
}