示例#1
0
 private void doExtensions(StringWriter setupContent, DynamicNode dnode) {
   if (dnode.hasProperty("draggable")) {
     if (dnode.getProperty("draggable").getBooleanValue()) {
       setupContent.append("setupDraggable(" + dnode.getId() + ",root);\n");
     }
   }
 }
示例#2
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();
    }
  }