mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
add doc
component tag reorg
This commit is contained in:
@@ -4,6 +4,7 @@ import javax.swing.Icon;
|
||||
|
||||
import org.diylc.core.CreationMethod;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.annotations.AutoCreateTag;
|
||||
import org.diylc.core.annotations.BomPolicy;
|
||||
|
||||
/**
|
||||
@@ -29,11 +30,12 @@ public class ComponentType {
|
||||
private BomPolicy bomPolicy;
|
||||
private boolean autoEdit;
|
||||
private boolean rotatable;
|
||||
private String autoCreateName;
|
||||
private AutoCreateTag autoCreateTag;
|
||||
|
||||
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 autoEdit, boolean rotatable, String autoCreateName) {
|
||||
boolean flexibleZOrder, boolean stretchable, BomPolicy bomPolicy, boolean autoEdit, boolean rotatable,
|
||||
AutoCreateTag autoCreateTag) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
@@ -49,7 +51,7 @@ public class ComponentType {
|
||||
this.bomPolicy = bomPolicy;
|
||||
this.autoEdit = autoEdit;
|
||||
this.rotatable = rotatable;
|
||||
this.autoCreateName = autoCreateName;
|
||||
this.autoCreateTag = autoCreateTag;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -107,9 +109,9 @@ public class ComponentType {
|
||||
public boolean isRotatable() {
|
||||
return rotatable;
|
||||
}
|
||||
|
||||
public String getAutoCreateName() {
|
||||
return autoCreateName;
|
||||
|
||||
public AutoCreateTag getAutoCreateTag() {
|
||||
return autoCreateTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package org.diylc.core.annotations;
|
||||
|
||||
public enum AutoCreateTag {
|
||||
NONE, SOLDER_PAD
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package org.diylc.core.annotations;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
/**
|
||||
* Annotation for {@link IDIYComponent} implementation. Tells the core which component should be auto-created as a solder pad.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface AutoCreated {
|
||||
/**
|
||||
* @return auto-create type name.
|
||||
*/
|
||||
String name();
|
||||
}
|
||||
@@ -80,4 +80,8 @@ public @interface ComponentDescriptor {
|
||||
*/
|
||||
boolean rotatable() default true;
|
||||
|
||||
AutoCreateTag autoCreateTag() default AutoCreateTag.NONE;
|
||||
|
||||
KeywordPolicy keywordPolicy() default KeywordPolicy.NEVER_SHOW;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package org.diylc.core.annotations;
|
||||
|
||||
public enum KeywordPolicy {
|
||||
SHOW_TYPE_NAME, SHOW_VALUE, NEVER_SHOW,
|
||||
}
|
||||
@@ -20,7 +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.AutoCreated;
|
||||
import org.diylc.core.annotations.AutoCreateTag;
|
||||
import org.diylc.core.annotations.BomPolicy;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
@@ -71,7 +71,7 @@ public class ComponentProcessor {
|
||||
BomPolicy bomPolicy;
|
||||
boolean autoEdit;
|
||||
boolean rotatable;
|
||||
String autoCreateName = null;
|
||||
AutoCreateTag autoCreateTag = null;
|
||||
if (clazz.isAnnotationPresent(ComponentDescriptor.class)) {
|
||||
ComponentDescriptor annotation = clazz.getAnnotation(ComponentDescriptor.class);
|
||||
name = annotation.name();
|
||||
@@ -86,6 +86,7 @@ public class ComponentProcessor {
|
||||
bomPolicy = annotation.bomPolicy();
|
||||
autoEdit = annotation.autoEdit();
|
||||
rotatable = annotation.rotatable();
|
||||
autoCreateTag = annotation.autoCreateTag();
|
||||
} else {
|
||||
name = clazz.getSimpleName();
|
||||
description = "";
|
||||
@@ -99,10 +100,7 @@ public class ComponentProcessor {
|
||||
bomPolicy = BomPolicy.SHOW_ALL_NAMES;
|
||||
autoEdit = true;
|
||||
rotatable = true;
|
||||
}
|
||||
if (clazz.isAnnotationPresent(AutoCreated.class)) {
|
||||
AutoCreated annotation = clazz.getAnnotation(AutoCreated.class);
|
||||
autoCreateName = annotation.name();
|
||||
autoCreateTag = AutoCreateTag.NONE;
|
||||
}
|
||||
icon = null;
|
||||
// Draw component icon.
|
||||
@@ -122,7 +120,7 @@ public class ComponentProcessor {
|
||||
}
|
||||
ComponentType componentType =
|
||||
new ComponentType(name, description, creationMethod, category, namePrefix, author, icon, clazz, zOrder,
|
||||
flexibleZOrder, stretchable, bomPolicy, autoEdit, rotatable, autoCreateName);
|
||||
flexibleZOrder, stretchable, bomPolicy, autoEdit, rotatable, autoCreateTag);
|
||||
componentTypeMap.put(clazz.getName(), componentType);
|
||||
return componentType;
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ import org.diylc.core.IView;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.Template;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.core.annotations.AutoCreateTag;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@@ -63,8 +64,6 @@ import com.thoughtworks.xstream.io.xml.DomDriver;
|
||||
*/
|
||||
public class Presenter implements IPlugInPort {
|
||||
|
||||
private static final String SOLDER_PAD = "SolderPad";
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(Presenter.class);
|
||||
|
||||
public static VersionNumber CURRENT_VERSION = new VersionNumber(3, 0, 0);
|
||||
@@ -92,7 +91,7 @@ public class Presenter implements IPlugInPort {
|
||||
/**
|
||||
* {@link ComponentType}s that can be autocreated, like Solder Pads
|
||||
*/
|
||||
private Map<String, ComponentType> autoCreateTypes;
|
||||
private Map<AutoCreateTag, ComponentType> autoCreateTypes;
|
||||
// Maps component class names to ComponentType objects.
|
||||
private List<IPlugIn> plugIns;
|
||||
|
||||
@@ -353,13 +352,13 @@ public class Presenter implements IPlugInPort {
|
||||
return componentTypes;
|
||||
}
|
||||
|
||||
private Map<String, ComponentType> getAutoCreateTypes() {
|
||||
private Map<AutoCreateTag, ComponentType> getAutoCreateTypes() {
|
||||
if (autoCreateTypes == null) {
|
||||
autoCreateTypes = new HashMap<String, ComponentType>();
|
||||
autoCreateTypes = new HashMap<AutoCreateTag, ComponentType>();
|
||||
for (Map.Entry<String, List<ComponentType>> entry : getComponentTypes().entrySet()) {
|
||||
for (ComponentType t : entry.getValue()) {
|
||||
if (t.getAutoCreateName() != null)
|
||||
autoCreateTypes.put(t.getAutoCreateName(), t);
|
||||
if (t.getAutoCreateTag() != null)
|
||||
autoCreateTypes.put(t.getAutoCreateTag(), t);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1641,7 +1640,7 @@ public class Presenter implements IPlugInPort {
|
||||
currentProject.getComponents().add(component);
|
||||
}
|
||||
|
||||
ComponentType padType = getAutoCreateTypes().get(SOLDER_PAD);
|
||||
ComponentType padType = getAutoCreateTypes().get(AutoCreateTag.SOLDER_PAD);
|
||||
if (canCreatePads && ConfigurationManager.getInstance().readBoolean(IPlugInPort.AUTO_PADS_KEY, false)
|
||||
&& padType != null && !(component.getClass().equals(padType.getInstanceClass()))) {
|
||||
for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||
|
||||
Reference in New Issue
Block a user