keyword auto-generation

This commit is contained in:
Branislav Stojkovic
2016-10-30 01:04:26 +02:00
parent 5de31dd7bb
commit 5e00e3128b
279 changed files with 2127 additions and 756 deletions
@@ -6,6 +6,7 @@ import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.annotations.BomPolicy;
import org.diylc.core.annotations.IAutoCreator;
import org.diylc.core.annotations.KeywordPolicy;
/**
* Entity class used to describe a component type.
@@ -31,11 +32,12 @@ public class ComponentType {
private boolean autoEdit;
private boolean rotatable;
private IAutoCreator autoCreator;
private KeywordPolicy keywordPolicy;
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,
IAutoCreator autoCreator) {
IAutoCreator autoCreator, KeywordPolicy keywordPolicy) {
super();
this.name = name;
this.description = description;
@@ -52,6 +54,7 @@ public class ComponentType {
this.autoEdit = autoEdit;
this.rotatable = rotatable;
this.autoCreator = autoCreator;
this.keywordPolicy = keywordPolicy;
}
public String getName() {
@@ -113,6 +116,10 @@ public class ComponentType {
public IAutoCreator getAutoCreateor() {
return autoCreator;
}
public KeywordPolicy getKeywordPolicy() {
return keywordPolicy;
}
@Override
public String toString() {
@@ -8,14 +8,22 @@ import java.net.NetworkInterface;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.ComponentType;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Project;
import org.diylc.core.annotations.KeywordPolicy;
import org.diylc.plugins.cloud.model.CommentEntity;
import org.diylc.plugins.cloud.model.IServiceAPI;
import org.diylc.plugins.cloud.model.ProjectEntity;
import org.diylc.plugins.cloud.model.UserEntity;
import org.diylc.presenter.ComponentProcessor;
import com.diyfever.httpproxy.PhpFlatProxy;
import com.diyfever.httpproxy.ProxyFactory;
@@ -144,8 +152,8 @@ public class CloudPresenter {
try {
String res =
getService().upload(username, token, getMachineId(), projectName, category, description, diylcVersion, keywords,
thumbnail, project);
getService().upload(username, token, getMachineId(), projectName, category, description, diylcVersion,
keywords, thumbnail, project);
if (!res.equals(SUCCESS))
throw new CloudException(res);
} catch (Exception e) {
@@ -291,6 +299,25 @@ public class CloudPresenter {
}
}
@SuppressWarnings("unchecked")
public String extractKeywords(Project project) {
Set<String> words = new HashSet<String>();
for (IDIYComponent<?> c : project.getComponents()) {
ComponentType cType =
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass());
if (cType.getKeywordPolicy() == KeywordPolicy.SHOW_TYPE_NAME)
words.add(cType.getName().toLowerCase());
if (cType.getKeywordPolicy() == KeywordPolicy.SHOW_VALUE && c.getValueForDisplay() != null
&& c.getValueForDisplay().trim().length() > 0)
words.add(c.getValueForDisplay().trim().toLowerCase());
}
StringBuilder sb = new StringBuilder();
for (String w : words)
sb.append(w).append(",");
if (sb.length() > 0)
sb.deleteCharAt(sb.length() - 1);
return sb.toString();
}
private String getMachineId() {
if (machineId == null) {
@@ -3,6 +3,7 @@ package org.diylc.presenter;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.Desktop.Action;
import java.awt.image.BufferedImage;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -25,6 +26,7 @@ import org.diylc.core.annotations.BomPolicy;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.annotations.IAutoCreator;
import org.diylc.core.annotations.KeywordPolicy;
/**
* Utility class with component processing methods.
@@ -73,6 +75,7 @@ public class ComponentProcessor {
boolean autoEdit;
boolean rotatable;
IAutoCreator autoCreator = null;
KeywordPolicy keywordPolicy;
if (clazz.isAnnotationPresent(ComponentDescriptor.class)) {
ComponentDescriptor annotation = clazz.getAnnotation(ComponentDescriptor.class);
name = annotation.name();
@@ -87,6 +90,7 @@ public class ComponentProcessor {
bomPolicy = annotation.bomPolicy();
autoEdit = annotation.autoEdit();
rotatable = annotation.rotatable();
keywordPolicy = annotation.keywordPolicy();
} else {
name = clazz.getSimpleName();
description = "";
@@ -100,6 +104,7 @@ public class ComponentProcessor {
bomPolicy = BomPolicy.SHOW_ALL_NAMES;
autoEdit = true;
rotatable = true;
keywordPolicy = KeywordPolicy.NEVER_SHOW;
}
if (clazz.isAnnotationPresent(AutoCreator.class)) {
AutoCreator annotation = clazz.getAnnotation(AutoCreator.class);
@@ -127,7 +132,7 @@ public class ComponentProcessor {
}
ComponentType componentType =
new ComponentType(name, description, creationMethod, category, namePrefix, author, icon, clazz, zOrder,
flexibleZOrder, stretchable, bomPolicy, autoEdit, rotatable, autoCreator);
flexibleZOrder, stretchable, bomPolicy, autoEdit, rotatable, autoCreator, keywordPolicy);
componentTypeMap.put(clazz.getName(), componentType);
return componentType;
}
@@ -19,6 +19,7 @@ import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.Project;
import org.diylc.core.Template;
import org.diylc.core.annotations.KeywordPolicy;
import org.diylc.core.measures.Size;
/**
@@ -40,7 +41,7 @@ public class InstantiationManager {
private static final ComponentType clipboardType = new ComponentType("Clipboard contents",
"Components from the clipboard", CreationMethod.SINGLE_CLICK, "Multi", "", "", null, null, 0, false, false, null,
false, true, null);
false, true, null, KeywordPolicy.NEVER_SHOW);
public InstantiationManager() {}
@@ -89,7 +89,8 @@ public class Presenter implements IPlugInPort {
private Project currentProject;
private Map<String, List<ComponentType>> componentTypes;
/**
* {@link ComponentType}s that can be autocreated, like Solder Pads
* {@link List} of {@link IAutoCreator} objects that are capable of creating more components
* automatically when a component is created, e.g. Solder Pads.
*/
private List<IAutoCreator> autoCreators;
// Maps component class names to ComponentType objects.
@@ -1643,9 +1644,9 @@ public class Presenter implements IPlugInPort {
// Check if we should auto-create something.
for (IAutoCreator creator : this.getAutoCreators()) {
List<IDIYComponent<?>> newComponents = creator.createIfNeeded(component);
List<IDIYComponent<?>> newComponents = creator.createIfNeeded(component);
if (newComponents != null) {
for(IDIYComponent<?> c : newComponents)
for (IDIYComponent<?> c : newComponents)
addComponent(c, false);
}
}