From c677e98cadc7b0806bb470b7b8f9ee5161c436ba Mon Sep 17 00:00:00 2001 From: bancika Date: Sat, 15 Jan 2011 10:31:07 +0000 Subject: [PATCH] editable project properties --- .../DIYLC/config.xml | 8 +-- .../src/org/diylc/common/IPlugInPort.java | 21 ++++++-- .../src/org/diylc/common/PropertyWrapper.java | 10 ++-- .../src/org/diylc/gui/DialogFactory.java | 5 +- .../gui/editor/PropertyEditorDialog.java | 8 +-- .../src/org/diylc/images/IconLoader.java | 3 +- .../src/org/diylc/images/document_edit.png | Bin 0 -> 765 bytes .../org/diylc/plugins/canvas/CanvasPanel.java | 50 ++++++++++-------- .../plugins/clipboard/ClipboardManager.java | 36 +++++++++++++ .../diylc/presenter/ComponentProcessor.java | 3 +- .../src/org/diylc/presenter/Presenter.java | 37 +++++++++++++ 11 files changed, 135 insertions(+), 46 deletions(-) create mode 100644 diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/images/document_edit.png diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/config.xml b/ diy-layout-creator --username bancika@gmail.com/DIYLC/config.xml index 65688254..6b58cd31 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/config.xml +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/config.xml @@ -7,12 +7,12 @@ - lastPath - C:\Documents and Settings\Branislav Stojkovic\Desktop + metric + true - metric - false + lastPath + C:\Documents and Settings\Branislav Stojkovic\Desktop default.org.diylc.components.semiconductors.DIL_IC:Value diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/IPlugInPort.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/IPlugInPort.java index 88b1d40a..0e524942 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/IPlugInPort.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/IPlugInPort.java @@ -288,11 +288,10 @@ public interface IPlugInPort { void setDefaultPropertyValue(String propertyName, Object value); /** - * Returns a list of properties that are mutual for all the selected - * components. Resulting list may be empty if selected components do not - * have mutual properties or can be null if the selection is empty. - * - * @return + * @return a list of properties that are mutual for all the selected + * components. Resulting list may be empty if selected components do + * not have mutual properties or can be null if the selection is + * empty. */ List getMutualSelectionProperties(); @@ -306,6 +305,18 @@ public interface IPlugInPort { */ void applyPropertiesToSelection(List properties) throws Exception; + /** + * @return a list of editable properties of the current project. + */ + List getProjectProperties(); + + /** + * Applies specified properties to the current project. + * + * @param properties + */ + void applyPropertiesToProject(List properties); + /** * Sets the new component slot. Specified component type will be used to * instantiate new component. diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/PropertyWrapper.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/PropertyWrapper.java index 0d943b4b..20829d82 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/PropertyWrapper.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/common/PropertyWrapper.java @@ -3,8 +3,6 @@ package org.diylc.common; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import org.diylc.core.IDIYComponent; - /** * Entity class for editable properties extracted from component objects. * Represents a single editable property together with it's current value. @@ -30,9 +28,9 @@ public class PropertyWrapper implements Cloneable { this.defaultable = defaultable; } - public void readFrom(IDIYComponent component) throws IllegalArgumentException, + public void readFrom(Object object) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { - this.value = getter.invoke(component); + this.value = getter.invoke(object); } // public void readUniqueFrom(IDIYComponent component) @@ -44,9 +42,9 @@ public class PropertyWrapper implements Cloneable { // } // } - public void writeTo(IDIYComponent component) throws IllegalArgumentException, + public void writeTo(Object object) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { - setter.invoke(component, value); + setter.invoke(object, value); } public String getName() { diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/gui/DialogFactory.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/gui/DialogFactory.java index af179495..792b0584 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/gui/DialogFactory.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/gui/DialogFactory.java @@ -56,8 +56,9 @@ public class DialogFactory { } } - public PropertyEditorDialog createPropertyEditorDialog(List properties) { - PropertyEditorDialog editor = new PropertyEditorDialog(mainFrame, properties); + public PropertyEditorDialog createPropertyEditorDialog(List properties, + String title) { + PropertyEditorDialog editor = new PropertyEditorDialog(mainFrame, properties, title); return editor; } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/gui/editor/PropertyEditorDialog.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/gui/editor/PropertyEditorDialog.java index db0fe1f6..4de9f841 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/gui/editor/PropertyEditorDialog.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/gui/editor/PropertyEditorDialog.java @@ -33,8 +33,8 @@ public class PropertyEditorDialog extends ButtonDialog { private List properties; private Set defaultedProperties; - public PropertyEditorDialog(JFrame owner, List properties) { - super(owner, "Component Editor", new String[] { ButtonDialog.OK, ButtonDialog.CANCEL }); + public PropertyEditorDialog(JFrame owner, List properties, String title) { + super(owner, title, new String[] { ButtonDialog.OK, ButtonDialog.CANCEL }); LOG.debug("Creating property editor for: " + properties); @@ -120,8 +120,8 @@ public class PropertyEditorDialog extends ButtonDialog { return defaultedProperties; } - public static boolean showFor(JFrame owner, List properties) { - PropertyEditorDialog editor = new PropertyEditorDialog(owner, properties); + public static boolean showFor(JFrame owner, List properties, String title) { + PropertyEditorDialog editor = new PropertyEditorDialog(owner, properties, title); editor.setVisible(true); if (OK.equals(editor.getSelectedButtonCaption())) { return true; diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/images/IconLoader.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/images/IconLoader.java index 4c1f5f12..ad5ae22f 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/images/IconLoader.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/images/IconLoader.java @@ -23,7 +23,8 @@ public enum IconLoader { "id_card.png"), IdCardAdd("id_card_add.png"), Chest("chest.png"), Upload("upload.png"), Wrench( "wrench.png"), Group("group.png"), Ungroup("ungroup.png"), TraceMask("trace_mask.png"), Faq( "faq.png"), Component("component.png"), Plugin("plugin.png"), Manual("manual.png"), Donate( - "donate.png"), Bug("bug.png"), AboutDialog("about_dialog.png"); + "donate.png"), Bug("bug.png"), AboutDialog("about_dialog.png"), DocumentEdit( + "document_edit.png"); protected String name; diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/images/document_edit.png b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/images/document_edit.png new file mode 100644 index 0000000000000000000000000000000000000000..35d01513a1bcbf844d3b10114c090c1b8f44c83b GIT binary patch literal 765 zcmVWdKcYATc!{L3L*!GB7YTATcpIGch_bG$1Q5F)%RM{uz1z000McNliru z)&&<0F*xfQnY#c0010qNS#tmY3h)2`3h)6!tTdPa000DMK}|sb0I`n?{9y$E00LD> zL_t(|+Kp06XcJKsJ@aWzv}BAe+FDZ)f0S<8+G+_Aq!O2+U~!{esY^E^bRoJC72G8t zq7WA%Dky><&`rRaklLzMOT|x<)>OgLT4LfPlbK}3`(9=wwWWCBHE;};tMlPU*4t;#t$1%oA>wh590vR( zTS*W^EK#I^NifP5^pc6-?lyR)M&R%Ey8MAHT|J_3owl_R+{{2=g6a|k0Rm?R6G=6J zO(#wv-@FrYE{9*R^0eGdSS|BA7WJiqKqP|)*(*rzis9CviZ!i$_|TrmS~pzY&?j9h(UXZuFG2f(B; zhT;5eG`brwk^F(tSQ=;h!brWy@X&-gf+jlxR)dKYBw0j#a~XHd3uy7J#bkOG@uAN+ zvTXo?4M99f-hdsy%&%Gf{*q|H>v7@TTog?{1v5W07=HB$!SzSc)36^}*;?@Ye+^8t z(gU_sTPtDvtb*v{H;4|sN9&5cIOsc$FVk6i+N!vA@hfQdD-=sCmw=lO6WG(zkIlUu zsCRG0SaP0^44aLA^pKsw;iGGbNPW*?M_?cFS_y{Qh~)fl%1L5cr properties = plugInPort .getMutualSelectionProperties(); - if (properties != null) { - if (properties.isEmpty()) { - - } else { - PropertyEditorDialog editor = DialogFactory.getInstance() - .createPropertyEditorDialog(properties); - editor.setVisible(true); - if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) { - try { - plugInPort.applyPropertiesToSelection(properties); - } catch (Exception e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - for (PropertyWrapper property : editor.getDefaultedProperties()) { - if (property.getValue() != null) { - plugInPort.setDefaultPropertyValue(property.getName(), - property.getValue()); - } - } + if (properties == null || properties.isEmpty()) { + properties = plugInPort.getProjectProperties(); + PropertyEditorDialog editor = DialogFactory.getInstance() + .createPropertyEditorDialog(properties, "Edit Project"); + editor.setVisible(true); + if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) { + plugInPort.applyPropertiesToProject(properties); + } + } else { + PropertyEditorDialog editor = DialogFactory.getInstance() + .createPropertyEditorDialog(properties, "Edit Selection"); + editor.setVisible(true); + if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) { + try { + plugInPort.applyPropertiesToSelection(properties); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + // Save default values. + for (PropertyWrapper property : editor.getDefaultedProperties()) { + if (property.getValue() != null) { + plugInPort.setDefaultPropertyValue(property.getName(), property + .getValue()); } } } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/plugins/clipboard/ClipboardManager.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/plugins/clipboard/ClipboardManager.java index 794e22ee..a89e6e6c 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/plugins/clipboard/ClipboardManager.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/plugins/clipboard/ClipboardManager.java @@ -19,10 +19,14 @@ import org.diylc.common.ComponentSelection; import org.diylc.common.EventType; import org.diylc.common.IPlugIn; import org.diylc.common.IPlugInPort; +import org.diylc.common.PropertyWrapper; import org.diylc.core.IDIYComponent; import org.diylc.core.Project; +import org.diylc.gui.DialogFactory; +import org.diylc.gui.editor.PropertyEditorDialog; import org.diylc.images.IconLoader; +import com.diyfever.gui.ButtonDialog; import com.diyfever.gui.undo.IUndoListener; import com.diyfever.gui.undo.UndoHandler; import com.rits.cloning.Cloner; @@ -76,6 +80,7 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner { plugInPort.injectMenuAction(pasteAction, EDIT_TITLE); plugInPort.injectMenuAction(null, EDIT_TITLE); plugInPort.injectMenuAction(new SelectAllAction(), EDIT_TITLE); + plugInPort.injectMenuAction(new EditProjectAction(), EDIT_TITLE); plugInPort.injectMenuAction(null, EDIT_TITLE); plugInPort.injectMenuAction(new GroupAction(), EDIT_TITLE); plugInPort.injectMenuAction(new UngroupAction(), EDIT_TITLE); @@ -232,6 +237,37 @@ public class ClipboardManager implements IPlugIn, ClipboardOwner { } } + class EditProjectAction extends AbstractAction { + + private static final long serialVersionUID = 1L; + + public EditProjectAction() { + super(); + putValue(AbstractAction.NAME, "Edit Project"); + putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_E, + ActionEvent.CTRL_MASK)); + putValue(AbstractAction.SMALL_ICON, IconLoader.DocumentEdit.getIcon()); + } + + @Override + public void actionPerformed(ActionEvent e) { + LOG.info("Edit Project triggered"); + List properties = plugInPort.getProjectProperties(); + PropertyEditorDialog editor = DialogFactory.getInstance().createPropertyEditorDialog( + properties, "Edit Project"); + editor.setVisible(true); + if (ButtonDialog.OK.equals(editor.getSelectedButtonCaption())) { + plugInPort.applyPropertiesToProject(properties); + } + // Save default values. + for (PropertyWrapper property : editor.getDefaultedProperties()) { + if (property.getValue() != null) { + plugInPort.setDefaultPropertyValue(property.getName(), property.getValue()); + } + } + } + } + // ClipboardOwner @Override diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/ComponentProcessor.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/ComponentProcessor.java index 5c2e3876..76b90772 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/ComponentProcessor.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/ComponentProcessor.java @@ -109,8 +109,7 @@ public class ComponentProcessor { * @param clazz * @return */ - @SuppressWarnings("unchecked") - public List extractProperties(Class clazz) { + public List extractProperties(Class clazz) { if (propertyCache.containsKey(clazz)) { return cloner.deepClone(propertyCache.get(clazz)); } diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java index e6f3ef2e..87afe2b1 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/presenter/Presenter.java @@ -1017,6 +1017,43 @@ public class Presenter implements IPlugInPort { } } + @Override + public List getProjectProperties() { + List properties = ComponentProcessor.getInstance().extractProperties( + Project.class); + try { + for (PropertyWrapper property : properties) { + property.readFrom(currentProject); + } + } catch (Exception e) { + LOG.error("Could not get project properties", e); + return null; + } + return properties; + } + + @Override + public void applyPropertiesToProject(List properties) { + LOG.debug(String.format("applyPropertiesToProject(%s)", properties)); + Project oldProject = cloner.deepClone(currentProject); + try { + for (PropertyWrapper property : properties) { + property.writeTo(currentProject); + } + } catch (Exception e) { + LOG.error("Could not apply project properties", e); + } finally { + // Notify the listeners. + if (!oldProject.equals(currentProject)) { + messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, cloner + .deepClone(currentProject), "Edit Project"); + } + messageDispatcher.dispatchMessage(EventType.REPAINT); + messageDispatcher.dispatchMessage(EventType.SELECTION_SIZE_CHANGED, + calculateSelectionDimension()); + } + } + @Override public void setNewComponentSlot(ComponentType componentType) { LOG.debug(String.format("setNewComponentSlot(%s)", componentType == null ? null