From e9a54d1fe2a3fd19f5efc43514cc7ce1a67fca81 Mon Sep 17 00:00:00 2001 From: bancika Date: Fri, 26 Apr 2013 12:05:34 +0000 Subject: [PATCH] Ability to import existing DIY files into a project --- .../src/org/diylc/images/IconLoader.java | 2 +- .../src/org/diylc/images/element_into.png | Bin 0 -> 595 bytes .../src/org/diylc/swing/ActionFactory.java | 86 ++++++++++++++++++ .../swing/plugins/file/FileMenuPlugin.java | 1 + .../diylc-swing/update.xml | 6 +- 5 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/images/element_into.png diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/images/IconLoader.java b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/images/IconLoader.java index b92ab115..5c6c6845 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/images/IconLoader.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/images/IconLoader.java @@ -38,7 +38,7 @@ public enum IconLoader { "size.png"), Front("front.png"), Back("back.png"), Pens("pens.png"), Sort( "sort.png"), ElementsSelection("elements_selection.png"), BranchAdd( "branch_add.png"), Briefcase_Add("briefcase_add.png"), RotateCW( - "rotate_cw.png"), RotateCCW("rotate_ccw.png"); + "rotate_cw.png"), RotateCCW("rotate_ccw.png"), ElementInto("element_into.png"); protected String name; diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/images/element_into.png b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/images/element_into.png new file mode 100644 index 0000000000000000000000000000000000000000..342537d729378cef218e0582bc85aa1a838e778d GIT binary patch literal 595 zcmV-Z0<8UsP)WdKueATl!`MrC3kGB7YRATcpIGdMaiH6SZ6F)%QqnH)+0000McNliru z)&&<0G63i`a^?U4010qNS#tmY3h)2`3h)6!tTdPa000DMK}|sb0I`n?{9y$E00FB> zL_t(|+TD^nNE}fVhW~SS#z|I3vmk zI}t$;Ha-v%1gjt^mfaM~3Q-cxLL$jNbh0z|UeDD9*9Tf@;el_?9XOAB{&Ru*XEcgc zc8?gx{NBLnr_4i4kgqd(y`l+w!h|iYH9XHdr-M`qQYt8A;h!WF z$VO4v@I?hzaCn@+gxO|vE08jHKerq}10fRXX-|v$HL)Wjxi0E^JTGG33Q(?#B02DE z2jtdpTIfu4Cd%|PjYdNn!yw|=c-!`|b#ft9lRfmIjfmVpX~hvd$6hjx?CcuHPn!Y{ zn7WcD8o{g{!8)JKJx!~JrtpPr8xhjX>ZLWZ)iWK;PbOC?QXZpA9G properties, Set defaultedProperties) { + return false; + } + }); + putValue(AbstractAction.NAME, "Import"); + putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke( + KeyEvent.VK_I, ActionEvent.CTRL_MASK)); + putValue(AbstractAction.SMALL_ICON, IconLoader.ElementInto.getIcon()); + } + + @Override + public void actionPerformed(ActionEvent e) { + LOG.info("ImportAction triggered"); + + final File file = DialogFactory.getInstance().showOpenDialog( + FileFilterEnum.DIY.getFilter(), null, + FileFilterEnum.DIY.getExtensions()[0], null); + if (file != null) { + swingUI.executeBackgroundTask(new ITask() { + + @Override + public Void doInBackground() throws Exception { + LOG.debug("Opening from " + file.getAbsolutePath()); + // Load project in temp presenter + presenter.loadProjectFromFile(file.getAbsolutePath()); + // Grab all components and paste them into the main presenter + plugInPort.pasteComponents(presenter.getCurrentProject().getComponents()); + // Cleanup components in the temp presenter, don't need them anymore + presenter.selectAll(); + presenter.deleteSelectedComponents(); + return null; + } + + @Override + public void complete(Void result) { + } + + @Override + public void failed(Exception e) { + swingUI.showMessage("Could not open file. " + + e.getMessage(), "Error", + ISwingUI.ERROR_MESSAGE); + } + }); + } + } + } public static class SaveAction extends AbstractAction { diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/file/FileMenuPlugin.java b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/file/FileMenuPlugin.java index aacd1d81..92b7ea39 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/file/FileMenuPlugin.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/file/FileMenuPlugin.java @@ -37,6 +37,7 @@ public class FileMenuPlugin implements IPlugIn { ActionFactory actionFactory = ActionFactory.getInstance(); swingUI.injectMenuAction(actionFactory.createNewAction(plugInPort), FILE_TITLE); swingUI.injectMenuAction(actionFactory.createOpenAction(plugInPort, swingUI), FILE_TITLE); + swingUI.injectMenuAction(actionFactory.createImportAction(plugInPort, swingUI), FILE_TITLE); swingUI.injectMenuAction(actionFactory.createSaveAction(plugInPort, swingUI), FILE_TITLE); swingUI.injectMenuAction(actionFactory.createSaveAsAction(plugInPort, swingUI), FILE_TITLE); swingUI.injectMenuAction(null, FILE_TITLE); diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/update.xml b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/update.xml index e83ff288..f04b9393 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/update.xml +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/update.xml @@ -1189,7 +1189,11 @@ 2013-04-25 20:00:00.000 CET - + + + NEW_FEATURE + Ability to import existing DIY files into a project + NEW_FEATURE Added primitive shapes - ellipse, polygon and (rounded) rectangle