@Override public void duplicate() { Selection sel = canvas.getSelection(); int n = sel.getSelected().size(); List<CanvasObject> select = new ArrayList<CanvasObject>(n); List<CanvasObject> clones = new ArrayList<CanvasObject>(n); for (CanvasObject o : sel.getSelected()) { if (o.canRemove()) { CanvasObject copy = o.clone(); copy.translate(10, 10); clones.add(copy); select.add(copy); } else { select.add(o); } } if (!clones.isEmpty()) { canvas .getProject() .doAction( new SelectionAction( canvas, Strings.getter("duplicateSelectionAction"), null, clones, select, null, null)); } }
@Override public void delete() { Selection sel = canvas.getSelection(); int n = sel.getSelected().size(); List<CanvasObject> select = new ArrayList<CanvasObject>(n); List<CanvasObject> remove = new ArrayList<CanvasObject>(n); Location anchorLocation = null; Direction anchorFacing = null; for (CanvasObject o : sel.getSelected()) { if (o.canRemove()) { remove.add(o); } else { select.add(o); if (o instanceof AppearanceAnchor) { AppearanceAnchor anchor = (AppearanceAnchor) o; anchorLocation = anchor.getLocation(); anchorFacing = anchor.getFacing(); } } } if (!remove.isEmpty()) { canvas .getProject() .doAction( new SelectionAction( canvas, Strings.getter("deleteSelectionAction"), remove, null, select, anchorLocation, anchorFacing)); } }