Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
  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. :(");
  }
Esempio n. 4
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;
 }
Esempio n. 5
0
  @Override
  public void execute() {

    if (USE_OMETA) {
      try {
        exportWithOmeta();
      } catch (Exception e) {
        e.printStackTrace();
      }
      return;
    }
    try {
      File dir = new File("/Users/josh/projects/Leo/t2");
      File html = new File(dir, "foo.html");
      File templatedir = new File("resources/");
      if (useRandomFile) {

      } else {

        // get a file to write to
        if (document.getExportFile() != null) {
          html = document.getExportFile();
          dir = html.getParentFile();
        } else {
          java.awt.FileDialog fd = new java.awt.FileDialog((Frame) null);
          fd.setMode(FileDialog.SAVE);
          fd.setVisible(true);
          if (fd.getFile() == null) {
            return;
          }
          String filename = fd.getFile();
          if (!filename.toLowerCase().endsWith(".html")) {
            filename += ".html";
          }
          html = new File(fd.getDirectory(), filename);
          dir = html.getParentFile();
        }
      }

      // File file = File.createTempFile("foo",".html");
      // file.deleteOnExit();
      StringWriter treeContent = new StringWriter();
      PrintWriter treeOut = new PrintWriter(treeContent);
      PropWriter treeWriter = new PropWriter(treeOut);
      StringWriter setupContent = new StringWriter();
      for (Layer layer : page.children()) {
        treeWriter.p("//layer");
        treeWriter.indent();
        for (SketchNode node : layer.children()) {
          DynamicNode dnode = (DynamicNode) node;
          exportNode(treeWriter, dnode, true, dir);
          if (node.isVisual() && AminoAdapter.shouldAddToScene(node, document.getBindings())) {
            setupContent.append("root.add(" + node.getId() + ");\n");
          }
          if (AminoAdapter.useSetup(dnode)) {
            setupContent.append(node.getId() + ".setup(root);\n");
          }
          doExtensions(setupContent, dnode);
        }
        treeWriter.outdent();
      }

      for (Binding binding : document.getBindings()) {
        exportBinding(new PrintWriter(setupContent), binding);
      }

      treeOut.close();
      setupContent.close();

      Map<String, String> subs = new HashMap<String, String>();
      subs.put("tree", treeContent.toString());
      subs.put("setup", setupContent.toString());

      if (!html.exists()) {
        StringUtils.applyTemplate(new File(templatedir, "index_template.html"), html, subs);
      }
      File js = new File(dir, "generated.js");
      StringUtils.applyTemplate(new File(templatedir, "generated_template.js"), js, subs);
      StringUtils.copyFile(new File(templatedir, "amino.js"), new File(dir, "amino.js"));
      StringUtils.copyFile(new File(templatedir, "jquery.js"), new File(dir, "jquery.js"));
      StringUtils.copyFile(new File(templatedir, "controls.js"), new File(dir, "controls.js"));

      File trimfile = new File("/Users/josh/");
      String partialPath =
          dir.getAbsolutePath().substring((int) trimfile.getAbsolutePath().length());
      OSUtil.openBrowser("http://localhost/~josh/" + partialPath + "/" + html.getName());

      document.setExportFile(html);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Esempio n. 6
0
 public HTMLBindingExport(SketchDocument document, boolean useRandomFile) {
   this.document = document;
   this.page = document.get(0);
   this.useRandomFile = useRandomFile;
 }