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;
|
package org.diylc.presenter;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Map;
|
import java.util.List;
|
||||||
|
|
||||||
import org.diylc.common.ComponentType;
|
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
|
|
||||||
public class ComparatorFactory {
|
public class ComparatorFactory {
|
||||||
@@ -11,7 +10,6 @@ public class ComparatorFactory {
|
|||||||
private static ComparatorFactory instance;
|
private static ComparatorFactory instance;
|
||||||
|
|
||||||
private Comparator<IDIYComponent<?>> componentNameComparator;
|
private Comparator<IDIYComponent<?>> componentNameComparator;
|
||||||
private Comparator<IDIYComponent<?>> componentZOrderComparator;
|
|
||||||
|
|
||||||
public static ComparatorFactory getInstance() {
|
public static ComparatorFactory getInstance() {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
@@ -39,18 +37,16 @@ public class ComparatorFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Comparator<IDIYComponent<?>> getComponentZOrderComparator(
|
public Comparator<IDIYComponent<?>> getComponentZOrderComparator(
|
||||||
final Map<Class<? extends IDIYComponent>, ComponentType> componentTypeMap) {
|
final List<IDIYComponent<?>> components) {
|
||||||
if (componentZOrderComparator == null) {
|
Comparator<IDIYComponent<?>> componentZOrderComparator = new Comparator<IDIYComponent<?>>() {
|
||||||
componentZOrderComparator = new Comparator<IDIYComponent<?>>() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(IDIYComponent<?> o1, IDIYComponent<?> o2) {
|
public int compare(IDIYComponent<?> o1, IDIYComponent<?> o2) {
|
||||||
int zIndex1 = componentTypeMap.get(o1.getClass()).getLayer().ordinal();
|
int index1 = components.indexOf(o1);
|
||||||
int zIndex2 = componentTypeMap.get(o2.getClass()).getLayer().ordinal();
|
int index2 = components.indexOf(o2);
|
||||||
return new Integer(zIndex1).compareTo(zIndex2);
|
return new Integer(index1).compareTo(index2);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
|
||||||
return componentZOrderComparator;
|
return componentZOrderComparator;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -404,7 +404,7 @@ public class Presenter implements IPlugInPort {
|
|||||||
}
|
}
|
||||||
// Sort by z-order.
|
// Sort by z-order.
|
||||||
Collections.sort(components, ComparatorFactory.getInstance().getComponentZOrderComparator(
|
Collections.sort(components, ComparatorFactory.getInstance().getComponentZOrderComparator(
|
||||||
componentTypeMap));
|
currentProject.getComponents()));
|
||||||
return components;
|
return components;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user