mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Duplicate selection option in Edit menu and popup menu (Ctrl+D)
This commit is contained in:
@@ -183,6 +183,11 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
|
|||||||
*/
|
*/
|
||||||
void pasteComponents(Collection<IDIYComponent<?>> components);
|
void pasteComponents(Collection<IDIYComponent<?>> components);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Duplicates selected components and places them nearby.
|
||||||
|
*/
|
||||||
|
void duplicateSelection();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes all the selected components from the project.
|
* Deletes all the selected components from the project.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1410,6 +1410,38 @@ public class Presenter implements IPlugInPort {
|
|||||||
instantiationManager.getFirstControlPoint());
|
instantiationManager.getFirstControlPoint());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void duplicateSelection() {
|
||||||
|
LOG.info("duplicateSelection()");
|
||||||
|
if (selectedComponents.isEmpty()) {
|
||||||
|
LOG.debug("Nothing to duplicate");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Project oldProject = currentProject.clone();
|
||||||
|
Set<IDIYComponent<?>> newSelection = new HashSet<IDIYComponent<?>>();
|
||||||
|
|
||||||
|
int grid = (int) currentProject.getGridSpacing().convertToPixels();
|
||||||
|
for (IDIYComponent<?> component : this.selectedComponents) {
|
||||||
|
try {
|
||||||
|
IDIYComponent<?> cloned = component.clone();
|
||||||
|
newSelection.add(cloned);
|
||||||
|
for (int i = 0; i < component.getControlPointCount(); i++) {
|
||||||
|
Point p = component.getControlPoint(i);
|
||||||
|
Point newPoint = new Point(p.x + grid, p.y + grid);
|
||||||
|
cloned.setControlPoint(newPoint, i);
|
||||||
|
}
|
||||||
|
currentProject.getComponents().add(cloned);
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateSelection(newSelection);
|
||||||
|
|
||||||
|
messageDispatcher.dispatchMessage(EventType.PROJECT_MODIFIED, oldProject, currentProject.clone(), "Duplicate");
|
||||||
|
projectFileManager.notifyFileChange();
|
||||||
|
messageDispatcher.dispatchMessage(EventType.REPAINT);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteSelectedComponents() {
|
public void deleteSelectedComponents() {
|
||||||
LOG.info("deleteSelectedComponents()");
|
LOG.info("deleteSelectedComponents()");
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -39,7 +39,8 @@ public enum IconLoader {
|
|||||||
"messages.png"), SearchBox("search-box.png"), Screwdriver("screwdriver.png"), Hammer("hammer.png"), FlipHorizontal(
|
"messages.png"), SearchBox("search-box.png"), Screwdriver("screwdriver.png"), Hammer("hammer.png"), FlipHorizontal(
|
||||||
"flip_horizontal.png"), FlipVertical("flip_vertical.png"), MagicWand("magic_wand.png"), PinGrey("pin_grey.png"), PinGreen(
|
"flip_horizontal.png"), FlipVertical("flip_vertical.png"), MagicWand("magic_wand.png"), PinGrey("pin_grey.png"), PinGreen(
|
||||||
"pin_green.png"), CoffeebeanEdit("coffeebean_edit.png"), ApplicationEdit("application_edit.png"), ComponentAdd(
|
"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");
|
"component_add.png"), History("history.png"), DocumentPlain("document_plain.png"), FitToSize("fit_to_size.png"), DocumentsGear(
|
||||||
|
"documents_gear.png");
|
||||||
|
|
||||||
protected String name;
|
protected String name;
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 782 B |
@@ -114,6 +114,10 @@ public class ActionFactory {
|
|||||||
return new PasteAction(plugInPort, clipboard);
|
return new PasteAction(plugInPort, clipboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DuplicateAction createDuplicateAction(IPlugInPort plugInPort) {
|
||||||
|
return new DuplicateAction(plugInPort);
|
||||||
|
}
|
||||||
|
|
||||||
public SelectAllAction createSelectAllAction(IPlugInPort plugInPort) {
|
public SelectAllAction createSelectAllAction(IPlugInPort plugInPort) {
|
||||||
return new SelectAllAction(plugInPort);
|
return new SelectAllAction(plugInPort);
|
||||||
}
|
}
|
||||||
@@ -652,33 +656,6 @@ public class ActionFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CopyAction extends AbstractAction {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
private IPlugInPort plugInPort;
|
|
||||||
private Clipboard clipboard;
|
|
||||||
private ClipboardOwner clipboardOwner;
|
|
||||||
|
|
||||||
public CopyAction(IPlugInPort plugInPort, Clipboard clipboard, ClipboardOwner clipboardOwner) {
|
|
||||||
super();
|
|
||||||
this.plugInPort = plugInPort;
|
|
||||||
this.clipboard = clipboard;
|
|
||||||
this.clipboardOwner = clipboardOwner;
|
|
||||||
putValue(AbstractAction.NAME, "Copy");
|
|
||||||
putValue(AbstractAction.ACCELERATOR_KEY,
|
|
||||||
KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
|
|
||||||
putValue(AbstractAction.SMALL_ICON, IconLoader.Copy.getIcon());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
LOG.info("Copy triggered");
|
|
||||||
clipboard.setContents(new ComponentTransferable(cloneComponents(plugInPort.getSelectedComponents())),
|
|
||||||
clipboardOwner);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class PasteAction extends AbstractAction {
|
public static class PasteAction extends AbstractAction {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
@@ -710,6 +687,60 @@ public class ActionFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class CopyAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private IPlugInPort plugInPort;
|
||||||
|
private Clipboard clipboard;
|
||||||
|
private ClipboardOwner clipboardOwner;
|
||||||
|
|
||||||
|
public CopyAction(IPlugInPort plugInPort, Clipboard clipboard, ClipboardOwner clipboardOwner) {
|
||||||
|
super();
|
||||||
|
this.plugInPort = plugInPort;
|
||||||
|
this.clipboard = clipboard;
|
||||||
|
this.clipboardOwner = clipboardOwner;
|
||||||
|
putValue(AbstractAction.NAME, "Copy");
|
||||||
|
putValue(AbstractAction.ACCELERATOR_KEY,
|
||||||
|
KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.Copy.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LOG.info("Copy triggered");
|
||||||
|
clipboard.setContents(new ComponentTransferable(cloneComponents(plugInPort.getSelectedComponents())),
|
||||||
|
clipboardOwner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class DuplicateAction extends AbstractAction {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private IPlugInPort plugInPort;
|
||||||
|
|
||||||
|
public DuplicateAction(IPlugInPort plugInPort) {
|
||||||
|
super();
|
||||||
|
this.plugInPort = plugInPort;
|
||||||
|
putValue(AbstractAction.NAME, "Duplicate");
|
||||||
|
putValue(AbstractAction.ACCELERATOR_KEY,
|
||||||
|
KeyStroke.getKeyStroke(KeyEvent.VK_D, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
|
||||||
|
putValue(AbstractAction.SMALL_ICON, IconLoader.DocumentsGear.getIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
LOG.info("Duplicate triggered");
|
||||||
|
try {
|
||||||
|
plugInPort.duplicateSelection();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LOG.error("Coule not duplicate.", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static List<IDIYComponent<?>> cloneComponents(Collection<IDIYComponent<?>> components) {
|
private static List<IDIYComponent<?>> cloneComponents(Collection<IDIYComponent<?>> components) {
|
||||||
List<IDIYComponent<?>> result = new ArrayList<IDIYComponent<?>>(components.size());
|
List<IDIYComponent<?>> result = new ArrayList<IDIYComponent<?>>(components.size());
|
||||||
for (IDIYComponent<?> component : components) {
|
for (IDIYComponent<?> component : components) {
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
private ActionFactory.CutAction cutAction;
|
private ActionFactory.CutAction cutAction;
|
||||||
private ActionFactory.CopyAction copyAction;
|
private ActionFactory.CopyAction copyAction;
|
||||||
private ActionFactory.PasteAction pasteAction;
|
private ActionFactory.PasteAction pasteAction;
|
||||||
|
private ActionFactory.DuplicateAction duplicateAction;
|
||||||
private ActionFactory.EditSelectionAction editSelectionAction;
|
private ActionFactory.EditSelectionAction editSelectionAction;
|
||||||
private ActionFactory.DeleteSelectionAction deleteSelectionAction;
|
private ActionFactory.DeleteSelectionAction deleteSelectionAction;
|
||||||
private ActionFactory.SaveAsTemplateAction saveAsTemplateAction;
|
private ActionFactory.SaveAsTemplateAction saveAsTemplateAction;
|
||||||
@@ -138,6 +139,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
boolean enabled = !plugInPort.getSelectedComponents().isEmpty();
|
boolean enabled = !plugInPort.getSelectedComponents().isEmpty();
|
||||||
getCutAction().setEnabled(enabled);
|
getCutAction().setEnabled(enabled);
|
||||||
getCopyAction().setEnabled(enabled);
|
getCopyAction().setEnabled(enabled);
|
||||||
|
getDuplicateAction().setEnabled(enabled);
|
||||||
try {
|
try {
|
||||||
getPasteAction().setEnabled(clipboard.isDataFlavorAvailable(ComponentTransferable.listFlavor));
|
getPasteAction().setEnabled(clipboard.isDataFlavorAvailable(ComponentTransferable.listFlavor));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@@ -172,7 +174,8 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed(KeyEvent e) {
|
public void keyPressed(KeyEvent e) {
|
||||||
if (plugInPort.keyPressed(e.getKeyCode(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(), e.isShiftDown(), e.isAltDown())) {
|
if (plugInPort.keyPressed(e.getKeyCode(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(),
|
||||||
|
e.isShiftDown(), e.isAltDown())) {
|
||||||
e.consume();
|
e.consume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,7 +186,8 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
@Override
|
@Override
|
||||||
public void mouseMoved(MouseEvent e) {
|
public void mouseMoved(MouseEvent e) {
|
||||||
canvasPanel.setCursor(plugInPort.getCursorAt(e.getPoint()));
|
canvasPanel.setCursor(plugInPort.getCursorAt(e.getPoint()));
|
||||||
plugInPort.mouseMoved(e.getPoint(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(), e.isShiftDown(), e.isAltDown());
|
plugInPort.mouseMoved(e.getPoint(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(), e.isShiftDown(),
|
||||||
|
e.isAltDown());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -191,8 +195,8 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
plugInPort.mouseClicked(e.getPoint(), e.getButton(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(), e.isShiftDown(),
|
plugInPort.mouseClicked(e.getPoint(), e.getButton(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(),
|
||||||
e.isAltDown(), e.getClickCount());
|
e.isShiftDown(), e.isAltDown(), e.getClickCount());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -279,6 +283,7 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
popupMenu.add(getCutAction());
|
popupMenu.add(getCutAction());
|
||||||
popupMenu.add(getCopyAction());
|
popupMenu.add(getCopyAction());
|
||||||
popupMenu.add(getPasteAction());
|
popupMenu.add(getPasteAction());
|
||||||
|
popupMenu.add(getDuplicateAction());
|
||||||
popupMenu.addSeparator();
|
popupMenu.addSeparator();
|
||||||
popupMenu.add(getEditSelectionAction());
|
popupMenu.add(getEditSelectionAction());
|
||||||
popupMenu.add(getDeleteSelectionAction());
|
popupMenu.add(getDeleteSelectionAction());
|
||||||
@@ -411,6 +416,13 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
return pasteAction;
|
return pasteAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ActionFactory.DuplicateAction getDuplicateAction() {
|
||||||
|
if (duplicateAction == null) {
|
||||||
|
duplicateAction = ActionFactory.getInstance().createDuplicateAction(plugInPort);
|
||||||
|
}
|
||||||
|
return duplicateAction;
|
||||||
|
}
|
||||||
|
|
||||||
public ActionFactory.EditSelectionAction getEditSelectionAction() {
|
public ActionFactory.EditSelectionAction getEditSelectionAction() {
|
||||||
if (editSelectionAction == null) {
|
if (editSelectionAction == null) {
|
||||||
editSelectionAction = ActionFactory.getInstance().createEditSelectionAction(plugInPort);
|
editSelectionAction = ActionFactory.getInstance().createEditSelectionAction(plugInPort);
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
private ActionFactory.CutAction cutAction;
|
private ActionFactory.CutAction cutAction;
|
||||||
private ActionFactory.CopyAction copyAction;
|
private ActionFactory.CopyAction copyAction;
|
||||||
private ActionFactory.PasteAction pasteAction;
|
private ActionFactory.PasteAction pasteAction;
|
||||||
|
private ActionFactory.DuplicateAction duplicateAction;
|
||||||
private ActionFactory.EditSelectionAction editSelectionAction;
|
private ActionFactory.EditSelectionAction editSelectionAction;
|
||||||
private ActionFactory.DeleteSelectionAction deleteSelectionAction;
|
private ActionFactory.DeleteSelectionAction deleteSelectionAction;
|
||||||
private ActionFactory.GroupAction groupAction;
|
private ActionFactory.GroupAction groupAction;
|
||||||
@@ -104,6 +105,13 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
return pasteAction;
|
return pasteAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ActionFactory.DuplicateAction getDuplicateAction() {
|
||||||
|
if (duplicateAction == null) {
|
||||||
|
duplicateAction = ActionFactory.getInstance().createDuplicateAction(plugInPort);
|
||||||
|
}
|
||||||
|
return duplicateAction;
|
||||||
|
}
|
||||||
|
|
||||||
public ActionFactory.EditSelectionAction getEditSelectionAction() {
|
public ActionFactory.EditSelectionAction getEditSelectionAction() {
|
||||||
if (editSelectionAction == null) {
|
if (editSelectionAction == null) {
|
||||||
editSelectionAction = ActionFactory.getInstance().createEditSelectionAction(plugInPort);
|
editSelectionAction = ActionFactory.getInstance().createEditSelectionAction(plugInPort);
|
||||||
@@ -246,6 +254,7 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
swingUI.injectMenuAction(getCutAction(), EDIT_TITLE);
|
swingUI.injectMenuAction(getCutAction(), EDIT_TITLE);
|
||||||
swingUI.injectMenuAction(getCopyAction(), EDIT_TITLE);
|
swingUI.injectMenuAction(getCopyAction(), EDIT_TITLE);
|
||||||
swingUI.injectMenuAction(getPasteAction(), EDIT_TITLE);
|
swingUI.injectMenuAction(getPasteAction(), EDIT_TITLE);
|
||||||
|
swingUI.injectMenuAction(getDuplicateAction(), EDIT_TITLE);
|
||||||
swingUI.injectMenuAction(null, EDIT_TITLE);
|
swingUI.injectMenuAction(null, EDIT_TITLE);
|
||||||
swingUI.injectMenuAction(actionFactory.createSelectAllAction(plugInPort), EDIT_TITLE);
|
swingUI.injectMenuAction(actionFactory.createSelectAllAction(plugInPort), EDIT_TITLE);
|
||||||
swingUI.injectMenuAction(getEditSelectionAction(), EDIT_TITLE);
|
swingUI.injectMenuAction(getEditSelectionAction(), EDIT_TITLE);
|
||||||
@@ -305,6 +314,7 @@ public class EditMenuPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
boolean enabled = !plugInPort.getSelectedComponents().isEmpty();
|
boolean enabled = !plugInPort.getSelectedComponents().isEmpty();
|
||||||
getCutAction().setEnabled(enabled);
|
getCutAction().setEnabled(enabled);
|
||||||
getCopyAction().setEnabled(enabled);
|
getCopyAction().setEnabled(enabled);
|
||||||
|
getDuplicateAction().setEnabled(enabled);
|
||||||
try {
|
try {
|
||||||
getPasteAction().setEnabled(clipboard.isDataFlavorAvailable(ComponentTransferable.listFlavor));
|
getPasteAction().setEnabled(clipboard.isDataFlavorAvailable(ComponentTransferable.listFlavor));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -1774,6 +1774,10 @@
|
|||||||
<changeType>NEW_FEATURE</changeType>
|
<changeType>NEW_FEATURE</changeType>
|
||||||
<description>Ability to change PCB board shape from rectangular to oval.</description>
|
<description>Ability to change PCB board shape from rectangular to oval.</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>NEW_FEATURE</changeType>
|
||||||
|
<description>Duplicate selection option in Edit menu and popup menu (Ctrl+D).</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>NEW_FEATURE</changeType>
|
<changeType>NEW_FEATURE</changeType>
|
||||||
<description>Added bitchin new splash screen</description>
|
<description>Added bitchin new splash screen</description>
|
||||||
|
|||||||
Reference in New Issue
Block a user