private void exportWithOmeta() throws IOException, URISyntaxException, InterruptedException {
    p("using ometa");

    // export to XML file
    File xmlFile = new File("foo.xml");
    toXML(xmlFile);
    // invoke converter
    execAndWait("/usr/local/bin/node");
    // apply template to make final file
    File genJSFile = new File("/Users/josh/projects/Leo2/foo.html");
    File dir = new File("/Users/josh/projects/Leo/t2");
    File html = new File(dir, "foo.html");
    File templatedir = new File("resources/");
    Map<String, String> subs = new HashMap<String, String>();

    String str = fileToString(genJSFile);
    subs.put("tree", str.toString());

    html.delete();
    if (!html.exists()) {
      StringUtils.applyTemplate(new File(templatedir, "index_aminolang_template.html"), html, subs);
      p("wrote out template.html to " + html.getAbsolutePath());
    }
    File js = new File(dir, "generated.js");
    StringUtils.applyTemplate(new File(templatedir, "generated_aminolang_template.js"), js, subs);
    p("wrote out: " + js.getAbsolutePath());
    // open browser
    File trimfile = new File("/Users/josh/");
    String partialPath = dir.getAbsolutePath().substring((int) trimfile.getAbsolutePath().length());
    OSUtil.openBrowser("http://localhost/~josh/" + partialPath + "/" + html.getName());
  }
 public void mousePressed(MouseEvent e) {
   logEvent("MousePressed", e);
   Node node = findTopNode(e.getX(), e.getY());
   Point2D point = convertSceneToNode(e.getX(), e.getY(), node);
   org.joshy.gfx.event.MouseEvent evt =
       toEvent(e, point, node, org.joshy.gfx.event.MouseEvent.MousePressed);
   EventBus.getSystem().setPressedNode(node);
   EventBus.getSystem().publish(evt);
   if (evt.isControlPressed() && OSUtil.isMac() || evt.getButton() == 3 || e.isPopupTrigger()) {
     org.joshy.gfx.event.MouseEvent evt2 =
         toEvent(e, point, node, org.joshy.gfx.event.MouseEvent.OpenContextMenu);
     EventBus.getSystem().publish(evt2);
   }
 }
Example #3
0
/**
 * Created by IntelliJ IDEA. User: josh Date: 5/3/12 Time: 12:28 PM To change this template use File
 * | Settings | File Templates.
 */
public class Settings {
  public static final File homedir =
      new File(
          OSUtil.getBaseStorageDir(
              System.getProperty("org.joshy.sketch.settings.basedirname", "Leonardo")));
  public static final File RECENT_FILES = new File(homedir, "recentfiles.xml");
  public static final File SETTINGS_FILE = new File(homedir, "settings.txt");
  public static final File SCRIPTS_DIR = new File(homedir, "scripts");
  public static final String TRACKING_PERMISSIONS = "org.joshy.gfx.sketch.tracking.allow";
  public static final String DEBUG_MENU = "org.joshy.gfx.sketch.debug.menuEnabled";
  public static final String DEFAULT_LOCALE = "org.joshy.gfx.sketch.defaultLocale";
  public static String UPDATE_URL = "";
  public static String DOWNLOAD_URL = "";
  public static String AMINO_BINARY_URL = null;
  public static final String DEFAULT_FONT_NAME = "OpenSans";
}
  @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();
    }
  }