Revision 3067 org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.rotate/src/main/java/org/gvsig/vectorediting/lib/prov/rotate/RotateEditingProvider.java
RotateEditingProvider.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import java.awt.geom.AffineTransform; |
27 | 27 |
import java.util.ArrayList; |
28 |
import java.util.Collections; |
|
28 | 29 |
import java.util.HashMap; |
29 | 30 |
import java.util.List; |
30 | 31 |
import java.util.Map; |
32 |
import org.apache.commons.collections4.CollectionUtils; |
|
31 | 33 |
import org.gvsig.fmap.dal.exception.DataException; |
32 | 34 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
33 | 35 |
import org.gvsig.fmap.dal.feature.Feature; |
... | ... | |
55 | 57 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.ISimpleTextSymbol; |
56 | 58 |
import org.gvsig.tools.ToolsLocator; |
57 | 59 |
import org.gvsig.tools.dataTypes.DataTypes; |
58 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
59 | 60 |
import org.gvsig.tools.dynobject.DynObject; |
60 | 61 |
import org.gvsig.tools.exception.BaseException; |
61 | 62 |
import org.gvsig.tools.i18n.I18nManager; |
... | ... | |
78 | 79 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
79 | 80 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
80 | 81 |
|
82 |
@SuppressWarnings("UseSpecificCatch") |
|
81 | 83 |
public class RotateEditingProvider extends AbstractEditingProvider implements |
82 | 84 |
EditingProvider { |
83 | 85 |
|
... | ... | |
138 | 140 |
|
139 | 141 |
private final FeatureStore featureStore; |
140 | 142 |
|
143 |
private List<Feature> selectedFeatures; |
|
144 |
|
|
141 | 145 |
public RotateEditingProvider(ProviderServices providerServices, |
142 | 146 |
DynObject parameters) { |
143 | 147 |
super(providerServices); |
... | ... | |
254 | 258 |
|
255 | 259 |
EditingProviderServices editingProviderServices = (EditingProviderServices) getProviderServices(); |
256 | 260 |
|
257 |
FeatureSelection selected |
|
258 |
= (FeatureSelection) values.get(selectionParameter); |
|
259 | 261 |
try { |
260 | 262 |
int subType |
261 | 263 |
= editingProviderServices.getSubType(featureStore); |
262 |
if ((selected != null) && !selected.isEmpty()) {
|
|
264 |
if ( !CollectionUtils.isEmpty(selectedFeatures) ) {
|
|
263 | 265 |
Point p1 = (Point) values.get(pivotPointParameter); |
264 |
Point p2 = null;
|
|
265 |
Point p3 = null;
|
|
266 |
Point p2; |
|
267 |
Point p3; |
|
266 | 268 |
Double angle = null; |
267 | 269 |
if (p1 != null) { |
268 | 270 |
drawingStatus.addStatus(p1, auxiliaryPointSymbolEditing, ""); |
... | ... | |
353 | 355 |
} |
354 | 356 |
|
355 | 357 |
if (angle != null) { |
356 |
DisposableIterator it; |
|
357 |
it = selected.fastIterator(); |
|
358 |
|
|
359 | 358 |
AffineTransform at; |
360 | 359 |
try { |
361 | 360 |
at = getRotateAffineTransform(p1, angle); |
... | ... | |
364 | 363 |
} |
365 | 364 |
|
366 | 365 |
Boolean separateElements = (Boolean) getValue(separateElementsParameter); |
367 |
while (it.hasNext()) { |
|
368 |
Feature feat = (Feature) it.next(); |
|
369 |
|
|
366 |
for (Feature feat : selectedFeatures) { |
|
370 | 367 |
ISymbol previewSymbol = this.getPreviewSymbol(feat); |
371 | 368 |
|
372 | 369 |
Geometry transformedGeometry = feat.getDefaultGeometry().cloneGeometry(); |
... | ... | |
411 | 408 |
} |
412 | 409 |
|
413 | 410 |
} |
414 |
it.dispose(); |
|
415 | 411 |
} |
416 | 412 |
} |
417 | 413 |
return drawingStatus; |
... | ... | |
489 | 485 |
|
490 | 486 |
public void stop() { |
491 | 487 |
values.clear(); |
488 |
this.selectedFeatures = Collections.EMPTY_LIST; |
|
492 | 489 |
} |
493 | 490 |
|
494 | 491 |
private void validateAndInsertValue(EditingServiceParameter param, |
... | ... | |
496 | 493 |
if (param == selectionParameter) { |
497 | 494 |
if (value instanceof FeatureSelection) { |
498 | 495 |
values.put(param, value); |
496 |
this.selectedFeatures = this.getSelectedFeaturesCopy((FeatureSelection) value); |
|
499 | 497 |
} else { |
500 | 498 |
throw new InvalidEntryException(null); |
501 | 499 |
} |
... | ... | |
586 | 584 |
@Override |
587 | 585 |
public void finishAndStore() throws FinishServiceException { |
588 | 586 |
|
589 |
FeatureSelection selected |
|
590 |
= (FeatureSelection) values.get(selectionParameter); |
|
591 | 587 |
EditingProviderServices editingProviderServices = (EditingProviderServices) getProviderServices(); |
592 | 588 |
|
593 | 589 |
try { |
594 | 590 |
int subType = editingProviderServices.getSubType(featureStore); |
595 |
if (!selected.isEmpty()) {
|
|
591 |
if (CollectionUtils.isNotEmpty(selectedFeatures)) {
|
|
596 | 592 |
Point p0 = (Point) values.get(pivotPointParameter); |
597 |
Point p1 = null;
|
|
593 |
Point p1; |
|
598 | 594 |
Object p2; |
599 | 595 |
Double angle = null; |
600 | 596 |
if(values.get(angleParameter) != null){ |
... | ... | |
628 | 624 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
629 | 625 |
|
630 | 626 |
try { |
631 |
selected.accept((Object obj) -> {
|
|
627 |
for (Feature feature : selectedFeatures) {
|
|
632 | 628 |
AffineTransform individualAt = at; |
633 |
Feature feature = (Feature) obj; |
|
634 | 629 |
Geometry geom |
635 | 630 |
= feature.getDefaultGeometry() |
636 | 631 |
.cloneGeometry(); |
... | ... | |
664 | 659 |
((EditingProviderServices) getProviderServices()) |
665 | 660 |
.updateFeatureInFeatureStore( |
666 | 661 |
editableFeature, featureStore); |
667 |
});
|
|
662 |
} |
|
668 | 663 |
} catch (BaseException e) { |
669 | 664 |
throw new FinishServiceException(e); |
670 | 665 |
} |
... | ... | |
683 | 678 |
|
684 | 679 |
@Override |
685 | 680 |
public void start() throws StartServiceException { |
686 |
this.values = new HashMap<>(); |
|
687 |
FeatureSelection selected = null;
|
|
681 |
this.values = new HashMap<>();
|
|
682 |
this.selectedFeatures = Collections.EMPTY_LIST;
|
|
688 | 683 |
if (featureStore != null) { |
684 |
FeatureSelection selected = null; |
|
689 | 685 |
try { |
690 |
selected |
|
691 |
= (FeatureSelection) featureStore.getFeatureSelection() |
|
692 |
.clone(); |
|
686 |
selected = (FeatureSelection) featureStore.getFeatureSelection().clone(); |
|
693 | 687 |
} catch (DataException e) { |
694 | 688 |
throw new StartServiceException(e); |
695 |
} catch (CloneNotSupportedException e) { |
|
696 |
// Do nothing
|
|
689 |
} catch (CloneNotSupportedException ex) {
|
|
690 |
LOGGER.debug("Can't init selection",ex);
|
|
697 | 691 |
} |
698 | 692 |
if ((selected != null) && (selected.getSelectedCount() > 0)) { |
699 | 693 |
values.put(selectionParameter, selected); |
694 |
this.selectedFeatures = this.getSelectedFeaturesCopy(selected); |
|
700 | 695 |
} |
701 | 696 |
} |
702 | 697 |
if (savedRotateMode != null) { |
... | ... | |
707 | 702 |
@Override |
708 | 703 |
public void restart() throws StartServiceException, InvalidEntryException, StopServiceException { |
709 | 704 |
values.put(selectionParameter, null); |
705 |
this.selectedFeatures = Collections.EMPTY_LIST; |
|
710 | 706 |
values.put(pivotPointParameter, null); |
711 | 707 |
center = null; |
712 | 708 |
values.put(angleParameter, null); |
... | ... | |
724 | 720 |
return values != null ? values.get(parameter) : null; |
725 | 721 |
} |
726 | 722 |
|
723 |
@Override |
|
727 | 724 |
public Object getValue(EditingServiceParameter parameter, EditingServiceParameter.TYPE type) { |
728 | 725 |
if(values == null){ |
729 | 726 |
return null; |
Also available in: Unified diff