From: <ha...@us...> - 2007-08-14 23:48:14
|
Revision: 8080 http://jmol.svn.sourceforge.net/jmol/?rev=8080&view=rev Author: hansonr Date: 2007-08-14 16:48:06 -0700 (Tue, 14 Aug 2007) Log Message: ----------- 11.3.10 preliminary webExport for application Modified Paths: -------------- trunk/Jmol/src/org/openscience/jmol/app/webexport/JmolPopIn.js trunk/Jmol/src/org/openscience/jmol/app/webexport/PopInJmol.java trunk/Jmol/src/org/openscience/jmol/app/webexport/ScriptButtons.java trunk/Jmol/src/org/openscience/jmol/app/webexport/WebPanel.java trunk/Jmol/src/org/openscience/jmol/app/webexport/pop_in_template.html trunk/Jmol/src/org/openscience/jmol/app/webexport/script_button_template.html Added Paths: ----------- trunk/Jmol/src/org/openscience/jmol/app/webexport/pop_in_template2.html trunk/Jmol/src/org/openscience/jmol/app/webexport/script_button_template2.html Modified: trunk/Jmol/src/org/openscience/jmol/app/webexport/JmolPopIn.js =================================================================== --- trunk/Jmol/src/org/openscience/jmol/app/webexport/JmolPopIn.js 2007-08-14 17:07:11 UTC (rev 8079) +++ trunk/Jmol/src/org/openscience/jmol/app/webexport/JmolPopIn.js 2007-08-14 23:48:06 UTC (rev 8080) @@ -27,7 +27,7 @@ + ' style="width:' + appletWidth + 'px; height:' + appletHeight + 'px;' + ' background-image:URL('+imageFileName+')"' + '>'; - tx += '<br><table cellpadding="10"><tr><td style="background-color:white">'; + tx += '<br><table cellpadding="10"><tr><td style="background-color:white;opacity:0.3">'; tx += 'To get a 3-D model you can manipulate, click '; tx += '<a href="javascript:void(popInJmol(' + molNr + ', \'' + molFileName + '\','+ appletWidth + ','+ appletHeight + '))">here</a>.'; tx += ' Download time may be significant the first time the applet is loaded.</td></tr></table></div>'; @@ -35,7 +35,7 @@ } function popInJmol(n,fileName,width,height) { - document.getElementById("Jmol"+n).innerHTML = jmolApplet([width,height],"script "+fileName+"",n); + document.getElementById("Jmol"+n).innerHTML = jmolApplet([width,height],"defaultDirectory = \""+dataDir+"\";script "+fileName+"",n); } function getHTML(element) { @@ -46,13 +46,12 @@ function addJmolDiv(i,floatdiv,name,width,height,caption,note) { if (arguments.length < 6) caption = getHTML(name+"_caption"); if (arguments.length < 7) note = getHTML(name+"_note"); - var s = "\n<br><div \"style='height:"+(height+100)+"px'\">\n<div class = \""+floatdiv+"\">"; + var s = "\n\n<tr><td>\n<br><div>\n<div class = \""+floatdiv+"\">"; s += "\n<table style=\"text-align: left; width: "+width+"px;\" border='1' cellpadding='2'"; s += "\n cellspacing='2'>"; s += "\n <tr>"; s += "\n <td style=\"vertical-align: top; width: "+width+"px; height: "+height+"px;\">"; document.write(s);//.replace(/\</g,"<")); - putJmolDiv(i, name+".spt",name+".png",width, height); s = "\n </td>"; @@ -63,9 +62,8 @@ s += "\n </tr>"; s += "\n</table>"; s += "\n</div>"; - s += "\n<div>"+note+"</div></div>"; + s += "\n<div>"+note+"</div></div></td></tr>\n"; document.write(s);//.replace(/\</g,"<")); - } function addAppletButton(i, name, label, info) { @@ -75,4 +73,4 @@ jmolButton('Script '+name+'.spt', label); var s = '</td></tr></table>\n' + info + "\n</br>"; document.write(s) -} \ No newline at end of file +} Modified: trunk/Jmol/src/org/openscience/jmol/app/webexport/PopInJmol.java =================================================================== --- trunk/Jmol/src/org/openscience/jmol/app/webexport/PopInJmol.java 2007-08-14 17:07:11 UTC (rev 8079) +++ trunk/Jmol/src/org/openscience/jmol/app/webexport/PopInJmol.java 2007-08-14 23:48:06 UTC (rev 8080) @@ -26,8 +26,8 @@ import javax.swing.*; import org.jmol.api.JmolViewer; +import org.jmol.util.TextFormat; - public class PopInJmol extends WebPanel { PopInJmol(JmolViewer viewer) { @@ -35,6 +35,8 @@ description = "Create a web page with images that convert to live Jmol on user click..."; infoFile = "pop_in_instructions.html"; templateName = "pop_in_template.html"; + appletTemplateName = "pop_in_template2.html"; + useAppletJS = false; } //Need the panel maker and the action listener. @@ -64,14 +66,24 @@ } String getAppletDefs(int i, String html, StringBuffer appletDefs, JmolInstance instance) { + String divClass = (i % 2 == 0 ? "floatRightDiv" : "floatLeftDiv"); String name = instance.name; int JmolSizeW = instance.width; int JmolSizeH = instance.height; + if (useAppletJS) { appletInfoDivs += "\n<div id=\""+name+"_caption\">\ninsert caption for "+name+" here\n</div>"; appletInfoDivs += "\n<div id=\""+name+"_note\">\ninsert note for "+name+" here\n</div>"; - String floatDiv = (i % 2 == 0 ? "floatRightDiv" : "floatLeftDiv"); - appletDefs.append("\naddJmolDiv(" + i + ",'"+floatDiv+"','" + name + "'," + appletDefs.append("\naddJmolDiv(" + i + ",'"+divClass+"','" + name + "'," + JmolSizeW + "," + JmolSizeH + ")"); + } else { + String s = htmlAppletTemplate; + s = TextFormat.simpleReplace(s, "@CLASS@", "" + divClass); + s = TextFormat.simpleReplace(s, "@I@", "" + i); + s = TextFormat.simpleReplace(s, "@WIDTH@", "" + JmolSizeW); + s = TextFormat.simpleReplace(s, "@HEIGHT@", "" + JmolSizeH); + s = TextFormat.simpleReplace(s, "@NAME@", name); + appletDefs.append(s); + } return html; } } Modified: trunk/Jmol/src/org/openscience/jmol/app/webexport/ScriptButtons.java =================================================================== --- trunk/Jmol/src/org/openscience/jmol/app/webexport/ScriptButtons.java 2007-08-14 17:07:11 UTC (rev 8079) +++ trunk/Jmol/src/org/openscience/jmol/app/webexport/ScriptButtons.java 2007-08-14 23:48:06 UTC (rev 8080) @@ -37,6 +37,8 @@ description = "Create a web page where a text and button pane scrolls next to a resizable Jmol."; infoFile = "script_button_instructions.html"; templateName = "script_button_template.html"; + appletTemplateName = "script_button_template2.html"; + useAppletJS = false; } //Need the panel maker and the action listener. @@ -91,17 +93,29 @@ } else { label = buttonname; } - String info = "info for " + name; - appletDefs.append("\naddAppletButton("+i+",'"+ name +"',\""+label+"\",\""+info+"\");"); + if (useAppletJS) { + String info = "info for " + name; + appletDefs.append("\naddAppletButton("+i+",'"+ name +"',\""+label+"\",\""+info+"\");"); + } else { + String s = htmlAppletTemplate; + s = TextFormat.simpleReplace(s, "@NAME@", name); + s = TextFormat.simpleReplace(s, "@LABEL@", label); + appletDefs.append(s); + } return html; } String fixScript(String script) { - script = TextFormat.simpleReplace(script, "set refreshing false;", - "set refreshing true;"); - script = TextFormat.simpleReplace(script, - "moveto /* time, axisAngle */ 0.0", - "moveto /* time, axisAngle */ 5.0"); + // I'm not convinced this is appropriate -- perhaps as + // an option, but not by default -- we want the script being + // precisely what it is with "show state". + // If you want it different, that can be accomplished in JavaScript. + + //script = TextFormat.simpleReplace(script, "set refreshing false;", + //"set refreshing true;"); + //script = TextFormat.simpleReplace(script, + //"moveto /* time, axisAngle */ 0.0", + //"moveto /* time, axisAngle */ 5.0"); return script; } Modified: trunk/Jmol/src/org/openscience/jmol/app/webexport/WebPanel.java =================================================================== --- trunk/Jmol/src/org/openscience/jmol/app/webexport/WebPanel.java 2007-08-14 17:07:11 UTC (rev 8079) +++ trunk/Jmol/src/org/openscience/jmol/app/webexport/WebPanel.java 2007-08-14 23:48:06 UTC (rev 8080) @@ -54,7 +54,10 @@ String templateName; String description; String infoFile; - static String appletInfoDivs; + String appletInfoDivs; + String htmlAppletTemplate; + String appletTemplateName; + boolean useAppletJS; WebPanel(JmolViewer viewer) { this.viewer = viewer; @@ -64,6 +67,7 @@ appletPath.setText(WebExport.getAppletPath()); } + class InstanceCellRenderer extends JLabel implements ListCellRenderer { public Component getListCellRendererComponent(JList list, // the list Object value, // value to display @@ -87,6 +91,31 @@ } } + URL getResource(String fileName) { + URL url = this.getClass().getResource(fileName); + if (url == null) { + System.err.println("Couldn't find file: " + infoFile); + } + return url; + } + + String getResourceString (String name) throws IOException { + URL templateFile = this.getClass().getResource(name); + if (templateFile == null) + throw new FileNotFoundException("Error loading resource " + name); + String filename = templateFile.getFile(); + BufferedReader br = new BufferedReader(new FileReader(filename)); + StringBuffer htmlBuf = new StringBuffer(); + String line; + while ((line = br.readLine()) != null) + htmlBuf.append(line).append("\n"); + br.close(); + String html = htmlBuf.toString(); + //LogPanel.Log("Loading html template " + templateFile + "(" + // + html.length() + " bytes)"); + return html; + } + //Need the panel maker and the action listener. protected JPanel getPanel(JComponent centerPanel, JPanel appletSizePanel) { @@ -206,15 +235,13 @@ //Create the instructions sub window (scrolling to read html file) JEditorPane instructions = new JEditorPane(); instructions.setEditable(false); - URL InstructionsURL = this.getClass().getResource(infoFile); + URL InstructionsURL = getResource(infoFile); if (InstructionsURL != null) { try { instructions.setPage(InstructionsURL); } catch (IOException e) { System.err.println("Attempted to read a bad URL: " + InstructionsURL); } - } else { - System.err.println("Couldn't find file: " + infoFile); } //Put the editor pane in a scroll pane. @@ -236,7 +263,7 @@ String name = JOptionPane .showInputDialog("Give the occurance of Jmol a one word name:"); if (name != null) { - name = TextFormat.simpleReplace(name, " ", "_"); + name = TextFormat.replaceAllCharacters(name, "' \"","_"); //need to get the script... String script = viewer.getStateInfo(); if (script == null) { @@ -300,7 +327,7 @@ boolean FileWriter(File file, JList InstanceList, String appletPath) throws IOException { //returns true if successful. - // JOptionPane.showMessageDialog(null, "Creating directory for data..."); + // JOptionPane.showMessageDialog(null, "Creating directory for data..."); String datadirPath = file.getPath(); String datadirName = file.getName(); String fileName = null; @@ -317,7 +344,7 @@ if (made_datadir) { LogPanel.Log("Created directory: " + datadirPath); LogPanel.Log("Writing javascript file JmolPopIn.js..."); - URL url = this.getClass().getResource("JmolPopIn.js"); + URL url = getResource("JmolPopIn.js"); PrintStream out = null; try { String outfilename = datadirPath + "/JmolPopIn.js"; @@ -387,28 +414,25 @@ throw IOe; } } - URL templateFile = this.getClass().getResource(templateName); - String filename = templateFile.getFile(); - BufferedReader br = new BufferedReader(new FileReader(filename)); - StringBuffer htmlBuf = new StringBuffer(); - String line; - while ((line = br.readLine()) != null) - htmlBuf.append(line).append("\n"); - br.close(); - String html = htmlBuf.toString(); - LogPanel.Log("Loading html template " + templateFile + "(" - + html.length() + " bytes)"); - if (html == null) - throw new FileNotFoundException("Error loading pop_in_template.html"); + String html = getResourceString(templateName); html = fixHtml(html); appletInfoDivs = ""; StringBuffer appletDefs = new StringBuffer(); + if (!useAppletJS) + htmlAppletTemplate = getResourceString(appletTemplateName); for (int i = 0; i < listModel.getSize(); i++) - html = getAppletDefs(i, html, appletDefs, (JmolInstance) listModel.getElementAt(i)); + html = getAppletDefs(i, html, appletDefs, (JmolInstance) listModel + .getElementAt(i)); html = TextFormat.simpleReplace(html, "@APPLETPATH@", appletPath); html = TextFormat.simpleReplace(html, "@DATADIRNAME@", datadirName); + if (appletInfoDivs.length() > 0) + appletInfoDivs = "\n<div style='display:none'>\n" + appletInfoDivs + + "\n</div>\n"; + String str = appletDefs.toString(); + if (htmlAppletTemplate == null) + str = "<script type='text/javascript'>\n" + str + "\n</script>"; html = TextFormat.simpleReplace(html, "@APPLETINFO@", appletInfoDivs); - html = TextFormat.simpleReplace(html, "@APPLETDEFS@", appletDefs.toString()); + html = TextFormat.simpleReplace(html, "@APPLETDEFS@", str); html = TextFormat.simpleReplace(html, "@CREATIONDATA@", WebExport .TimeStamp_WebLink()); LogPanel.Log("Writing HTML file for this web page at " + datadirPath Modified: trunk/Jmol/src/org/openscience/jmol/app/webexport/pop_in_template.html =================================================================== --- trunk/Jmol/src/org/openscience/jmol/app/webexport/pop_in_template.html 2007-08-14 17:07:11 UTC (rev 8079) +++ trunk/Jmol/src/org/openscience/jmol/app/webexport/pop_in_template.html 2007-08-14 23:48:06 UTC (rev 8080) @@ -28,8 +28,17 @@ .floatRightDiv { padding:0.3em 0.5ex; font-size:0.9em; float:right;} .floatLeftDiv { padding:0.3em 0.5ex; font-size:0.9em; float:left;} </style> + <script src="JmolPopIn.js" type="text/javascript"></script> <script src="@APPLETPATH@/Jmol.js" type="text/javascript"></script> - <script src="JmolPopIn.js" type="text/javascript"></script> + + +<script type='text/javascript'> + jmolInitialize("@APPLETPATH@"); //Where Jmol.jar is; if you change this, also change it in the above script tag + jmolSetDocument(false); //Required + dataDir = "."; //Where the data AND SCRIPT files are to be found. +</script> + + <meta content="J. Gutow" name="author"> <meta content="Based on javascript by A. Herraez" name="description"> </head> @@ -38,14 +47,12 @@ <div style="text-align: center;"><Insert Your TITLE HERE><br> </div> <Insert Your INTRODUCTION HERE></div> -<div style="display:none"> + @APPLETINFO@ -</div> -<script type='text/javascript'> -jmolInitialize("@APPLETPATH@"); -jmolSetDocument(false); + +<table style="width:100%"> @APPLETDEFS@ -</script> +</table> <div style="text-align: right;">Based on template by A. Herraez as modified by J. Gutow</div> <div style="text-align: right;"> Added: trunk/Jmol/src/org/openscience/jmol/app/webexport/pop_in_template2.html =================================================================== --- trunk/Jmol/src/org/openscience/jmol/app/webexport/pop_in_template2.html (rev 0) +++ trunk/Jmol/src/org/openscience/jmol/app/webexport/pop_in_template2.html 2007-08-14 23:48:06 UTC (rev 8080) @@ -0,0 +1,30 @@ +<tr><td> +<br><div> +<div class = "@CLASS@"> +<table style="text-align: left; width: @WIDTH@px;" border='1' cellpadding='2' cellspacing='2'> + <tr> + <td style="vertical-align: top; width: @WIDTH@px; height: @HEIGHT@px;"> + + <script type="text/javascript"> + + putJmolDiv(@I@, "@NAME@.spt", "@NAME@.png", @WIDTH@, @HEIGHT@); + + </script> + + </td> + </tr> + <tr> + <td style="vertical-align: top;"> + + insert caption for @NAME@ here + + </td> + </tr> +</table> +</div> +<div> + + insert note for @NAME@ here + +</div></div></td></tr> + Modified: trunk/Jmol/src/org/openscience/jmol/app/webexport/script_button_template.html =================================================================== --- trunk/Jmol/src/org/openscience/jmol/app/webexport/script_button_template.html 2007-08-14 17:07:11 UTC (rev 8079) +++ trunk/Jmol/src/org/openscience/jmol/app/webexport/script_button_template.html 2007-08-14 23:48:06 UTC (rev 8080) @@ -20,26 +20,37 @@ --> <title>Dynamically resized Jmol</title> + + <style type="text/css"> + /* These are important, don't change: */ html, body { height:100%; overflow:hidden; margin:0; padding:0; } .JmolPanels { position:absolute; overflow:hidden; } .textPanels { position:absolute; overflow:auto; } -/* Don't add margin nor padding to textPane; if needed, use an inner div with desired style (like 'contents' below) */ +/* Don't add margin or padding to textPane; if needed, use an inner div with desired style (like 'contents' below) */ + /* These are aesthetic, can be customized: */ .content { padding:0.5em 1ex; } .textPanels, .JmolPanels { background-color:rgb(102, 255, 255); } + + </style> + + + +<script src="JmolPopIn.js" type="text/javascript"></script> <script src="@APPLETPATH@/Jmol.js" type="text/javascript"></script> -<script src="JmolPopIn.js" type="text/javascript"></script> -<script type="text/javascript"> -// USER'S SETTINGS: - var side = "right" // sets the side of the page that the model appears on, you can set this to "left" or "right" - var w = @WIDTHPERCENT@ // you can set this to any integer, meaning percent of window width assigned to Jmol + +<script type='text/javascript'> + jmolInitialize("@APPLETPATH@"); //Where Jmol.jar is; if you change this, also change it in the above script tag + dataDir = "."; //Where the data AND SCRIPT files are to be found. + + var side = "right" // sets the side of the page that the model appears on, you can set this to "left" or "right" + var w = @WIDTHPERCENT@ // you can set this to any integer, meaning percent of window width assigned to Jmol // (Jmol.js, JmolApplet0.jar and the others) // If you place them in the same directory as this file, use "./" - jmolInitialize("@APPLETPATH@"); //jmolSetAppletColor("#CCFFCC") //Only set if you don't like the default // -------------- @@ -49,24 +60,42 @@ cssTx += '</style>' document.writeln(cssTx) </script> + + </head> <body style="color: rgb(0, 0, 0); background-color: rgb(102, 255, 255);" alink="#000099" link="#000099" vlink="#990099"> + <div id="JmolPane" class="JmolPanels"> + <script type="text/javascript"> - jmolApplet("100%", "script @APPLETNAME0@.scpt") // DO NOT change 100% - // of course, you should change the script to load your model or run your script -</script></div> + jmolApplet("100%", "defaultDirectory = \""+dataDir+"\";script @APPLETNAME0@.spt") // DO NOT change 100% +</script> + +</div> + + <div id="mainPane" class="textPanels"> -<div class="content"><Insert your TITLE and INTRODUCTION here.><br> -<script type="text/javascript"> +<div class="content"> + +<Insert your TITLE and INTRODUCTION here.><br> + @APPLETDEFS@ -</script> + + +<br /> +<br /> +<br /> + <div style="text-align: right;">Based on template by A. Herraez as modified by J. Gutow</div> -<div style="text-align: right;"> -@CREATIONDATA@ -</div> +<div style="text-align: right;">@CREATIONDATA@</div> + + </div><!--content--> </div><!--mainPane--> + + + + </body> </html> Added: trunk/Jmol/src/org/openscience/jmol/app/webexport/script_button_template2.html =================================================================== --- trunk/Jmol/src/org/openscience/jmol/app/webexport/script_button_template2.html (rev 0) +++ trunk/Jmol/src/org/openscience/jmol/app/webexport/script_button_template2.html 2007-08-14 23:48:06 UTC (rev 8080) @@ -0,0 +1,12 @@ +<table style="text-align: center; width: 100%" border="1" cellpadding="2" cellspacing="2"><tr><td> + + <script type="text/javascript"> + + jmolButton("script @NAME@.spt", "@LABEL@"); + + </script> + +</td></tr></table> + + info for @NAME@ </br> + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |