From 162b67bf254458df7883c36c73ab53c15489a2d2 Mon Sep 17 00:00:00 2001 From: bancika Date: Thu, 16 Aug 2012 15:51:21 +0000 Subject: [PATCH] Remove junk from BOM (eyelets, wires, traces) --- .../src/org/diylc/common/ComponentType.java | 10 ++++++++- .../core/annotations/ComponentDescriptor.java | 7 ++++++- .../diylc/presenter/ComponentProcessor.java | 6 +++++- .../diylc/presenter/InstantiationManager.java | 1 + .../src/org/diylc/utils/BomEntry.java | 14 ++++++++++++- .../src/org/diylc/utils/BomMaker.java | 21 ++++++++++++++++--- 6 files changed, 52 insertions(+), 7 deletions(-) diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/common/ComponentType.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/common/ComponentType.java index f10717cb..1e1082c4 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/common/ComponentType.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/common/ComponentType.java @@ -4,6 +4,7 @@ import javax.swing.Icon; import org.diylc.core.CreationMethod; import org.diylc.core.IDIYComponent; +import org.diylc.core.annotations.BomPolicy; /** * Entity class used to describe a component type. @@ -24,10 +25,12 @@ public class ComponentType { private Class> instanceClass; private double zOrder; private boolean stretchable; + private BomPolicy bomPolicy; public ComponentType(String name, String description, CreationMethod creationMethod, String category, String namePrefix, String author, Icon icon, - Class> instanceClass, double zOrder, boolean stretchable) { + Class> instanceClass, double zOrder, + boolean stretchable, BomPolicy bomPolicy) { super(); this.name = name; this.description = description; @@ -39,6 +42,7 @@ public class ComponentType { this.instanceClass = instanceClass; this.zOrder = zOrder; this.stretchable = stretchable; + this.bomPolicy = bomPolicy; } public String getName() { @@ -80,6 +84,10 @@ public class ComponentType { public boolean isStretchable() { return stretchable; } + + public BomPolicy getBomPolicy() { + return bomPolicy; + } @Override public String toString() { diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/core/annotations/ComponentDescriptor.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/core/annotations/ComponentDescriptor.java index c9bbaa21..ad6b1f17 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/core/annotations/ComponentDescriptor.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/core/annotations/ComponentDescriptor.java @@ -14,7 +14,7 @@ import org.diylc.core.IDIYComponent; */ @Retention(RetentionPolicy.RUNTIME) public @interface ComponentDescriptor { - + /** * @return component type name. */ @@ -58,5 +58,10 @@ public @interface ComponentDescriptor { * move together with it. */ boolean stretchable() default true; + + /** + * @return controls what should be shown the BOM + */ + BomPolicy bomPolicy() default BomPolicy.SHOW_ALL_NAMES; } diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/ComponentProcessor.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/ComponentProcessor.java index 3eb9bee2..b32009e4 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/ComponentProcessor.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/ComponentProcessor.java @@ -20,6 +20,7 @@ import org.diylc.common.PropertyWrapper; import org.diylc.core.CreationMethod; import org.diylc.core.IDIYComponent; import org.diylc.core.IPropertyValidator; +import org.diylc.core.annotations.BomPolicy; import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.annotations.EditableProperty; @@ -70,6 +71,7 @@ public class ComponentProcessor { Icon icon; double zOrder; boolean stretchable; + BomPolicy bomPolicy; if (clazz.isAnnotationPresent(ComponentDescriptor.class)) { ComponentDescriptor annotation = clazz.getAnnotation(ComponentDescriptor.class); name = annotation.name(); @@ -80,6 +82,7 @@ public class ComponentProcessor { author = annotation.author(); zOrder = annotation.zOrder(); stretchable = annotation.stretchable(); + bomPolicy = annotation.bomPolicy(); } else { name = clazz.getSimpleName(); description = ""; @@ -89,6 +92,7 @@ public class ComponentProcessor { author = "Unknown"; zOrder = IDIYComponent.COMPONENT; stretchable = true; + bomPolicy = BomPolicy.SHOW_ALL_NAMES; } icon = null; // Draw component icon. @@ -108,7 +112,7 @@ public class ComponentProcessor { e.printStackTrace(); } ComponentType componentType = new ComponentType(name, description, creationMethod, - category, namePrefix, author, icon, clazz, zOrder, stretchable); + category, namePrefix, author, icon, clazz, zOrder, stretchable, bomPolicy); componentTypeMap.put(clazz.getName(), componentType); return componentType; } diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/InstantiationManager.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/InstantiationManager.java index b272ff7a..543d9f3e 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/InstantiationManager.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/presenter/InstantiationManager.java @@ -14,6 +14,7 @@ import org.diylc.common.Orientation; import org.diylc.common.PropertyWrapper; import org.diylc.core.IDIYComponent; import org.diylc.core.Project; +import org.diylc.core.annotations.ComponentDescriptor; import org.diylc.core.measures.Size; import com.rits.cloning.Cloner; diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/utils/BomEntry.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/utils/BomEntry.java index fb09a7fa..c8fa7510 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/utils/BomEntry.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/utils/BomEntry.java @@ -2,17 +2,23 @@ package org.diylc.utils; public class BomEntry { + private String type; private String name; private String value; private Integer quantity; private String notes; - public BomEntry(String name, String value, int quantity) { + public BomEntry(String type, String name, String value, int quantity) { super(); + this.type = type; this.name = name; this.value = value; this.quantity = quantity; } + + public String getType() { + return type; + } public String getName() { return name; @@ -50,6 +56,7 @@ public class BomEntry { public int hashCode() { final int prime = 31; int result = 1; + result = prime * result + ((type == null) ? 0 : type.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((notes == null) ? 0 : notes.hashCode()); result = prime * result + quantity; @@ -66,6 +73,11 @@ public class BomEntry { if (getClass() != obj.getClass()) return false; BomEntry other = (BomEntry) obj; + if (type == null) { + if (other.type != null) + return false; + } else if (!type.equals(other.type)) + return false; if (name == null) { if (other.name != null) return false; diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/utils/BomMaker.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/utils/BomMaker.java index e1b8da32..a5a29289 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/utils/BomMaker.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/utils/BomMaker.java @@ -7,7 +7,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.diylc.common.ComponentType; import org.diylc.core.IDIYComponent; +import org.diylc.core.annotations.BomPolicy; +import org.diylc.presenter.ComponentProcessor; public class BomMaker { @@ -26,15 +29,27 @@ public class BomMaker { public List createBom(List> components) { Map entryMap = new HashMap(); for (IDIYComponent component : components) { + ComponentType type = ComponentProcessor.getInstance() + .extractComponentTypeFrom( + (Class>) component + .getClass()); + if (type.getBomPolicy() == BomPolicy.NEVER_SHOW) + continue; String name = component.getName(); - String value = component.getValue() == null ? null : component.getValue().toString(); + String value = component.getValue() == null ? null : component + .getValue().toString(); if ((name != null) && (value != null)) { - String key = name + "|" + value; + String key = type.getName() + "|" + value; if (entryMap.containsKey(key)) { BomEntry entry = entryMap.get(key); entry.setQuantity(entry.getQuantity() + 1); + if (type.getBomPolicy() == BomPolicy.SHOW_ALL_NAMES) { + entry.setName(entry.getName() + ", " + name); + } } else { - entryMap.put(key, new BomEntry(name, value, 1)); + entryMap.put(key, new BomEntry(type.getName(), type + .getBomPolicy() == BomPolicy.SHOW_ALL_NAMES ? name + : type.getName(), value, 1)); } } }