mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
renamed BOM objects
This commit is contained in:
+2
-2
@@ -4,7 +4,7 @@ import java.awt.Point;
|
|||||||
|
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
import org.diylc.core.VisibilityPolicy;
|
import org.diylc.core.VisibilityPolicy;
|
||||||
import org.diylc.core.annotations.BomName;
|
import org.diylc.core.annotations.ComponentName;
|
||||||
import org.diylc.core.annotations.ControlPoint;
|
import org.diylc.core.annotations.ControlPoint;
|
||||||
import org.diylc.core.annotations.EditableProperty;
|
import org.diylc.core.annotations.EditableProperty;
|
||||||
import org.diylc.core.measures.Size;
|
import org.diylc.core.measures.Size;
|
||||||
@@ -48,7 +48,7 @@ public abstract class AbstractLeadedDIYComponent implements IDIYComponent {
|
|||||||
*/
|
*/
|
||||||
protected abstract Size getDefaultHeight();
|
protected abstract Size getDefaultHeight();
|
||||||
|
|
||||||
@BomName
|
@ComponentName
|
||||||
@EditableProperty
|
@EditableProperty
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
|
|||||||
+4
-4
@@ -7,8 +7,8 @@ import java.awt.Point;
|
|||||||
import org.diylc.core.ComponentState;
|
import org.diylc.core.ComponentState;
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
import org.diylc.core.VisibilityPolicy;
|
import org.diylc.core.VisibilityPolicy;
|
||||||
import org.diylc.core.annotations.BomName;
|
import org.diylc.core.annotations.ComponentName;
|
||||||
import org.diylc.core.annotations.BomValue;
|
import org.diylc.core.annotations.ComponentValue;
|
||||||
import org.diylc.core.annotations.ComponentDescriptor;
|
import org.diylc.core.annotations.ComponentDescriptor;
|
||||||
import org.diylc.core.annotations.ControlPoint;
|
import org.diylc.core.annotations.ControlPoint;
|
||||||
import org.diylc.core.annotations.EditableProperty;
|
import org.diylc.core.annotations.EditableProperty;
|
||||||
@@ -47,7 +47,7 @@ public class MockDIYComponent implements IDIYComponent {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@BomName
|
@ComponentName
|
||||||
@EditableProperty
|
@EditableProperty
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
@@ -75,7 +75,7 @@ public class MockDIYComponent implements IDIYComponent {
|
|||||||
this.testField = testField;
|
this.testField = testField;
|
||||||
}
|
}
|
||||||
|
|
||||||
@BomValue
|
@ComponentValue
|
||||||
@EditableProperty(defaultable = true)
|
@EditableProperty(defaultable = true)
|
||||||
public Capacitance getC() {
|
public Capacitance getC() {
|
||||||
return c;
|
return c;
|
||||||
|
|||||||
+3
-2
@@ -5,11 +5,12 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Annotates getter for the component name that will be shown in the BOM. Only
|
* Annotates getter for the component name that will be shown in the BOM. Only
|
||||||
* one getter per class may be tagged with this annotation.
|
* one getter per class may be tagged with this annotation and, must return
|
||||||
|
* string type and there has to be a matching setter.
|
||||||
*
|
*
|
||||||
* @author Branislav Stojkovic
|
* @author Branislav Stojkovic
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface BomName {
|
public @interface ComponentName {
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -10,6 +10,6 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
* @author Branislav Stojkovic
|
* @author Branislav Stojkovic
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface BomValue {
|
public @interface ComponentValue {
|
||||||
|
|
||||||
}
|
}
|
||||||
+2
-2
@@ -28,8 +28,8 @@ 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 HashMap<String, BomEntry>();
|
||||||
for (IDIYComponent component : components) {
|
for (IDIYComponent component : components) {
|
||||||
String name = ComponentProcessor.getInstance().extractBomName(component);
|
String name = ComponentProcessor.getInstance().extractComponentName(component);
|
||||||
String value = ComponentProcessor.getInstance().extractBomValue(component);
|
String value = ComponentProcessor.getInstance().extractComponentValue(component);
|
||||||
if ((name != null) && (value != null)) {
|
if ((name != null) && (value != null)) {
|
||||||
String key = name + "|" + value;
|
String key = name + "|" + value;
|
||||||
if (entryMap.containsKey(key)) {
|
if (entryMap.containsKey(key)) {
|
||||||
|
|||||||
+2
-2
@@ -193,14 +193,14 @@ public class StatusBar extends JPanel implements IPlugIn {
|
|||||||
if (componentsUnderCursor.size() == 1) {
|
if (componentsUnderCursor.size() == 1) {
|
||||||
getStatusLabel().setText(
|
getStatusLabel().setText(
|
||||||
"Drag \""
|
"Drag \""
|
||||||
+ ComponentProcessor.getInstance().extractBomName(
|
+ ComponentProcessor.getInstance().extractComponentName(
|
||||||
componentsUnderCursor.get(0)) + "\"");
|
componentsUnderCursor.get(0)) + "\"");
|
||||||
} else {
|
} else {
|
||||||
getStatusLabel().setText(
|
getStatusLabel().setText(
|
||||||
"Hold CTRL key to drag all "
|
"Hold CTRL key to drag all "
|
||||||
+ componentsUnderCursor.size()
|
+ componentsUnderCursor.size()
|
||||||
+ " components under the cursor or drag only \""
|
+ " components under the cursor or drag only \""
|
||||||
+ ComponentProcessor.getInstance().extractBomName(
|
+ ComponentProcessor.getInstance().extractComponentName(
|
||||||
componentsUnderCursor.get(0)) + "\"");
|
componentsUnderCursor.get(0)) + "\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-20
@@ -11,8 +11,8 @@ import org.apache.log4j.Logger;
|
|||||||
import org.diylc.common.ControlPointWrapper;
|
import org.diylc.common.ControlPointWrapper;
|
||||||
import org.diylc.common.PropertyWrapper;
|
import org.diylc.common.PropertyWrapper;
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
import org.diylc.core.annotations.BomName;
|
import org.diylc.core.annotations.ComponentName;
|
||||||
import org.diylc.core.annotations.BomValue;
|
import org.diylc.core.annotations.ComponentValue;
|
||||||
import org.diylc.core.annotations.ControlPoint;
|
import org.diylc.core.annotations.ControlPoint;
|
||||||
import org.diylc.core.annotations.EditableProperty;
|
import org.diylc.core.annotations.EditableProperty;
|
||||||
|
|
||||||
@@ -91,8 +91,8 @@ public class ComponentProcessor {
|
|||||||
* Reads all control points from the specified component class. Note than
|
* Reads all control points from the specified component class. Note than
|
||||||
* control points are cached, so it may happen that control points returned
|
* control points are cached, so it may happen that control points returned
|
||||||
* already have their values populated. Always use
|
* already have their values populated. Always use
|
||||||
* {@link ControlPointWrapper#readFrom(IDIYComponent)} to update their
|
* {@link ControlPointWrapper#readFrom(IDIYComponent)} to update their state
|
||||||
* state from an actual component.
|
* from an actual component.
|
||||||
*
|
*
|
||||||
* @param clazz
|
* @param clazz
|
||||||
* @return
|
* @return
|
||||||
@@ -135,8 +135,7 @@ public class ComponentProcessor {
|
|||||||
* @param selectedComponents
|
* @param selectedComponents
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public List<PropertyWrapper> getMutualSelectionProperties(
|
public List<PropertyWrapper> getMutualSelectionProperties(List<IDIYComponent> selectedComponents) {
|
||||||
List<IDIYComponent> selectedComponents) {
|
|
||||||
if (selectedComponents.isEmpty()) {
|
if (selectedComponents.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -177,16 +176,16 @@ public class ComponentProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the method annotated with {@link BomName} annotations and calls it
|
* Finds the method annotated with {@link ComponentName} annotations and
|
||||||
* to retrieve component name.
|
* calls it to retrieve component name.
|
||||||
*
|
*
|
||||||
* @param component
|
* @param component
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String extractBomName(IDIYComponent component) {
|
public String extractComponentName(IDIYComponent component) {
|
||||||
String name = null;
|
String name = null;
|
||||||
for (Method method : component.getClass().getMethods()) {
|
for (Method method : component.getClass().getMethods()) {
|
||||||
if (method.isAnnotationPresent(BomName.class)) {
|
if (method.isAnnotationPresent(ComponentName.class)) {
|
||||||
try {
|
try {
|
||||||
name = method.invoke(component).toString();
|
name = method.invoke(component).toString();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -198,36 +197,38 @@ public class ComponentProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the method annotated with {@link BomName} and it's matching setter
|
* Finds the method annotated with {@link ComponentName} and it's matching
|
||||||
* and calls the setter to update the component name.
|
* setter and calls the setter to update the component name.
|
||||||
*
|
*
|
||||||
* @param component
|
* @param component
|
||||||
* @param newBomName
|
* @param newName
|
||||||
*/
|
*/
|
||||||
public void writeBomName(IDIYComponent component, String newBomName) {
|
public void writeComponentName(IDIYComponent component, String newName) {
|
||||||
for (Method method : component.getClass().getMethods()) {
|
for (Method method : component.getClass().getMethods()) {
|
||||||
if (method.isAnnotationPresent(BomName.class)) {
|
if (method.isAnnotationPresent(ComponentName.class)) {
|
||||||
try {
|
try {
|
||||||
Method setter = component.getClass().getMethod(
|
Method setter = component.getClass().getMethod(
|
||||||
method.getName().replaceFirst("get", "set"), String.class);
|
method.getName().replaceFirst("get", "set"), String.class);
|
||||||
setter.invoke(component, newBomName);
|
setter.invoke(component, newName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
LOG.warn("Could not update component name on a component of type "
|
||||||
|
+ component.getClass().getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the method annotated with {@link BomValue} annotations and calls it
|
* Finds the method annotated with {@link ComponentValue} annotations and
|
||||||
* to retrieve component value.
|
* calls it to retrieve component value.
|
||||||
*
|
*
|
||||||
* @param component
|
* @param component
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String extractBomValue(IDIYComponent component) {
|
public String extractComponentValue(IDIYComponent component) {
|
||||||
String value = null;
|
String value = null;
|
||||||
for (Method method : component.getClass().getMethods()) {
|
for (Method method : component.getClass().getMethods()) {
|
||||||
if (method.isAnnotationPresent(BomValue.class)) {
|
if (method.isAnnotationPresent(ComponentValue.class)) {
|
||||||
try {
|
try {
|
||||||
value = method.invoke(component).toString();
|
value = method.invoke(component).toString();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
+2
-2
@@ -714,14 +714,14 @@ public class Presenter implements IPlugInPort {
|
|||||||
String name = namePrefix + i;
|
String name = namePrefix + i;
|
||||||
exists = false;
|
exists = false;
|
||||||
for (IDIYComponent c : currentProject.getComponents()) {
|
for (IDIYComponent c : currentProject.getComponents()) {
|
||||||
String cName = ComponentProcessor.getInstance().extractBomName(c);
|
String cName = ComponentProcessor.getInstance().extractComponentName(c);
|
||||||
if (cName.equals(name)) {
|
if (cName.equals(name)) {
|
||||||
exists = true;
|
exists = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ComponentProcessor.getInstance().writeBomName(component, namePrefix + i);
|
ComponentProcessor.getInstance().writeComponentName(component, namePrefix + i);
|
||||||
|
|
||||||
// Add it to the project.
|
// Add it to the project.
|
||||||
currentProject.getComponents().add(component);
|
currentProject.getComponents().add(component);
|
||||||
|
|||||||
Reference in New Issue
Block a user