mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
import/export variants and building blocks
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
|
||||
DIY Layout Creator (DIYLC).
|
||||
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
|
||||
This file is part of DIYLC.
|
||||
|
||||
DIYLC is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
DIYLC is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
package org.diylc.common;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import org.diylc.core.IDIYComponent;
|
||||
|
||||
public class BuildingBlockPackage {
|
||||
|
||||
private Map<String, Collection<IDIYComponent<?>>> block;
|
||||
private String owner;
|
||||
|
||||
public BuildingBlockPackage(Map<String, Collection<IDIYComponent<?>>> blocks, String owner) {
|
||||
super();
|
||||
this.block = blocks;
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public Map<String, Collection<IDIYComponent<?>>> getBlocks() {
|
||||
return block;
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
*/
|
||||
package org.diylc.common;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface IBlockProcessor {
|
||||
|
||||
@@ -29,7 +31,9 @@ public interface IBlockProcessor {
|
||||
|
||||
void loadBlock(String blockName) throws InvalidBlockException;
|
||||
|
||||
void deleteBlock(String blockName);
|
||||
void deleteBlock(String blockName);
|
||||
|
||||
int importBlocks(String fileName) throws IOException;
|
||||
|
||||
public class BlockAlreadyExistsException extends Exception {
|
||||
|
||||
|
||||
@@ -21,8 +21,10 @@
|
||||
*/
|
||||
package org.diylc.common;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
import org.diylc.core.Template;
|
||||
|
||||
public interface IVariantProcessor {
|
||||
@@ -32,17 +34,19 @@ public interface IVariantProcessor {
|
||||
|
||||
void saveSelectedComponentAsVariant(String variantName);
|
||||
|
||||
List<Template> getVariantsFor(String categoryName, String componentTypeName);
|
||||
List<Template> getVariantsFor(ComponentType type);
|
||||
|
||||
List<Template> getVariantsForSelection();
|
||||
|
||||
void applyVariantToSelection(Template variant);
|
||||
|
||||
void deleteVariant(String categoryName, String componentTypeName, String variantName);
|
||||
void deleteVariant(ComponentType type, String variantName);
|
||||
|
||||
void setDefaultVariant(String categoryName, String componentTypeName, String variantName);
|
||||
void setDefaultVariant(ComponentType type, String variantName);
|
||||
|
||||
String getDefaultVariant(String categoryName, String componentTypeName);
|
||||
int importVariants(String fileName) throws IOException;
|
||||
|
||||
String getDefaultVariant(ComponentType type);
|
||||
|
||||
public class VariantAlreadyExistsException extends Exception {
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
|
||||
DIY Layout Creator (DIYLC).
|
||||
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||
|
||||
This file is part of DIYLC.
|
||||
|
||||
DIYLC is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
DIYLC is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
package org.diylc.common;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.diylc.core.Template;
|
||||
|
||||
public class VariantPackage {
|
||||
|
||||
private Map<String, List<Template>> variants;
|
||||
private String owner;
|
||||
|
||||
public VariantPackage(Map<String, List<Template>> variants, String owner) {
|
||||
super();
|
||||
this.variants = variants;
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public Map<String, List<Template>> getVariants() {
|
||||
return variants;
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,7 @@ import org.diylc.appframework.miscutils.Utils;
|
||||
import org.diylc.appframework.simplemq.MessageDispatcher;
|
||||
import org.diylc.appframework.update.Version;
|
||||
import org.diylc.appframework.update.VersionNumber;
|
||||
import org.diylc.common.BuildingBlockPackage;
|
||||
import org.diylc.common.ComponentType;
|
||||
import org.diylc.common.DrawOption;
|
||||
import org.diylc.common.EventType;
|
||||
@@ -63,6 +64,7 @@ import org.diylc.common.IKeyProcessor;
|
||||
import org.diylc.common.IPlugIn;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.common.VariantPackage;
|
||||
import org.diylc.core.ExpansionMode;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IView;
|
||||
@@ -2157,8 +2159,8 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
// try to find a default template if none is provided
|
||||
if (componentType != null && template == null) {
|
||||
String defaultTemplate = getDefaultVariant(componentType.getCategory(), componentType.getName());
|
||||
List<Template> templates = getVariantsFor(componentType.getCategory(), componentType.getName());
|
||||
String defaultTemplate = getDefaultVariant(componentType);
|
||||
List<Template> templates = getVariantsFor(componentType);
|
||||
if (templates != null && defaultTemplate != null)
|
||||
for (Template t : templates) {
|
||||
if (t.getName().equals(defaultTemplate)) {
|
||||
@@ -2205,7 +2207,7 @@ public class Presenter implements IPlugInPort {
|
||||
if (variantMap == null) {
|
||||
variantMap = new HashMap<String, List<Template>>();
|
||||
}
|
||||
String key = type.getCategory() + "." + type.getName();
|
||||
String key = type.getInstanceClass().getCanonicalName();
|
||||
List<Template> variants = variantMap.get(key);
|
||||
if (variants == null) {
|
||||
variants = new ArrayList<Template>();
|
||||
@@ -2293,7 +2295,7 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<Template> getVariantsFor(String categoryName, String componentTypeName) {
|
||||
public List<Template> getVariantsFor(ComponentType type) {
|
||||
Map<String, List<Template>> lookupMap = new TreeMap<String, List<Template>>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
Map<String, List<Template>> variantMap =
|
||||
@@ -2301,14 +2303,24 @@ public class Presenter implements IPlugInPort {
|
||||
if (variantMap != null)
|
||||
lookupMap.putAll(variantMap);
|
||||
|
||||
// try by class name and then by old category.type format
|
||||
String key1 = type.getInstanceClass().getCanonicalName();
|
||||
String key2 = type.getCategory() + "." + type.getName();
|
||||
|
||||
List<Template> variants = new ArrayList<Template>();
|
||||
if (variantMap != null) {
|
||||
List<Template> userVariants = variantMap.get(categoryName + "." + componentTypeName);
|
||||
List<Template> userVariants = variantMap.get(key1);
|
||||
if (userVariants != null && !userVariants.isEmpty())
|
||||
variants.addAll(userVariants);
|
||||
userVariants = variantMap.get(key2);
|
||||
if (userVariants != null && !userVariants.isEmpty())
|
||||
variants.addAll(userVariants);
|
||||
}
|
||||
if (defaultVariantMap != null) {
|
||||
List<Template> defaultVariants = defaultVariantMap.get(categoryName + "." + componentTypeName);
|
||||
List<Template> defaultVariants = defaultVariantMap.get(key1);
|
||||
if (defaultVariants != null && !defaultVariants.isEmpty())
|
||||
variants.addAll(defaultVariants);
|
||||
defaultVariants = defaultVariantMap.get(key2);
|
||||
if (defaultVariants != null && !defaultVariants.isEmpty())
|
||||
variants.addAll(defaultVariants);
|
||||
}
|
||||
@@ -2339,7 +2351,7 @@ public class Presenter implements IPlugInPort {
|
||||
else if (selectedType.getInstanceClass() != type.getInstanceClass())
|
||||
return null;
|
||||
}
|
||||
return getVariantsFor(selectedType.getCategory(), selectedType.getName());
|
||||
return getVariantsFor(selectedType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2370,12 +2382,26 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void deleteVariant(String categoryName, String componentTypeName, String templateName) {
|
||||
LOG.debug(String.format("deleteTemplate(%s, %s, %s)", categoryName, componentTypeName, templateName));
|
||||
public void deleteVariant(ComponentType type, String templateName) {
|
||||
LOG.debug(String.format("deleteTemplate(%s, %s)", type, templateName));
|
||||
Map<String, List<Template>> templateMap =
|
||||
(Map<String, List<Template>>) ConfigurationManager.getInstance().readObject(TEMPLATES_KEY, null);
|
||||
if (templateMap != null) {
|
||||
List<Template> templates = templateMap.get(categoryName + "." + componentTypeName);
|
||||
// try by class name and then by old category.type format
|
||||
String key1 = type.getInstanceClass().getCanonicalName();
|
||||
String key2 = type.getCategory() + "." + type.getName();
|
||||
|
||||
List<Template> templates = templateMap.get(key1);
|
||||
if (templates != null) {
|
||||
Iterator<Template> i = templates.iterator();
|
||||
while (i.hasNext()) {
|
||||
Template t = i.next();
|
||||
if (t.getName().equalsIgnoreCase(templateName)) {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
templates = templateMap.get(key2);
|
||||
if (templates != null) {
|
||||
Iterator<Template> i = templates.iterator();
|
||||
while (i.hasNext()) {
|
||||
@@ -2391,27 +2417,44 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void setDefaultVariant(String categoryName, String componentTypeName, String templateName) {
|
||||
LOG.debug(String.format("setTemplateDefault(%s, %s, %s)", categoryName, componentTypeName, templateName));
|
||||
public void setDefaultVariant(ComponentType type, String templateName) {
|
||||
LOG.debug(String.format("setTemplateDefault(%s, %s)", type, templateName));
|
||||
Map<String, String> defaultTemplateMap =
|
||||
(Map<String, String>) ConfigurationManager.getInstance().readObject(DEFAULT_TEMPLATES_KEY, null);
|
||||
if (defaultTemplateMap == null)
|
||||
defaultTemplateMap = new HashMap<String, String>();
|
||||
if (templateName.equals(defaultTemplateMap.get(categoryName + "." + componentTypeName)))
|
||||
defaultTemplateMap.remove(categoryName + "." + componentTypeName);
|
||||
else
|
||||
defaultTemplateMap.put(categoryName + "." + componentTypeName, templateName);
|
||||
|
||||
// try by class name and then by old category.type format
|
||||
String key1 = type.getInstanceClass().getCanonicalName();
|
||||
String key2 = type.getCategory() + "." + type.getName();
|
||||
|
||||
if (templateName.equals(defaultTemplateMap.get(key1)) || templateName.equals(defaultTemplateMap.get(key2))) {
|
||||
defaultTemplateMap.remove(key1);
|
||||
defaultTemplateMap.remove(key2);
|
||||
}
|
||||
else {
|
||||
// get rid of legacy key
|
||||
defaultTemplateMap.remove(key2);
|
||||
defaultTemplateMap.put(key1, templateName);
|
||||
}
|
||||
ConfigurationManager.getInstance().writeValue(DEFAULT_TEMPLATES_KEY, defaultTemplateMap);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public String getDefaultVariant(String categoryName, String componentTypeName) {
|
||||
public String getDefaultVariant(ComponentType type) {
|
||||
Map<String, String> defaultTemplateMap =
|
||||
(Map<String, String>) ConfigurationManager.getInstance().readObject(DEFAULT_TEMPLATES_KEY, null);
|
||||
if (defaultTemplateMap == null)
|
||||
return null;
|
||||
return defaultTemplateMap.get(categoryName + "." + componentTypeName);
|
||||
|
||||
String key1 = type.getInstanceClass().getCanonicalName();
|
||||
String key2 = type.getCategory() + "." + type.getName();
|
||||
|
||||
if (defaultTemplateMap.containsKey(key1))
|
||||
return defaultTemplateMap.get(key1);
|
||||
|
||||
return defaultTemplateMap.get(key2);
|
||||
}
|
||||
|
||||
private Set<IDIYComponent<?>> getLockedComponents() {
|
||||
@@ -2519,4 +2562,75 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
return extraSpace;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public int importVariants(String fileName) throws IOException {
|
||||
LOG.debug(String.format("importVariants(%s)", fileName));
|
||||
BufferedInputStream in = new BufferedInputStream(new FileInputStream(fileName));
|
||||
XStream xStream = new XStream(new DomDriver());
|
||||
|
||||
VariantPackage pkg = (VariantPackage) xStream.fromXML(in);
|
||||
|
||||
in.close();
|
||||
|
||||
if (pkg == null || pkg.getVariants().isEmpty())
|
||||
return 0;
|
||||
|
||||
Map<String, List<Template>> variantMap =
|
||||
(Map<String, List<Template>>) ConfigurationManager.getInstance().readObject(TEMPLATES_KEY, null);
|
||||
if (variantMap == null) {
|
||||
variantMap = new HashMap<String, List<Template>>();
|
||||
}
|
||||
|
||||
for (Map.Entry<String, List<Template>> entry : pkg.getVariants().entrySet()) {
|
||||
List<Template> templates;
|
||||
templates = variantMap.get(entry.getKey());
|
||||
if (templates == null)
|
||||
{
|
||||
templates = new ArrayList<Template>();
|
||||
variantMap.put(entry.getKey(), templates);
|
||||
}
|
||||
for (Template t : entry.getValue()) {
|
||||
templates.add(new Template(t.getName() + " by " + pkg.getOwner(), t.getValues(), t.getPoints()));
|
||||
}
|
||||
}
|
||||
|
||||
ConfigurationManager.getInstance().writeValue(TEMPLATES_KEY, variantMap);
|
||||
|
||||
LOG.info(String.format("Loaded variants for %d components", pkg.getVariants().size()));
|
||||
|
||||
return pkg.getVariants().size();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public int importBlocks(String fileName) throws IOException {
|
||||
LOG.debug(String.format("importBlocks(%s)", fileName));
|
||||
BufferedInputStream in = new BufferedInputStream(new FileInputStream(fileName));
|
||||
XStream xStream = new XStream(new DomDriver());
|
||||
|
||||
BuildingBlockPackage pkg = (BuildingBlockPackage) xStream.fromXML(in);
|
||||
|
||||
in.close();
|
||||
|
||||
if (pkg == null || pkg.getBlocks().isEmpty())
|
||||
return 0;
|
||||
|
||||
Map<String, Collection<IDIYComponent<?>>> blocks =
|
||||
(Map<String, Collection<IDIYComponent<?>>>) ConfigurationManager.getInstance().readObject(BLOCKS_KEY, null);
|
||||
if (blocks == null) {
|
||||
blocks = new HashMap<String, Collection<IDIYComponent<?>>>();
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Collection<IDIYComponent<?>>> entry : pkg.getBlocks().entrySet()) {
|
||||
blocks.put(entry.getKey() + " by " + pkg.getOwner(), entry.getValue());
|
||||
}
|
||||
|
||||
ConfigurationManager.getInstance().writeValue(BLOCKS_KEY, blocks);
|
||||
|
||||
LOG.info(String.format("Loaded building blocks for %d components", pkg.getBlocks().size()));
|
||||
|
||||
return pkg.getBlocks().size();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,5 +11,5 @@
|
||||
<stringAttribute key="org.eclipse.debug.core.source_locator_memento" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <sourceLookupDirector> <sourceContainers duplicates="false"> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;javaProject name=&quot;Library&quot;/&gt;&#13;&#10;" typeId="org.eclipse.jdt.launching.sourceContainer.javaProject"/> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;javaProject name=&quot;DIYLC&quot;/&gt;&#13;&#10;" typeId="org.eclipse.jdt.launching.sourceContainer.javaProject"/> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;javaProject name=&quot;diylc-core&quot;/&gt;&#13;&#10;" typeId="org.eclipse.jdt.launching.sourceContainer.javaProject"/> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;javaProject name=&quot;diylc-library&quot;/&gt;&#13;&#10;" typeId="org.eclipse.jdt.launching.sourceContainer.javaProject"/> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;default/&gt;&#13;&#10;" typeId="org.eclipse.debug.core.containerType.default"/> </sourceContainers> </sourceLookupDirector> "/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.diylc.DIYLCStarter"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="diylc-swing"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-splash:splash.png -Xms256m -Xmx512m -Dorg.diylc.scriptRun=true -Ddorg.diylc.debugContinuityAreas=true -Dorg.diylc.WriteStaticVariants=true -Ddorg.diylc.debugComponentAreas=true"/>
|
||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-splash:splash.png -Xms256m -Xmx512m -Dorg.diylc.scriptRun=true -Ddorg.diylc.debugContinuityAreas=true -Ddorg.diylc.WriteStaticVariants=true -Ddorg.diylc.debugComponentAreas=true"/>
|
||||
</launchConfiguration>
|
||||
|
||||
Binary file not shown.
@@ -62,7 +62,8 @@ public enum IconLoader {
|
||||
"pin_green.png"), CoffeebeanEdit("coffeebean_edit.png"), ApplicationEdit("application_edit.png"), ComponentAdd(
|
||||
"component_add.png"), History("history.png"), DocumentPlain("document_plain.png"), FitToSize("fit_to_size.png"), DocumentsGear(
|
||||
"documents_gear.png"), SplashResistor("splash_resistor.png"), SplashCeramic("splash_ceramic.png"), SplashElectrolytic(
|
||||
"splash_electrolytic.png"), SplashFilm("splash_film.png"), Splash("splash.png"), Help("help2.png"), ScrollInformation("scroll_information.png");
|
||||
"splash_electrolytic.png"), SplashFilm("splash_film.png"), Splash("splash.png"), Help("help2.png"), ScrollInformation("scroll_information.png"),
|
||||
Node("node.png");
|
||||
|
||||
protected String name;
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 865 B |
@@ -23,10 +23,14 @@ import java.awt.datatransfer.ClipboardOwner;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.print.PrinterException;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
@@ -35,14 +39,17 @@ import javax.swing.KeyStroke;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.appframework.miscutils.ConfigurationManager;
|
||||
import org.diylc.common.BuildingBlockPackage;
|
||||
import org.diylc.common.IComponentTransformer;
|
||||
import org.diylc.common.IPlugInPort;
|
||||
import org.diylc.common.ITask;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.common.VariantPackage;
|
||||
import org.diylc.core.ExpansionMode;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IView;
|
||||
import org.diylc.core.Project;
|
||||
import org.diylc.core.Template;
|
||||
import org.diylc.core.Theme;
|
||||
import org.diylc.core.measures.Nudge;
|
||||
import org.diylc.core.measures.Size;
|
||||
@@ -60,6 +67,9 @@ import org.diylc.swingframework.IDrawingProvider;
|
||||
import org.diylc.swingframework.export.DrawingExporter;
|
||||
import org.diylc.utils.BomEntry;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.io.xml.DomDriver;
|
||||
|
||||
public class ActionFactory {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(ActionFactory.class);
|
||||
@@ -112,6 +122,22 @@ public class ActionFactory {
|
||||
public PrintAction createPrintAction(IDrawingProvider drawingProvider, int keyModifiers) {
|
||||
return new PrintAction(drawingProvider, keyModifiers);
|
||||
}
|
||||
|
||||
public ExportVariantsAction createExportVariantsAction(ISwingUI swingUI) {
|
||||
return new ExportVariantsAction(swingUI);
|
||||
}
|
||||
|
||||
public ImportVariantsAction createImportVariantsAction(ISwingUI swingUI, IPlugInPort plugInPort) {
|
||||
return new ImportVariantsAction(swingUI, plugInPort);
|
||||
}
|
||||
|
||||
public ExportBlocksAction createExportBlocksAction(ISwingUI swingUI) {
|
||||
return new ExportBlocksAction(swingUI);
|
||||
}
|
||||
|
||||
public ImportBlocksAction createImportBlocksAction(ISwingUI swingUI, IPlugInPort plugInPort) {
|
||||
return new ImportBlocksAction(swingUI, plugInPort);
|
||||
}
|
||||
|
||||
public ExitAction createExitAction(IPlugInPort plugInPort) {
|
||||
return new ExitAction(plugInPort);
|
||||
@@ -653,11 +679,239 @@ public class ActionFactory {
|
||||
try {
|
||||
DrawingExporter.getInstance().print(this.drawingProvider);
|
||||
} catch (PrinterException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ExportVariantsAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ISwingUI swingUI;
|
||||
|
||||
public ExportVariantsAction(ISwingUI swingUI) {
|
||||
super();
|
||||
this.swingUI = swingUI;
|
||||
putValue(AbstractAction.NAME, "Export Variants");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
LOG.info("ExportVariantsAction triggered");
|
||||
Map<String, List<Template>> variantMap =
|
||||
(Map<String, List<Template>>) ConfigurationManager.getInstance().readObject(IPlugInPort.TEMPLATES_KEY, null);
|
||||
if (variantMap == null || variantMap.isEmpty()) {
|
||||
swingUI.showMessage("No variants found to export.", "Error", IView.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
final VariantPackage variantPkg = new VariantPackage(variantMap, System.getProperty("user.name"));
|
||||
|
||||
File initialFile =
|
||||
new File(variantPkg.getOwner() == null ? "variants.xml" : ("variants by "
|
||||
+ variantPkg.getOwner().toLowerCase() + ".xml"));
|
||||
|
||||
final File file =
|
||||
DialogFactory.getInstance().showSaveDialog(swingUI.getOwnerFrame(), FileFilterEnum.XML.getFilter(),
|
||||
initialFile, FileFilterEnum.XML.getExtensions()[0], null);
|
||||
|
||||
if (file != null) {
|
||||
swingUI.executeBackgroundTask(new ITask<Void>() {
|
||||
|
||||
@Override
|
||||
public Void doInBackground() throws Exception {
|
||||
LOG.debug("Exporting variants to " + file.getAbsolutePath());
|
||||
|
||||
try {
|
||||
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
|
||||
XStream xStream = new XStream(new DomDriver());
|
||||
xStream.toXML(variantPkg, out);
|
||||
out.close();
|
||||
LOG.info("Exported variants succesfully");
|
||||
} catch (IOException e) {
|
||||
LOG.error("Could not export variants", e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(Void result) {
|
||||
swingUI.showMessage("Variants exported to \"" + file.getName() + "\".", "Success",
|
||||
ISwingUI.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Exception e) {
|
||||
swingUI.showMessage("Could not export variants: " + e.getMessage(), "Error", ISwingUI.ERROR_MESSAGE);
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ImportVariantsAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ISwingUI swingUI;
|
||||
private IPlugInPort plugInPort;
|
||||
|
||||
public ImportVariantsAction(ISwingUI swingUI, IPlugInPort plugInPort) {
|
||||
super();
|
||||
this.swingUI = swingUI;
|
||||
this.plugInPort = plugInPort;
|
||||
putValue(AbstractAction.NAME, "Import Variants");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
LOG.info("ImportVariantsAction triggered");
|
||||
|
||||
|
||||
final File file =
|
||||
DialogFactory.getInstance().showOpenDialog(FileFilterEnum.XML.getFilter(),
|
||||
null, FileFilterEnum.XML.getExtensions()[0], null, swingUI.getOwnerFrame());
|
||||
|
||||
if (file != null) {
|
||||
swingUI.executeBackgroundTask(new ITask<Integer>() {
|
||||
|
||||
@Override
|
||||
public Integer doInBackground() throws Exception {
|
||||
return plugInPort.importVariants(file.getAbsolutePath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(Integer result) {
|
||||
swingUI.showMessage(result + " variant(s) imported from \"" + file.getName() + "\".", "Success",
|
||||
ISwingUI.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Exception e) {
|
||||
swingUI.showMessage("Could not import variants: " + e.getMessage(), "Error", ISwingUI.ERROR_MESSAGE);
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ExportBlocksAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ISwingUI swingUI;
|
||||
|
||||
public ExportBlocksAction(ISwingUI swingUI) {
|
||||
super();
|
||||
this.swingUI = swingUI;
|
||||
putValue(AbstractAction.NAME, "Export Building Blocks");
|
||||
// putValue(AbstractAction.SMALL_ICON, IconLoader.Print.getIcon());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
LOG.info("ExportBuildingBlocksAction triggered");
|
||||
Map<String, Collection<IDIYComponent<?>>> blocks =
|
||||
(Map<String, Collection<IDIYComponent<?>>>) ConfigurationManager.getInstance().readObject(IPlugInPort.BLOCKS_KEY, null);
|
||||
if (blocks == null || blocks.isEmpty()) {
|
||||
swingUI.showMessage("No building blocks found to export.", "Error", IView.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
final BuildingBlockPackage variantPkg = new BuildingBlockPackage(blocks, System.getProperty("user.name"));
|
||||
|
||||
File initialFile =
|
||||
new File(variantPkg.getOwner() == null ? "building blocks.xml" : ("building blocks by "
|
||||
+ variantPkg.getOwner().toLowerCase() + ".xml"));
|
||||
|
||||
final File file =
|
||||
DialogFactory.getInstance().showSaveDialog(swingUI.getOwnerFrame(), FileFilterEnum.XML.getFilter(),
|
||||
initialFile, FileFilterEnum.XML.getExtensions()[0], null);
|
||||
|
||||
if (file != null) {
|
||||
swingUI.executeBackgroundTask(new ITask<Void>() {
|
||||
|
||||
@Override
|
||||
public Void doInBackground() throws Exception {
|
||||
LOG.debug("Exporting variants to " + file.getAbsolutePath());
|
||||
|
||||
try {
|
||||
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
|
||||
XStream xStream = new XStream(new DomDriver());
|
||||
xStream.toXML(variantPkg, out);
|
||||
out.close();
|
||||
LOG.info("Exported building blocks succesfully");
|
||||
} catch (IOException e) {
|
||||
LOG.error("Could not export building blocks", e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(Void result) {
|
||||
swingUI.showMessage("Building blocks exported to \"" + file.getName() + "\".", "Success",
|
||||
ISwingUI.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Exception e) {
|
||||
swingUI.showMessage("Could not export building blocks: " + e.getMessage(), "Error", ISwingUI.ERROR_MESSAGE);
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ImportBlocksAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ISwingUI swingUI;
|
||||
private IPlugInPort plugInPort;
|
||||
|
||||
public ImportBlocksAction(ISwingUI swingUI, IPlugInPort plugInPort) {
|
||||
super();
|
||||
this.swingUI = swingUI;
|
||||
this.plugInPort = plugInPort;
|
||||
putValue(AbstractAction.NAME, "Import Building Blocks");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
LOG.info("ImportBlocksAction triggered");
|
||||
|
||||
|
||||
final File file =
|
||||
DialogFactory.getInstance().showOpenDialog(FileFilterEnum.XML.getFilter(),
|
||||
null, FileFilterEnum.XML.getExtensions()[0], null, swingUI.getOwnerFrame());
|
||||
|
||||
if (file != null) {
|
||||
swingUI.executeBackgroundTask(new ITask<Integer>() {
|
||||
|
||||
@Override
|
||||
public Integer doInBackground() throws Exception {
|
||||
return plugInPort.importBlocks(file.getAbsolutePath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete(Integer result) {
|
||||
swingUI.showMessage(result + " building block(s) imported from \"" + file.getName() + "\".", "Success",
|
||||
ISwingUI.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Exception e) {
|
||||
swingUI.showMessage("Could not import building blocks: " + e.getMessage(), "Error", ISwingUI.ERROR_MESSAGE);
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class ExitAction extends AbstractAction {
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public enum FileFilterEnum {
|
||||
|
||||
PNG("PNG Images (*.png)", "png"), PDF("PDF Files (*.pdf)", "pdf"), DIY("DIY Project Files (*.diy)", "diy"), EXCEL(
|
||||
"Excel Workbooks (*.xls)", "xls"), CSV("Comma Separated Files (*.csv)", "csv"), HTML("HTML Files (*.html)",
|
||||
"html"), IMAGES("Image Files (*.png, *.jpg, *.gif)", "png", "jpg", "gif");
|
||||
"html"), IMAGES("Image Files (*.png, *.jpg, *.gif)", "png", "jpg", "gif"), XML("XML Files (*.xml)", "xml");
|
||||
|
||||
FileFilter filter;
|
||||
String[] extensions;
|
||||
|
||||
@@ -46,7 +46,8 @@ public class FileMenuPlugin implements IPlugIn, IDynamicSubmenuHandler {
|
||||
private static final Logger LOG = Logger.getLogger(FileMenuPlugin.class);
|
||||
|
||||
private static final String FILE_TITLE = "File";
|
||||
private static final String TRACE_MASK_TITLE = "Trace Mask";
|
||||
private static final String TRACE_MASK_TITLE = "Trace Mask";
|
||||
private static final String INTEGRATION_TITLE = "Integration";
|
||||
|
||||
private ProjectDrawingProvider drawingProvider;
|
||||
private TraceMaskDrawingProvider traceMaskDrawingProvider;
|
||||
@@ -84,7 +85,14 @@ public class FileMenuPlugin implements IPlugIn, IDynamicSubmenuHandler {
|
||||
swingUI.injectMenuAction(
|
||||
actionFactory.createPrintAction(traceMaskDrawingProvider, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
|
||||
| KeyEvent.SHIFT_DOWN_MASK), TRACE_MASK_TITLE);
|
||||
swingUI.injectMenuAction(actionFactory.createBomAction(plugInPort), FILE_TITLE);
|
||||
swingUI.injectMenuAction(actionFactory.createBomAction(plugInPort), FILE_TITLE);
|
||||
swingUI.injectMenuAction(null, FILE_TITLE);
|
||||
swingUI.injectSubmenu(INTEGRATION_TITLE, IconLoader.Node.getIcon(), FILE_TITLE);
|
||||
swingUI.injectMenuAction(actionFactory.createImportBlocksAction(swingUI, plugInPort), INTEGRATION_TITLE);
|
||||
swingUI.injectMenuAction(actionFactory.createExportBlocksAction(swingUI), INTEGRATION_TITLE);
|
||||
swingUI.injectMenuAction(null, INTEGRATION_TITLE);
|
||||
swingUI.injectMenuAction(actionFactory.createImportVariantsAction(swingUI, plugInPort), INTEGRATION_TITLE);
|
||||
swingUI.injectMenuAction(actionFactory.createExportVariantsAction(swingUI), INTEGRATION_TITLE);
|
||||
swingUI.injectMenuAction(null, FILE_TITLE);
|
||||
swingUI.injectMenuAction(actionFactory.createExitAction(plugInPort), FILE_TITLE);
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ public class ComponentButtonFactory {
|
||||
}
|
||||
});
|
||||
|
||||
String defaultVariant = plugInPort.getDefaultVariant(componentType.getCategory(), componentType.getName());
|
||||
String defaultVariant = plugInPort.getDefaultVariant(componentType);
|
||||
|
||||
JLabel label = new JLabel(variant.getName().equals(defaultVariant) ? IconLoader.PinGreen.getIcon() : IconLoader.PinGrey.getIcon());
|
||||
label.setToolTipText(variant.getName().equals(defaultVariant) ? "Remove default variant" : "Set default variant");
|
||||
@@ -140,7 +140,7 @@ public class ComponentButtonFactory {
|
||||
JPopupMenu m = (JPopupMenu) c;
|
||||
m.setVisible(false);
|
||||
}
|
||||
plugInPort.setDefaultVariant(componentType.getCategory(), componentType.getName(), variant.getName());
|
||||
plugInPort.setDefaultVariant(componentType, variant.getName());
|
||||
e.consume();
|
||||
}
|
||||
});
|
||||
@@ -167,7 +167,7 @@ public class ComponentButtonFactory {
|
||||
if (result != JOptionPane.YES_OPTION) {
|
||||
return;
|
||||
}
|
||||
plugInPort.deleteVariant(componentType.getCategory(), componentType.getName(), variant.getName());
|
||||
plugInPort.deleteVariant(componentType, variant.getName());
|
||||
e.consume();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -257,7 +257,7 @@ class ComponentTabbedPane extends JTabbedPane {
|
||||
@Override
|
||||
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
|
||||
variantPopup.removeAll();
|
||||
List<Template> variants = plugInPort.getVariantsFor(componentType.getCategory(), componentType.getName());
|
||||
List<Template> variants = plugInPort.getVariantsFor(componentType);
|
||||
if (variants == null || variants.isEmpty()) {
|
||||
JMenuItem item = new JMenuItem("<no variants>");
|
||||
item.setEnabled(false);
|
||||
|
||||
@@ -463,7 +463,7 @@ public class TreePanel extends JPanel {
|
||||
popup.add(shortcutSubmenu);
|
||||
popup.add(new JSeparator());
|
||||
|
||||
List<Template> templates = plugInPort.getVariantsFor(componentType.getCategory(), componentType.getName());
|
||||
List<Template> templates = plugInPort.getVariantsFor(componentType);
|
||||
if (templates == null || templates.isEmpty()) {
|
||||
JMenuItem item = new JMenuItem("<no variants>");
|
||||
item.setEnabled(false);
|
||||
@@ -650,7 +650,7 @@ public class TreePanel extends JPanel {
|
||||
}
|
||||
|
||||
if (payload.getComponentType() != null) {
|
||||
List<Template> variants = plugInPort.getVariantsFor(payload.getComponentType().getCategory(), payload.getComponentType().getName());
|
||||
List<Template> variants = plugInPort.getVariantsFor(payload.getComponentType());
|
||||
if (variants != null && !variants.isEmpty()) {
|
||||
variantsHtml = " <a style=\"text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black; background-color: #D7FFC6; color: #666666;\">[+"
|
||||
+ variants.size() + "]</a>";
|
||||
|
||||
@@ -2397,6 +2397,10 @@
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Added extra work space around the layout that can be used to store additional components and helpers, but does not get exported to a file. Configurable from the menu</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>Ability to export and import building blocks and variants from the File menu</description>
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
|
||||
Reference in New Issue
Block a user