mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
fixed z-order selection
This commit is contained in:
+10
-14
@@ -1,9 +1,8 @@
|
||||
package org.diylc.presenter;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
import org.diylc.common.ComponentType;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class ComparatorFactory {
|
||||
@@ -11,7 +10,6 @@ public class ComparatorFactory {
|
||||
private static ComparatorFactory instance;
|
||||
|
||||
private Comparator<IDIYComponent<?>> componentNameComparator;
|
||||
private Comparator<IDIYComponent<?>> componentZOrderComparator;
|
||||
|
||||
public static ComparatorFactory getInstance() {
|
||||
if (instance == null) {
|
||||
@@ -39,18 +37,16 @@ public class ComparatorFactory {
|
||||
}
|
||||
|
||||
public Comparator<IDIYComponent<?>> getComponentZOrderComparator(
|
||||
final Map<Class<? extends IDIYComponent>, ComponentType> componentTypeMap) {
|
||||
if (componentZOrderComparator == null) {
|
||||
componentZOrderComparator = new Comparator<IDIYComponent<?>>() {
|
||||
final List<IDIYComponent<?>> components) {
|
||||
Comparator<IDIYComponent<?>> componentZOrderComparator = new Comparator<IDIYComponent<?>>() {
|
||||
|
||||
@Override
|
||||
public int compare(IDIYComponent<?> o1, IDIYComponent<?> o2) {
|
||||
int zIndex1 = componentTypeMap.get(o1.getClass()).getLayer().ordinal();
|
||||
int zIndex2 = componentTypeMap.get(o2.getClass()).getLayer().ordinal();
|
||||
return new Integer(zIndex1).compareTo(zIndex2);
|
||||
}
|
||||
};
|
||||
}
|
||||
@Override
|
||||
public int compare(IDIYComponent<?> o1, IDIYComponent<?> o2) {
|
||||
int index1 = components.indexOf(o1);
|
||||
int index2 = components.indexOf(o2);
|
||||
return new Integer(index1).compareTo(index2);
|
||||
}
|
||||
};
|
||||
return componentZOrderComparator;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -404,7 +404,7 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
// Sort by z-order.
|
||||
Collections.sort(components, ComparatorFactory.getInstance().getComponentZOrderComparator(
|
||||
componentTypeMap));
|
||||
currentProject.getComponents()));
|
||||
return components;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user