debug comment out
[jalview.git] / src / jalview / bin / Jalview.java
index 047356b..fae2b75 100755 (executable)
@@ -20,6 +20,7 @@
  */
 package jalview.bin;
 
+import jalview.api.AlignCalcWorkerI;
 import jalview.api.AlignFrameI;
 import jalview.api.AlignViewportI;
 import jalview.api.JalviewApp;
@@ -83,9 +84,6 @@ import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Map;
 import java.util.Vector;
-import java.util.logging.ConsoleHandler;
-import java.util.logging.Level;
-import java.util.logging.Logger;
 
 import javax.swing.LookAndFeel;
 import javax.swing.UIManager;
@@ -146,6 +144,30 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
 
   protected JSFunctionExec jsFunctionExec;
 
+  private boolean noCalculation, noMenuBar, noStatus;
+
+  private boolean noAnnotation;
+
+  public boolean getStartCalculations()
+  {
+    return !noCalculation;
+  }
+
+  public boolean getAllowMenuBar()
+  {
+    return !noMenuBar;
+  }
+
+  public boolean getShowStatus()
+  {
+    return !noStatus;
+  }
+
+  public boolean getShowAnnotation()
+  {
+    return !noAnnotation;
+  }
+
   public static AlignFrame getCurrentAlignFrame()
   {
     return getInstance().currentAlignFrame;
@@ -251,71 +273,12 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
    */
   public static void main(String[] args)
   {
-    // setLogging(); // BH - for event debugging in JavaScript
+    // Platform.startJavaLogging();
     getInstance().doMain(args);
   }
 
-  /**
-   * Allow an outside entity to initiate the second half of argument parsing
-   * (only).
-   * 
-   * @param args
-   * @return null is good
-   */
-  @Override
-  public Object parseArguments(String[] args)
-  {
-
-    try
-    {
-      ArgsParser aparser = new ArgsParser(args);
-      return parseArguments(aparser, false);
-    } catch (Throwable t)
-    {
-      return t;
-    }
-  }
-
-  private static void logClass(String name)
-  {
-    // BH - for event debugging in JavaScript
-    ConsoleHandler consoleHandler = new ConsoleHandler();
-    consoleHandler.setLevel(Level.ALL);
-    Logger logger = Logger.getLogger(name);
-    logger.setLevel(Level.ALL);
-    logger.addHandler(consoleHandler);
-  }
 
   @SuppressWarnings("unused")
-  private static void setLogging()
-  {
-
-    /**
-     * @j2sIgnore
-     * 
-     */
-    {
-      System.out.println("not in js");
-    }
-
-    // BH - for event debugging in JavaScript (Java mode only)
-    if (!Platform.isJS())
-    /**
-     * Java only
-     * 
-     * @j2sIgnore
-     */
-    {
-      Logger.getLogger("").setLevel(Level.ALL);
-      logClass("java.awt.EventDispatchThread");
-      logClass("java.awt.EventQueue");
-      logClass("java.awt.Component");
-      logClass("java.awt.focus.Component");
-      logClass("java.awt.focus.DefaultKeyboardFocusManager");
-    }
-
-  }
-
   /**
    * @param args
    */
@@ -323,7 +286,11 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
   {
 
     boolean isJS = Platform.isJS();
-    if (!isJS)
+    if (isJS)
+    {
+      Platform.setAppClass(this);
+    }
+    else
     {
       System.setSecurityManager(null);
     }
@@ -553,8 +520,34 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
     parseArguments(aparser, true);
   }
 
-  private Object parseArguments(ArgsParser aparser,
-          boolean isStartup)
+  /**
+   * Allow an outside entity to initiate the second half of argument parsing
+   * (only).
+   * 
+   * @param args
+   * @return null is good
+   */
+  @Override
+  public Object parseArguments(String[] args)
+  {
+
+    try
+    {
+      ArgsParser aparser = new ArgsParser(args);
+      return parseArguments(aparser, false);
+    } catch (Throwable t)
+    {
+      return t;
+    }
+  }
+
+  /**
+   * 
+   * @param aparser
+   * @param isStartup
+   * @return
+   */
+  private Object parseArguments(ArgsParser aparser, boolean isStartup)
   {
     boolean isJS = Platform.isJS();
 
@@ -570,7 +563,6 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
     String fileFormat = (isJavaAppletTag
             ? aparser.getAppletValue("format", null)
             : null);
-
     FileFormatI format = null;
     DataSourceType protocol = null;
 
@@ -598,8 +590,11 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
       }
     }
 
+    String data;
+
     if (file != null)
     {
+
       if (!headless)
       {
         desktop.setProgressBar(
@@ -646,6 +641,30 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
         // TODO ?
       }
 
+      if (aparser.contains(ArgsParser.NOMENUBAR))
+      {
+        noMenuBar = true;
+        System.out.println("CMD [nomenu] executed successfully!");
+      }
+
+      if (aparser.contains(ArgsParser.NOSTATUS))
+      {
+        noStatus = true;
+        System.out.println("CMD [nostatus] executed successfully!");
+      }
+
+      if (aparser.contains(ArgsParser.NOANNOTATION)
+              || aparser.contains(ArgsParser.NOANNOTATION2))
+      {
+        noAnnotation = true;
+        System.out.println("CMD no-annotation executed successfully!");
+      }
+      if (aparser.contains(ArgsParser.NOCALCULATION))
+      {
+        noCalculation = true;
+        System.out.println("CMD [nocalculation] executed successfully!");
+      }
+
       AlignFrame af = new FileLoader(!headless).loadFileWaitTillLoaded(file,
               protocol, format);
       if (af == null)
@@ -687,7 +706,7 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
 
         // TODO: file2 How to implement file2 for the applet spit screen?
 
-        String data = aparser.getValue(ArgsParser.COLOUR, true);
+        data = aparser.getValue(ArgsParser.COLOUR, true);
         if (data != null)
         {
           data.replaceAll("%20", " ");
@@ -731,6 +750,13 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
           System.out.println(
                   "CMD [-annotations " + data + "] executed successfully!");
         }
+
+        if (aparser.contains(ArgsParser.SHOWOVERVIEW))
+        {
+          af.overviewMenuItem_actionPerformed(null);
+          System.out.println("CMD [showoverview] executed successfully!");
+        }
+
         // set or clear the sortbytree flag.
         if (aparser.contains(ArgsParser.SORTBYTREE))
         {
@@ -740,13 +766,30 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
             System.out.println("CMD [-sortbytree] executed successfully!");
           }
         }
-        if (aparser.contains(ArgsParser.NOANNOTATION)
-                || aparser.contains(ArgsParser.NOANNOTATION2))
+
+        boolean doUpdateAnnotation = false;
+
+        /**
+         * we do this earlier in JalviewJS because of a complication with
+         * SHOWOVERVIEW
+         * 
+         * For now, just fixing this in JalviewJS.
+         *
+         * 
+         * @j2sIgnore
+         * 
+         */
         {
-          af.getViewport().setShowAnnotation(false);
-          if (!af.getViewport().isShowAnnotation())
+          if (aparser.contains(ArgsParser.NOANNOTATION)
+                  || aparser.contains(ArgsParser.NOANNOTATION2))
           {
-            System.out.println("CMD no-annotation executed successfully!");
+            af.getViewport().setShowAnnotation(false);
+            if (!af.getViewport().isShowAnnotation())
+            {
+              doUpdateAnnotation = true;
+              System.out
+                      .println("CMD no-annotation executed successfully!");
+            }
           }
         }
         if (aparser.contains(ArgsParser.NOSORTBYTREE))
@@ -754,10 +797,16 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
           af.getViewport().setSortByTree(false);
           if (!af.getViewport().getSortByTree())
           {
+            doUpdateAnnotation = true;
             System.out
                     .println("CMD [-nosortbytree] executed successfully!");
           }
         }
+        if (doUpdateAnnotation)
+        { // BH 2019.07.24
+          af.setMenusForViewport();
+          af.alignPanel.updateLayout();
+        }
         data = aparser.getValue(ArgsParser.TREE, true);
         if (data != null)
         {
@@ -1321,6 +1370,17 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
     JalviewApp app = new JalviewApp()
     {
 
+      // TODO BH 2019
+      //
+      // These are methods that are in JalviewLite that various classes call
+      // but are not in JalviewLiteJsApi. Or, even if they are, other classes
+      // call
+      // them to JalviewLite directly. Some may not be necessary, but they have
+      // to
+      // be at least mentioned here, or the classes calling them should
+      // reference
+      // JalviewLite itself.
+
       private boolean alignPDBStructures; // From JalviewLite; not implemented
 
       private Hashtable<String, Hashtable<String, String[]>> jsmessages;
@@ -1472,7 +1532,7 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
       @Override
       public StructureSelectionManagerProvider getStructureSelectionManagerProvider()
       {
-        // TODO Auto-generated method stub
+        // TODO Q: what exactly is this? BH
         return null;
       }
 
@@ -1489,8 +1549,8 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
               ColumnSelection colsel, HiddenColumns hidden,
               SelectionSource source, Object alignFrame)
       {
-        // TODO Auto-generated method stub
-        return null;
+        return appLoader.getSelectionForListener(getCurrentAlignFrame(),
+                seqsel, colsel, hidden, source, alignFrame);
       }
 
       @Override
@@ -1502,16 +1562,14 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
       @Override
       public Hashtable<String, int[]> getJSHashes()
       {
-        return (jshashes == null
-                ? (jshashes = new Hashtable<>())
+        return (jshashes == null ? (jshashes = new Hashtable<>())
                 : jshashes);
       }
 
       @Override
       public Hashtable<String, Hashtable<String, String[]>> getJSMessages()
       {
-        return (jsmessages == null
-                ? (jsmessages = new Hashtable<>())
+        return (jsmessages == null ? (jsmessages = new Hashtable<>())
                 : jsmessages);
       }
 
@@ -1602,11 +1660,10 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
   }
 
   @Override
-  public void highlightIn(AlignFrameI alf,
-          String sequenceId, String position, String alignedPosition)
+  public void highlightIn(AlignFrameI alf, String sequenceId,
+          String position, String alignedPosition)
   {
-    appLoader.highlightIn(alf, sequenceId, position,
-            alignedPosition);
+    appLoader.highlightIn(alf, sequenceId, position, alignedPosition);
   }
 
   @Override
@@ -1622,15 +1679,14 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
   }
 
   @Override
-  public void selectIn(AlignFrameI alf, String sequenceIds,
-          String columns)
+  public void selectIn(AlignFrameI alf, String sequenceIds, String columns)
   {
     selectIn(alf, sequenceIds, columns, null);
   }
 
   @Override
-  public void selectIn(AlignFrameI alf, String sequenceIds,
-          String columns, String sep)
+  public void selectIn(AlignFrameI alf, String sequenceIds, String columns,
+          String sep)
   {
     appLoader.selectIn(alf, sequenceIds, columns, sep);
   }
@@ -1644,8 +1700,8 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
   }
 
   @Override
-  public String getSelectedSequencesAsAlignmentFrom(
-          AlignFrameI alf, String format, String sep)
+  public String getSelectedSequencesAsAlignmentFrom(AlignFrameI alf,
+          String format, String sep)
   {
     return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format, sep);
   }
@@ -1663,8 +1719,7 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
   }
 
   @Override
-  public String getAlignmentOrderFrom(AlignFrameI alf,
-          String sep)
+  public String getAlignmentOrderFrom(AlignFrameI alf, String sep)
   {
     return appLoader.getAlignmentOrderFrom(alf, sep);
   }
@@ -1682,8 +1737,8 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
   }
 
   @Override
-  public String orderAlignmentBy(AlignFrameI alf,
-          String order, String undoName, String sep)
+  public String orderAlignmentBy(AlignFrameI alf, String order,
+          String undoName, String sep)
   {
     return appLoader.orderAlignmentBy(alf, order, undoName, sep);
   }
@@ -1695,8 +1750,7 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
   }
 
   @Override
-  public String getAlignmentFrom(AlignFrameI alf,
-          String format)
+  public String getAlignmentFrom(AlignFrameI alf, String format)
   {
     return getAlignmentFrom(alf, format, null);
   }
@@ -1708,8 +1762,8 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
   }
 
   @Override
-  public String getAlignmentFrom(AlignFrameI alf,
-          String format, String suffix)
+  public String getAlignmentFrom(AlignFrameI alf, String format,
+          String suffix)
   {
     return appLoader.getAlignmentFrom(alf, format, suffix);
   }
@@ -1717,176 +1771,106 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
   @Override
   public void loadAnnotation(String annotation)
   {
-    // TODO Auto-generated method stub
-
+    loadAnnotationFrom(getCurrentAlignFrame(), annotation);
   }
 
   @Override
-  public void loadAnnotationFrom(AlignFrameI alf,
-          String annotation)
+  public void loadAnnotationFrom(AlignFrameI alf, String annotation)
   {
-    // TODO Auto-generated method stub
-
+    appLoader.loadAnnotationFrom(alf, annotation);
   }
 
   @Override
   public void loadFeatures(String features, boolean autoenabledisplay)
   {
-    // TODO Auto-generated method stub
-
+    loadFeaturesFrom(currentAlignFrame, features, autoenabledisplay);
   }
 
   @Override
-  public boolean loadFeaturesFrom(AlignFrameI alf,
-          String features, boolean autoenabledisplay)
+  public boolean loadFeaturesFrom(AlignFrameI alf, String features,
+          boolean autoenabledisplay)
   {
-    // TODO Auto-generated method stub
-    return false;
+    return appLoader.loadFeaturesFrom(alf, features, autoenabledisplay);
   }
 
   @Override
   public String getFeatures(String format)
   {
-    // TODO Auto-generated method stub
-    return null;
+    return getFeaturesFrom(getCurrentAlignFrame(), format);
   }
 
   @Override
-  public String getFeaturesFrom(AlignFrameI alf,
-          String format)
+  public String getFeaturesFrom(AlignFrameI alf, String format)
   {
-    // TODO Auto-generated method stub
-    return null;
+    return appLoader.getFeaturesFrom(alf, format);
   }
 
   @Override
   public String getAnnotation()
   {
-    // TODO Auto-generated method stub
-    return null;
+    return getAnnotationFrom(getCurrentAlignFrame());
   }
 
   @Override
   public String getAnnotationFrom(AlignFrameI alf)
   {
-    // TODO Auto-generated method stub
-    return null;
+    return appLoader.getAnnotationFrom(alf);
   }
 
   @Override
   public AlignFrameI newView()
   {
-    // TODO Auto-generated method stub
-    return null;
+    return newViewFrom(getCurrentAlignFrame(), null);
   }
 
   @Override
   public AlignFrameI newView(String name)
   {
-    // TODO Auto-generated method stub
-    return null;
+    return newViewFrom(getCurrentAlignFrame(), name);
   }
 
   @Override
   public AlignFrameI newViewFrom(AlignFrameI alf)
   {
-    // TODO Auto-generated method stub
-    return null;
+    return newViewFrom(alf, null);
   }
 
   @Override
   public AlignFrameI newViewFrom(AlignFrameI alf, String name)
   {
-    // TODO Auto-generated method stub
-    return null;
+    return appLoader.newViewFrom(alf, name);
   }
 
   @Override
-  public AlignFrameI loadAlignment(String text,
-          String title)
+  public AlignFrameI loadAlignment(String text, String title)
   {
     return appLoader.loadAlignment(text, AlignFrame.DEFAULT_WIDTH,
             AlignFrame.DEFAULT_HEIGHT, title);
   }
 
   @Override
-  public void setMouseoverListener(String listener)
-  {
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public void setMouseoverListener(AlignFrameI af,
-          String listener)
-  {
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public void setSelectionListener(String listener)
-  {
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public void setSelectionListener(AlignFrameI af,
-          String listener)
-  {
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public void setStructureListener(String listener, String modelSet)
-  {
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public void removeJavascriptListener(AlignFrameI af,
-          String listener)
-  {
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public void mouseOverStructure(String pdbResNum, String chain,
-          String pdbfile)
-  {
-    // TODO Auto-generated method stub
-
-  }
-
-  @Override
-  public boolean addPdbFile(AlignFrameI alFrame,
-          String sequenceId, String pdbEntryString, String pdbFile)
+  public boolean addPdbFile(AlignFrameI alFrame, String sequenceId,
+          String pdbEntryString, String pdbFile)
   {
     return appLoader.addPdbFile(alFrame, sequenceId, pdbEntryString,
             pdbFile);
   }
 
   @Override
-  public void scrollViewToIn(AlignFrameI alf,
-          String topRow, String leftHandColumn)
+  public void scrollViewToIn(AlignFrameI alf, String topRow,
+          String leftHandColumn)
   {
     appLoader.scrollViewToIn(alf, topRow, leftHandColumn);
   }
 
   @Override
-  public void scrollViewToRowIn(AlignFrameI alf,
-          String topRow)
+  public void scrollViewToRowIn(AlignFrameI alf, String topRow)
   {
     appLoader.scrollViewToRowIn(alf, topRow);
   }
 
   @Override
-  public void scrollViewToColumnIn(AlignFrameI alf,
-          String leftHandColumn)
+  public void scrollViewToColumnIn(AlignFrameI alf, String leftHandColumn)
   {
     appLoader.scrollViewToColumnIn(alf, leftHandColumn);
   }
@@ -1910,15 +1894,14 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
   }
 
   @Override
-  public String getFeatureGroupsOfStateOn(AlignFrameI alf,
-          boolean visible)
+  public String getFeatureGroupsOfStateOn(AlignFrameI alf, boolean visible)
   {
     return appLoader.getFeatureGroupsOfStateOn(alf, visible);
   }
 
   @Override
-  public void setFeatureGroupStateOn(AlignFrameI alf,
-          String groups, boolean state)
+  public void setFeatureGroupStateOn(AlignFrameI alf, String groups,
+          boolean state)
   {
     setFeatureGroupStateOn(alf, groups, state);
   }
@@ -1980,4 +1963,98 @@ public class Jalview implements ApplicationSingletonI, JalviewJSApi
     return CalculationChooser.openPcaPanel(af, modelName, null);
   }
 
+  @Override
+  public String getSelectedSequencesAsAlignment(String format,
+          boolean suffix)
+  {
+    return getSelectedSequencesAsAlignmentFrom(getCurrentAlignFrame(),
+            format, suffix);
+  }
+
+  @Override
+  public String getSelectedSequencesAsAlignmentFrom(AlignFrameI alf,
+          String format, boolean suffix)
+  {
+    return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format,
+            "" + suffix);
+  }
+
+  @Override
+  public String arrayToSeparatorList(String[] array)
+  {
+    return appLoader.arrayToSeparatorList(array);
+  }
+
+  @Override
+  public String[] separatorListToArray(String list)
+  {
+    return appLoader.separatorListToArray(list);
+  }
+
+  //// probably not needed in JalviewJS -- From when Jmol and Jalview did not
+  //// have a direct connection?
+
+  @Override
+  public void setMouseoverListener(String listener)
+  {
+    // TODO Auto-generated method stub
+
+  }
+
+  @Override
+  public void setMouseoverListener(AlignFrameI af, String listener)
+  {
+    // TODO Auto-generated method stub
+
+  }
+
+  @Override
+  public void setSelectionListener(String listener)
+  {
+    // TODO Auto-generated method stub
+
+  }
+
+  @Override
+  public void setSelectionListener(AlignFrameI af, String listener)
+  {
+    // TODO Auto-generated method stub
+
+  }
+
+  @Override
+  public void setStructureListener(String listener, String modelSet)
+  {
+    // TODO Auto-generated method stub
+
+  }
+
+  @Override
+  public void removeJavascriptListener(AlignFrameI af, String listener)
+  {
+    // TODO Auto-generated method stub
+
+  }
+
+  @Override
+  public void mouseOverStructure(String pdbResNum, String chain,
+          String pdbfile)
+  {
+    // TODO Auto-generated method stub
+
+  }
+
+  @Override
+  public void showOverview()
+  {
+    currentAlignFrame.overviewMenuItem_actionPerformed(null);
+  }
+
+  public void notifyWorker(AlignCalcWorkerI worker, String status)
+  {
+    // System.out.println("Jalview worker " + worker.getClass().getSimpleName()
+    // + " " + status);
+  }
+
 }
+