svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.impl / src / main / java / org / gvsig / export / swing / impl / panels / SelectGeometryTypePanel.java @ 43968
History | View | Annotate | Download (9.47 KB)
1 | 43925 | jjdelcerro | package org.gvsig.export.swing.impl.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.export.ExportParameters; |
||
12 | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
||
13 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
14 | import org.gvsig.fmap.geom.Geometry; |
||
15 | import org.gvsig.fmap.geom.type.GeometryType; |
||
16 | import org.gvsig.tools.ToolsLocator; |
||
17 | import org.gvsig.tools.i18n.I18nManager; |
||
18 | import org.gvsig.tools.swing.api.ListElement; |
||
19 | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
||
20 | import org.gvsig.tools.swing.api.ToolsSwingManager; |
||
21 | import org.gvsig.export.ExportParametersGeometry; |
||
22 | import org.gvsig.export.swing.JExportProcessPanel; |
||
23 | import org.gvsig.export.swing.spi.ExportPanel; |
||
24 | import org.gvsig.export.swing.spi.ExportPanelValidationException; |
||
25 | import org.gvsig.export.swing.spi.ExportPanelsManager; |
||
26 | |||
27 | /**
|
||
28 | *
|
||
29 | * @author jjdelcerro
|
||
30 | */
|
||
31 | public class SelectGeometryTypePanel |
||
32 | extends SelectGeometryTypePanelView
|
||
33 | implements ExportPanel
|
||
34 | { |
||
35 | |||
36 | private final ExportParametersGeometry parameters; |
||
37 | private int[] geometryTypes; |
||
38 | private int[] geometrySubtypes; |
||
39 | private final Map<Integer, String> geometryTypeNames; |
||
40 | private final Map<Integer, String> geometrySubtypeNames; |
||
41 | private boolean updateComponents; |
||
42 | private final JExportProcessPanel processPanel; |
||
43 | |||
44 | |||
45 | public SelectGeometryTypePanel(
|
||
46 | JExportProcessPanel processPanel, |
||
47 | ExportParametersGeometry parameters |
||
48 | ) { |
||
49 | this(processPanel,parameters,null,null); |
||
50 | } |
||
51 | |||
52 | public SelectGeometryTypePanel(
|
||
53 | JExportProcessPanel processPanel, |
||
54 | ExportParameters parameters, |
||
55 | int[] geometryTypes, |
||
56 | int[] geometrySubtypes |
||
57 | ) { |
||
58 | this.processPanel = processPanel;
|
||
59 | this.geometryTypeNames = new HashMap<>(); |
||
60 | this.geometrySubtypeNames = new HashMap<>(); |
||
61 | this.parameters = (ExportParametersGeometry) parameters;
|
||
62 | this.geometryTypes = geometryTypes;
|
||
63 | this.geometrySubtypes = geometrySubtypes;
|
||
64 | this.initData();
|
||
65 | this.initComponents();
|
||
66 | } |
||
67 | |||
68 | private void initData() { |
||
69 | FeatureType ft = this.parameters.getSourceFeatureType();
|
||
70 | FeatureAttributeDescriptor geomDescriptor = ft.getDefaultGeometryAttribute(); |
||
71 | |||
72 | if( geomDescriptor == null ) { |
||
73 | 43936 | jjdelcerro | this.parameters.setTargetGeometryType(Geometry.TYPES.GEOMETRY);
|
74 | this.parameters.setTargetGeometrySubtype(Geometry.SUBTYPES.GEOM2D);
|
||
75 | 43925 | jjdelcerro | } else {
|
76 | GeometryType gt = geomDescriptor.getGeomType(); |
||
77 | 43936 | jjdelcerro | this.parameters.setTargetGeometryType(gt.getType());
|
78 | this.parameters.setTargetGeometrySubtype(gt.getSubType());
|
||
79 | 43925 | jjdelcerro | } |
80 | |||
81 | if( ArrayUtils.isEmpty(this.geometryTypes) ) { |
||
82 | this.geometryTypes = new int[] { |
||
83 | Geometry.TYPES.GEOMETRY, |
||
84 | Geometry.TYPES.POINT, |
||
85 | Geometry.TYPES.CURVE, |
||
86 | Geometry.TYPES.SURFACE, |
||
87 | Geometry.TYPES.SOLID, |
||
88 | Geometry.TYPES.AGGREGATE, |
||
89 | Geometry.TYPES.MULTIPOINT, |
||
90 | Geometry.TYPES.MULTICURVE, |
||
91 | Geometry.TYPES.MULTISURFACE, |
||
92 | Geometry.TYPES.MULTISOLID, |
||
93 | Geometry.TYPES.CIRCLE, |
||
94 | Geometry.TYPES.ARC, |
||
95 | Geometry.TYPES.ELLIPSE, |
||
96 | Geometry.TYPES.SPLINE, |
||
97 | Geometry.TYPES.ELLIPTICARC, |
||
98 | Geometry.TYPES.COMPLEX, |
||
99 | Geometry.TYPES.LINE, |
||
100 | Geometry.TYPES.POLYGON, |
||
101 | //Geometry.TYPES.RING,
|
||
102 | Geometry.TYPES.MULTILINE, |
||
103 | Geometry.TYPES.MULTIPOLYGON, |
||
104 | Geometry.TYPES.CIRCUMFERENCE, |
||
105 | Geometry.TYPES.PERIELLIPSE, |
||
106 | Geometry.TYPES.FILLEDSPLINE |
||
107 | }; |
||
108 | } |
||
109 | if( ArrayUtils.isEmpty(this.geometrySubtypes) ) { |
||
110 | this.geometrySubtypes = new int[] { |
||
111 | Geometry.SUBTYPES.GEOM2D, |
||
112 | Geometry.SUBTYPES.GEOM2DM, |
||
113 | Geometry.SUBTYPES.GEOM3D, |
||
114 | Geometry.SUBTYPES.GEOM3DM |
||
115 | }; |
||
116 | } |
||
117 | this.geometryTypeNames.put(Geometry.TYPES.GEOMETRY,"GEOMETRY"); |
||
118 | this.geometryTypeNames.put(Geometry.TYPES.POINT,"POINT"); |
||
119 | this.geometryTypeNames.put(Geometry.TYPES.CURVE,"CURVE"); |
||
120 | this.geometryTypeNames.put(Geometry.TYPES.SURFACE,"SURFACE"); |
||
121 | this.geometryTypeNames.put(Geometry.TYPES.SOLID,"SOLID"); |
||
122 | this.geometryTypeNames.put(Geometry.TYPES.AGGREGATE,"AGGREGATE"); |
||
123 | this.geometryTypeNames.put(Geometry.TYPES.MULTIPOINT,"MULTIPOINT"); |
||
124 | this.geometryTypeNames.put(Geometry.TYPES.MULTICURVE,"MULTICURVE"); |
||
125 | this.geometryTypeNames.put(Geometry.TYPES.MULTISURFACE,"MULTISURFACE"); |
||
126 | this.geometryTypeNames.put(Geometry.TYPES.MULTISOLID,"MULTISOLID"); |
||
127 | this.geometryTypeNames.put(Geometry.TYPES.CIRCLE,"CIRCLE"); |
||
128 | this.geometryTypeNames.put(Geometry.TYPES.ARC,"ARC"); |
||
129 | this.geometryTypeNames.put(Geometry.TYPES.ELLIPSE,"ELLIPSE"); |
||
130 | this.geometryTypeNames.put(Geometry.TYPES.SPLINE,"SPLINE"); |
||
131 | this.geometryTypeNames.put(Geometry.TYPES.ELLIPTICARC,"ELLIPTICARC"); |
||
132 | this.geometryTypeNames.put(Geometry.TYPES.COMPLEX,"COMPLEX"); |
||
133 | this.geometryTypeNames.put(Geometry.TYPES.LINE,"LINE"); |
||
134 | this.geometryTypeNames.put(Geometry.TYPES.POLYGON,"POLYGON"); |
||
135 | this.geometryTypeNames.put(Geometry.TYPES.NULL,"NULL"); |
||
136 | this.geometryTypeNames.put(Geometry.TYPES.RING,"RING"); |
||
137 | this.geometryTypeNames.put(Geometry.TYPES.MULTILINE,"MULTILINE"); |
||
138 | this.geometryTypeNames.put(Geometry.TYPES.MULTIPOLYGON,"MULTIPOLYGON"); |
||
139 | this.geometryTypeNames.put(Geometry.TYPES.CIRCUMFERENCE,"CIRCUMFERENCE"); |
||
140 | this.geometryTypeNames.put(Geometry.TYPES.PERIELLIPSE,"PERIELLIPSE"); |
||
141 | this.geometryTypeNames.put(Geometry.TYPES.FILLEDSPLINE,"FILLEDSPLINE"); |
||
142 | this.geometrySubtypeNames.put(Geometry.SUBTYPES.GEOM2D,"2D"); |
||
143 | this.geometrySubtypeNames.put(Geometry.SUBTYPES.GEOM2DM,"2DM"); |
||
144 | this.geometrySubtypeNames.put(Geometry.SUBTYPES.GEOM3D,"3D"); |
||
145 | this.geometrySubtypeNames.put(Geometry.SUBTYPES.GEOM3DM,"3DM"); |
||
146 | this.geometrySubtypeNames.put(Geometry.SUBTYPES.UNKNOWN,"UNKNOWN"); |
||
147 | } |
||
148 | |||
149 | private void initComponents() { |
||
150 | List<ListElement<Integer>> items; |
||
151 | |||
152 | items = new ArrayList<>(); |
||
153 | for (int geometryType : this.geometryTypes) { |
||
154 | items.add(new ListElement<>(
|
||
155 | this.geometryTypeNames.getOrDefault(geometryType, "unknown ("+geometryType+")"), |
||
156 | geometryType |
||
157 | ) |
||
158 | ); |
||
159 | } |
||
160 | items.sort(new Comparator<ListElement<Integer>>() { |
||
161 | @Override
|
||
162 | public int compare(ListElement<Integer> o1, ListElement<Integer> o2) { |
||
163 | return o1.toString().compareToIgnoreCase(o2.toString());
|
||
164 | } |
||
165 | }); |
||
166 | DefaultComboBoxModel model1 = new DefaultComboBoxModel(); |
||
167 | for (ListElement<Integer> item : items) { |
||
168 | model1.addElement(item); |
||
169 | } |
||
170 | this.cboType.setModel(model1);
|
||
171 | |||
172 | |||
173 | items = new ArrayList<>(); |
||
174 | for (int geometrySubtype : this.geometrySubtypes) { |
||
175 | items.add(new ListElement<>(
|
||
176 | this.geometrySubtypeNames.getOrDefault(geometrySubtype, "unknown ("+geometrySubtype+")"), |
||
177 | geometrySubtype |
||
178 | ) |
||
179 | ); |
||
180 | } |
||
181 | items.sort(new Comparator<ListElement<Integer>>() { |
||
182 | @Override
|
||
183 | public int compare(ListElement<Integer> o1, ListElement<Integer> o2) { |
||
184 | return o1.toString().compareToIgnoreCase(o2.toString());
|
||
185 | } |
||
186 | }); |
||
187 | model1 = new DefaultComboBoxModel(); |
||
188 | for (ListElement<Integer> item : items) { |
||
189 | model1.addElement(item); |
||
190 | } |
||
191 | this.cboSubtype.setModel(model1);
|
||
192 | this.updateComponents=true; |
||
193 | this.translate();
|
||
194 | } |
||
195 | |||
196 | private void translate() { |
||
197 | ToolsSwingManager i18nc = ToolsSwingLocator.getToolsSwingManager(); |
||
198 | i18nc.translate(this.lblSelectTargetGeometryType);
|
||
199 | i18nc.translate(this.lblSubtype);
|
||
200 | i18nc.translate(this.lblType);
|
||
201 | } |
||
202 | |||
203 | @Override
|
||
204 | public String getIdPanel() { |
||
205 | return ExportPanelsManager.PANEL_SELECT_GEOMETRY_TYPE;
|
||
206 | } |
||
207 | |||
208 | @Override
|
||
209 | public String getTitlePanel() { |
||
210 | I18nManager i18nManager = ToolsLocator.getI18nManager(); |
||
211 | return i18nManager.getTranslation("_Select_geometry_type"); |
||
212 | } |
||
213 | |||
214 | @Override
|
||
215 | public boolean validatePanel() throws ExportPanelValidationException { |
||
216 | return true; |
||
217 | } |
||
218 | |||
219 | @Override
|
||
220 | 43968 | jjdelcerro | public void previousPanel() { |
221 | |||
222 | } |
||
223 | |||
224 | @Override
|
||
225 | public void nextPanel() { |
||
226 | 43925 | jjdelcerro | Integer n = (Integer) ListElement.getSelected(cboType); |
227 | if( n!=null ) { |
||
228 | 43936 | jjdelcerro | this.parameters.setTargetGeometryType(n);
|
229 | 43925 | jjdelcerro | } |
230 | n = (Integer) ListElement.getSelected(cboSubtype);
|
||
231 | if( n!=null ) { |
||
232 | 43936 | jjdelcerro | this.parameters.setTargetGeometrySubtype(n);
|
233 | 43925 | jjdelcerro | } |
234 | } |
||
235 | |||
236 | @Override
|
||
237 | public void enterPanel() { |
||
238 | if( this.updateComponents ) { |
||
239 | 43936 | jjdelcerro | ListElement.setSelected(cboType, this.parameters.getTargetGeometryTypeAsInt());
|
240 | ListElement.setSelected(cboSubtype, this.parameters.getTargetGeometrySubtype());
|
||
241 | 43925 | jjdelcerro | } |
242 | this.updateComponents=false; |
||
243 | } |
||
244 | |||
245 | @Override
|
||
246 | public JComponent asJComponent() { |
||
247 | return this; |
||
248 | } |
||
249 | |||
250 | } |