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 00000000..35d01513 Binary files /dev/null and b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/images/document_edit.png differ diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/plugins/canvas/CanvasPanel.java b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/plugins/canvas/CanvasPanel.java index 822b8d93..caba0507 100644 --- a/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/plugins/canvas/CanvasPanel.java +++ b/ diy-layout-creator --username bancika@gmail.com/DIYLC/src/org/diylc/plugins/canvas/CanvasPanel.java @@ -166,8 +166,9 @@ class CanvasPanel extends JComponent implements Autoscroll { if (e.getKeyCode() == KeyEvent.VK_DELETE) { plugInPort.deleteSelectedComponents(); } -// plugInPort.mouseMoved(getMousePosition(), e.isControlDown(), e.isShiftDown(), e -// .isAltDown()); + // plugInPort.mouseMoved(getMousePosition(), e.isControlDown(), + // e.isShiftDown(), e + // .isAltDown()); } }); addMouseMotionListener(new MouseAdapter() { @@ -187,26 +188,31 @@ class CanvasPanel extends JComponent implements Autoscroll { if (e.getClickCount() == 2) { List 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