Revision 365 org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.regularpolygon/src/main/java/org/gvsig/vectorediting/lib/prov/regularpolygon/RegularPolygonEditingProvider.java
RegularPolygonEditingProvider.java | ||
---|---|---|
70 | 70 |
public class RegularPolygonEditingProvider extends AbstractEditingProvider |
71 | 71 |
implements EditingProvider { |
72 | 72 |
|
73 |
protected final Integer DEFAULT_VALUE_SIDES = 5; |
|
74 |
|
|
75 |
protected final String DEFAULT_VALUE_MODE = "key_inscribed"; |
|
76 |
|
|
73 | 77 |
protected EditingServiceParameter polygonSides; |
74 | 78 |
|
75 | 79 |
protected EditingServiceParameter center; |
... | ... | |
92 | 96 |
.getDynValue(EditingProviderFactory.FEATURE_STORE_FIELD); |
93 | 97 |
|
94 | 98 |
polygonSides = |
95 |
new DefaultEditingServiceParameter("sides", |
|
99 |
new DefaultEditingServiceParameter("sides", DEFAULT_VALUE_SIDES,
|
|
96 | 100 |
"sides_of_regular_polygon", EditingServiceParameter.TYPE.VALUE); |
97 | 101 |
|
98 | 102 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
... | ... | |
109 | 113 |
|
110 | 114 |
mode = |
111 | 115 |
new DefaultEditingServiceParameter("mode", consoleMsg, options, |
116 |
i18nManager.getTranslation(DEFAULT_VALUE_MODE), |
|
112 | 117 |
EditingServiceParameter.TYPE.OPTION); |
113 | 118 |
|
114 | 119 |
center = |
... | ... | |
145 | 150 |
|
146 | 151 |
if (values != null) { |
147 | 152 |
|
148 |
Double sidesValue = (Double) values.get(polygonSides);
|
|
153 |
Integer sidesValue = (Integer) values.get(polygonSides);
|
|
149 | 154 |
String modeValue = (String) values.get(mode); |
150 | 155 |
Point centerValue = (Point) values.get(center); |
151 | 156 |
|
152 |
if ((modeValue != null) && (centerValue != null)) {
|
|
157 |
if (centerValue != null) {
|
|
153 | 158 |
|
154 | 159 |
try { |
155 | 160 |
|
... | ... | |
158 | 163 |
int subtype = |
159 | 164 |
editingProviderServices.getSubType(featureStore); |
160 | 165 |
|
166 |
if (modeValue == null) { |
|
167 |
modeValue = DEFAULT_VALUE_MODE; |
|
168 |
} |
|
169 |
|
|
161 | 170 |
Curve polygon = |
162 | 171 |
calculateRegularPolygon(modeValue, centerValue, |
163 |
mousePosition, sidesValue.intValue());
|
|
172 |
mousePosition, sidesValue); |
|
164 | 173 |
Curve line = |
165 | 174 |
editingProviderServices.createLine(centerValue, |
166 | 175 |
mousePosition, subtype); |
... | ... | |
214 | 223 |
double radiusValue = pointOfCircle.distance(centerValue); |
215 | 224 |
double theta = (2 * Math.PI) / sidesValue; |
216 | 225 |
|
217 |
I18nManager i18nManager = ToolsLocator.getI18nManager();
|
|
226 |
if (modeValue.equalsIgnoreCase("key_inscribed")) {
|
|
218 | 227 |
|
219 |
if (modeValue.equalsIgnoreCase(i18nManager |
|
220 |
.getTranslation("key_inscribed"))) { |
|
221 |
|
|
222 | 228 |
for (int i = 0; i < sidesValue; ++i) { |
223 | 229 |
|
224 | 230 |
double x = |
... | ... | |
234 | 240 |
polygon.addVertex(createPoint); |
235 | 241 |
} |
236 | 242 |
|
237 |
} else if (modeValue.equalsIgnoreCase(i18nManager |
|
238 |
.getTranslation("key_circumscribed"))) { |
|
243 |
} else if (modeValue.equalsIgnoreCase("key_circumscribed")) { |
|
239 | 244 |
|
240 | 245 |
for (int i = 0; i < sidesValue; ++i) { |
241 | 246 |
|
... | ... | |
367 | 372 |
if (param == polygonSides) { |
368 | 373 |
if (value instanceof Double) { |
369 | 374 |
|
370 |
double sides = (Double) value;
|
|
375 |
Integer sides = ((Double) value).intValue();
|
|
371 | 376 |
|
372 | 377 |
if (sides > 2) { |
373 | 378 |
values.put(param, sides); |
... | ... | |
375 | 380 |
} else { |
376 | 381 |
throw new InvalidEntryException(null); |
377 | 382 |
} |
383 |
} else if (value instanceof Point) { |
|
384 |
|
|
385 |
values.put(param, DEFAULT_VALUE_SIDES); |
|
386 |
values.put(center, (Point) value); |
|
387 |
return; |
|
378 | 388 |
} |
379 | 389 |
} else if (param == mode) { |
380 | 390 |
|
... | ... | |
384 | 394 |
String option = (String) value; |
385 | 395 |
|
386 | 396 |
if (option.equalsIgnoreCase(i18nManager |
387 |
.getTranslation("key_inscribed")) |
|
388 |
|| option.equalsIgnoreCase(i18nManager |
|
389 |
.getTranslation("key_circumscribed"))) { |
|
397 |
.getTranslation("key_inscribed"))) { |
|
390 | 398 |
|
391 |
values.put(param, value);
|
|
399 |
values.put(param, "key_inscribed");
|
|
392 | 400 |
return; |
393 | 401 |
|
402 |
} else if (option.equalsIgnoreCase(i18nManager |
|
403 |
.getTranslation("key_circumscribed"))) { |
|
404 |
|
|
405 |
values.put(param, "key_circumscribed"); |
|
406 |
return; |
|
407 |
|
|
394 | 408 |
} else { |
395 | 409 |
throw new InvalidEntryException(null); |
396 | 410 |
} |
411 |
} else if (value instanceof Point) { |
|
412 |
|
|
413 |
values.put(param, DEFAULT_VALUE_MODE); |
|
414 |
if(values.get(center) != null){ |
|
415 |
values.put(pointOfCircle, (Point) value); |
|
416 |
} else { |
|
417 |
values.put(center, (Point) value); |
|
418 |
} |
|
419 |
return; |
|
397 | 420 |
} |
398 | 421 |
|
399 | 422 |
} else if (param == center) { |
... | ... | |
417 | 440 |
|
418 | 441 |
if (values != null) { |
419 | 442 |
|
420 |
Double sidesValue = (Double) values.get(polygonSides);
|
|
443 |
Integer sidesValue = (Integer) values.get(polygonSides);
|
|
421 | 444 |
String modeValue = (String) values.get(mode); |
422 | 445 |
Point centerValue = (Point) values.get(center); |
423 | 446 |
Point pointOfCircleValue = (Point) values.get(pointOfCircle); |
... | ... | |
425 | 448 |
try { |
426 | 449 |
Curve polygon = |
427 | 450 |
calculateRegularPolygon(modeValue, centerValue, |
428 |
pointOfCircleValue, sidesValue.intValue());
|
|
451 |
pointOfCircleValue, sidesValue); |
|
429 | 452 |
|
430 | 453 |
EditingProviderServices editingProviderServices = |
431 | 454 |
(EditingProviderServices) getProviderServices(); |
Also available in: Unified diff