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 stretchable;
private BomPolicy bomPolicy;
private boolean autoEdit;
public ComponentType(String name, String description, CreationMethod creationMethod,
String category, String namePrefix, String author, Icon icon,
Class<? extends IDIYComponent<?>> instanceClass, double zOrder, boolean flexibleZOrder,
boolean stretchable, BomPolicy bomPolicy) {
boolean stretchable, BomPolicy bomPolicy, boolean autoEdit) {
super();
this.name = name;
this.description = description;
@@ -45,6 +46,7 @@ public class ComponentType {
this.flexibleZOrder = flexibleZOrder;
this.stretchable = stretchable;
this.bomPolicy = bomPolicy;
this.autoEdit = autoEdit;
}
public String getName() {
@@ -94,6 +96,10 @@ public class ComponentType {
public BomPolicy getBomPolicy() {
return bomPolicy;
}
public boolean isAutoEdit() {
return autoEdit;
}
@Override
public String toString() {
@@ -71,4 +71,10 @@ public @interface ComponentDescriptor {
*/
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 stretchable;
BomPolicy bomPolicy;
boolean autoEdit;
if (clazz.isAnnotationPresent(ComponentDescriptor.class)) {
ComponentDescriptor annotation = clazz
.getAnnotation(ComponentDescriptor.class);
@@ -83,6 +84,7 @@ public class ComponentProcessor {
flexibleZOrder = annotation.flexibleZOrder();
stretchable = annotation.stretchable();
bomPolicy = annotation.bomPolicy();
autoEdit = annotation.autoEdit();
} else {
name = clazz.getSimpleName();
description = "";
@@ -94,6 +96,7 @@ public class ComponentProcessor {
flexibleZOrder = false;
stretchable = true;
bomPolicy = BomPolicy.SHOW_ALL_NAMES;
autoEdit = true;
}
icon = null;
// Draw component icon.
@@ -114,7 +117,7 @@ public class ComponentProcessor {
}
ComponentType componentType = new ComponentType(name, description,
creationMethod, category, namePrefix, author, icon, clazz,
zOrder, flexibleZOrder, stretchable, bomPolicy);
zOrder, flexibleZOrder, stretchable, bomPolicy, autoEdit);
componentTypeMap.put(clazz.getName(), componentType);
return componentType;
}
@@ -57,7 +57,7 @@ public class Presenter implements IPlugInPort {
private static final Logger LOG = Logger.getLogger(Presenter.class);
public static final VersionNumber CURRENT_VERSION = new VersionNumber(3,
11, 0);
12, 0);
public static final String DEFAULTS_KEY_PREFIX = "default.";
public static final List<IDIYComponent<?>> EMPTY_SELECTION = Collections
@@ -436,8 +436,9 @@ public class Presenter implements IPlugInPort {
.getName(), e);
}
if (ConfigurationManager.getInstance().readBoolean(
IPlugInPort.AUTO_EDIT_KEY, false)) {
if (componentTypeSlot.isAutoEdit()
&& ConfigurationManager.getInstance().readBoolean(
IPlugInPort.AUTO_EDIT_KEY, false)) {
editSelection();
}
if (ConfigurationManager.getInstance().readBoolean(
@@ -484,8 +485,10 @@ public class Presenter implements IPlugInPort {
updateSelection(newSelection);
messageDispatcher.dispatchMessage(EventType.REPAINT);
if (ConfigurationManager.getInstance().readBoolean(
IPlugInPort.AUTO_EDIT_KEY, false)) {
if (componentTypeSlot.isAutoEdit()
&& ConfigurationManager.getInstance()
.readBoolean(IPlugInPort.AUTO_EDIT_KEY,
false)) {
editSelection();
}
if (ConfigurationManager.getInstance().readBoolean(
@@ -1541,8 +1544,8 @@ public class Presenter implements IPlugInPort {
.getInstance()
.extractComponentTypeFrom(
(Class<? extends IDIYComponent<?>>) currentProject
.getComponents().get(index - 1).getClass())
.getZOrder()) {
.getComponents().get(index - 1)
.getClass()).getZOrder()) {
index--;
}
if (index < currentProject.getComponents().size()) {
@@ -4,8 +4,11 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.diylc.common.ComponentType;
import org.diylc.core.IDIYComponent;
@@ -27,8 +30,33 @@ public class BomMaker {
}
public List<BomEntry> createBom(List<IDIYComponent<?>> components) {
Map<String, BomEntry> entryMap = new HashMap<String, BomEntry>();
for (IDIYComponent<?> component : components) {
Map<String, BomEntry> entryMap = new LinkedHashMap<String, BomEntry>();
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()
.extractComponentTypeFrom(
(Class<? extends IDIYComponent<?>>) component
@@ -45,7 +73,7 @@ public class BomMaker {
entry.setQuantity(entry.getQuantity() + 1);
if (type.getBomPolicy() == BomPolicy.SHOW_ALL_NAMES) {
entry.setName(entry.getName() + ", " + name);
}
}
} else {
entryMap.put(key, new BomEntry(type.getName(), type
.getBomPolicy() == BomPolicy.SHOW_ALL_NAMES ? name
@@ -54,17 +82,6 @@ public class BomMaker {
}
}
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;
}
}