mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
improve auto-generated keywords
This commit is contained in:
@@ -33,11 +33,12 @@ public class ComponentType {
|
||||
private boolean rotatable;
|
||||
private IAutoCreator autoCreator;
|
||||
private KeywordPolicy keywordPolicy;
|
||||
private String keywordTag;
|
||||
|
||||
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, KeywordPolicy keywordPolicy) {
|
||||
IAutoCreator autoCreator, KeywordPolicy keywordPolicy, String keywordTag) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
@@ -55,6 +56,7 @@ public class ComponentType {
|
||||
this.rotatable = rotatable;
|
||||
this.autoCreator = autoCreator;
|
||||
this.keywordPolicy = keywordPolicy;
|
||||
this.keywordTag = keywordTag;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -120,6 +122,10 @@ public class ComponentType {
|
||||
public KeywordPolicy getKeywordPolicy() {
|
||||
return keywordPolicy;
|
||||
}
|
||||
|
||||
public String getKeywordTag() {
|
||||
return keywordTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -80,6 +80,19 @@ public @interface ComponentDescriptor {
|
||||
*/
|
||||
boolean rotatable() default true;
|
||||
|
||||
/**
|
||||
* Defines if and how a component should appear in auto-generated project keywords. See
|
||||
* {@link KeywordPolicy} for more info.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
KeywordPolicy keywordPolicy() default KeywordPolicy.NEVER_SHOW;
|
||||
|
||||
/**
|
||||
* Only used if {@link KeywordPolicy} is set to {@link KeywordPolicy#SHOW_TAG}.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String keywordTag() default "";
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,25 @@
|
||||
package org.diylc.core.annotations;
|
||||
|
||||
public enum KeywordPolicy {
|
||||
SHOW_TYPE_NAME, SHOW_VALUE, NEVER_SHOW,
|
||||
/**
|
||||
* The component is represented with its type.
|
||||
*/
|
||||
SHOW_TYPE_NAME,
|
||||
/**
|
||||
* The component is represented with its value.
|
||||
*/
|
||||
SHOW_VALUE,
|
||||
/**
|
||||
* The component is not important enough and will not be shown in the keywords.
|
||||
*/
|
||||
NEVER_SHOW,
|
||||
/**
|
||||
* The component is represented with the value of {@link ComponentDescriptor#keywordTag()}
|
||||
*/
|
||||
SHOW_TAG,
|
||||
/**
|
||||
* The component is represented with both the value of {@link ComponentDescriptor#keywordTag()}
|
||||
* and the actual component value
|
||||
*/
|
||||
SHOW_TAG_AND_VALUE,
|
||||
}
|
||||
|
||||
@@ -8,22 +8,14 @@ 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;
|
||||
@@ -299,26 +291,6 @@ 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) {
|
||||
try {
|
||||
|
||||
@@ -3,7 +3,6 @@ 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;
|
||||
@@ -76,6 +75,7 @@ public class ComponentProcessor {
|
||||
boolean rotatable;
|
||||
IAutoCreator autoCreator = null;
|
||||
KeywordPolicy keywordPolicy;
|
||||
String keywordTag;
|
||||
if (clazz.isAnnotationPresent(ComponentDescriptor.class)) {
|
||||
ComponentDescriptor annotation = clazz.getAnnotation(ComponentDescriptor.class);
|
||||
name = annotation.name();
|
||||
@@ -91,7 +91,8 @@ public class ComponentProcessor {
|
||||
autoEdit = annotation.autoEdit();
|
||||
rotatable = annotation.rotatable();
|
||||
keywordPolicy = annotation.keywordPolicy();
|
||||
} else {
|
||||
keywordTag = annotation.keywordTag();
|
||||
} else { // default
|
||||
name = clazz.getSimpleName();
|
||||
description = "";
|
||||
creationMethod = CreationMethod.SINGLE_CLICK;
|
||||
@@ -105,6 +106,7 @@ public class ComponentProcessor {
|
||||
autoEdit = true;
|
||||
rotatable = true;
|
||||
keywordPolicy = KeywordPolicy.NEVER_SHOW;
|
||||
keywordTag = null;
|
||||
}
|
||||
if (clazz.isAnnotationPresent(AutoCreator.class)) {
|
||||
AutoCreator annotation = clazz.getAnnotation(AutoCreator.class);
|
||||
@@ -132,7 +134,7 @@ public class ComponentProcessor {
|
||||
}
|
||||
ComponentType componentType =
|
||||
new ComponentType(name, description, creationMethod, category, namePrefix, author, icon, clazz, zOrder,
|
||||
flexibleZOrder, stretchable, bomPolicy, autoEdit, rotatable, autoCreator, keywordPolicy);
|
||||
flexibleZOrder, stretchable, bomPolicy, autoEdit, rotatable, autoCreator, keywordPolicy, keywordTag);
|
||||
componentTypeMap.put(clazz.getName(), componentType);
|
||||
return componentType;
|
||||
}
|
||||
|
||||
@@ -41,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, KeywordPolicy.NEVER_SHOW);
|
||||
false, true, null, KeywordPolicy.NEVER_SHOW, null);
|
||||
|
||||
public InstantiationManager() {}
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.diylc.utils;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.diylc.common.ComponentType;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.annotations.KeywordPolicy;
|
||||
import org.diylc.presenter.ComponentProcessor;
|
||||
|
||||
public class KeywordExtractor {
|
||||
|
||||
private static KeywordExtractor instance;
|
||||
|
||||
public static KeywordExtractor getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new KeywordExtractor();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private KeywordExtractor() {}
|
||||
|
||||
@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 || cType.getKeywordPolicy() == KeywordPolicy.SHOW_TAG_AND_VALUE)
|
||||
&& c.getValueForDisplay() != null && c.getValueForDisplay().trim().length() > 0)
|
||||
words.add(c.getValueForDisplay().trim().toLowerCase());
|
||||
if ((cType.getKeywordPolicy() == KeywordPolicy.SHOW_TAG || cType.getKeywordPolicy() == KeywordPolicy.SHOW_TAG_AND_VALUE)
|
||||
&& cType.getKeywordTag() != null && cType.getKeywordTag().length() > 0)
|
||||
words.add(cType.getKeywordTag().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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user