diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/lib/diylc-core.jar b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/lib/diylc-core.jar index 9d5585e0..ccf7a42b 100644 Binary files a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/lib/diylc-core.jar and b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/lib/diylc-core.jar differ diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/library/main.jar b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/library/main.jar index 7eafb229..4a95af99 100644 Binary files a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/library/main.jar and b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/library/main.jar differ 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 5c6c6845..15adbee6 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 @@ -37,8 +37,9 @@ public enum IconLoader { "document_edit.png"), EditComponent("edit_component.png"), Size( "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"), ElementInto("element_into.png"); + "branch_add.png"), BriefcaseAdd("briefcase_add.png"), BriefcaseInto( + "briefcase_into.png"), RotateCW("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/briefcase_into.png b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/images/briefcase_into.png new file mode 100644 index 00000000..f01a999d Binary files /dev/null and b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/images/briefcase_into.png differ diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/ActionFactory.java b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/ActionFactory.java index c178564f..b5198ce8 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/ActionFactory.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/ActionFactory.java @@ -22,6 +22,7 @@ import org.diylc.common.PropertyWrapper; import org.diylc.core.ExpansionMode; import org.diylc.core.IDIYComponent; import org.diylc.core.IView; +import org.diylc.core.Template; import org.diylc.core.Theme; import org.diylc.images.IconLoader; import org.diylc.presenter.Presenter; @@ -60,8 +61,9 @@ public class ActionFactory { public OpenAction createOpenAction(IPlugInPort plugInPort, ISwingUI swingUI) { return new OpenAction(plugInPort, swingUI); } - - public ImportAction createImportAction(IPlugInPort plugInPort, ISwingUI swingUI) { + + public ImportAction createImportAction(IPlugInPort plugInPort, + ISwingUI swingUI) { return new ImportAction(plugInPort, swingUI); } @@ -270,7 +272,7 @@ public class ActionFactory { } } } - + public static class ImportAction extends AbstractAction { private static final long serialVersionUID = 1L; @@ -286,31 +288,35 @@ public class ActionFactory { this.presenter = new Presenter(new IView() { @Override - public int showConfirmDialog(String message, String title, int optionType, - int messageType) { + public int showConfirmDialog(String message, String title, + int optionType, int messageType) { return JOptionPane.showConfirmDialog(null, message, title, optionType, messageType); } @Override - public void showMessage(String message, String title, int messageType) { - JOptionPane.showMessageDialog(null, message, title, messageType); + public void showMessage(String message, String title, + int messageType) { + JOptionPane.showMessageDialog(null, message, title, + messageType); } - + @Override public File promptFileSave() { return null; } - + @Override - public boolean editProperties(List properties, Set defaultedProperties) { + public boolean editProperties(List 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()); + putValue(AbstractAction.SMALL_ICON, IconLoader.ElementInto + .getIcon()); } @Override @@ -328,9 +334,12 @@ public class ActionFactory { 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 + // 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; @@ -911,7 +920,7 @@ public class ActionFactory { super(); this.plugInPort = plugInPort; putValue(AbstractAction.NAME, "Save as Template"); - putValue(AbstractAction.SMALL_ICON, IconLoader.Briefcase_Add + putValue(AbstractAction.SMALL_ICON, IconLoader.BriefcaseAdd .getIcon()); } @@ -1006,6 +1015,8 @@ public class ActionFactory { this.plugInPort = plugInPort; putValue(AbstractAction.NAME, "Send Backward"); putValue(AbstractAction.SMALL_ICON, IconLoader.Back.getIcon()); + putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke( + KeyEvent.VK_DOWN, ActionEvent.ALT_MASK)); } @Override @@ -1026,6 +1037,8 @@ public class ActionFactory { this.plugInPort = plugInPort; putValue(AbstractAction.NAME, "Bring Forward"); putValue(AbstractAction.SMALL_ICON, IconLoader.Front.getIcon()); + putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke( + KeyEvent.VK_UP, ActionEvent.ALT_MASK)); } @Override diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/canvas/CanvasPlugin.java b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/canvas/CanvasPlugin.java index fd618ae4..215a533d 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/canvas/CanvasPlugin.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/canvas/CanvasPlugin.java @@ -23,6 +23,7 @@ import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; import org.apache.log4j.Logger; import org.diylc.appframework.miscutils.ConfigurationManager; @@ -33,6 +34,7 @@ import org.diylc.common.IPlugIn; import org.diylc.common.IPlugInPort; import org.diylc.core.ExpansionMode; import org.diylc.core.IDIYComponent; +import org.diylc.core.Template; import org.diylc.core.measures.Size; import org.diylc.core.measures.SizeUnit; import org.diylc.images.IconLoader; @@ -53,6 +55,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner { private JPopupMenu popupMenu; private JMenu selectionMenu; private JMenu expandMenu; + private JMenu applyTemplateMenu; private ActionFactory.CutAction cutAction; private ActionFactory.CopyAction copyAction; @@ -104,37 +107,52 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner { } @Override - public void mouseReleased(MouseEvent e) { - if (plugInPort.getNewComponentTypeSlot() == null - && e.isPopupTrigger()) { - // Enable actions. - boolean enabled = !plugInPort.getSelectedComponents() - .isEmpty(); - getCutAction().setEnabled(enabled); - getCopyAction().setEnabled(enabled); - try { - getPasteAction() - .setEnabled( - clipboard - .isDataFlavorAvailable(ComponentTransferable.listFlavor)); - } catch (Exception ex) { - getPasteAction().setEnabled(false); + public void mouseReleased(final MouseEvent e) { + plugInPort.mouseClicked(e.getPoint(), e.getButton(), e + .isControlDown(), e.isShiftDown(), e.isAltDown(), e + .getClickCount()); + // Invoke the rest of the code later so we get the chance to + // process selection messages. + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + if (plugInPort.getNewComponentTypeSlot() == null + && e.isPopupTrigger()) { + // Enable actions. + boolean enabled = !plugInPort + .getSelectedComponents().isEmpty(); + getCutAction().setEnabled(enabled); + getCopyAction().setEnabled(enabled); + try { + getPasteAction() + .setEnabled( + clipboard + .isDataFlavorAvailable(ComponentTransferable.listFlavor)); + } catch (Exception ex) { + getPasteAction().setEnabled(false); + } + getEditSelectionAction().setEnabled(enabled); + getDeleteSelectionAction().setEnabled(enabled); + getExpandSelectionAllAction().setEnabled( + enabled); + getExpandSelectionImmediateAction().setEnabled( + enabled); + getExpandSelectionSameTypeAction().setEnabled( + enabled); + getGroupAction().setEnabled(enabled); + getUngroupAction().setEnabled(enabled); + getSendToBackAction().setEnabled(enabled); + getBringToFrontAction().setEnabled(enabled); + + getSaveAsTemplateAction().setEnabled( + plugInPort.getSelectedComponents() + .size() == 1); + + showPopupAt(e.getX(), e.getY()); + } } - getEditSelectionAction().setEnabled(enabled); - getDeleteSelectionAction().setEnabled(enabled); - getExpandSelectionAllAction().setEnabled(enabled); - getExpandSelectionImmediateAction().setEnabled(enabled); - getExpandSelectionSameTypeAction().setEnabled(enabled); - getGroupAction().setEnabled(enabled); - getUngroupAction().setEnabled(enabled); - getSendToBackAction().setEnabled(enabled); - getBringToFrontAction().setEnabled(enabled); - - getSaveAsTemplateAction().setEnabled( - plugInPort.getSelectedComponents().size() == 1); - - showPopupAt(e.getX(), e.getY()); - } + }); } }); @@ -158,14 +176,12 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner { .isShiftDown(), e.isAltDown()); } }); - + canvasPanel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - plugInPort.mouseClicked(e.getPoint(), e.getButton(), e - .isControlDown(), e.isShiftDown(), e.isAltDown(), e - .getClickCount()); + } }); } @@ -234,6 +250,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner { private void showPopupAt(int x, int y) { updateSelectionMenu(x, y); + updateApplyTemplateMenu(); getPopupMenu().show(canvasPanel, x, y); } @@ -255,6 +272,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner { popupMenu.add(getSendToBackAction()); popupMenu.add(getBringToFrontAction()); popupMenu.add(getSaveAsTemplateAction()); + popupMenu.add(getApplyTemplateMenu()); popupMenu.add(getExpandMenu()); popupMenu.addSeparator(); popupMenu.add(ActionFactory.getInstance().createEditProjectAction( @@ -282,6 +300,14 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner { return expandMenu; } + public JMenu getApplyTemplateMenu() { + if (applyTemplateMenu == null) { + applyTemplateMenu = new JMenu("Apply Template"); + applyTemplateMenu.setIcon(IconLoader.BriefcaseInto.getIcon()); + } + return applyTemplateMenu; + } + private void updateSelectionMenu(int x, int y) { getSelectionMenu().removeAll(); for (IDIYComponent component : plugInPort @@ -302,6 +328,36 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner { } } + private void updateApplyTemplateMenu() { + getApplyTemplateMenu().removeAll(); + List