Better sorting in the BOM (e.g. R2 should go before R10)

Better Audo-Edit
This commit is contained in:
bancika
2012-08-22 10:16:44 +00:00
parent c406632299
commit 9209782401
6 changed files with 58 additions and 23 deletions
@@ -27,11 +27,12 @@ public class ComponentType {
private boolean flexibleZOrder; private boolean flexibleZOrder;
private boolean stretchable; private boolean stretchable;
private BomPolicy bomPolicy; private BomPolicy bomPolicy;
private boolean autoEdit;
public ComponentType(String name, String description, CreationMethod creationMethod, public ComponentType(String name, String description, CreationMethod creationMethod,
String category, String namePrefix, String author, Icon icon, String category, String namePrefix, String author, Icon icon,
Class<? extends IDIYComponent<?>> instanceClass, double zOrder, boolean flexibleZOrder, Class<? extends IDIYComponent<?>> instanceClass, double zOrder, boolean flexibleZOrder,
boolean stretchable, BomPolicy bomPolicy) { boolean stretchable, BomPolicy bomPolicy, boolean autoEdit) {
super(); super();
this.name = name; this.name = name;
this.description = description; this.description = description;
@@ -45,6 +46,7 @@ public class ComponentType {
this.flexibleZOrder = flexibleZOrder; this.flexibleZOrder = flexibleZOrder;
this.stretchable = stretchable; this.stretchable = stretchable;
this.bomPolicy = bomPolicy; this.bomPolicy = bomPolicy;
this.autoEdit = autoEdit;
} }
public String getName() { public String getName() {
@@ -95,6 +97,10 @@ public class ComponentType {
return bomPolicy; return bomPolicy;
} }
public boolean isAutoEdit() {
return autoEdit;
}
@Override @Override
public String toString() { public String toString() {
return name; return name;
@@ -71,4 +71,10 @@ public @interface ComponentDescriptor {
*/ */
BomPolicy bomPolicy() default BomPolicy.SHOW_ALL_NAMES; BomPolicy bomPolicy() default BomPolicy.SHOW_ALL_NAMES;
/**
* @return when true, component editor dialog should be shown in Auto-Edit
* mode.
*/
boolean autoEdit() default true;
} }
@@ -70,6 +70,7 @@ public class ComponentProcessor {
boolean flexibleZOrder; boolean flexibleZOrder;
boolean stretchable; boolean stretchable;
BomPolicy bomPolicy; BomPolicy bomPolicy;
boolean autoEdit;
if (clazz.isAnnotationPresent(ComponentDescriptor.class)) { if (clazz.isAnnotationPresent(ComponentDescriptor.class)) {
ComponentDescriptor annotation = clazz ComponentDescriptor annotation = clazz
.getAnnotation(ComponentDescriptor.class); .getAnnotation(ComponentDescriptor.class);
@@ -83,6 +84,7 @@ public class ComponentProcessor {
flexibleZOrder = annotation.flexibleZOrder(); flexibleZOrder = annotation.flexibleZOrder();
stretchable = annotation.stretchable(); stretchable = annotation.stretchable();
bomPolicy = annotation.bomPolicy(); bomPolicy = annotation.bomPolicy();
autoEdit = annotation.autoEdit();
} else { } else {
name = clazz.getSimpleName(); name = clazz.getSimpleName();
description = ""; description = "";
@@ -94,6 +96,7 @@ public class ComponentProcessor {
flexibleZOrder = false; flexibleZOrder = false;
stretchable = true; stretchable = true;
bomPolicy = BomPolicy.SHOW_ALL_NAMES; bomPolicy = BomPolicy.SHOW_ALL_NAMES;
autoEdit = true;
} }
icon = null; icon = null;
// Draw component icon. // Draw component icon.
@@ -114,7 +117,7 @@ public class ComponentProcessor {
} }
ComponentType componentType = new ComponentType(name, description, ComponentType componentType = new ComponentType(name, description,
creationMethod, category, namePrefix, author, icon, clazz, creationMethod, category, namePrefix, author, icon, clazz,
zOrder, flexibleZOrder, stretchable, bomPolicy); zOrder, flexibleZOrder, stretchable, bomPolicy, autoEdit);
componentTypeMap.put(clazz.getName(), componentType); componentTypeMap.put(clazz.getName(), componentType);
return componentType; return componentType;
} }
@@ -57,7 +57,7 @@ public class Presenter implements IPlugInPort {
private static final Logger LOG = Logger.getLogger(Presenter.class); private static final Logger LOG = Logger.getLogger(Presenter.class);
public static final VersionNumber CURRENT_VERSION = new VersionNumber(3, public static final VersionNumber CURRENT_VERSION = new VersionNumber(3,
11, 0); 12, 0);
public static final String DEFAULTS_KEY_PREFIX = "default."; public static final String DEFAULTS_KEY_PREFIX = "default.";
public static final List<IDIYComponent<?>> EMPTY_SELECTION = Collections public static final List<IDIYComponent<?>> EMPTY_SELECTION = Collections
@@ -436,8 +436,9 @@ public class Presenter implements IPlugInPort {
.getName(), e); .getName(), e);
} }
if (ConfigurationManager.getInstance().readBoolean( if (componentTypeSlot.isAutoEdit()
IPlugInPort.AUTO_EDIT_KEY, false)) { && ConfigurationManager.getInstance().readBoolean(
IPlugInPort.AUTO_EDIT_KEY, false)) {
editSelection(); editSelection();
} }
if (ConfigurationManager.getInstance().readBoolean( if (ConfigurationManager.getInstance().readBoolean(
@@ -484,8 +485,10 @@ public class Presenter implements IPlugInPort {
updateSelection(newSelection); updateSelection(newSelection);
messageDispatcher.dispatchMessage(EventType.REPAINT); messageDispatcher.dispatchMessage(EventType.REPAINT);
if (ConfigurationManager.getInstance().readBoolean( if (componentTypeSlot.isAutoEdit()
IPlugInPort.AUTO_EDIT_KEY, false)) { && ConfigurationManager.getInstance()
.readBoolean(IPlugInPort.AUTO_EDIT_KEY,
false)) {
editSelection(); editSelection();
} }
if (ConfigurationManager.getInstance().readBoolean( if (ConfigurationManager.getInstance().readBoolean(
@@ -1541,8 +1544,8 @@ public class Presenter implements IPlugInPort {
.getInstance() .getInstance()
.extractComponentTypeFrom( .extractComponentTypeFrom(
(Class<? extends IDIYComponent<?>>) currentProject (Class<? extends IDIYComponent<?>>) currentProject
.getComponents().get(index - 1).getClass()) .getComponents().get(index - 1)
.getZOrder()) { .getClass()).getZOrder()) {
index--; index--;
} }
if (index < currentProject.getComponents().size()) { if (index < currentProject.getComponents().size()) {
@@ -4,8 +4,11 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.diylc.common.ComponentType; import org.diylc.common.ComponentType;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
@@ -27,8 +30,33 @@ public class BomMaker {
} }
public List<BomEntry> createBom(List<IDIYComponent<?>> components) { public List<BomEntry> createBom(List<IDIYComponent<?>> components) {
Map<String, BomEntry> entryMap = new HashMap<String, BomEntry>(); Map<String, BomEntry> entryMap = new LinkedHashMap<String, BomEntry>();
for (IDIYComponent<?> component : components) { List<IDIYComponent<?>> sortedComponents = new ArrayList<IDIYComponent<?>>(
components);
Collections.sort(sortedComponents, new Comparator<IDIYComponent<?>>() {
@Override
public int compare(IDIYComponent<?> o1, IDIYComponent<?> o2) {
String name1 = o1.getName();
String name2 = o2.getName();
Pattern p = Pattern.compile("(\\D*)(\\d*)");
Matcher m1 = p.matcher(name1);
Matcher m2 = p.matcher(name2);
if (m1.matches() && m2.matches()) {
String prefix1 = m1.group(1);
int value1 = Integer.parseInt(m1.group(2));
String prefix2 = m2.group(1);
int value2 = Integer.parseInt(m2.group(2));
int compare = prefix1.compareToIgnoreCase(prefix2);
if (compare != 0) {
return compare;
}
return new Integer(value1).compareTo(value2);
}
return 0;
}
});
for (IDIYComponent<?> component : sortedComponents) {
ComponentType type = ComponentProcessor.getInstance() ComponentType type = ComponentProcessor.getInstance()
.extractComponentTypeFrom( .extractComponentTypeFrom(
(Class<? extends IDIYComponent<?>>) component (Class<? extends IDIYComponent<?>>) component
@@ -54,17 +82,6 @@ public class BomMaker {
} }
} }
List<BomEntry> bom = new ArrayList<BomEntry>(entryMap.values()); List<BomEntry> bom = new ArrayList<BomEntry>(entryMap.values());
Collections.sort(bom, new Comparator<BomEntry>() {
@Override
public int compare(BomEntry o1, BomEntry o2) {
int compare = o1.getName().compareToIgnoreCase(o2.getName());
if (compare != 0) {
return compare;
}
return o1.getValue().compareToIgnoreCase(o2.getValue());
}
});
return bom; return bom;
} }
} }