Example #1
0
 @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();
 }
Example #2
0
    @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();
    }
 public static SketchDocument importSVG(URL url) throws Exception {
   SketchDocument sdoc = importSVG(url.openStream());
   // sdoc.setFile(file);
   sdoc.setTitle(url.getPath() + "");
   sdoc.setCurrentPage(0);
   sdoc.setDirty(false);
   return sdoc;
 }
 public static SketchDocument importSVG(File file) throws Exception {
   SketchDocument sdoc = importSVG(new FileInputStream(file));
   // sdoc.setFile(file);
   sdoc.setTitle(file.getName() + "");
   sdoc.setCurrentPage(0);
   sdoc.setDirty(false);
   return sdoc;
 }
Example #5
0
 @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();
 }
Example #6
0
 @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();
 }
  private void load(File file) throws Exception {
    if (file.getName().toLowerCase().endsWith(".svg")) {
      SketchDocument doc = importSVG(file);
      if (doc.isPresentation()) {
        context.getMain().setupNewDoc(new PresoModeHelper(context.getMain()), doc);
      } else {
        context.getMain().setupNewDoc(new VectorModeHelper(context.getMain()), doc);
      }
      return;
    }

    StandardDialog.showError(
        "Could not open file " + file.getName() + ".\nUnknown format. Sorry. :(");
  }
Example #8
0
    @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);
      }
    }
Example #9
0
    @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);
    }
Example #10
0
 private static SketchDocument importSVG(InputStream stream) throws Exception {
   SketchDocument sdoc = new SketchDocument();
   sdoc.removePage(sdoc.getCurrentPage());
   SketchDocument.SketchPage page = sdoc.addPage();
   u.p("parsing");
   Doc doc = XMLParser.parse(stream);
   u.p("parsed");
   Elem svg = doc.xpathElement("/svg");
   for (Elem n : svg.xpath("./*")) {
     u.p("node = " + n + " " + n.name());
     SNode node = loadNode(n);
     if (node != null) page.add(node);
   }
   return sdoc;
 }
Example #11
0
    @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);
    }