Revision: 20896
          http://sourceforge.net/p/jmol/code/20896
Author:   hansonr
Date:     2015-12-20 22:03:44 +0000 (Sun, 20 Dec 2015)
Log Message:
-----------
Jmol.___JmolVersion="14.5.1_2015.12.20"

code: (JavaScript) adding use of array.slice and implementing Java byte[] as 
JavaScript Int8Array()

bug fix: array handling for labels very inefficient
bug fix: y = javascript("x") only creates string equivalent of x, not actual 
numerical/object values
bug fix: y = javascript("x") draws "x" from wrapped anonymous function using 
eval() instead of global context using window.eval()

Modified Paths:
--------------
    trunk/Jmol/src/javajs/util/AU.java
    trunk/Jmol/src/javajs/util/BS.java
    trunk/Jmol/src/javajs/util/CompoundDocHeader.java
    trunk/Jmol/src/javajs/util/PT.java
    trunk/Jmol/src/javajs/util/Rdr.java
    trunk/Jmol/src/org/jmol/adapter/readers/pymol/JmolObject.java
    trunk/Jmol/src/org/jmol/applet/Jmol.java
    trunk/Jmol/src/org/jmol/appletjs/Jmol.java
    trunk/Jmol/src/org/jmol/jvxl/readers/IsoFxyReader.java
    trunk/Jmol/src/org/jmol/jvxl/readers/IsoMOReader.java
    trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceReader.java
    trunk/Jmol/src/org/jmol/jvxl/readers/VolumeFileReader.java
    trunk/Jmol/src/org/jmol/modelset/Atom.java
    trunk/Jmol/src/org/jmol/script/SV.java
    trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java
    trunk/Jmol/src/org/jmol/scriptext/IsoExt.java
    trunk/Jmol/src/org/jmol/scriptext/MathExt.java
    trunk/Jmol/src/org/jmol/shape/AtomShape.java
    trunk/Jmol/src/org/jmol/shape/Labels.java
    trunk/Jmol/src/org/jmol/util/GenericApplet.java
    trunk/Jmol/src/org/jmol/viewer/Jmol.properties
    trunk/Jmol/src/org/jmol/viewer/StatusManager.java
    trunk/Jmol/src/org/jmol/viewer/Viewer.java

Modified: trunk/Jmol/src/javajs/util/AU.java
===================================================================
--- trunk/Jmol/src/javajs/util/AU.java  2015-12-20 22:01:37 UTC (rev 20895)
+++ trunk/Jmol/src/javajs/util/AU.java  2015-12-20 22:03:44 UTC (rev 20896)
@@ -36,46 +36,36 @@
 
   /**
    * Very important that this not be used with Int32Array or Float32Array,
-   * because it is not initialized to all zeros in MSIE 9.
+   * because it is not initialized to all zeros in MSIE 9. 
    * 
    * @param array
    * @param minimumLength
    * @return array
    */
   public static Object ensureLength(Object array, int minimumLength) {
-    if (array != null && getLength(array) >= minimumLength)
-      return array;
-    return arrayCopyObject(array, minimumLength);
+    return (array != null && getLength(array) >= minimumLength ? array 
+        : arrayCopyObject(array, minimumLength));
   }
 
   public static String[] ensureLengthS(String[] array, int minimumLength) {
-    if (array != null && array.length >= minimumLength)
-      return array;
-    return arrayCopyS(array, minimumLength);
+    return (array != null && array.length >= minimumLength ? array
+        : arrayCopyS(array, minimumLength));
   }
 
   public static float[] ensureLengthA(float[] array, int minimumLength) {
-    if (array != null && array.length >= minimumLength)
-      return array;
-    return arrayCopyF(array, minimumLength);
+   return (array != null && array.length >= minimumLength ? array: 
arrayCopyF(array, minimumLength));
   }
 
   public static int[] ensureLengthI(int[] array, int minimumLength) {
-    if (array != null && array.length >= minimumLength)
-      return array;
-    return arrayCopyI(array, minimumLength);
+    return (array != null && array.length >= minimumLength ? array : 
arrayCopyI(array, minimumLength));
   }
 
   public static short[] ensureLengthShort(short[] array, int minimumLength) {
-    if (array != null && array.length >= minimumLength)
-      return array;
-    return arrayCopyShort(array, minimumLength);
+    return (array != null && array.length >= minimumLength ? array : 
arrayCopyShort(array, minimumLength));
   }
 
   public static byte[] ensureLengthByte(byte[] array, int minimumLength) {
-    if (array != null && array.length >= minimumLength)
-      return array;
-    return arrayCopyByte(array, minimumLength);
+    return (array != null && array.length >= minimumLength ? array : 
arrayCopyByte(array, minimumLength));
   }
 
   /**
@@ -132,22 +122,26 @@
   }
 
   /**
-   * note -- cannot copy if array is null!
+   * note -- cannot copy if array is null! does not copy if length is unchanged
    * 
    * @param array
    * @param newLength
    * @return array
    */
-  public static Object arrayCopyObject(Object array, int newLength) {
-    //System.out.println("ArrayUtil.copy " + newLength + " " + array + "  ");
-    if (array == null) {
-      return null; // We can't allocate since we don't know the type of array
-    }
-    int oldLength = getLength(array);
+  public static Object arrayCopyObject(Object array, int newLength) {  
+    int oldLength = (array == null ? -1 : getLength(array));
+    if (newLength < 0) newLength = oldLength;
     if (newLength == oldLength)
-      return array;
+     return array;
+    /**
+     * @j2sNative
+     * 
+     *     if (newLength < oldLength) return Clazz.newArray(-1, array, 0, 
newLength);
+     */
+    {}
     Object t = newInstanceO(array, newLength);
-    System.arraycopy(array, 0, t, 0, oldLength < newLength ? oldLength
+    if (oldLength > 0)
+      System.arraycopy(array, 0, t, 0, oldLength < newLength ? oldLength
         : newLength);
     return t;
 
@@ -190,11 +184,16 @@
   }
 
   public static String[] arrayCopyS(String[] array, int newLength) {
-    if (newLength < 0)
-      newLength = array.length;
+    int oldLength = (array == null ? -1 : array.length);
+    if (newLength < 0) newLength = oldLength;
+    /**
+     * @j2sNative
+     * 
+     *     if (newLength < oldLength) return Clazz.newArray(-1, array, 0, 
newLength);
+     */
+    {}
     String[] t = new String[newLength];
     if (array != null) {
-      int oldLength = array.length;
       System.arraycopy(array, 0, t, 0, oldLength < newLength ? oldLength
           : newLength);
     }
@@ -224,11 +223,16 @@
   }
 
   public static float[] arrayCopyF(float[] array, int newLength) {
-    if (newLength < 0)
-      newLength = array.length;
+    int oldLength = (array == null ? -1 : array.length);
+    if (newLength < 0) newLength = oldLength;
+    /**
+     * @j2sNative
+     * 
+     *     if (newLength < oldLength) return Clazz.newArray(-1, array, 0, 
newLength);
+     */
+    {}
     float[] t = new float[newLength];
     if (array != null) {
-      int oldLength = array.length;
       System.arraycopy(array, 0, t, 0, oldLength < newLength ? oldLength
           : newLength);
     }
@@ -236,11 +240,16 @@
   }
 
   public static int[] arrayCopyI(int[] array, int newLength) {
-    if (newLength < 0)
-      newLength = array.length;
+    int oldLength = (array == null ? -1 : array.length);
+    if (newLength < 0) newLength = oldLength;
+    /**
+     * @j2sNative
+     * 
+     *     if (newLength < oldLength) return Clazz.newArray(-1, array, 0, 
newLength);
+     */
+    {}
     int[] t = new int[newLength];
     if (array != null) {
-      int oldLength = array.length;
       System.arraycopy(array, 0, t, 0, oldLength < newLength ? oldLength
           : newLength);
     }
@@ -261,29 +270,49 @@
     int oldLength = array.length;
     if (n == -1) n = oldLength;
     if (n == -2) n = oldLength / 2;
-    n = n - i0;
-    int[] t = new int[n];
-    System.arraycopy(array, i0, t, 0, n);
-    return t;
+    /**
+     * @j2sNative
+     * 
+     * return Clazz.newArray(-1, array, i0, n);
+     * 
+     */
+    {
+      n -= i0;
+      int[] t = new int[n];
+      System.arraycopy(array, i0, t, 0, n);
+      return t;
+    }
   }
 
   public static int[] arrayCopyRangeRevI(int[] array, int i0, int n) {
     if (array == null)
       return null;
-    int[] t = arrayCopyRangeI(array, i0, n);
-    if (n < 0)
-      n = array.length;
-    for (int i = n / 2; --i >= 0;)
-      swapInt(t, i, n - 1 - i);
-    return t;
+    /**
+     * @j2sNative
+     * 
+     * return Clazz.newArray(-1, array, i0, n).reverse();
+     */
+    {
+      int[] t = arrayCopyRangeI(array, i0, n);
+      if (n < 0)
+        n = array.length;
+      for (int i = n / 2; --i >= 0;)
+        swapInt(t, i, n - 1 - i);
+      return t;
+    }
   }
 
   public static short[] arrayCopyShort(short[] array, int newLength) {
-    if (newLength < 0)
-      newLength = array.length;
+    int oldLength = (array == null ? -1 : array.length);
+    if (newLength < 0) newLength = oldLength;
+    /**
+     * @j2sNative
+     * 
+     *     if (newLength < oldLength) return Clazz.newArray(-1, array, 0, 
newLength);
+     */
+    {}
     short[] t = new short[newLength];
     if (array != null) {
-      int oldLength = array.length;
       System.arraycopy(array, 0, t, 0, oldLength < newLength ? oldLength
           : newLength);
     }
@@ -291,11 +320,16 @@
   }
 
   public static byte[] arrayCopyByte(byte[] array, int newLength) {
-    if (newLength < 0)
-      newLength = array.length;
+    int oldLength = (array == null ? -1 : array.length);
+    if (newLength < 0) newLength = oldLength;
+    /**
+     * @j2sNative
+     * 
+     *     if (newLength < oldLength) return Clazz.newArray(-1, array, 0, 
newLength);
+     */
+    {}
     byte[] t = new byte[newLength];
     if (array != null) {
-      int oldLength = array.length;
       System.arraycopy(array, 0, t, 0, oldLength < newLength ? oldLength
           : newLength);
     }
@@ -303,11 +337,16 @@
   }
 
   public static boolean[] arrayCopyBool(boolean[] array, int newLength) {
-    if (newLength < 0)
-      newLength = array.length;
+    int oldLength = (array == null ? -1 : array.length);
+    if (newLength < 0) newLength = oldLength;
+    /**
+     * @j2sNative
+     * 
+     *     if (newLength < oldLength) return Clazz.newArray(-1, array, 0, 
newLength);
+     */
+    {}
     boolean[] t = new boolean[newLength];
     if (array != null) {
-      int oldLength = array.length;
       System.arraycopy(array, 0, t, 0, oldLength < newLength ? oldLength
           : newLength);
     }
@@ -584,7 +623,7 @@
        public static boolean isAB(Object x) {
          /**
           * @j2sNative
-          *  return Clazz.isAI(x);
+          *  return Clazz.isAB(x);
           */
          {
          return x instanceof byte[];
@@ -636,6 +675,7 @@
         * process, but particularly out of file reading.
         * 
         * @param b
+        * @return b
         */
        public static byte[] ensureSignedBytes(byte[] b) {
                if (b != null) {

Modified: trunk/Jmol/src/javajs/util/BS.java
===================================================================
--- trunk/Jmol/src/javajs/util/BS.java  2015-12-20 22:01:37 UTC (rev 20895)
+++ trunk/Jmol/src/javajs/util/BS.java  2015-12-20 22:03:44 UTC (rev 20896)
@@ -728,9 +728,18 @@
    * @param n 
    */
   private void setLength(int n) {
+    /**
+     * @j2sNative
+     *     if (n == this.words.length) return;
+     *     if (n == this.wordsInUse) {
+     *      this.words = Clazz.newArray(-1, this.words, 0, n);
+     *      return;
+     *     }
+     */
+    {}
     int[] a = new int[n];
-    System.arraycopy(words, 0, a, 0, Math.min(wordsInUse, n));
-    words = a;
+    System.arraycopy(words, 0, a, 0, wordsInUse);
+    words = a;    
   }
 
   /**
@@ -798,8 +807,21 @@
     if (wordCount == 0) {
       bs.words = emptyBitmap;
     } else {
-      bs.words = new int[bs.wordsInUse = wordCount];
-      System.arraycopy(bitsetToCopy.words, 0, bs.words, 0, wordCount);
+      
+      /**
+       * Clazz.clone will copy wordsInUse and sizeIsSticky, 
+       * but just a pointer to the words array.
+       * 
+       * @j2sNative
+       * 
+       *   bs.words = Clazz.newArray(-1, bitsetToCopy.words, 0, bs.wordsInUse 
= wordCount);
+       * 
+       */
+      {
+        bs.words = new int[bs.wordsInUse = wordCount];
+        System.arraycopy(bitsetToCopy.words, 0, bs.words, 0, wordCount);
+      }
+
     }
     return bs;
   }
@@ -820,8 +842,8 @@
   @Override
   public String toJSON() {
 
-    int numBits = (wordsInUse > 128) ? cardinality() : wordsInUse
-        * BITS_PER_WORD;
+    int numBits = (wordsInUse > 128 ? cardinality() : wordsInUse
+        * BITS_PER_WORD);
     SB b = SB.newN(6 * numBits + 2);
     b.appendC('[');
 

Modified: trunk/Jmol/src/javajs/util/CompoundDocHeader.java
===================================================================
--- trunk/Jmol/src/javajs/util/CompoundDocHeader.java   2015-12-20 22:01:37 UTC 
(rev 20895)
+++ trunk/Jmol/src/javajs/util/CompoundDocHeader.java   2015-12-20 22:03:44 UTC 
(rev 20896)
@@ -77,10 +77,10 @@
   final boolean readData() {
     try {
       cd.readByteArray(magicNumbers, 0, 8);
-      if (magicNumbers[0] != (byte) 0xD0 || magicNumbers[1] != (byte) 0xCF
-          || magicNumbers[2] != (byte) 0x11 || magicNumbers[3] != (byte) 0xE0
-          || magicNumbers[4] != (byte) 0xA1 || magicNumbers[5] != (byte) 0xB1
-          || magicNumbers[6] != (byte) 0x1A || magicNumbers[7] != (byte) 0xE1)
+      if ((magicNumbers[0] & 0xFF) != 0xD0 || (magicNumbers[1] & 0xFF) != 0xCF
+          || (magicNumbers[2] & 0xFF) != 0x11 || (magicNumbers[3] & 0xFF) != 
0xE0
+          || (magicNumbers[4] & 0xFF) != 0xA1 || (magicNumbers[5] & 0xFF) != 
0xB1
+          || (magicNumbers[6] & 0xFF) != 0x1A || (magicNumbers[7] & 0xFF) != 
0xE1)
         return false;
       cd.readByteArray(uniqueID16, 0, 16);
       revNumber = cd.readByte();

Modified: trunk/Jmol/src/javajs/util/PT.java
===================================================================
--- trunk/Jmol/src/javajs/util/PT.java  2015-12-20 22:01:37 UTC (rev 20895)
+++ trunk/Jmol/src/javajs/util/PT.java  2015-12-20 22:03:44 UTC (rev 20896)
@@ -863,7 +863,7 @@
   }
 
   /**
-   * Checks to see if an object is an array, and if it is, returns null;
+   * Checks to see if an object is an array (including typed arrays), and if 
it is, returns null;
    * otherwise it returns the string equivalent of that object.
    * 
    * @param x
@@ -873,7 +873,7 @@
     /**
      * @j2sNative
      * 
-     * return (x.constructor == Array ? null : x.toString());
+     * return (x.constructor == Array || x.BYTES_PER_ELEMENT ? null : 
x.toString());
      * 
      */
     {

Modified: trunk/Jmol/src/javajs/util/Rdr.java
===================================================================
--- trunk/Jmol/src/javajs/util/Rdr.java 2015-12-20 22:01:37 UTC (rev 20895)
+++ trunk/Jmol/src/javajs/util/Rdr.java 2015-12-20 22:03:44 UTC (rev 20896)
@@ -96,17 +96,17 @@
   }
 
   private static Encoding getUTFEncoding(byte[] bytes) {
-    if (bytes.length >= 3 && bytes[0] == (byte) 0xEF && bytes[1] == (byte) 
0xBB && bytes[2] == (byte) 0xBF)
+    if (bytes.length >= 3 && (bytes[0] & 0xFF) == 0xEF && (bytes[1] & 0xFF) == 
0xBB && (bytes[2] & 0xFF) == 0xBF)
       return Encoding.UTF8;
-    if (bytes.length >= 4 && bytes[0] == (byte) 0 && bytes[1] == (byte) 0 
-        && bytes[2] == (byte) 0xFE && bytes[3] == (byte) 0xFF)
+    if (bytes.length >= 4 && (bytes[0] & 0xFF) == 0 && (bytes[1] & 0xFF) == 0 
+        && (bytes[2] & 0xFF) == 0xFE && (bytes[3] & 0xFF) == 0xFF)
       return Encoding.UTF_32BE;
-    if (bytes.length >= 4 && bytes[0] == (byte) 0xFF && bytes[1] == (byte) 
0xFE 
-        && bytes[2] == (byte) 0 && bytes[3] == (byte) 0)
+    if (bytes.length >= 4 && (bytes[0] & 0xFF) == 0xFF && (bytes[1] & 0xFF) == 
0xFE 
+        && (bytes[2] & 0xFF) == 0 && (bytes[3] & 0xFF) == 0)
       return Encoding.UTF_32LE;
-    if (bytes.length >= 2 && bytes[0] == (byte) 0xFF && bytes[1] == (byte) 
0xFE)
+    if (bytes.length >= 2 && (bytes[0] & 0xFF) == 0xFF && (bytes[1] & 0xFF) == 
0xFE)
       return Encoding.UTF_16LE;
-    if (bytes.length >= 2 && bytes[0] == (byte) 0xFE && bytes[1] == (byte) 
0xFF)
+    if (bytes.length >= 2 && (bytes[0] & 0xFF) == 0xFE && (bytes[1] & 0xFF) == 
0xFF)
       return Encoding.UTF_16BE;
     return Encoding.NONE;
   
@@ -145,11 +145,11 @@
   }
 
   public static boolean isCompoundDocumentB(byte[] bytes) {
-    return (bytes.length >= 8 && bytes[0] == (byte) 0xD0
-        && bytes[1] == (byte) 0xCF && bytes[2] == (byte) 0x11
-        && bytes[3] == (byte) 0xE0 && bytes[4] == (byte) 0xA1
-        && bytes[5] == (byte) 0xB1 && bytes[6] == (byte) 0x1A 
-        && bytes[7] == (byte) 0xE1);
+    return (bytes.length >= 8 && (bytes[0] & 0xFF) == 0xD0
+        && (bytes[1] & 0xFF) == 0xCF && (bytes[2] & 0xFF) == 0x11
+        && (bytes[3] & 0xFF) == 0xE0 && (bytes[4] & 0xFF) == 0xA1
+        && (bytes[5] & 0xFF) == 0xB1 && (bytes[6] & 0xFF) == 0x1A 
+        && (bytes[7] & 0xFF) == 0xE1);
   }
 
   public static boolean isGzipS(InputStream is) {
@@ -158,7 +158,7 @@
 
   public static boolean isGzipB(byte[] bytes) {    
       return (bytes != null && bytes.length >= 2 
-          && bytes[0] == (byte) 0x1F && bytes[1] == (byte) 0x8B);
+          && (bytes[0] & 0xFF) == 0x1F && (bytes[1] & 0xFF) == 0x8B);
   }
 
   public static boolean isPickleS(InputStream is) {
@@ -167,7 +167,7 @@
 
   public static boolean isPickleB(byte[] bytes) {    
       return (bytes != null && bytes.length >= 2 
-          && bytes[0] == (byte) 0x7D && bytes[1] == (byte) 0x71);
+          && (bytes[0] & 0xFF) == 0x7D && (bytes[1] & 0xFF) == 0x71);
   }
 
   public static boolean isPngZipStream(InputStream is) {

Modified: trunk/Jmol/src/org/jmol/adapter/readers/pymol/JmolObject.java
===================================================================
--- trunk/Jmol/src/org/jmol/adapter/readers/pymol/JmolObject.java       
2015-12-20 22:01:37 UTC (rev 20895)
+++ trunk/Jmol/src/org/jmol/adapter/readers/pymol/JmolObject.java       
2015-12-20 22:03:44 UTC (rev 20896)
@@ -187,7 +187,7 @@
       return;
     case JC.SHAPE_LABELS:
       sm.loadShape(id);
-      sm.setShapePropertyBs(id, "textLabels", info, bsAtoms);
+      sm.setShapePropertyBs(id, "pymolLabels", info, bsAtoms);
       return;
     case T.bonds:
       break;

Modified: trunk/Jmol/src/org/jmol/applet/Jmol.java
===================================================================
--- trunk/Jmol/src/org/jmol/applet/Jmol.java    2015-12-20 22:01:37 UTC (rev 
20895)
+++ trunk/Jmol/src/org/jmol/applet/Jmol.java    2015-12-20 22:03:44 UTC (rev 
20896)
@@ -24,26 +24,26 @@
 
 package org.jmol.applet;
 
-import org.jmol.awt.FileDropper;
-import org.jmol.c.CBK;
-import org.jmol.util.GenericApplet;
-import org.jmol.util.Logger;
-import org.jmol.util.Parser;
-
 import java.applet.Applet;
 import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.Graphics;
 import java.net.URL;
-import javajs.util.PT;
-
 import java.util.Hashtable;
 import java.util.Map;
 
+import javajs.util.PT;
+
 import javax.swing.UIManager;
 
 import netscape.javascript.JSObject;
 
+import org.jmol.awt.FileDropper;
+import org.jmol.c.CBK;
+import org.jmol.util.GenericApplet;
+import org.jmol.util.Logger;
+import org.jmol.util.Parser;
+
 /*
  * 
  * 
@@ -679,5 +679,4 @@
       //ignore if page is closing
     }
   }
-
 }

Modified: trunk/Jmol/src/org/jmol/appletjs/Jmol.java
===================================================================
--- trunk/Jmol/src/org/jmol/appletjs/Jmol.java  2015-12-20 22:01:37 UTC (rev 
20895)
+++ trunk/Jmol/src/org/jmol/appletjs/Jmol.java  2015-12-20 22:03:44 UTC (rev 
20896)
@@ -24,22 +24,21 @@
 
 package org.jmol.appletjs;
 
-import org.jmol.util.Logger;
-import org.jmol.util.Parser;
-import org.jmol.util.GenericApplet;
-
 import java.net.URL;
+import java.util.Hashtable;
+import java.util.Map;
 
 import javajs.api.JSInterface;
 import javajs.util.PT;
 
-import java.util.Hashtable;
-import java.util.Map;
+import org.jmol.util.GenericApplet;
+import org.jmol.util.Logger;
+import org.jmol.util.Parser;
 
 /**
  * Java2Script rendition of Jmol using HTML5-only or WebGL-based graphics
  * 
- * @author Bob Hanson hans...@stolaf.edu, Takanori Nakane, with the assistance
+ * @author Bob Hanson hans...@stolaf.edu, Takanori Nakane, with the assistance 
 
  *         of Jhou Renjian
  * 
  */
@@ -128,7 +127,7 @@
             /**
              * @j2sNative
              * 
-             *            fxy[i][j] = eval(functionName)(this.htmlName, i, j);
+             *            fxy[i][j] = window.eval(functionName)(this.htmlName, 
i, j);
              */
             {
             }
@@ -138,7 +137,7 @@
         /**
          * @j2sNative
          * 
-         *            data = eval(functionName)(this.htmlName, nX, nY);
+         *            data = window.eval(functionName)(this.htmlName, nX, nY);
          * 
          */
         {
@@ -156,7 +155,7 @@
         /**
          * @j2sNative
          * 
-         *            data = eval(functionName)(this.htmlName, nX, nY, fxy);
+         *            data = window.eval(functionName)(this.htmlName, nX, nY, 
fxy);
          * 
          */
         {
@@ -182,7 +181,7 @@
       /**
        * @j2sNative
        * 
-       *            eval(functionName)(this.htmlName, nX, nY, nZ, fxyz);
+       *            window.eval(functionName)(this.htmlName, nX, nY, nZ, fxyz);
        * 
        */
       {
@@ -240,13 +239,17 @@
     return "";
   }
 
+  /**
+   * return RAW JAVASCRIPT OBJECT, NOT A STRING 
+   */
   @Override
   protected String doEval(String strEval) {
     try {
       /**
+       * 
        * @j2sNative
        * 
-       *            return "" + eval(strEval);
+       *            return window.eval(strEval);
        */
       {
       }

Modified: trunk/Jmol/src/org/jmol/jvxl/readers/IsoFxyReader.java
===================================================================
--- trunk/Jmol/src/org/jmol/jvxl/readers/IsoFxyReader.java      2015-12-20 
22:01:37 UTC (rev 20895)
+++ trunk/Jmol/src/org/jmol/jvxl/readers/IsoFxyReader.java      2015-12-20 
22:03:44 UTC (rev 20896)
@@ -99,7 +99,7 @@
 
   @Override
   public float[] getPlane(int x) {
-    float[] plane = getPlane2(x);
+    float[] plane = getPlaneSR(x);
     setPlane(x, plane);
     return plane;
   }

Modified: trunk/Jmol/src/org/jmol/jvxl/readers/IsoMOReader.java
===================================================================
--- trunk/Jmol/src/org/jmol/jvxl/readers/IsoMOReader.java       2015-12-20 
22:01:37 UTC (rev 20895)
+++ trunk/Jmol/src/org/jmol/jvxl/readers/IsoMOReader.java       2015-12-20 
22:03:44 UTC (rev 20896)
@@ -343,7 +343,7 @@
   public float[] getPlane(int x) {
     if (!qSetupDone) 
       setupCalculation();
-    return getPlane2(x); 
+    return getPlaneSR(x); 
   }
 
   private boolean qSetupDone;

Modified: trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceReader.java
===================================================================
--- trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceReader.java     2015-12-20 
22:01:37 UTC (rev 20895)
+++ trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceReader.java     2015-12-20 
22:03:44 UTC (rev 20896)
@@ -547,10 +547,10 @@
   
   @Override
   public float[] getPlane(int x) {
-    return getPlane2(x);
+    return getPlaneSR(x);
   }
 
-  protected float[] getPlane2(int x) {
+  protected float[] getPlaneSR(int x) {
     if (yzCount == 0)
       initPlanes();
     if (qpc != null)

Modified: trunk/Jmol/src/org/jmol/jvxl/readers/VolumeFileReader.java
===================================================================
--- trunk/Jmol/src/org/jmol/jvxl/readers/VolumeFileReader.java  2015-12-20 
22:01:37 UTC (rev 20895)
+++ trunk/Jmol/src/org/jmol/jvxl/readers/VolumeFileReader.java  2015-12-20 
22:03:44 UTC (rev 20896)
@@ -327,9 +327,9 @@
       initPlanes();
     if (preProcessPlanes)
       return getPlaneProcessed(x);
-    float[] plane = getPlane2(x);
+    float[] plane = getPlaneSR(x);
     if (qpc == null)
-      getPlane(plane, true);
+      getPlaneVFR(plane, true);
     return plane;
   }
 
@@ -362,8 +362,8 @@
       qpc.setPlanes(yzPlanesRaw = new float[4][yzCount]);
       if (hasColorData) {
         //float nan = qpc.getNoValue();
-        getPlane(yzPlanesRaw[0], false);
-        getPlane(yzPlanesRaw[1], false);
+        getPlaneVFR(yzPlanesRaw[0], false);
+        getPlaneVFR(yzPlanesRaw[1], false);
         plane = yzPlanes[0];
         for (int i = 0; i < yzCount; i++)
           plane[i] = Float.NaN;
@@ -391,7 +391,7 @@
       plane = yzPlanesRaw[iPlaneRaw];
     }
     if (x < x1) {
-      getPlane(plane, false);
+      getPlaneVFR(plane, false);
       qpc.calcPlane(x, plane = yzPlanes[x % 2]);
       for (int i = 0; i < yzCount; i++)
         if (plane[i] != nan)
@@ -403,7 +403,7 @@
     return plane;
   }
 
-  private void getPlane(float[] plane, boolean doRecord) {
+  private void getPlaneVFR(float[] plane, boolean doRecord) {
     try {
       for (int y = 0, ptyz = 0; y < nPointsY; ++y) {
         for (int z = 0; z < nPointsZ; ++z) {

Modified: trunk/Jmol/src/org/jmol/modelset/Atom.java
===================================================================
--- trunk/Jmol/src/org/jmol/modelset/Atom.java  2015-12-20 22:01:37 UTC (rev 
20895)
+++ trunk/Jmol/src/org/jmol/modelset/Atom.java  2015-12-20 22:03:44 UTC (rev 
20896)
@@ -441,7 +441,7 @@
 
   public void setValence(int nBonds) {
     if (!isDeleted()) // no resurrection
-      valence = (byte) (nBonds < 0 ? 0 : nBonds < 0xEF ? nBonds : 0xEF);
+      valence = (byte) (nBonds < 0 ? 0 : nBonds <= 0x7F ? nBonds : 0x7F);
   }
 
   /**

Modified: trunk/Jmol/src/org/jmol/script/SV.java
===================================================================
--- trunk/Jmol/src/org/jmol/script/SV.java      2015-12-20 22:01:37 UTC (rev 
20895)
+++ trunk/Jmol/src/org/jmol/script/SV.java      2015-12-20 22:03:44 UTC (rev 
20896)
@@ -86,6 +86,13 @@
     return sv;
   }
   
+  public static SV newF(float f) {
+    SV sv = new SV();
+    sv.tok = decimal;
+    sv.value = Float.valueOf(f);
+    return sv;
+  }
+  
   public static SV newS(String s) {
     return newV(string, s);
   }
@@ -267,6 +274,7 @@
     if (x instanceof ScriptContext)
       return newV(context, x);
     // rest are specific array types supported
+    // DO NOT ADD MORE UNLESS YOU CHANGE isArray(), above
     if (Escape.isAV(x))
       return getVariableAV((SV[]) x);
     if (AU.isAI(x))
@@ -291,12 +299,53 @@
       return getVariableADD((double[][]) x);
     if (AU.isAFloat(x))
       return newV(listf, x);
-    return newS(x.toString());
+    return newJSVar(x);
   }
 
+  /**
+   * Conversion to Jmol variables of JavaScript variables using
+   * y = javascript("x")
+   * 
+   * @param x a JavaScript variable, perhaps
+   * @return SV
+   */
+  @SuppressWarnings("unused")
+  private static SV newJSVar(Object x) {
+    // JavaScript only
+    /**
+     * @j2sNative
+     * 
+     *            switch(x.BYTES_PER_ELEMENT ? Array : x.constructor) {
+     *            case Boolean:
+     *              return (x ? org.jmol.script.SV.vT : org.jmol.script.SV.vF);
+     *            case Number:
+     *              return (x > Integer.MAX_VALUE || x != Math.floor(x) ? 
org.jmol.script.SV.newF(x) : org.jmol.script.SV.newI(x));
+     *            case Array:
+     *              var v =  new javajs.util.Lst();
+     *              for (var i = 0, n = x.length; i < n; i++)
+     *                v.addLast(org.jmol.script.SV.newJSVar(x[i]));
+     *              return org.jmol.script.SV.getVariableList(v);
+     *            case Object: 
+     *              var keys = Object.keys(x);
+     *              var v =  new java.util.Hashtable();
+     *              for (var i = keys.length; --i >= 0;)
+     *                v.put(keys[i],org.jmol.script.SV.newJSVar(x[keys[i]]));
+     *              return org.jmol.script.SV.getVariableMap(v);
+     *            }
+     *            
+     */
+    {
+      // for reference only; not included in JavaScript
+      if (false) {
+        getVariableList(new Lst<SV>());
+        getVariableMap(new Hashtable<String, Object>());
+      }
+    }
+    return newS(x.toString());    
+  }
+
   @SuppressWarnings("unchecked")
-  public
-  static SV getVariableMap(Map<String, ?> x) {
+  public static SV getVariableMap(Map<String, ?> x) {
     Map<String, Object> ht = (Map<String, Object>) x;
     Object o = null;
     for (Object oo : ht.values()) {
@@ -1080,16 +1129,17 @@
       intValue = index = Integer.MAX_VALUE;
       break;
     case varray:
-      len = getList().size();
+      @SuppressWarnings("unchecked")
+      Lst<SV> v = (Lst<SV>) value;
+      len = v.size();
       if (pt1 <= 0)
         pt1 = len + pt1;
       if (--pt1 < 0)
         pt1 = 0;
-      if (len <= pt1) {
+      if (len <= pt1)
         for (int i = len; i <= pt1; i++)
-          getList().addLast(newV(string, ""));
-      }
-      getList().set(pt1, var);
+          v.addLast(newV(string, ""));
+      v.set(pt1, var);
       break;
     }
   }
@@ -1511,27 +1561,6 @@
     return list;
   }
 
-// I have no idea! 
-//
-//  static List<Object> listAny(SV x) {
-//    List<Object> list = new List<Object>();
-//    List<SV> l = x.getList();
-//    for (int i = 0; i < l.size(); i++) {
-//      SV v = l.get(i);
-//      List<SV> l2 = v.getList();
-//      if (l2 == null) {
-//        list.addLast(v.value);        
-//      } else {
-//        List<Object> o = new List<Object>();
-//        for (int j = 0; j < l2.size(); j++) {
-//          v = l2.get(j);
-//        }
-//        list.addLast(o);
-//      }
-//    }
-//    return list;    
-//  }
-  
   public static float[] flistValue(T x, int nMin) {
     if (x.tok != varray)
       return new float[] { fValue(x) };
@@ -1776,4 +1805,5 @@
         + (property instanceof SV ? PT.esc(key) + " : " + format(new SV[] { 
null, (SV) property },
             0) : PT.toJSON(key, property)) + "}";
   }
+
 }

Modified: trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java
===================================================================
--- trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java     2015-12-20 
22:01:37 UTC (rev 20895)
+++ trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java     2015-12-20 
22:03:44 UTC (rev 20896)
@@ -274,7 +274,7 @@
   public boolean addXFloat(float x) {
     if (Float.isNaN(x))
       return addXStr("NaN");
-    putX(SV.newV(T.decimal, Float.valueOf(x)));
+    putX(SV.newF(x));
     return wasX = true;
   }
 
@@ -309,7 +309,7 @@
           float f = ((Float) x.value).floatValue();
           if (f < 0 || f == 0 && 1 / f == Float.NEGATIVE_INFINITY) {
             addOp(T.tokenMinus);
-            v = SV.newV(T.decimal, Float.valueOf(-f));
+            v = SV.newF(-f);
             break;
           }
         }

Modified: trunk/Jmol/src/org/jmol/scriptext/IsoExt.java
===================================================================
--- trunk/Jmol/src/org/jmol/scriptext/IsoExt.java       2015-12-20 22:01:37 UTC 
(rev 20895)
+++ trunk/Jmol/src/org/jmol/scriptext/IsoExt.java       2015-12-20 22:03:44 UTC 
(rev 20896)
@@ -3545,7 +3545,7 @@
           + ret + "}", false);
       Lst<SV> params = new Lst<SV>();
       for (int i = 0; i < xyz.length(); i += 2)
-        params.addLast(SV.newV(T.decimal, Float.valueOf(0f)).setName(
+        params.addLast(SV.newF(0).setName(
             xyz.substring(i, i + 1)));
       return new Object[] { e.aatoken[0][1].value, params };
     } catch (Exception ex) {

Modified: trunk/Jmol/src/org/jmol/scriptext/MathExt.java
===================================================================
--- trunk/Jmol/src/org/jmol/scriptext/MathExt.java      2015-12-20 22:01:37 UTC 
(rev 20895)
+++ trunk/Jmol/src/org/jmol/scriptext/MathExt.java      2015-12-20 22:03:44 UTC 
(rev 20896)
@@ -460,8 +460,8 @@
         map.put("_bin", SV.newI(bin));
         float v1 = f0 + df * bin;
         float v2 = v1 + df;
-        map.put("_binMin", SV.newV(T.decimal,  Float.valueOf(bin == 0 ? 
-Float.MAX_VALUE : v1)));
-        map.put("_binMax", SV.newV(T.decimal,  Float.valueOf(bin == nbins - 1 
? Float.MAX_VALUE  : v2)));        
+        map.put("_binMin", SV.newF(bin == 0 ? -Float.MAX_VALUE : v1));
+        map.put("_binMax", SV.newF(bin == nbins - 1 ? Float.MAX_VALUE  : v2)); 
       
       }
     }
     return mp.addXAI(array);
@@ -1945,14 +1945,14 @@
       else if (Float.isNaN(list2[i]))
         b = SV.getVariable(SV.unescapePointOrBitsetAsVariable(sList2[i]));
       else
-        b = SV.newV(T.decimal, Float.valueOf(list2[i]));
+        b = SV.newF(list2[i]);
       if (!isScalar1) {
         if (isArray1)
           a = alist1.get(i);
         else if (Float.isNaN(list1[i]))
           a = SV.getVariable(SV.unescapePointOrBitsetAsVariable(sList1[i]));
         else
-          a = SV.newV(T.decimal, Float.valueOf(list1[i]));
+          a = SV.newF(list1[i]);
       }
       if (tok == T.join) {
         if (a.tok != T.varray) {
@@ -2792,8 +2792,7 @@
       e.runScriptBuffer("show " + s, sb, true);
       break;
     case T.javascript:
-      sb.append(vwr.jsEval(s));
-      break;
+      return mp.addX(vwr.jsEvalSV(s));
     }
     s = sb.toString();
     float f;

Modified: trunk/Jmol/src/org/jmol/shape/AtomShape.java
===================================================================
--- trunk/Jmol/src/org/jmol/shape/AtomShape.java        2015-12-20 22:01:37 UTC 
(rev 20895)
+++ trunk/Jmol/src/org/jmol/shape/AtomShape.java        2015-12-20 22:03:44 UTC 
(rev 20896)
@@ -105,11 +105,11 @@
     if (atoms == null)  // vector values are ignored if there are none for a 
model 
       return;
     isActive = true;
-    if (bsSizeSet == null)
-      bsSizeSet = new BS();
     boolean isVisible = (rd != null && rd.value != 0);
     boolean isAll = (bsSelected == null);
     int i0 = (isAll ? ac - 1 : bsSelected.nextSetBit(0));
+    if (bsSizeSet == null)
+      bsSizeSet = BS.newN(ac);
     if (mads == null && i0 >= 0)
       mads = new short[ac];
     for (int i = i0; i >= 0; i = (isAll ? i - 1 : bsSelected.nextSetBit(i + 
1)))
@@ -128,9 +128,8 @@
       isActive = true;
       short colix = C.getColixO(value);
       byte pid = PAL.pidOf(value);
-      if (bsColixSet == null)
-        bsColixSet = new BS();
-      for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1))
+      int n = checkColixLength(colix, bs.length());
+      for (int i = bs.nextSetBit(0); i >= 0 && i < n; i = bs.nextSetBit(i + 1))
         setColixAndPalette(colix, pid, i);
       return;
     }
@@ -149,7 +148,8 @@
       int i0 = bs.nextSetBit(0);
       if (mads == null && i0 >= 0)
         mads = new short[ac];
-      for (int i = i0, pt = 0; i >= 0; i = bs.nextSetBit(i + 1), pt++) {
+      int n = checkColixLength(colixes == null ? 0 : C.BLACK, bs.length());
+      for (int i = i0, pt = 0; i >= 0 && i < n; i = bs.nextSetBit(i + 1), 
pt++) {
         short colix = (colixes == null ? 0 : colixes[pt]);
         if (colix == 0)
           colix = C.INHERIT_ALL;
@@ -200,15 +200,20 @@
     setPropS(propertyName, value, bs);
   }
 
-  protected void setColixAndPalette(short colix, byte paletteID, int 
atomIndex) {
-    if (colixes == null || atomIndex >= colixes.length) {
-      if (colix == C.INHERIT_ALL)
-        return;
-      colixes = AU.ensureLengthShort(colixes, atomIndex + 1);
-      paletteIDs = AU.ensureLengthByte(paletteIDs, atomIndex + 1);
+  protected int checkColixLength(short colix, int n) {
+    n = Math.min(ac, n);
+    if (colix == C.INHERIT_ALL)
+      return (colixes == null ? 0 : colixes.length);
+    if (colixes == null || n > colixes.length) {
+      colixes = AU.ensureLengthShort(colixes, n);
+      paletteIDs = AU.ensureLengthByte(paletteIDs, n);
     }
     if (bsColixSet == null)
       bsColixSet = BS.newN(ac);
+    return n;
+  }
+  
+  protected void setColixAndPalette(short colix, byte paletteID, int 
atomIndex) {
     colixes[atomIndex] = colix = getColixI(colix, paletteID, atomIndex);
     bsColixSet.setBitTo(atomIndex, colix != C.INHERIT_ALL);
     paletteIDs[atomIndex] = paletteID;

Modified: trunk/Jmol/src/org/jmol/shape/Labels.java
===================================================================
--- trunk/Jmol/src/org/jmol/shape/Labels.java   2015-12-20 22:01:37 UTC (rev 
20895)
+++ trunk/Jmol/src/org/jmol/shape/Labels.java   2015-12-20 22:03:44 UTC (rev 
20896)
@@ -84,6 +84,8 @@
     defaultColix = 0; //"none" -- inherit from atom
     defaultBgcolix = 0; //"none" -- off
     defaultOffset = JC.LABEL_DEFAULT_OFFSET;
+    defaultAlignment = JC.TEXT_ALIGN_LEFT;
+    defaultPointer = JC.LABEL_POINTER_NONE;
     defaultZPos = 0;
     translucentAllowed = false;
   }
@@ -101,10 +103,12 @@
     if ("color" == propertyName) {
       byte pid = PAL.pidOf(value);
       short colix = C.getColixO(value);
-      if (!setDefaults)
-        for (int i = bsSelected.nextSetBit(0); i >= 0 && i < ac; i = bsSelected
+      if (!setDefaults) {
+        int n = checkColixLength(colix, bsSelected.length());
+        for (int i = bsSelected.nextSetBit(0); i >= 0 && i < n; i = bsSelected
             .nextSetBit(i + 1))
           setLabelColix(i, colix, pid);
+      }
       if (setDefaults || !defaultsOnlyForNone) {
         defaultColix = colix;
         defaultPaletteID = pid;
@@ -117,10 +121,9 @@
         return;
       float val = ((Float) value).floatValue();
       float scalePixelsPerMicron = (val == 0 ? 0 : 10000f / val);
-      for (int i = bsSelected.nextSetBit(0); i >= 0 && i < ac; i = bsSelected
+      int n = Math.min(ac, strings.length);
+      for (int i = bsSelected.nextSetBit(0); i >= 0 && i < n; i = bsSelected
           .nextSetBit(i + 1)) {
-        if (strings.length <= i)
-          continue;
         Text text = getLabel(i);
         if (text == null) {
           text = Text.newLabel(vwr, null, strings[i], C.INHERIT_ALL, (short) 0,
@@ -136,15 +139,16 @@
     if ("label" == propertyName) {
       setScaling();
       LabelToken[][] tokens = null;
+      int nbs = checkStringLength(bsSelected.length());
       if (value instanceof Lst) {
         Lst<SV> list = (Lst<SV>) value;
         int n = list.size();
         tokens = new LabelToken[][] { null };
-        for (int pt = 0, i = bsSelected.nextSetBit(0); i >= 0 && i < ac; i = 
bsSelected
+        for (int pt = 0, i = bsSelected.nextSetBit(0); i >= 0 && i < nbs; i = 
bsSelected
             .nextSetBit(i + 1)) {
           if (pt >= n) {
             setLabel(nullToken, "", i, true);
-            return;
+            continue;
           }
           tokens[0] = null;
           setLabel(tokens, SV.sValue(list.get(pt++)), i, true);
@@ -160,19 +164,16 @@
       return;
     }
 
-// see label:
-//    if ("labels" == propertyName) {
-//      setScaling();
-//      Lst<String> labels = (Lst<String>) value;
-//      for (int i = bsSelected.nextSetBit(0), pt = 0; i >= 0 && i < ac; i = 
bsSelected
-//          .nextSetBit(i + 1)) {
-//        String strLabel = labels.get(pt++);
-//        LabelToken[][] tokens = (strLabel == null || strLabel.length() == 0 
? nullToken
-//            : new LabelToken[][] { null });
-//        setLabel(tokens, strLabel, i, true);
-//      }
-//      return;
-//    }
+    if (propertyName.startsWith("label:")) {
+      // from @1.label = "xxx"
+      setScaling();
+      // in principle, we could make this more efficient,
+      // it would be at the cost of general atom property setting
+      checkStringLength(ac);
+      setLabel(new LabelToken[][] { null }, propertyName.substring(6),
+          ((Integer) value).intValue(), false);
+      return;
+    }
 
     if ("clearBoxes" == propertyName) {
       labelBoxes = null;
@@ -187,12 +188,14 @@
     if ("bgcolor" == propertyName) {
       isActive = true;
       if (bsBgColixSet == null)
-        bsBgColixSet = new BS();
+        bsBgColixSet = BS.newN(ac);
       short bgcolix = C.getColixO(value);
-      if (!setDefaults)
-        for (int i = bsSelected.nextSetBit(0); i >= 0 && i < ac; i = bsSelected
+      if (!setDefaults) {
+        int n = checkBgColixLength(bgcolix, bsSelected.length());
+        for (int i = bsSelected.nextSetBit(0); i >= 0 && i < n; i = bsSelected
             .nextSetBit(i + 1))
           setBgcolix(i, bgcolix);
+      }
       if (setDefaults || !defaultsOnlyForNone)
         defaultBgcolix = bgcolix;
       return;
@@ -201,7 +204,7 @@
     // the rest require bsFontSet setting
 
     if (bsFontSet == null)
-      bsFontSet = new BS();
+      bsFontSet = BS.newN(ac);
 
     if ("fontsize" == propertyName) {
       int fontsize = ((Integer) value).intValue();
@@ -232,10 +235,11 @@
 
     if ("offset" == propertyName) {
       if (!(value instanceof Integer)) {
-        if (!setDefaults)
+        if (!setDefaults) {
           for (int i = bsSelected.nextSetBit(0); i >= 0 && i < ac; i = 
bsSelected
               .nextSetBit(i + 1))
             setPymolOffset(i, (float[]) value);
+        }
         return;
       }
 
@@ -250,12 +254,11 @@
     }
 
     if ("align" == propertyName) {
+      // note that if the label is not offset, this centers the label with 
offset 0 0
       String type = (String) value;
-      int hAlignment = JC.TEXT_ALIGN_LEFT;
-      if (type.equalsIgnoreCase("right"))
-        hAlignment = JC.TEXT_ALIGN_RIGHT;
-      else if (type.equalsIgnoreCase("center"))
-        hAlignment = JC.TEXT_ALIGN_CENTER;
+      int hAlignment = (type.equalsIgnoreCase("right") ? JC.TEXT_ALIGN_RIGHT
+          : type.equalsIgnoreCase("center") ? JC.TEXT_ALIGN_CENTER
+              : JC.TEXT_ALIGN_LEFT);
       for (int i = bsSelected.nextSetBit(0); i >= 0 && i < ac; i = bsSelected
           .nextSetBit(i + 1))
         setHorizAlignment(i, hAlignment);
@@ -309,17 +312,19 @@
       LabelToken[] tokensUNK = null;
       String strLabel;
       LabelToken[] tokens;
+      int nstr = checkStringLength(bsSelected.length());
+      short bgcolix = defaultBgcolix;
+      int nbg = checkBgColixLength(bgcolix, bsSelected.length());
+      short thisMad = (short) (mode >= 0 ? 1 : -1);
       for (int i = bsSelected.nextSetBit(0); i >= 0 && i < ac; i = bsSelected
           .nextSetBit(i + 1)) {
         Atom atom = atoms[i];
-        if (formats == null || i >= formats.length)
-          formats = AU.ensureLengthS(formats, i + 1);
-        if (strings != null && strings.length > i && strings[i] != null) {
-          mads[i] = (short) (mode == 0 && mads[i] < 0 || mode == 1 ? 1 : -1);
+        if (i < nstr && strings[i] != null) {
+          // an old string -- toggle
+          mads[i] = (short) (mode == 1 || mode == 0 && mads[i] < 0 ? 1 : -1);
         } else {
-          if (bsSizeSet == null)
-            bsSizeSet = new BS();
-          strings = AU.ensureLengthS(strings, i + 1);
+          // a new string -- turn on
+          mads[i] = thisMad;
           if (atom.getGroup3(false).equals("UNK")) {
             if (strLabelUNK == null) {
               strLabelUNK = vwr.getStandardLabelFormat(1);
@@ -339,37 +344,20 @@
               null, ptTemp);
           formats[i] = strLabel;
           bsSizeSet.set(i);
-          if ((bsBgColixSet == null || !bsBgColixSet.get(i))
-              && defaultBgcolix != 0)
+          if (i < nbg && !bsBgColixSet.get(i))
             setBgcolix(i, defaultBgcolix);
-          mads[i] = (short) (mode >= 0 ? 1 : -1);
         }
         setShapeVisibility(atom, strings != null && i < strings.length
             && strings[i] != null && mads[i] >= 0);
-        //        } else if (strings != null && atomIndex < strings.length) {
-        //        strings[atomIndex] = null;          
       }
       return;
     }
 
-    if (propertyName.startsWith("label:")) {
-      // from @1.label = "xxx"
-      setScaling();
-      setLabel(new LabelToken[1][], propertyName.substring(6),
-          ((Integer) value).intValue(), false);
+    if ("pymolLabels" == propertyName) {
+      setPymolLabels((Map<Integer, Text>) value, bsSelected);
       return;
     }
 
-    if ("textLabels" == propertyName) {
-      // from PyMOL reader
-      setScaling();
-      Map<Integer, Text> labels = (Map<Integer, Text>) value;
-      for (int i = bsSelected.nextSetBit(0); i >= 0 && i < ac; i = bsSelected
-          .nextSetBit(i + 1))
-        setTextLabel(i, labels.get(Integer.valueOf(i)), null);
-      return;
-    }
-
     if (propertyName == "deleteModelAtoms") {
       labelBoxes = null;
       int firstAtomDeleted = ((int[]) ((Object[]) value)[2])[1];
@@ -392,10 +380,47 @@
 
   }
 
+  private int checkStringLength(int n) {
+    n = Math.min(ac, n);
+    if (strings == null || n > strings.length) {
+      formats = AU.ensureLengthS(formats, n);
+      strings = AU.ensureLengthS(strings, n);
+      if (bsSizeSet == null)
+        bsSizeSet = BS.newN(n);
+    }
+    return n;
+  }
+
+  private int checkBgColixLength(short colix, int n) {
+    n = Math.min(ac, n);
+    if (colix == C.INHERIT_ALL)
+      return (bgcolixes == null ? 0 : bgcolixes.length);
+    if (bgcolixes == null || n > bgcolixes.length)
+      bgcolixes = AU.ensureLengthShort(bgcolixes, n);
+    return n;
+  }
+  
+  private void setPymolLabels(Map<Integer, Text> labels, BS bsSelected) {
+    // from PyMOL reader
+    setScaling();
+    int n = checkStringLength(ac);
+    for (int i = bsSelected.nextSetBit(0); i >= 0 && i < n; i = bsSelected
+        .nextSetBit(i + 1))
+      setPymolLabel(i, labels.get(Integer.valueOf(i)), null);
+  }
+
+  /**
+   * Sets offset using PyMOL standard array;
+   * only operates in cases where label is already defined
+   * 
+   * @param i
+   * @param value
+   */
   private void setPymolOffset(int i, float[] value) {
+    // from PyMOL reader or from set labeloffset [...]
     Text text = getLabel(i);
     if (text == null) {
-      if (strings == null || strings.length <= i || strings[i] == null)
+      if (strings == null || i >= strings.length || strings[i] == null)
         return;
       byte fid = (bsFontSet != null && bsFontSet.get(i) ? fids[i] : -1);
       if (fid < 0)
@@ -403,9 +428,7 @@
       text = Text.newLabel(vwr, Font.getFont3D(fid), strings[i],
           getColix2(i, atoms[i], false), getColix2(i, atoms[i], true), 0,
           scalePixelsPerMicron);
-      setTextLabel(i, text, formats[i]);
-      if (text == null)
-        return;
+      setPymolLabel(i, text, formats[i]);
     }
     text.pymolOffset = value;
   }
@@ -418,13 +441,13 @@
   private void setScaling() {
     isActive = true;
     if (bsSizeSet == null)
-      bsSizeSet = new BS();
+      bsSizeSet = BS.newN(ac);
     isScaled = vwr.getBoolean(T.fontscaling);
     scalePixelsPerMicron = (isScaled ? vwr
         .getScalePixelsPerAngstrom(false) * 10000f : 0);
   }
   
-  private void setTextLabel(int i, Text t, String format) {
+  private void setPymolLabel(int i, Text t, String format) {
     if (t == null)
       return;
     String label = t.getText();
@@ -438,6 +461,7 @@
   }
 
   private void setLabel(LabelToken[][] temp, String strLabel, int i, boolean 
doAll) {
+    // checkStringLength must be first
     Atom atom = atoms[i];
     LabelToken[] tokens = temp[0];
     if (tokens == null)
@@ -476,10 +500,6 @@
 
   private boolean addString(Atom atom, int i, String label, String strLabel) {
     setShapeVisibility(atom, label != null);
-    if (strings == null || i >= strings.length)
-      strings = AU.ensureLengthS(strings, i + 1);
-    if (formats == null || i >= formats.length)
-      formats = AU.ensureLengthS(formats, i + 1);
     boolean notNull = (strLabel != null);
     boolean isNew = (strings[i] == null);
     strings[i] = label;
@@ -533,11 +553,6 @@
   }
 
   private void setBgcolix(int i, short bgcolix) {
-    if (bgcolixes == null || i >= bgcolixes.length) {
-      if (bgcolix == 0)
-        return;
-      bgcolixes = AU.ensureLengthShort(bgcolixes, i + 1);
-    }
     bgcolixes[i] = bgcolix;
     bsBgColixSet.setBitTo(i, bgcolix != 0);
     Text text = getLabel(i);
@@ -548,12 +563,10 @@
   private void setOffsets(int i, int offset) {
     
     if (offsets == null || i >= offsets.length) {
-      if (offset == 0)
+      if (offset == JC.LABEL_DEFAULT_OFFSET)
         return;
-      offsets = AU.ensureLengthI(offsets, i + 1);
+      offsets = AU.ensureLengthI(offsets, ac);
     }
-    if (offset == 0)
-      offset = JC.LABEL_DEFAULT_OFFSET;
     offsets[i] = (offsets[i] & JC.LABEL_FLAGS) | offset;
 
     Text text = getLabel(i);
@@ -563,10 +576,15 @@
 
   private void setHorizAlignment(int i, int hAlign) {
     if (offsets == null || i >= offsets.length) {
-      if (hAlign == JC.TEXT_ALIGN_LEFT)
+      switch (hAlign) {
+      case JC.TEXT_ALIGN_NONE:
+      case JC.TEXT_ALIGN_LEFT:
         return;
-      offsets = AU.ensureLengthI(offsets, i + 1);
+      }
+      offsets = AU.ensureLengthI(offsets, ac);
     }
+    if (hAlign == JC.TEXT_ALIGN_NONE)
+      hAlign = JC.TEXT_ALIGN_LEFT;
     offsets[i] = JC.setHorizAlignment(offsets[i], hAlign);
     Text text = getLabel(i);
     if (text != null)
@@ -577,7 +595,7 @@
     if (offsets == null || i >= offsets.length) {
       if (pointer == JC.LABEL_POINTER_NONE)
         return;
-      offsets = AU.ensureLengthI(offsets, i + 1);
+      offsets = AU.ensureLengthI(offsets, ac);
     }
     offsets[i] = JC.setPointer(offsets[i], pointer);
     Text text = getLabel(i);
@@ -589,7 +607,7 @@
     if (offsets == null || i >= offsets.length) {
       if (!TF)
         return;
-      offsets = AU.ensureLengthI(offsets, i + 1);
+      offsets = AU.ensureLengthI(offsets, ac);
     }
     offsets[i] = JC.setZPosition(offsets[i], TF ? flag : 0);
   }
@@ -598,7 +616,7 @@
     if (fids == null || i >= fids.length) {
       if (fid == zeroFontId)
         return;
-      fids = AU.ensureLengthByte(fids, i + 1);
+      fids = AU.ensureLengthByte(fids, ac);
     }
     fids[i] = fid;
     bsFontSet.set(i);

Modified: trunk/Jmol/src/org/jmol/util/GenericApplet.java
===================================================================
--- trunk/Jmol/src/org/jmol/util/GenericApplet.java     2015-12-20 22:01:37 UTC 
(rev 20895)
+++ trunk/Jmol/src/org/jmol/util/GenericApplet.java     2015-12-20 22:03:44 UTC 
(rev 20896)
@@ -6,7 +6,6 @@
 import java.util.Hashtable;
 import java.util.Map;
 
-import javajs.awt.Dimension;
 import javajs.util.Lst;
 import javajs.util.PT;
 import javajs.util.SB;
@@ -73,7 +72,7 @@
   abstract protected String getJmolParameter(String name);
 
   // callback implementations
-  abstract protected String doEval(String strEval);
+  abstract protected String doEval(String strEval); // in JavaScript, this 
will be an Object, Number, String, etc.
 
   abstract protected float[][] doFunctionXY(String functionName, int nX, int 
nY);
 

Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties
===================================================================
--- trunk/Jmol/src/org/jmol/viewer/Jmol.properties      2015-12-20 22:01:37 UTC 
(rev 20895)
+++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties      2015-12-20 22:03:44 UTC 
(rev 20896)
@@ -62,8 +62,16 @@
 
 TODO: consider if models with no atoms will cause issues in relation to 
model.firstAtomIndex
 
-Jmol.___JmolVersion="14.5.1_2015.12.14"
+Jmol.___JmolVersion="14.5.1_2015.12.20"
 
+code: (JavaScript) adding use of array.slice and implementing Java byte[] as 
JavaScript Int8Array()
+
+bug fix: array handling for labels very inefficient
+bug fix: y = javascript("x") only creates string equivalent of x, not actual 
numerical/object values
+bug fix: y = javascript("x") draws "x" from wrapped anonymous function using 
eval() instead of global context using window.eval()
+
+JmolVersion="14.5.1_2015.12.14"
+
 bug fix: JSmol (JSmolCore.js) check for MS Edge browser, which does not 
support dataURI
 
 JmolVersion="14.5.0_2015.12.13"

Modified: trunk/Jmol/src/org/jmol/viewer/StatusManager.java
===================================================================
--- trunk/Jmol/src/org/jmol/viewer/StatusManager.java   2015-12-20 22:01:37 UTC 
(rev 20895)
+++ trunk/Jmol/src/org/jmol/viewer/StatusManager.java   2015-12-20 22:03:44 UTC 
(rev 20896)
@@ -692,6 +692,12 @@
       jsl.functionXYZ(functionName, nX, nY, nZ));
   }
   
+  /**
+   * 
+   * @param strEval
+   * @return in Java a String; in JavaScript window.eval() 
+   * 
+   */
   String jsEval(String strEval) {
     return (jsl == null ? "" : jsl.eval(strEval));
   }

Modified: trunk/Jmol/src/org/jmol/viewer/Viewer.java
===================================================================
--- trunk/Jmol/src/org/jmol/viewer/Viewer.java  2015-12-20 22:01:37 UTC (rev 
20895)
+++ trunk/Jmol/src/org/jmol/viewer/Viewer.java  2015-12-20 22:03:44 UTC (rev 
20896)
@@ -4641,9 +4641,13 @@
    */
 
   public String jsEval(String strEval) {
-    return sm.jsEval(strEval);
+    return "" + sm.jsEval(strEval);
   }
 
+  public SV jsEvalSV(String strEval) {
+    return SV.getVariable(isJS ? sm.jsEval(strEval) : jsEval(strEval));
+  }
+
   /*
    * loadStructCallback indicates file load status.
    * 
@@ -5746,7 +5750,7 @@
       break;
     default:
       if (!g.htNonbooleanParameterValues.containsKey(key.toLowerCase())) {
-        g.setUserVariable(key, SV.newV(T.decimal, Float.valueOf(value)));
+        g.setUserVariable(key, SV.newF(value));
         return;
       }
     }

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


------------------------------------------------------------------------------
_______________________________________________
Jmol-commits mailing list
Jmol-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-commits

Reply via email to