Revision: 18661
          http://sourceforge.net/p/jmol/code/18661
Author:   hansonr
Date:     2013-09-17 21:24:53 +0000 (Tue, 17 Sep 2013)
Log Message:
-----------
JmolVersion="13.2.6"

___JmolVersion="13.2.6_dev_2013.09.17"

bug fix: JSmol/HTML5 not allowing drag-drop or file loading from a local drive.
bug fix: JSmol/HTML5 not allowing WRITE FILE ?
bug fix: JSmol/HTML5 not allowing WRITE xxx.pdb, xxx.mol, etc
bug fix: chains improperly selected in JSmol/HTML5

Modified Paths:
--------------
    branches/v13_2/Jmol/src/org/jmol/awtjs2d/JmolFileAdapter.java
    branches/v13_2/Jmol/src/org/jmol/io/OutputStringBuilder.java
    branches/v13_2/Jmol/src/org/jmol/io2/ZipUtil.java
    branches/v13_2/Jmol/src/org/jmol/script/ScriptEvaluator.java
    branches/v13_2/Jmol/src/org/jmol/viewer/FileManager.java
    branches/v13_2/Jmol/src/org/jmol/viewer/Jmol.properties
    branches/v13_2/Jmol/src/org/jmol/viewer/StateCreator.java
    branches/v13_2/Jmol/src/org/jmol/viewer/StatusManager.java

Added Paths:
-----------
    branches/v13_2/Jmol/src/org/jmol/awtjs2d/WebOutputChannel.java

Removed Paths:
-------------
    branches/v13_2/Jmol/src/org/jmol/awtjs2d/WebPostOutputChannel.java

Modified: branches/v13_2/Jmol/src/org/jmol/awtjs2d/JmolFileAdapter.java
===================================================================
--- branches/v13_2/Jmol/src/org/jmol/awtjs2d/JmolFileAdapter.java       
2013-09-17 20:35:38 UTC (rev 18660)
+++ branches/v13_2/Jmol/src/org/jmol/awtjs2d/JmolFileAdapter.java       
2013-09-17 21:24:53 UTC (rev 18661)
@@ -35,7 +35,7 @@
        }
 
   public Object openOutputChannel(double privateKey, FileManager fm, String 
fileName, boolean asWriter) {
-    return new WebPostOutputChannel(fm, fileName, asWriter);
+    return new WebOutputChannel(fileName);
   }
 
   public InputStream openFileInputStream(double privateKey, String fileName)

Added: branches/v13_2/Jmol/src/org/jmol/awtjs2d/WebOutputChannel.java
===================================================================
--- branches/v13_2/Jmol/src/org/jmol/awtjs2d/WebOutputChannel.java              
                (rev 0)
+++ branches/v13_2/Jmol/src/org/jmol/awtjs2d/WebOutputChannel.java      
2013-09-17 21:24:53 UTC (rev 18661)
@@ -0,0 +1,43 @@
+package org.jmol.awtjs2d;
+
+import java.io.ByteArrayOutputStream;
+
+import org.jmol.util.SB;
+
+/**
+ * A surrogate for FileOutputStream, allowing collection of byte
+ * or character data for final posting to a server as bytes to
+ * be returned to the user via a browser dialog.
+ *  
+ */
+
+public class WebOutputChannel extends ByteArrayOutputStream {
+ 
+  private String fileName;
+  private SB sb;
+  
+  public WebOutputChannel(String fileName) {
+    this.fileName = fileName;
+  }
+
+  public void write(String data) {
+    if (sb == null)
+      sb = new SB();
+    sb.append(data);
+  }
+
+  @Override
+  public void close() {
+    if (fileName == null)
+      return;
+
+    /**
+     * @j2sNative
+     * 
+     *     Jmol._doAjax(this.fileName, null, (this.sb == null ? 
this.toByteArray() : this.sb.toString()));
+     * 
+     */
+    {
+    }
+  }
+}

Deleted: branches/v13_2/Jmol/src/org/jmol/awtjs2d/WebPostOutputChannel.java
===================================================================
--- branches/v13_2/Jmol/src/org/jmol/awtjs2d/WebPostOutputChannel.java  
2013-09-17 20:35:38 UTC (rev 18660)
+++ branches/v13_2/Jmol/src/org/jmol/awtjs2d/WebPostOutputChannel.java  
2013-09-17 21:24:53 UTC (rev 18661)
@@ -1,45 +0,0 @@
-package org.jmol.awtjs2d;
-
-import java.io.BufferedWriter;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-
-import org.jmol.io.JmolBinary;
-import org.jmol.viewer.FileManager;
-
-public class WebPostOutputChannel extends ByteArrayOutputStream {
- 
-  private String fileName;
-  private FileManager fm;
-  private BufferedWriter bw;
-  
-  public WebPostOutputChannel(FileManager fm, String fileName, boolean 
asWriter) {
-    this.fm = fm;
-    this.fileName = fileName;
-    if (asWriter)
-      bw = new BufferedWriter(new OutputStreamWriter(this));
-  }
-
-  // methods of BufferedWriter. These will be accessed by JavaScript, so no 
type checking
-  
-  public void write(String data) throws IOException {
-    bw.write(data);
-  }
-
-  @Override
-  public void flush() {
-    if (bw != null)
-      try {
-        bw.flush();
-      } catch (IOException e) {
-      }
-    else
-      flush();
-  }
-  
-  @Override
-  public void close() {
-    JmolBinary.postByteArray(fm, fileName, toByteArray()); 
-  }
-}

Modified: branches/v13_2/Jmol/src/org/jmol/io/OutputStringBuilder.java
===================================================================
--- branches/v13_2/Jmol/src/org/jmol/io/OutputStringBuilder.java        
2013-09-17 20:35:38 UTC (rev 18660)
+++ branches/v13_2/Jmol/src/org/jmol/io/OutputStringBuilder.java        
2013-09-17 21:24:53 UTC (rev 18661)
@@ -23,8 +23,15 @@
       if (asBytes) {
         this.bos = bos;
       } else {
-        OutputStreamWriter osw = new OutputStreamWriter(bos);
-        bw = new BufferedWriter(osw, 8192);
+        /** 
+         * @j2sNative
+         * 
+         * this.bw = bos;
+         * 
+         */
+        {
+          bw = new BufferedWriter(new OutputStreamWriter(bos), 8192);
+        }
       }
     } else if (asBytes) {
       buf = new byte[8092];

Modified: branches/v13_2/Jmol/src/org/jmol/io2/ZipUtil.java
===================================================================
--- branches/v13_2/Jmol/src/org/jmol/io2/ZipUtil.java   2013-09-17 20:35:38 UTC 
(rev 18660)
+++ branches/v13_2/Jmol/src/org/jmol/io2/ZipUtil.java   2013-09-17 21:24:53 UTC 
(rev 18661)
@@ -464,7 +464,10 @@
       }
       os.close();
       Logger.info(nBytesOut + " bytes prior to compression");
-      if (bos != null) {
+      if (bos == null) {
+        fullFilePath = viewer.getAbsolutePath(privateKey, 
outFileName).replace('\\', '/');
+        nBytes = viewer.getFileLength(privateKey, outFileName);
+      } else {
         byte[] bytes = bos.toByteArray();
         if (outFileName == null)
           return bytes;
@@ -474,10 +477,6 @@
         if (ret.indexOf("Exception") >= 0)
           return ret;
         msg += " " + ret;
-      } else {
-        JmolFileInterface f = viewer.apiPlatform.newFile(outFileName);
-        fullFilePath = f.getAbsolutePath().replace('\\', '/');
-        nBytes = f.length();
       }
     } catch (IOException e) {
       Logger.info(e.toString());

Modified: branches/v13_2/Jmol/src/org/jmol/script/ScriptEvaluator.java
===================================================================
--- branches/v13_2/Jmol/src/org/jmol/script/ScriptEvaluator.java        
2013-09-17 20:35:38 UTC (rev 18660)
+++ branches/v13_2/Jmol/src/org/jmol/script/ScriptEvaluator.java        
2013-09-17 21:24:53 UTC (rev 18661)
@@ -15179,6 +15179,14 @@
       }
       if (bytes != null && bytes instanceof String) {
         // load error or completion message here
+        /**
+         * @j2sNative
+         * 
+         * if (bytes.indexOf("OK") != 0)alert(bytes);
+         * 
+         */
+        {
+        }
         scriptStatusOrBuffer((String) bytes);
         return (String) bytes;
       }
@@ -15199,8 +15207,17 @@
         showString(Logger.getTimerMsg("write", 0));
     }
     if (!chk && msg != null) {
-      if (!msg.startsWith("OK"))
+      if (!msg.startsWith("OK")) {
         evalError(msg, null);
+        /**
+         * @j2sNative
+         * 
+         * alert(msg);
+         * 
+         */
+        {   
+        }
+      }
       scriptStatusOrBuffer(msg
           + (isImage ? "; width=" + width + "; height=" + height : ""));
       return msg;

Modified: branches/v13_2/Jmol/src/org/jmol/viewer/FileManager.java
===================================================================
--- branches/v13_2/Jmol/src/org/jmol/viewer/FileManager.java    2013-09-17 
20:35:38 UTC (rev 18660)
+++ branches/v13_2/Jmol/src/org/jmol/viewer/FileManager.java    2013-09-17 
21:24:53 UTC (rev 18661)
@@ -951,7 +951,7 @@
       return new String[] { null };
     boolean doSetPathForAllFiles = (pathForAllFiles.length() > 0);
     if (name.startsWith("?")) {
-       if ((name = viewer.dialogAsk("load", name.substring(1))) == null)
+       if ((name = viewer.dialogAsk("Load", name.substring(1))) == null)
          return new String[] { isFullLoad ? "#CANCELED#" : null };
        doSetPathForAllFiles = false;
     }

Modified: branches/v13_2/Jmol/src/org/jmol/viewer/Jmol.properties
===================================================================
--- branches/v13_2/Jmol/src/org/jmol/viewer/Jmol.properties     2013-09-17 
20:35:38 UTC (rev 18660)
+++ branches/v13_2/Jmol/src/org/jmol/viewer/Jmol.properties     2013-09-17 
21:24:53 UTC (rev 18661)
@@ -9,11 +9,14 @@
 #  Don't use ___ in your text, as that is the key for stripping out
 #  the information saved in the JAR version of this file.
 
-___JmolVersion="13.2.6_dev_2013.09.016"
+JmolVersion="13.2.6"
 
-bug fix: chains improperly selected in JSmol/HTML5
+___JmolVersion="13.2.6_dev_2013.09.17"
+
 bug fix: JSmol/HTML5 not allowing drag-drop or file loading from a local drive.
 bug fix: JSmol/HTML5 not allowing WRITE FILE ?
+bug fix: JSmol/HTML5 not allowing WRITE xxx.pdb, xxx.mol, etc
+bug fix: chains improperly selected in JSmol/HTML5
 
 bug fix: JavaScript version InputStreamReader not processing non-UTF data 
correctly
 bug fix: second reading of older PNG files with embedded script fails

Modified: branches/v13_2/Jmol/src/org/jmol/viewer/StateCreator.java
===================================================================
--- branches/v13_2/Jmol/src/org/jmol/viewer/StateCreator.java   2013-09-17 
20:35:38 UTC (rev 18660)
+++ branches/v13_2/Jmol/src/org/jmol/viewer/StateCreator.java   2013-09-17 
21:24:53 UTC (rev 18661)
@@ -2011,18 +2011,22 @@
      */
 
     Object ret = null;
+    boolean isClip = (fileName == null);
+    // localName will be fileName only if we are able to write to disk.
     String localName = null;
-    boolean isClip = (fileName == null);
     if (!isClip) {
       if (doCheck)
         fileName = getOutputFileNameFromDialog(fileName, quality);
       if (fileName == null)
         return null;
-      if (!viewer.isJS && FileManager.isLocal(fileName))
+      if (FileManager.isLocal(fileName))
         localName = fileName;
       if (fullPath != null)
         fullPath[0] = fileName;
     }
+    // JSmol/HTML5 WILL produce a localName now
+    if (!isClip && fullPath != null && (fileName = fullPath[0]) == null)
+      return null;
     int saveWidth = viewer.dimScreen.width;
     int saveHeight = viewer.dimScreen.height;
     viewer.creatingImage = true;
@@ -2048,9 +2052,8 @@
         } else {
           // see if application wants to do it (returns non-null String)
           // both Jmol application and applet return null
-          if (!type.equals("OutputStream"))
-            ret = viewer.statusManager.createImage(fileName, type, text, bytes,
-                quality);
+          ret = viewer.statusManager.createImage(fileName, type, text, bytes,
+              quality);
           if (ret == null) {
             // application can do it itself or allow Jmol to do it here
             JmolImageCreatorInterface c = viewer.getImageCreator();
@@ -2255,9 +2258,7 @@
     fileName = FileManager.getLocalPathForWritingFile(viewer, fileName);
     if (useDialog)
       fileName = viewer.dialogAsk(quality == Integer.MIN_VALUE ? "save"
-          : "saveImage", fileName);
-    if (viewer.isJS && fileName.indexOf("http:") < 0)
-      fileName = "POST://" + fileName;
+          : "Save Image", fileName);
     return fileName;
   }
 
@@ -2342,7 +2343,7 @@
     /**
      * @j2sNative
      * 
-     *            bos = os; asBytes = true;
+     *            bos = os;
     */
     {
       bos = new BufferedOutputStream(os);
@@ -2367,28 +2368,24 @@
     } catch (IOException e) {
       // ignore
     }
-    /**
-     * @j2sNative
-     * 
-     *            J.io.JmolBinary.postByteArray(this.viewer.fileManager,
-     *            fileName, os.toByteArray());
-     * 
-     */
-    {
-    }
     return msg;
   }
 
-  public OutputStream getOutputStream(String localName, String[] fullPath) {
+  public OutputStream getOutputStream(String fileName, String[] fullPath) {
     if (!viewer.isRestricted(ACCESS.ALL))
       return null;
-    Object ret = createImagePathCheck(localName, "OutputStream", null, null,
-        null, Integer.MIN_VALUE, 0, 0, fullPath, true);
-    if (ret instanceof String) {
-      Logger.error((String) ret);
+    fileName = getOutputFileNameFromDialog(fileName, Integer.MIN_VALUE);
+    if (fileName == null)
       return null;
+    if (fullPath != null)
+      fullPath[0] = fileName;
+    String localName = (FileManager.isLocal(fileName) ? fileName : null);
+    try {
+      return (OutputStream) viewer.openOutputChannel(privateKey, localName, 
false);
+    } catch (IOException e) {
+      Logger.info(e.toString());
+      return null;
     }
-    return (OutputStream) ret;
   }
 
   public void openFileAsync(String fileName, boolean pdbCartoons) {
@@ -2507,7 +2504,7 @@
           data = data.substring(0, ptEnd);
         out.write(data);
         if (ptEnd < 0)
-          out.write('\n');
+          out.write("\n");
       }
       out.close();
     } catch (Exception e) {

Modified: branches/v13_2/Jmol/src/org/jmol/viewer/StatusManager.java
===================================================================
--- branches/v13_2/Jmol/src/org/jmol/viewer/StatusManager.java  2013-09-17 
20:35:38 UTC (rev 18660)
+++ branches/v13_2/Jmol/src/org/jmol/viewer/StatusManager.java  2013-09-17 
21:24:53 UTC (rev 18661)
@@ -674,7 +674,7 @@
   private String imageType;
 
   String dialogAsk(String type, String fileName) {
-    boolean isImage = (type.startsWith("saveImage"));
+    boolean isImage = (type.equals("Save Image"));
     JmolDialogInterface sd = (JmolDialogInterface) Interface
     .getOptionInterface("export.dialog.Dialog");
     if (sd == null)

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13. 
http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk
_______________________________________________
Jmol-commits mailing list
Jmol-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-commits

Reply via email to