public PropWriter prop(String name, Object value) { pindent(); out.print(".set" + name.substring(0, 1).toUpperCase() + name.substring(1)); out.print("(" + valueToString(value) + ")"); out.println(); return this; }
public PropWriter p(String name, double value) { pindent(); out.print(".set" + name.substring(0, 1).toUpperCase() + name.substring(1)); out.print("(" + "" + value + "" + ")"); out.println(); return this; }
public PropWriter newObjVarClose() { pindent(); out.println(")"); return this; }
public PropWriter newObjVarOpen(String id, String name) { pindent(); out.println("var " + id + " = new " + name + "("); return this; }
public PropWriter newObj(String name) { pindent(); out.println(" new " + name + "()"); return this; }
public PropWriter p(String s) { pindent(); out.println(s); return this; }
public PropWriter pwen() { pindent(); out.println(")"); return this; }
@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(); } }
private void pindent() { for (int i = 0; i < indent; i++) { out.print(" "); } }
private void exportBinding(PrintWriter out, Binding binding) { if (AminoAdapter.shouldExportAsSetter(binding)) { String prop = binding.getTargetProperty().getName(); out.println( binding.getTarget().getId() + ".set" + prop.substring(0, 1).toUpperCase() + prop.substring(1) + "(" + binding.getSource().getId() + ");"); return; } if (AminoAdapter.shouldExportAsAdder(binding)) { out.print(binding.getTarget().getId() + ".add("); out.print(binding.getSource().getId()); out.println(");"); return; } if (AminoAdapter.shouldExportAsTrigger(binding)) { out.println(binding.getSource().getId() + ".setCallback(" + "function(){\n"); out.println(" " + binding.getTarget().getId() + ".execute();"); out.println("});"); return; } if (binding.getSource().getName().equals("ListView")) { if (binding.getSourceProperty().isProxy()) { p("it's a proxy! " + binding.getSourceProperty().getName()); p("master = " + binding.getSourceProperty().getMasterProperty()); String n = binding.getTargetProperty().getName(); String setterName = "set" + n.substring(0, 1).toUpperCase() + n.substring(1); out.println( binding.getSource().getId() + ".listen(function(e){\n" + " var val = e.getSelectedObject()." + binding.getSourceProperty().getName() + ";\n" + " " + binding.getTarget().getId() + "." + setterName + "(val);\n" + "});\n"); return; } } out.println( "var binder = new Binder()" + ".set(" + binding.getSource().getId() + ",'" + binding.getSourceProperty().getName() + "'," + binding.getTarget().getId() + ",'" + binding.getTargetProperty().getName() + "');\n" + "engine.addAnim(binder);\n" + "binder.start();\n"); }