mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
simplified auto-create logic
cloud management work
This commit is contained in:
@@ -31,14 +31,13 @@ public class ComponentType {
|
||||
private BomPolicy bomPolicy;
|
||||
private boolean autoEdit;
|
||||
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, String keywordTag) {
|
||||
KeywordPolicy keywordPolicy, String keywordTag) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
@@ -54,7 +53,6 @@ public class ComponentType {
|
||||
this.bomPolicy = bomPolicy;
|
||||
this.autoEdit = autoEdit;
|
||||
this.rotatable = rotatable;
|
||||
this.autoCreator = autoCreator;
|
||||
this.keywordPolicy = keywordPolicy;
|
||||
this.keywordTag = keywordTag;
|
||||
}
|
||||
@@ -115,14 +113,10 @@ public class ComponentType {
|
||||
return rotatable;
|
||||
}
|
||||
|
||||
public IAutoCreator getAutoCreateor() {
|
||||
return autoCreator;
|
||||
}
|
||||
|
||||
public KeywordPolicy getKeywordPolicy() {
|
||||
return keywordPolicy;
|
||||
}
|
||||
|
||||
|
||||
public String getKeywordTag() {
|
||||
return keywordTag;
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package org.diylc.core.annotations;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface AutoCreator {
|
||||
public Class<? extends IAutoCreator> creatorClass();
|
||||
}
|
||||
@@ -20,11 +20,9 @@ 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.AutoCreator;
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -73,7 +71,6 @@ public class ComponentProcessor {
|
||||
BomPolicy bomPolicy;
|
||||
boolean autoEdit;
|
||||
boolean rotatable;
|
||||
IAutoCreator autoCreator = null;
|
||||
KeywordPolicy keywordPolicy;
|
||||
String keywordTag;
|
||||
if (clazz.isAnnotationPresent(ComponentDescriptor.class)) {
|
||||
@@ -108,14 +105,6 @@ public class ComponentProcessor {
|
||||
keywordPolicy = KeywordPolicy.NEVER_SHOW;
|
||||
keywordTag = null;
|
||||
}
|
||||
if (clazz.isAnnotationPresent(AutoCreator.class)) {
|
||||
AutoCreator annotation = clazz.getAnnotation(AutoCreator.class);
|
||||
try {
|
||||
autoCreator = annotation.creatorClass().newInstance();
|
||||
} catch (Exception e) {
|
||||
LOG.error("Could not instantiate auto-creator for " + name, e);
|
||||
}
|
||||
}
|
||||
icon = null;
|
||||
// Draw component icon.
|
||||
try {
|
||||
@@ -134,7 +123,7 @@ public class ComponentProcessor {
|
||||
}
|
||||
ComponentType componentType =
|
||||
new ComponentType(name, description, creationMethod, category, namePrefix, author, icon, clazz, zOrder,
|
||||
flexibleZOrder, stretchable, bomPolicy, autoEdit, rotatable, autoCreator, keywordPolicy, keywordTag);
|
||||
flexibleZOrder, stretchable, bomPolicy, autoEdit, rotatable, 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, null);
|
||||
false, true, KeywordPolicy.NEVER_SHOW, null);
|
||||
|
||||
public InstantiationManager() {}
|
||||
|
||||
|
||||
@@ -312,42 +312,27 @@ public class Presenter implements IPlugInPort {
|
||||
Set<Class<?>> componentTypeClasses = null;
|
||||
try {
|
||||
componentTypeClasses = Utils.getClasses("org.diylc.components");
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
// for (String path : classPath) {
|
||||
// path = path.replace('\\', '/');
|
||||
// File f = new File(path);
|
||||
// try {
|
||||
// if (f.isDirectory()) {
|
||||
// LOG.info("Scanning folder for components: "
|
||||
// + f.getAbsolutePath());
|
||||
// componentTypeClasses.addAll(JarScanner.getInstance()
|
||||
// .scanFolder(path, IDIYComponent.class));
|
||||
// } else {
|
||||
// LOG.info("Scanning JAR for components: "
|
||||
// + f.getAbsolutePath());
|
||||
// componentTypeClasses.addAll(JarScanner.getInstance()
|
||||
// .scanJar(f, IDIYComponent.class));
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// LOG.warn("Could not scan path " + path, e);
|
||||
// }
|
||||
// }
|
||||
for (Class<?> clazz : componentTypeClasses) {
|
||||
if (!Modifier.isAbstract(clazz.getModifiers()) && IDIYComponent.class.isAssignableFrom(clazz)) {
|
||||
ComponentType componentType =
|
||||
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) clazz);
|
||||
List<ComponentType> nestedList;
|
||||
if (componentTypes.containsKey(componentType.getCategory())) {
|
||||
nestedList = componentTypes.get(componentType.getCategory());
|
||||
} else {
|
||||
nestedList = new ArrayList<ComponentType>();
|
||||
componentTypes.put(componentType.getCategory(), nestedList);
|
||||
|
||||
for (Class<?> clazz : componentTypeClasses) {
|
||||
if (!Modifier.isAbstract(clazz.getModifiers()) && IDIYComponent.class.isAssignableFrom(clazz)) {
|
||||
ComponentType componentType =
|
||||
ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) clazz);
|
||||
List<ComponentType> nestedList;
|
||||
if (componentTypes.containsKey(componentType.getCategory())) {
|
||||
nestedList = componentTypes.get(componentType.getCategory());
|
||||
} else {
|
||||
nestedList = new ArrayList<ComponentType>();
|
||||
componentTypes.put(componentType.getCategory(), nestedList);
|
||||
}
|
||||
nestedList.add(componentType);
|
||||
}
|
||||
nestedList.add(componentType);
|
||||
}
|
||||
|
||||
for (Map.Entry<String, List<ComponentType>> e : componentTypes.entrySet()) {
|
||||
LOG.debug(e.getKey() + ": " + e.getValue());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error loading component types", e);
|
||||
}
|
||||
}
|
||||
return componentTypes;
|
||||
@@ -356,11 +341,17 @@ public class Presenter implements IPlugInPort {
|
||||
public List<IAutoCreator> getAutoCreators() {
|
||||
if (autoCreators == null) {
|
||||
autoCreators = new ArrayList<IAutoCreator>();
|
||||
for (Map.Entry<String, List<ComponentType>> entry : getComponentTypes().entrySet()) {
|
||||
for (ComponentType t : entry.getValue()) {
|
||||
if (t.getAutoCreateor() != null)
|
||||
autoCreators.add(t.getAutoCreateor());
|
||||
Set<Class<?>> classes = null;
|
||||
try {
|
||||
classes = Utils.getClasses("org.diylc.components.autocreate");
|
||||
for (Class<?> clazz : classes) {
|
||||
if (IAutoCreator.class.isAssignableFrom(clazz)) {
|
||||
autoCreators.add((IAutoCreator) clazz.newInstance());
|
||||
LOG.debug("Loaded auto-cretor: " + clazz.getName());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error loading auto-creator types", e);
|
||||
}
|
||||
}
|
||||
return autoCreators;
|
||||
|
||||
+2
-1
@@ -1,10 +1,11 @@
|
||||
package org.diylc.components.connectivity;
|
||||
package org.diylc.components.autocreate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.components.connectivity.SolderPad;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.annotations.IAutoCreator;
|
||||
|
||||
@@ -11,7 +11,6 @@ import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.VisibilityPolicy;
|
||||
import org.diylc.core.annotations.AutoCreator;
|
||||
import org.diylc.core.annotations.BomPolicy;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
@@ -21,7 +20,6 @@ import org.diylc.core.measures.Size;
|
||||
import org.diylc.core.measures.SizeUnit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
@AutoCreator(creatorClass = SolderPadAutoCreator.class)
|
||||
@ComponentDescriptor(name = "Solder Pad", category = "Connectivity", author = "Branislav Stojkovic",
|
||||
description = "Copper solder pad, round or square", instanceNamePrefix = "Pad", stretchable = false,
|
||||
zOrder = IDIYComponent.TRACE + 0.1, bomPolicy = BomPolicy.NEVER_SHOW, autoEdit = false,
|
||||
|
||||
@@ -32,10 +32,10 @@ public enum IconLoader {
|
||||
"briefcase_into.png"), RotateCW("rotate_cw.png"), RotateCCW("rotate_ccw.png"), ElementInto("element_into.png"), Arrow(
|
||||
"arrow.png"), Cloud("cloud.png"), CloudUp("cloud_up.png"), CloudGear("cloud_gear.png"), IdCardEdit(
|
||||
"id_card_edit.png"), KeyEdit("key_edit.png"), Find("find.png"), Dashboard("dashboard.png"), DataFind(
|
||||
"data_find.png"), CloudDownload("cloud_download.png"), CloudUpload("cloud_upload.png"), NavLeftBlue(
|
||||
"nav_left_blue.png"), NavRightBlue("nav_right_blue.png"), MissingImage("missing_image.png"), CloudBg(
|
||||
"cloud_bg.png"), CloudBig("cloud_big.png"), CloudWait("cloud_wait.png"), Spinning("spinning.gif"), Megaphone(
|
||||
"megaphone.png"), Download("download.png"), Eye("eye.png"), Messages("messages.png");
|
||||
"data_find.png"), CloudDownload("cloud_download.png"), CloudDelete("cloud_delete.png"), CloudUpload(
|
||||
"cloud_upload.png"), NavLeftBlue("nav_left_blue.png"), NavRightBlue("nav_right_blue.png"), MissingImage(
|
||||
"missing_image.png"), CloudBg("cloud_bg.png"), CloudBig("cloud_big.png"), CloudWait("cloud_wait.png"), Spinning(
|
||||
"spinning.gif"), Megaphone("megaphone.png"), Download("download.png"), Eye("eye.png"), Messages("messages.png");
|
||||
|
||||
protected String name;
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 886 B |
+1
-1
@@ -176,7 +176,7 @@ public class CloudBrowserFrame extends JFrame implements ISimpleView {
|
||||
|
||||
private ResultsScrollPanel getResultsScrollPane() {
|
||||
if (resultsScrollPane == null) {
|
||||
resultsScrollPane = new ResultsScrollPanel(swingUI, this, plugInPort, pagingProvider, cloudPresenter);
|
||||
resultsScrollPane = new ResultsScrollPanel(swingUI, this, plugInPort, pagingProvider, cloudPresenter, false);
|
||||
}
|
||||
return resultsScrollPane;
|
||||
}
|
||||
|
||||
+35
-4
@@ -2,6 +2,7 @@ package org.diylc.swing.plugins.cloud.view.browser;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
@@ -81,14 +82,17 @@ public class ResultsScrollPanel extends JScrollPane {
|
||||
|
||||
private Icon spinnerIcon = IconLoader.Spinning.getIcon();
|
||||
|
||||
private boolean showEditControls;
|
||||
|
||||
public ResultsScrollPanel(ISwingUI mainUI, ISimpleView cloudUI, IPlugInPort plugInPort, PagingProvider provider,
|
||||
CloudPresenter cloudPresenter) {
|
||||
CloudPresenter cloudPresenter, boolean showEditControls) {
|
||||
super();
|
||||
this.mainUI = mainUI;
|
||||
this.cloudUI = cloudUI;
|
||||
this.plugInPort = plugInPort;
|
||||
this.provider = provider;
|
||||
this.cloudPresenter = cloudPresenter;
|
||||
this.showEditControls = showEditControls;
|
||||
|
||||
this.getVerticalScrollBar().setUnitIncrement(16);
|
||||
this.setBorder(null);
|
||||
@@ -230,6 +234,7 @@ public class ResultsScrollPanel extends JScrollPane {
|
||||
downloadButton.setBorderPainted(false);
|
||||
downloadButton.setContentAreaFilled(false);
|
||||
downloadButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
downloadButton.setToolTipText("Download to local drive");
|
||||
downloadButton.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
@@ -292,6 +297,25 @@ public class ResultsScrollPanel extends JScrollPane {
|
||||
}
|
||||
});
|
||||
|
||||
JButton reuploadButton = new JButton(IconLoader.CloudUpload.getIcon());
|
||||
reuploadButton.setContentAreaFilled(false);
|
||||
reuploadButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
reuploadButton.setToolTipText("Re-upload to the cloud");
|
||||
|
||||
JButton deleteButton = new JButton(IconLoader.CloudDelete.getIcon());
|
||||
deleteButton.setContentAreaFilled(false);
|
||||
deleteButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
deleteButton.setToolTipText("Delete from the cloud");
|
||||
|
||||
JPanel buttonPanel = new JPanel(new FlowLayout());
|
||||
buttonPanel.setBackground(Color.white);
|
||||
// buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
|
||||
buttonPanel.add(downloadButton);
|
||||
if (showEditControls) {
|
||||
buttonPanel.add(reuploadButton);
|
||||
buttonPanel.add(deleteButton);
|
||||
}
|
||||
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.anchor = GridBagConstraints.NORTHWEST;
|
||||
gbc.insets = new Insets(2, 2, 2, 2);
|
||||
@@ -308,6 +332,10 @@ public class ResultsScrollPanel extends JScrollPane {
|
||||
gbc.insets = new Insets(2, 6, 2, 2);
|
||||
getResultsPanel().add(nameLabel, gbc);
|
||||
|
||||
gbc.gridx++;
|
||||
gbc.weightx = 0.1;
|
||||
getResultsPanel().add(new JLabel(), gbc);
|
||||
|
||||
gbc.gridx++;
|
||||
gbc.weightx = 0;
|
||||
getResultsPanel().add(commentLabel, gbc);
|
||||
@@ -322,7 +350,7 @@ public class ResultsScrollPanel extends JScrollPane {
|
||||
gbc.gridx = 1;
|
||||
gbc.weighty = 1;
|
||||
gbc.weightx = 1;
|
||||
gbc.gridwidth = 5;
|
||||
gbc.gridwidth = 6;
|
||||
gbc.anchor = GridBagConstraints.NORTHWEST;
|
||||
gbc.fill = GridBagConstraints.BOTH;
|
||||
gbc.insets = new Insets(2, 6, 2, 2);
|
||||
@@ -330,19 +358,22 @@ public class ResultsScrollPanel extends JScrollPane {
|
||||
|
||||
gbc.gridy++;
|
||||
gbc.gridwidth = 1;
|
||||
gbc.weightx = 1;
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
gbc.weighty = 0;
|
||||
getResultsPanel().add(categoryLabel, gbc);
|
||||
|
||||
gbc.gridx++;
|
||||
gbc.gridheight = 3;
|
||||
gbc.gridwidth = 3;
|
||||
gbc.gridwidth = 4;
|
||||
gbc.weightx = 0;
|
||||
gbc.insets = new Insets(2, 2, 2, 2);
|
||||
gbc.anchor = GridBagConstraints.SOUTHEAST;
|
||||
getResultsPanel().add(downloadButton, gbc);
|
||||
getResultsPanel().add(buttonPanel, gbc);
|
||||
|
||||
gbc.gridy++;
|
||||
gbc.gridx = 1;
|
||||
gbc.weightx = 1;
|
||||
gbc.gridheight = 1;
|
||||
gbc.insets = new Insets(2, 6, 2, 2);
|
||||
gbc.anchor = GridBagConstraints.NORTHWEST;
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ public class UploadManagerFrame extends JFrame implements ISimpleView {
|
||||
|
||||
private ResultsScrollPanel getResultsScrollPane() {
|
||||
if (resultsScrollPane == null) {
|
||||
resultsScrollPane = new ResultsScrollPanel(swingUI, this, plugInPort, null, cloudPresenter);
|
||||
resultsScrollPane = new ResultsScrollPanel(swingUI, this, plugInPort, null, cloudPresenter, true);
|
||||
}
|
||||
return resultsScrollPane;
|
||||
}
|
||||
|
||||
@@ -9,8 +9,7 @@ import org.apache.log4j.Logger;
|
||||
import org.diylc.common.EventType;
|
||||
import org.diylc.common.IPlugIn;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.components.connectivity.SolderPad;
|
||||
import org.diylc.components.connectivity.SolderPadAutoCreator;
|
||||
import org.diylc.components.autocreate.SolderPadAutoCreator;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.images.IconLoader;
|
||||
import org.diylc.swing.ActionFactory;
|
||||
|
||||
Reference in New Issue
Block a user