JAL-3026 Jmol functioning; some issues
authorhansonr <hansonr@STO24954W.ad.stolaf.edu>
Mon, 27 Aug 2018 08:36:29 +0000 (03:36 -0500)
committerhansonr <hansonr@STO24954W.ad.stolaf.edu>
Mon, 27 Aug 2018 08:36:29 +0000 (03:36 -0500)
Reworked mouse event handling. Temporarily lost out-of-frame business.
Or, more specifically, hovering over the scroll bar to auto-scroll.

libjs/jmol-app.zip
src/jalview/ext/jmol/JalviewJmolBinding.java
src/jalview/ext/jmol/JmolParser.java
src/jalview/gui/AppJmol.java
src/jalview/gui/AppJmolBinding.java
swingjs/SwingJS-site.zip
swingjs/timestamp
swingjs/ver/3.2.2/SwingJS-site.zip
swingjs/ver/3.2.2/timestamp
utils/test/JalviewJSTest.java

index dd6b193..02efd09 100644 (file)
Binary files a/libjs/jmol-app.zip and b/libjs/jmol-app.zip differ
index ca82744..babebc5 100644 (file)
@@ -1351,7 +1351,17 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
    */
   public abstract void showConsole(boolean show);
 
+  
+  public static Viewer getJmolData(JmolParser jmolParser)
+  {
+    return (Viewer) JmolViewer.allocateViewer(null, null, null, null, null,
+            "-x -o -n", jmolParser);
+  }
+
   /**
+   * 
+   * 
+   * 
    * @param renderPanel
    * @param jmolfileio
    *          - when true will initialise jmol's file IO system (should be false
@@ -1382,13 +1392,16 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
    * @param consolePanel
    *          - panel to contain Jmol console
    * @param buttonsToShow
-   *          - buttons to show on the console, in ordr
+   *          - buttons to show on the console, in order
    */
   public void allocateViewer(Container renderPanel, boolean jmolfileio,
           String htmlName, URL documentBase, URL codeBase,
           String commandOptions, final Container consolePanel,
           String buttonsToShow)
   {
+    
+    System.err.println("Allocating Jmol Viewer: " + commandOptions);
+    
     if (commandOptions == null)
     {
       commandOptions = "";
@@ -1400,7 +1413,12 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
 
     viewer.setJmolStatusListener(this); // extends JmolCallbackListener
 
-    console = null;//createJmolConsole(consolePanel, buttonsToShow);
+    try {
+      console = createJmolConsole(consolePanel, buttonsToShow);
+    } catch (Throwable e) {
+      System.err.println("Could not create Jmol application console. " + e.getMessage());
+      e.printStackTrace();
+    }
     if (consolePanel != null)
     {
       consolePanel.addComponentListener(this);
@@ -1412,6 +1430,9 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
   protected abstract JmolAppConsoleInterface createJmolConsole(
           Container consolePanel, String buttonsToShow);
 
+  // BH 2018 -- Jmol console is not working due to problems with styled documents.
+  
+
   protected org.jmol.api.JmolAppConsoleInterface console = null;
 
   @Override
@@ -1425,7 +1446,14 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
 
   private String jmolScript(String script)
   {
-    return viewer.scriptWait(script);
+    
+    System.err.println(">>Jmol>> " + script);
+    
+    String s = viewer.scriptWait(script);
+    
+    System.err.println("<<Jmol<< " + s);
+    
+    return s;
   }
 
   @Override
@@ -1488,4 +1516,5 @@ public abstract class JalviewJmolBinding extends AAStructureBindingModel
   {
     showConsole(false);
   }
+
 }
index e94da73..542b2bc 100644 (file)
@@ -135,8 +135,7 @@ public class JmolParser extends StructureFile implements JmolStatusListener
          * see http://wiki.jmol.org/index.php/Jmol_Application
          */
         
-        viewer = (Viewer) JmolViewer.allocateViewer(null, null, null, null,
-                null, "-x -o -n", this);
+        viewer = JalviewJmolBinding.getJmolData(this);
         // ensure the 'new' (DSSP) not 'old' (Ramachandran) SS method is used
         viewer.setBooleanProperty("defaultStructureDSSP", true);
       } catch (ClassCastException x)
index 16c6d8a..cbadbf9 100644 (file)
@@ -344,6 +344,8 @@ public class AppJmol extends StructureViewerBase
       } catch (Exception ex)
       {
         Cache.log.error("Couldn't open Jmol viewer!", ex);
+        ex.printStackTrace();
+        return;
       }
     }
     else
@@ -363,9 +365,12 @@ public class AppJmol extends StructureViewerBase
         new OOMWarning("When trying to add structures to the Jmol viewer!",
                 oomerror);
         Cache.log.debug("File locations are " + filesString);
+        return;
       } catch (Exception ex)
       {
         Cache.log.error("Couldn't add files to Jmol viewer!", ex);
+        ex.printStackTrace();
+        return;
       }
     }
 
index 8730a57..eeb4888 100644 (file)
@@ -169,7 +169,7 @@ public class AppJmolBinding extends JalviewJmolBinding
           Container consolePanel, String buttonsToShow)
   {
     viewer.setJmolCallbackListener(this);
-    return new AppConsole(viewer, consolePanel, buttonsToShow);
+    return null;//BH can't do this yet. new AppConsole(viewer, consolePanel, buttonsToShow);
   }
 
   @Override
index 0a54e13..a1b7b8e 100644 (file)
Binary files a/swingjs/SwingJS-site.zip and b/swingjs/SwingJS-site.zip differ
index 3c00905..342f911 100644 (file)
@@ -1 +1 @@
-20180824015733 
+20180827031835 
index 0a54e13..a1b7b8e 100644 (file)
Binary files a/swingjs/ver/3.2.2/SwingJS-site.zip and b/swingjs/ver/3.2.2/SwingJS-site.zip differ
index 3c00905..342f911 100644 (file)
@@ -1 +1 @@
-20180824015733 
+20180827031835 
index 95737d4..d8fb401 100644 (file)
@@ -5,12 +5,22 @@ import java.awt.Container;
 import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.GridLayout;
+import java.awt.MediaTracker;
+import java.awt.MenuItem;
 
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
 import javax.swing.JCheckBox;
+import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
 import javax.swing.JPanel;
 import javax.swing.JRadioButton;
+import javax.swing.JRadioButtonMenuItem;
 import javax.swing.SwingConstants;
+import javax.swing.WindowConstants;
 import javax.swing.border.TitledBorder;
 
 /**
@@ -18,7 +28,6 @@ import javax.swing.border.TitledBorder;
  * behaviour. The J2S transpiler should generate an html entry point for this
  * class, allowing comparison between Java and Javascript execution.
  */
-@SuppressWarnings("serial")
 public class JalviewJSTest extends JPanel
 {
   public static void main(String[] args)
@@ -32,7 +41,12 @@ public class JalviewJSTest extends JPanel
   void doTest()
   {
     JFrame main = new JFrame();
-    main.setContentPane(getVisualPaneContent());
+    main.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+    JMenu menu = new JMenu("testing");
+    menu.setHorizontalAlignment(SwingConstants.RIGHT);
+    main.setContentPane(getVisualPaneContent(menu));
+    main.setJMenuBar(new JMenuBar());
+    main.getJMenuBar().add(menu);
     main.pack();
     main.setVisible(true);
   }
@@ -40,8 +54,9 @@ public class JalviewJSTest extends JPanel
   /**
    * Builds a cut-down 'Preferences Visual tab' for a minimal test of layout
    * problems
+ * @param menu 
    */
-  Container getVisualPaneContent()
+  Container getVisualPaneContent(JMenu menu)
   {
     JPanel panel = new JPanel();
     panel.setPreferredSize(new Dimension(400, 500));
@@ -56,33 +71,36 @@ public class JalviewJSTest extends JPanel
      * bug 21/08/18:
      * - checkbox label and text extend outside the enclosing panel in JS
      */
-    JCheckBox cb1 = new JCheckBox();
     Font font = new Font("Verdana", Font.PLAIN, 11);
-    cb1.setFont(font);
-    cb1.setText("Maximise Window");
-    cb1.setHorizontalTextPosition(SwingConstants.LEADING);
-    cb1.setHorizontalAlignment(SwingConstants.LEFT);
 
-    /*
-     * bug 21/08/18:
-     * - label should precede checkbox, but it doesn't
-     */
-    JCheckBox cb2 = new JCheckBox("Open Overview");
-    cb2.setFont(font);
-    cb2.setHorizontalTextPosition(SwingConstants.LEADING);
-    // uncommenting this line gives 'leading text', but
-    // also results in label and checkbox outside container
-    //cb2.setHorizontalAlignment(SwingConstants.RIGHT);
+    JLabel l1 = new JLabel(getImage("test2.png"));
+    l1.setText("trailing right");
+    l1.setHorizontalTextPosition(SwingConstants.TRAILING);
+    l1.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
+    l1.setHorizontalAlignment(SwingConstants.RIGHT);
+
+    JLabel l2 = new JLabel(getImage("test2.png"));
+    l2.setText("leading left");
+    l2.setFont(font);
+    l2.setHorizontalTextPosition(SwingConstants.LEADING);
+    l2.setHorizontalAlignment(SwingConstants.LEFT);
+
+    JButton b1 = new JButton("right left");
+    b1.setIcon(getImage("test2.png"));
+    b1.setFont(font);
+    b1.setHorizontalTextPosition(SwingConstants.RIGHT);
+    b1.setHorizontalAlignment(SwingConstants.LEFT);
+
+    firstColumn.add(l1);
+    firstColumn.add(l2);
+    firstColumn.add(b1);
 
     
-//    ImageIcon icon =  new ImageIcon(getClass()
-//            .getClassLoader()
-//            .getResource("test2.png"), "test");
-//    
-    JCheckBox cb3 = new JCheckBox("leading,left-to-right");
+    JCheckBox cb3 = new JCheckBox("leading,left-to-right,rt");
     cb3.setFont(font);
     cb3.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
     cb3.setHorizontalTextPosition(SwingConstants.LEADING);
+    cb3.setHorizontalAlignment(SwingConstants.TRAILING);
 
     JCheckBox cb4 = new JCheckBox("leading,right-to-left");
     cb4.setFont(font);
@@ -94,11 +112,6 @@ public class JalviewJSTest extends JPanel
     cb5.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
     cb5.setHorizontalTextPosition(SwingConstants.TRAILING);
 
-    JCheckBox cb6 = new JCheckBox("trailing,right-to-left");
-    cb6.setFont(font);
-    cb6.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
-    cb6.setHorizontalTextPosition(SwingConstants.TRAILING);
-
     JRadioButton rb1 = new JRadioButton("trailing,right-to-left");
     rb1.setFont(font);
     rb1.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
@@ -116,22 +129,78 @@ public class JalviewJSTest extends JPanel
 
 
     
-    firstColumn.add(cb1);
-    firstColumn.add(cb2);
     firstColumn.add(cb3);
     firstColumn.add(cb4);
     firstColumn.add(cb5);
-    firstColumn.add(cb6);
     firstColumn.add(rb1);
     firstColumn.add(rb2);
     firstColumn.add(rb3);
-    firstColumn.setBounds(20, 20, 200, 500);
-
+    firstColumn.setBounds(200, 20, 200, 500);
+
+    JCheckBoxMenuItem cb3m = new JCheckBoxMenuItem("leading,left-to-right");
+    cb3m.setFont(font);
+    cb3m.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
+    cb3m.setHorizontalTextPosition(SwingConstants.LEADING);
+
+    JCheckBoxMenuItem cb4m = new JCheckBoxMenuItem("leading,right-to-left");
+    cb4m.setFont(font);
+    cb4m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
+    cb4m.setHorizontalTextPosition(SwingConstants.LEADING);
+
+    JCheckBoxMenuItem cb5m = new JCheckBoxMenuItem("trailing,left-to-right");
+    cb5m.setFont(font);
+    cb5m.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
+    cb5m.setHorizontalTextPosition(SwingConstants.TRAILING);
+
+    JCheckBoxMenuItem cb6m = new JCheckBoxMenuItem("trailing,right-to-left");
+    cb6m.setFont(font);
+    cb6m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
+    cb6m.setHorizontalTextPosition(SwingConstants.TRAILING);
+
+    JRadioButtonMenuItem rb1m = new JRadioButtonMenuItem("trailing,right-to-left");
+    rb1m.setFont(font);
+    rb1m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
+    rb1m.setHorizontalTextPosition(SwingConstants.TRAILING);
+
+    JRadioButtonMenuItem rb2m = new JRadioButtonMenuItem("right,left-to-right");
+    rb2m.setFont(font);
+    rb2m.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
+    rb2m.setHorizontalTextPosition(SwingConstants.RIGHT);
+
+    JRadioButtonMenuItem rb3m = new JRadioButtonMenuItem("right,right-to-left");
+    rb3m.setFont(font);
+    rb3m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
+    rb3m.setHorizontalTextPosition(SwingConstants.RIGHT);
+
+    JMenu m1 = new JMenu("left");
+    JMenu m2 = new JMenu("right");
+    menu.add(m1);
+    menu.add(m2);
+    m1.add(cb3m);
+    m2.add(cb4m);
+    m1.add(cb5m);
+    m2.add(cb6m);
+    m2.add(rb1m);
+    m1.add(rb2m);
+    m2.add(rb3m);
+    
     JPanel theTab = new JPanel();
+    
     theTab.setLayout(null);
     theTab.add(firstColumn);
     panel.add(theTab);
 
     return panel;
   }
+
+private ImageIcon getImage(String name) {
+    ImageIcon icon = new ImageIcon(getClass().getResource(name));
+
+    while(icon.getImageLoadStatus() == MediaTracker.LOADING)
+               try {
+                       Thread.sleep(10);
+               } catch (InterruptedException e) {
+               }
+    return icon;
+}
 }