@Override public void execute() { if (context.getSelection().isEmpty()) return; SketchDocument doc = context.getDocument(); List<SNode> nodes = new ArrayList<SNode>(); for (SNode node : context.getSelection().items()) { nodes.add(node); } int max = -1; for (SNode node : nodes) { max = Math.max(max, doc.getCurrentPage().getModel().indexOf(node)); } // if there is room to move up List<SNode> model = doc.getCurrentPage().getModel(); if (max + 1 < model.size()) { SNode nextNode = model.get(max + 1); model.removeAll(nodes); int n = model.indexOf(nextNode); model.addAll(n + 1, nodes); } else { // just remove and move all to the top model.removeAll(nodes); model.addAll(nodes); } context.redraw(); }
@Override public void execute() { if (context.getSelection().isEmpty()) return; SketchDocument doc = context.getDocument(); List<SNode> model = doc.getCurrentPage().getModel(); List<SNode> nodes = new ArrayList<SNode>(); for (SNode node : context.getSelection().items()) { nodes.add(node); } int min = Integer.MAX_VALUE; for (SNode node : nodes) { min = Math.min(model.indexOf(node), min); } // if there is room to move down if (min > 0) { SNode prevNode = model.get(min - 1); model.removeAll(nodes); model.addAll(model.indexOf(prevNode), nodes); } else { // just remove and move all to the bottom model.removeAll(nodes); model.addAll(0, nodes); } context.redraw(); }
@Override public void execute() { for (SNode node : context.getSelection().items()) { node.setScaleX(1); node.setScaleY(1); node.setRotate(0); } context.redraw(); }
@Override public void execute() { SketchDocument doc = context.getDocument(); List<SNode> model = doc.getCurrentPage().getModel(); List<SNode> nodes = new ArrayList<SNode>(); for (SNode node : context.getSelection().items()) { nodes.add(node); } model.removeAll(nodes); model.addAll(nodes); context.redraw(); }
@Override public void execute() { if (context.getSelection().isEmpty()) return; SketchDocument doc = context.getDocument(); List<SNode> model = doc.getCurrentPage().getModel(); List<SNode> nodes = new ArrayList<SNode>(); for (SNode node : context.getSelection().items()) { nodes.add(node); } // just remove and move all to the bottom model.removeAll(nodes); model.addAll(0, nodes); context.redraw(); }
@Override public void execute() { // duplicate the selection final List<SNode> dupes = new ArrayList<SNode>(); SketchDocument doc = (SketchDocument) context.getDocument(); for (SNode node : context.getSelection().sortedItems(doc)) { SNode dupe = node.duplicate(null); if (offset) { dupe.setTranslateX(dupe.getTranslateX() + 100); dupe.setTranslateY(dupe.getTranslateY() + 100); } dupes.add(dupe); } // make it undoable context .getUndoManager() .pushAction( new UndoManager.UndoableAction() { public void executeUndo() { SketchDocument doc = (SketchDocument) context.getDocument(); for (SNode dupe : dupes) { doc.getCurrentPage().remove(dupe); } context.getSelection().clear(); } public void executeRedo() { SketchDocument doc = (SketchDocument) context.getDocument(); for (SNode dupe : dupes) { doc.getCurrentPage().add(dupe); doc.setDirty(true); } } public String getName() { return "duplicate"; } }); // clear selection context.getSelection().clear(); // add to the doc for (SNode dupe : dupes) { doc.getCurrentPage().add(dupe); doc.setDirty(true); context.getSelection().addSelectedNode(dupe); } }
public void executeRedo() { for (SNode node : diffs.keySet()) { node.setTranslateX(node.getTranslateX() + diffs.get(node).getX()); node.setTranslateY(node.getTranslateY() + diffs.get(node).getY()); } context.redraw(); }
@Override public void execute() { if (context.getSelection().size() != 1) return; SNode n = context.getSelection().items().iterator().next(); if (!(n instanceof SGroup)) return; final SGroup group = (SGroup) n; SketchDocument doc = context.getDocument(); final List<SNode> model = doc.getCurrentPage().getModel(); model.remove(group); model.addAll(group.getNodes()); context.getSelection().clear(); for (SNode node : group.getNodes()) { node.setTranslateX(node.getTranslateX() + group.getTranslateX()); node.setTranslateY(node.getTranslateY() + group.getTranslateY()); context.getSelection().addSelectedNode(node); } context.redraw(); UndoManager.UndoableAction action = new UndoManager.UndoableAction() { public void executeUndo() { model.removeAll(group.getNodes()); for (SNode node : group.getNodes()) { node.setTranslateX(node.getTranslateX() - group.getTranslateX()); node.setTranslateY(node.getTranslateY() - group.getTranslateY()); } model.add(group); context.getSelection().setSelectedNode(group); context.redraw(); } public void executeRedo() { model.remove(group); for (SNode node : group.getNodes()) { model.add(node); node.setTranslateX(node.getTranslateX() + group.getTranslateX()); node.setTranslateY(node.getTranslateY() + group.getTranslateY()); } context.getSelection().setSelectedNodes(group.getNodes()); context.redraw(); } public CharSequence getName() { return "ungroup shapes"; } }; context.getUndoManager().pushAction(action); }
@Override public void execute() { if (context.getSelection().size() < 2) return; SketchDocument doc = context.getDocument(); final List<SNode> model = doc.getCurrentPage().getModel(); final List<SNode> nodes = new ArrayList<SNode>(); for (SNode node : model) { if (context.getSelection().contains(node)) { nodes.add(node); } } model.removeAll(nodes); final SGroup group = new SGroup(); group.addAll(nodes); model.add(group); context.getSelection().clear(); context.getSelection().setSelectedNode(group); context.redraw(); UndoManager.UndoableAction action = new UndoManager.UndoableAction() { public void executeUndo() { model.remove(group); for (SNode node : nodes) { model.add(node); node.setTranslateX(node.getTranslateX() + group.getTranslateX()); node.setTranslateY(node.getTranslateY() + group.getTranslateY()); } context.getSelection().setSelectedNodes(nodes); context.redraw(); } public void executeRedo() { model.removeAll(nodes); group.addAll(nodes); model.add(group); context.getSelection().setSelectedNode(group); context.redraw(); } public CharSequence getName() { return "group shapes"; } }; context.getUndoManager().pushAction(action); }
@Override public void execute() { context.getSelection().clear(); }