mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Preserve z-order of components when copy-pasting
This commit is contained in:
@@ -22,10 +22,11 @@
|
||||
package org.diylc.presenter;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
|
||||
import org.diylc.common.ComponentType;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.Project;
|
||||
|
||||
public class ComparatorFactory {
|
||||
|
||||
@@ -127,5 +128,17 @@ public class ComparatorFactory {
|
||||
};
|
||||
}
|
||||
return componentZOrderComparator;
|
||||
}
|
||||
|
||||
public Comparator<IDIYComponent<?>> getComponentProjectZOrderComparator(final Project project) {
|
||||
return new Comparator<IDIYComponent<?>>() {
|
||||
|
||||
@Override
|
||||
public int compare(IDIYComponent<?> o1, IDIYComponent<?> o2) {
|
||||
int index1 = project.getComponents().indexOf(o1);
|
||||
int index2 = project.getComponents().indexOf(o2);
|
||||
return new Integer(index1).compareTo(index2);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -831,7 +831,9 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@Override
|
||||
public Collection<IDIYComponent<?>> getSelectedComponents() {
|
||||
return selectedComponents;
|
||||
List<IDIYComponent<?>> selection = new ArrayList<IDIYComponent<?>>(selectedComponents);
|
||||
Collections.sort(selection, ComparatorFactory.getInstance().getComponentProjectZOrderComparator(currentProject));
|
||||
return selection;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
Reference in New Issue
Block a user