JAL-3626 from JAL-3253-applet web page embedding
authorBobHanson <hansonr@stolaf.edu>
Tue, 2 Jun 2020 00:32:42 +0000 (19:32 -0500)
committerBobHanson <hansonr@stolaf.edu>
Tue, 2 Jun 2020 00:32:42 +0000 (19:32 -0500)
16 files changed:
src/jalview/bin/Jalview.java
src/jalview/bin/JalviewAppLoader.java [new file with mode: 0644]
src/jalview/gui/AlignFrame.java
src/jalview/gui/Desktop.java
src/jalview/gui/OverviewPanel.java
src/jalview/gui/PCAPanel.java
src/jalview/io/FileLoader.java
src/jalview/jbgui/GAlignFrame.java
src/jalview/jbgui/GDesktop.java
src/jalview/jbgui/GPCAPanel.java
src/jalview/jbgui/GStructureViewer.java
src/jalview/jbgui/GTreePanel.java
src/jalview/project/Jalview2XML.java
src/jalview/viewmodel/OverviewDimensions.java
src/jalview/viewmodel/OverviewDimensionsHideHidden.java
src/jalview/viewmodel/OverviewDimensionsShowHidden.java

index cdd8cc1..98dc039 100755 (executable)
  */
 package jalview.bin;
 
+import jalview.api.AlignCalcWorkerI;
+import jalview.api.AlignViewportI;
+import jalview.api.JalviewApp;
+import jalview.api.StructureSelectionManagerProvider;
+import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.HiddenColumns;
+import jalview.datamodel.PDBEntry;
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
 import jalview.ext.so.SequenceOntology;
 import jalview.gui.AlignFrame;
+import jalview.gui.AlignmentPanel;
+import jalview.gui.CalculationChooser;
 import jalview.gui.Desktop;
 import jalview.gui.PromptUserConfig;
+import jalview.gui.StructureViewer;
 import jalview.io.AppletFormatAdapter;
 import jalview.io.BioJsHTMLOutput;
 import jalview.io.DataSourceType;
@@ -35,12 +47,19 @@ import jalview.io.HtmlSvgOutput;
 import jalview.io.IdentifyFile;
 import jalview.io.NewickFile;
 import jalview.io.gff.SequenceOntologyFactory;
+import jalview.javascript.JSFunctionExec;
+import jalview.javascript.MouseOverStructureListener;
+import jalview.renderer.seqfeatures.FeatureRenderer;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ColourSchemeProperty;
+import jalview.structure.SelectionSource;
+import jalview.structure.VamsasSource;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.ws.jws2.Jws2Discoverer;
+import netscape.javascript.JSObject;
 
+import java.applet.AppletContext;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileOutputStream;
@@ -58,6 +77,7 @@ import java.security.PermissionCollection;
 import java.security.Permissions;
 import java.security.Policy;
 import java.util.HashMap;
+import java.util.Hashtable;
 import java.util.Map;
 import java.util.Vector;
 import java.util.logging.ConsoleHandler;
@@ -87,7 +107,7 @@ import groovy.util.GroovyScriptEngine;
  * @author $author$
  * @version $Revision$
  */
-public class Jalview
+public class Jalview implements JalviewJSApi
 {
   static
   {
@@ -102,6 +122,39 @@ public class Jalview
 
   public static AlignFrame currentAlignFrame;
 
+  public boolean isJavaAppletTag;
+
+  public String appletResourcePath;
+
+  JalviewAppLoader appLoader;
+
+  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;
+  }
+
+
   static
   {
     if (!Platform.isJS())
@@ -202,53 +255,14 @@ public class Jalview
    */
   public static void main(String[] args)
   {
-//     setLogging(); // BH - for event debugging in JavaScript
-    instance = new Jalview();
-    instance.doMain(args);
-}
-
-  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
-     * 
-     */
+    if (false)
     {
-      System.out.println("not in js");
+      Platform.startJavaLogging();
     }
 
-         // 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"); 
-       }       
-
-  }
-  
-
-  
+    instance = new Jalview();
+    instance.doMain(args);
+}
 
   /**
    * @param args
@@ -1086,4 +1100,817 @@ public class Jalview
   {
     Jalview.currentAlignFrame = currentAlignFrame;
   }
+  
+  /**
+   * Get the SwingJS applet ID and combine that with the frameType
+   * 
+   * @param frameType
+   *          "alignment", "desktop", etc., or null
+   * @return
+   */
+  public static String getAppID(String frameType)
+  {
+    String id = Cache.getProperty("Info.j2sAppletID");
+    if (id == null)
+    {
+      id = "jalview";
+    }
+    return id + (frameType == null ? "" : "-" + frameType);
+  }
+
+  /**
+   * Handle all JalviewLite applet parameters
+   * 
+   * @param aparser
+   * @param af
+   */
+  private void loadAppletParams(ArgsParser aparser, AlignFrame af)
+  {
+    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;
+
+      private Hashtable<String, int[]> jshashes;
+
+      @Override
+      public String getParameter(String name)
+      {
+        return aparser.getAppletValue(name, null);
+      }
+
+      @Override
+      public boolean getDefaultParameter(String name, boolean def)
+      {
+        String stn;
+        return ((stn = getParameter(name)) == null ? def
+                : "true".equalsIgnoreCase(stn));
+      }
+
+      /**
+       * Get the applet-like document base even though this is an application.
+       */
+      @Override
+      public URL getDocumentBase()
+      {
+        return Platform.getDocumentBase();
+      }
+
+      /**
+       * Get the applet-like code base even though this is an application.
+       */
+      @Override
+      public URL getCodeBase()
+      {
+        return Platform.getCodeBase();
+      }
+
+      @Override
+      public AlignViewportI getViewport()
+      {
+        return af.getViewport();
+      }
+
+      /**
+       * features
+       * 
+       */
+      @Override
+      public boolean parseFeaturesFile(String filename,
+              DataSourceType protocol)
+      {
+        return af.parseFeaturesFile(filename, protocol);
+      }
+
+      /**
+       * scorefile
+       * 
+       */
+      @Override
+      public boolean loadScoreFile(String sScoreFile) throws IOException
+      {
+        af.loadJalviewDataFile(sScoreFile, null, null, null);
+        return true;
+      }
+
+      /**
+       * annotations, jpredfile, jnetfile
+       * 
+       */
+      @Override
+      public void updateForAnnotations()
+      {
+        af.updateForAnnotations();
+      }
+
+      @Override
+      public void loadTree(NewickFile fin, String treeFile)
+              throws IOException
+      {
+        // n/a -- already done by standard Jalview command line processing
+      }
+
+      @Override
+      public void setAlignPdbStructures(boolean defaultParameter)
+      {
+        alignPDBStructures = true;
+      }
+
+      @Override
+      public void newStructureView(PDBEntry pdb, SequenceI[] seqs,
+              String[] chains, DataSourceType protocol)
+      {
+        StructureViewer.launchStructureViewer(af.alignPanel, pdb, seqs);
+      }
+
+      @Override
+      public void setFeatureGroupState(String[] groups, boolean state)
+      {
+        af.setFeatureGroupState(groups, state);
+      }
+
+      @Override
+      public void alignedStructureView(PDBEntry[] pdb, SequenceI[][] seqs,
+              String[][] chains, String[] protocols)
+      {
+        System.err.println(
+                "Jalview applet interface alignedStructureView not implemented");
+      }
+
+      @Override
+      public void newFeatureSettings()
+      {
+        System.err.println(
+                "Jalview applet interface newFeatureSettings not implemented");
+      }
+
+      private Vector<Runnable> jsExecQueue;
+
+      @Override
+      public Vector<Runnable> getJsExecQueue(JSFunctionExec exec)
+      {
+        jsFunctionExec = exec;
+        return (jsExecQueue == null ? (jsExecQueue = new Vector<>())
+                : jsExecQueue);
+      }
+
+      @Override
+      public AppletContext getAppletContext()
+      {
+        // TODO Auto-generated method stub
+        return null;
+      }
+
+      @Override
+      public boolean isJsfallbackEnabled()
+      {
+        // TODO Auto-generated method stub
+        return false;
+      }
+
+      @Override
+      public JSObject getJSObject()
+      {
+        // TODO Auto-generated method stub
+        return null;
+      }
+
+      @Override
+      public StructureSelectionManagerProvider getStructureSelectionManagerProvider()
+      {
+        // TODO Q: what exactly is this? BH
+        return null;
+      }
+
+      @Override
+      public void updateColoursFromMouseOver(Object source,
+              MouseOverStructureListener mouseOverStructureListener)
+      {
+        // TODO Auto-generated method stub
+
+      }
+
+      @Override
+      public Object[] getSelectionForListener(SequenceGroup seqsel,
+              ColumnSelection colsel, HiddenColumns hidden,
+              SelectionSource source, Object alignFrame)
+      {
+        return appLoader.getSelectionForListener(getCurrentAlignFrame(),
+                seqsel, colsel, hidden, source, alignFrame);
+      }
+
+      @Override
+      public String arrayToSeparatorList(String[] array)
+      {
+        return appLoader.arrayToSeparatorList(array);
+      }
+
+      @Override
+      public Hashtable<String, int[]> getJSHashes()
+      {
+        return (jshashes == null ? (jshashes = new Hashtable<>())
+                : jshashes);
+      }
+
+      @Override
+      public Hashtable<String, Hashtable<String, String[]>> getJSMessages()
+      {
+        return (jsmessages == null ? (jsmessages = new Hashtable<>())
+                : jsmessages);
+      }
+
+      @Override
+      public Object getFrameForSource(VamsasSource source)
+      {
+        if (source != null)
+        {
+          AlignFrame af;
+          if (source instanceof jalview.gui.AlignViewport
+                  && source == (af = getCurrentAlignFrame()).getViewport())
+          {
+            // should be valid if it just generated an event!
+            return af;
+          }
+          // TODO: ensure that if '_af' is specified along with a handler
+          // function, then only events from that alignFrame are sent to that
+          // function
+        }
+        return null;
+      }
+
+      @Override
+      public FeatureRenderer getNewFeatureRenderer(AlignViewportI vp)
+      {
+        return new jalview.gui.FeatureRenderer((AlignmentPanel) vp);
+      }
+
+    };
+
+    appLoader = new JalviewAppLoader(true);
+    appLoader.load(app);
+  }
+
+  /**
+   * 
+   * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences()
+   */
+  @Override
+  public String getSelectedSequences()
+  {
+    return getSelectedSequencesFrom(getCurrentAlignFrame());
+  }
+
+  /**
+   * 
+   * @see jalview.bin.JalviewLiteJsApi#getSelectedSequences(java.lang.String)
+   */
+  @Override
+  public String getSelectedSequences(String sep)
+  {
+    return getSelectedSequencesFrom(getCurrentAlignFrame(), sep);
+  }
+
+  /**
+   * 
+   * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
+   *      .AlignFrame)
+   */
+  @Override
+  public String getSelectedSequencesFrom(AlignFrame alf)
+  {
+    if (alf == null)
+    {
+      alf = getCurrentAlignFrame();
+    }
+    return getSelectedSequencesFrom(alf, null);
+  }
+
+  /**
+   * 
+   * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
+   *      .AlignFrame, java.lang.String)
+   */
+  @Override
+  public String getSelectedSequencesFrom(AlignFrame alf, String sep)
+  {
+    if (alf == null)
+    {
+      alf = getCurrentAlignFrame();
+    }
+    return appLoader.getSelectedSequencesFrom(alf, sep);
+  }
+
+  /**
+   * 
+   * @see jalview.bin.JalviewLiteJsApi#getSelectedSequencesFrom(jalview.appletgui
+   *      .AlignFrame, java.lang.String)
+   */
+  @Override
+  public void highlight(String sequenceId, String position,
+          String alignedPosition)
+  {
+    highlightIn(null, sequenceId, position,
+            alignedPosition);
+  }
+
+  @Override
+  public void highlightIn(AlignFrame alf, String sequenceId,
+          String position, String alignedPosition)
+  {
+    if (alf == null)
+    {
+      alf = getCurrentAlignFrame();
+    }
+    appLoader.highlightIn(alf, sequenceId, position, alignedPosition);
+  }
+
+  @Override
+  public void select(String sequenceIds, String columns)
+  {
+    selectIn(getCurrentAlignFrame(), sequenceIds, columns, null);
+  }
+
+  @Override
+  public void select(String sequenceIds, String columns, String sep)
+  {
+    selectIn(null, sequenceIds, columns, sep);
+  }
+
+  @Override
+  public void selectIn(AlignFrame alf, String sequenceIds, String columns)
+  {
+    selectIn(alf, sequenceIds, columns, null);
+  }
+
+  @Override
+  public void selectIn(AlignFrame alf, String sequenceIds, String columns,
+          String sep)
+  {
+    if (alf == null)
+    {
+      alf = getCurrentAlignFrame();
+    }
+    appLoader.selectIn(alf, sequenceIds, columns, sep);
+  }
+
+  @Override
+  public String getSelectedSequencesAsAlignment(String format,
+          String suffix)
+  {
+    return getSelectedSequencesAsAlignmentFrom(null,
+            format, suffix);
+  }
+
+  @Override
+  public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
+          String format, String sep)
+  {
+    if (alf == null)
+    {
+      alf = getCurrentAlignFrame();
+    }
+    return appLoader.getSelectedSequencesAsAlignmentFrom(alf, format, sep);
+  }
+
+  @Override
+  public String getAlignmentOrder()
+  {
+    return getAlignmentFrom(getCurrentAlignFrame(), null);
+  }
+
+  @Override
+  public String getAlignmentOrderFrom(AlignFrame alf)
+  {
+    return getAlignmentFrom(alf, null);
+  }
+
+  @Override
+  public String getAlignmentOrderFrom(AlignFrame alf, String sep)
+  {
+    if (alf == null)
+    {
+      alf = getCurrentAlignFrame();
+    }
+    return appLoader.getAlignmentOrderFrom(alf, sep);
+  }
+
+  @Override
+  public String orderBy(String order, String undoName)
+  {
+    return orderBy(order, undoName, null);
+  }
+
+  @Override
+  public String orderBy(String order, String undoName, String sep)
+  {
+    return orderAlignmentBy(getCurrentAlignFrame(), order, undoName, sep);
+  }
+
+  @Override
+  public String orderAlignmentBy(AlignFrame alf, String order,
+          String undoName, String sep)
+  {
+    if (alf == null)
+    {
+      alf = getCurrentAlignFrame();
+    }
+    return appLoader.orderAlignmentBy(alf, order, undoName, sep);
+  }
+
+  @Override
+  public String getAlignment(String format)
+  {
+    return getAlignmentFrom(null, format, null);
+  }
+
+  @Override
+  public String getAlignmentFrom(AlignFrame alf, String format)
+  {
+    return getAlignmentFrom(alf, format, null);
+  }
+
+  @Override
+  public String getAlignment(String format, String suffix)
+  {
+    return getAlignmentFrom(getCurrentAlignFrame(), format, suffix);
+  }
+
+  @Override
+  public String getAlignmentFrom(AlignFrame alf, String format,
+          String suffix)
+  {
+    return appLoader.getAlignmentFrom(alf, format, suffix);
+  }
+
+  @Override
+  public void loadAnnotation(String annotation)
+  {
+    loadAnnotationFrom(getCurrentAlignFrame(), annotation);
+  }
+
+  @Override
+  public void loadAnnotationFrom(AlignFrame alf, String annotation)
+  {
+    if (alf == null)
+    {
+      alf = getCurrentAlignFrame();
+    }
+    appLoader.loadAnnotationFrom(alf, annotation);
+  }
+
+  @Override
+  public void loadFeatures(String features, boolean autoenabledisplay)
+  {
+    loadFeaturesFrom(currentAlignFrame, features, autoenabledisplay);
+  }
+
+  @Override
+  public boolean loadFeaturesFrom(AlignFrame alf, String features,
+          boolean autoenabledisplay)
+  {
+    if (alf == null)
+    {
+      alf = getCurrentAlignFrame();
+    }
+    return appLoader.loadFeaturesFrom(alf, features, autoenabledisplay);
+  }
+
+  @Override
+  public String getFeatures(String format)
+  {
+    return getFeaturesFrom(null, format);
+  }
+
+  @Override
+  public String getFeaturesFrom(AlignFrame alf, String format)
+  {
+    if (alf == null)
+    {
+      alf = getCurrentAlignFrame();
+    }
+    return appLoader.getFeaturesFrom(alf, format);
+  }
+
+  @Override
+  public String getAnnotation()
+  {
+    return getAnnotationFrom(null);
+  }
+
+  @Override
+  public String getAnnotationFrom(AlignFrame alf)
+  {
+    if (alf == null)
+    {
+      alf = getCurrentAlignFrame();
+    }
+    return appLoader.getAnnotationFrom(alf);
+  }
+
+//  @Override
+//  public AlignFrame newView()
+//  {
+//    return newViewFrom(null, null);
+//  }
+//
+//  @Override
+//  public AlignFrame newView(String name)
+//  {
+//    return newViewFrom(null, name);
+//  }
+//
+//  @Override
+//  public AlignFrame newViewFrom(AlignFrame alf)
+//  {
+//    return newViewFrom(alf, null);
+//  }
+//
+//  @Override
+//  public AlignFrame newViewFrom(AlignFrame alf, String name)
+//  {
+//    if (alf == null)
+//    {
+//      alf = getCurrentAlignFrame();
+//    }
+//    return appLoader.newViewFrom(alf, name);
+//  }
+
+  @Override
+  public AlignFrame loadAlignment(String text, String title)
+  {
+    return appLoader.loadAlignment(text, AlignFrame.DEFAULT_WIDTH,
+            AlignFrame.DEFAULT_HEIGHT, title);
+  }
+
+  @Override
+  public boolean addPdbFile(AlignFrame alFrame, String sequenceId,
+          String pdbEntryString, String pdbFile)
+  {
+    if (alFrame == null)
+    {
+      alFrame = getCurrentAlignFrame();
+    }
+    return appLoader.addPdbFile(alFrame, sequenceId, pdbEntryString,
+            pdbFile);
+  }
+
+  @Override
+  public void scrollViewToIn(AlignFrame alf, String topRow,
+          String leftHandColumn)
+  {
+    if (alf == null)
+    {
+      alf = getCurrentAlignFrame();
+    }
+    appLoader.scrollViewToIn(alf, topRow, leftHandColumn);
+  }
+
+  @Override
+  public void scrollViewToRowIn(AlignFrame alf, String topRow)
+  {
+    if (alf == null)
+    {
+      alf = getCurrentAlignFrame();
+    }
+    appLoader.scrollViewToRowIn(alf, topRow);
+  }
+
+  @Override
+  public void scrollViewToColumnIn(AlignFrame alf, String leftHandColumn)
+  {
+    if (alf == null)
+    {
+      alf = getCurrentAlignFrame();
+    }
+    appLoader.scrollViewToColumnIn(alf, leftHandColumn);
+  }
+
+  @Override
+  public String getFeatureGroups()
+  {
+    return getFeatureGroupsOn(null);
+  }
+
+  @Override
+  public String getFeatureGroupsOn(AlignFrame alf)
+  {
+    if (alf == null)
+    {
+      alf = getCurrentAlignFrame();
+    }
+    return appLoader.getFeatureGroupsOn(alf);
+  }
+
+  @Override
+  public String getFeatureGroupsOfState(boolean visible)
+  {
+    return getFeatureGroupsOfStateOn(null, visible);
+  }
+
+  @Override
+  public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
+  {
+    if (alf == null)
+    {
+      alf = getCurrentAlignFrame();
+    }
+    return appLoader.getFeatureGroupsOfStateOn(alf, visible);
+  }
+
+  @Override
+  public void setFeatureGroupState(String groups, boolean state)
+  { // JalviewLite API
+    setFeatureGroupStateOn(null, groups, state);
+  }
+
+  @Override
+  public void setFeatureGroupStateOn(AlignFrame alf, String groups,
+          boolean state)
+  {
+    if (alf == null)
+    {
+      alf = getCurrentAlignFrame();
+    }
+    appLoader.setFeatureGroupStateOn(alf, groups, state);
+  }
+
+  @Override
+  public String getSeparator()
+  {
+    return appLoader.getSeparator();
+  }
+
+  @Override
+  public void setSeparator(String separator)
+  {
+    appLoader.setSeparator(separator);
+  }
+
+  @Override
+  public String getJsMessage(String messageclass, String viewId)
+  {
+    // see http://www.jalview.org/examples/jalviewLiteJs.html
+    return null;
+  }
+
+  /**
+   * Open a new Tree panel on the desktop statically. Params are standard (not
+   * set by Groovy). No dialog is opened.
+   * 
+   * @param af
+   * @param treeType
+   * @param modelName
+   * @return null, or the string "label.you_need_at_least_n_sequences" if number
+   *         of sequences selected is inappropriate
+   */
+  @Override
+  public Object openTreePanel(AlignFrame af, String treeType,
+          String modelName)
+  { // JalviewJS api
+    if (af == null)
+    {
+      af = getCurrentAlignFrame();
+    }
+    return CalculationChooser.openTreePanel(af, treeType, modelName, null);
+  }
+
+  /**
+   * public static method for JalviewJS API to open a PCAPanel without
+   * necessarily using a dialog.
+   * 
+   * @param af
+   * @param modelName
+   * @return the PCAPanel, or the string "label.you_need_at_least_n_sequences"
+   *         if number of sequences selected is inappropriate
+   */
+  @Override
+  public Object openPcaPanel(AlignFrame af, String modelName)
+  {
+    if (af == null)
+    {
+      af = getCurrentAlignFrame();
+    }
+    return CalculationChooser.openPcaPanel(af, modelName, null);
+  }
+
+  @Override
+  public String getSelectedSequencesAsAlignment(String format,
+          boolean suffix)
+  {
+    return getSelectedSequencesAsAlignmentFrom(null,
+            format, suffix);
+  }
+
+  @Override
+  public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
+          String format, boolean suffix)
+  {
+    if (alf == null)
+    {
+      alf = getCurrentAlignFrame();
+    }
+    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(AlignFrame af, String listener)
+  {
+    // TODO Auto-generated method stub
+
+  }
+
+  @Override
+  public void setSelectionListener(String listener)
+  {
+    // TODO Auto-generated method stub
+
+  }
+
+  @Override
+  public void setSelectionListener(AlignFrame 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(AlignFrame 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);
+  }
+
+  @Override
+  public Object parseArguments(String[] args)
+  {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+
+  
+  
 }
diff --git a/src/jalview/bin/JalviewAppLoader.java b/src/jalview/bin/JalviewAppLoader.java
new file mode 100644 (file)
index 0000000..1cdeaec
--- /dev/null
@@ -0,0 +1,1500 @@
+package jalview.bin;
+
+import jalview.api.JalviewApp;
+import jalview.api.StructureSelectionManagerProvider;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.AlignmentOrder;
+import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.HiddenColumns;
+import jalview.datamodel.PDBEntry;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
+import jalview.gui.AlignFrame;
+import jalview.gui.AlignViewport;
+import jalview.gui.Desktop;
+import jalview.io.AnnotationFile;
+import jalview.io.AppletFormatAdapter;
+import jalview.io.DataSourceType;
+import jalview.io.FeaturesFile;
+import jalview.io.FileFormat;
+import jalview.io.FileFormatI;
+import jalview.io.FileFormats;
+import jalview.io.IdentifyFile;
+import jalview.io.JPredFile;
+import jalview.io.JnetAnnotationMaker;
+import jalview.io.NewickFile;
+import jalview.structure.SelectionSource;
+import jalview.structure.StructureSelectionManager;
+import jalview.util.HttpUtils;
+import jalview.util.MessageManager;
+
+import java.awt.EventQueue;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+/**
+ * A class to load parameters for either JalviewLite or Jalview
+ * 
+ * @author hansonr
+ *
+ */
+public class JalviewAppLoader
+{
+
+  private JalviewApp app; // Jalview or JalviewJS or JalviewLite
+
+  private boolean debug;
+
+  String separator = "\u00AC"; // JalviewLite note: the default used to
+                                       // be '|', but many sequence IDS include
+                                       // pipes.
+
+  public String getSeparator()
+  {
+    return separator;
+  }
+
+  public void setSeparator(String separator)
+  {
+    this.separator = separator;
+  }
+
+  public JalviewAppLoader(boolean debug)
+  {
+    this.debug = debug;
+  }
+
+  public void load(JalviewApp app)
+  {
+
+    this.app = app;
+
+    String sep = app.getParameter("separator");
+    if (sep != null)
+    {
+      if (sep.length() > 0)
+      {
+        separator = sep;
+      }
+      else
+      {
+        throw new Error(MessageManager
+                .getString("error.invalid_separator_parameter"));
+      }
+    }
+
+    loadTree();
+    loadScoreFile();
+    loadFeatures();
+    loadAnnotations();
+    loadJnetFile();
+    loadPdbFiles();
+    callInitCallback();
+  }
+
+  /**
+   * Load PDBFiles if any specified by parameter(s). Returns true if loaded,
+   * else false.
+   * 
+   * @param loaderFrame
+   * @return
+   */
+  protected boolean loadPdbFiles()
+  {
+    boolean result = false;
+    /*
+     * <param name="alignpdbfiles" value="false/true"/> Undocumented for 2.6 -
+     * related to JAL-434
+     */
+
+    boolean doAlign = app.getDefaultParameter("alignpdbfiles", false);
+    app.setAlignPdbStructures(doAlign);
+    /*
+     * <param name="PDBfile" value="1gaq.txt PDB|1GAQ|1GAQ|A PDB|1GAQ|1GAQ|B
+     * PDB|1GAQ|1GAQ|C">
+     * 
+     * <param name="PDBfile2" value="1gaq.txt A=SEQA B=SEQB C=SEQB">
+     * 
+     * <param name="PDBfile3" value="1q0o Q45135_9MICO">
+     */
+
+    // Accumulate pdbs here if they are heading for the same view (if
+    // alignPdbStructures is true)
+    Vector<Object[]> pdbs = new Vector<>();
+    // create a lazy matcher if we're asked to
+    jalview.analysis.SequenceIdMatcher matcher = (app
+            .getDefaultParameter("relaxedidmatch", false))
+                    ? new jalview.analysis.SequenceIdMatcher(
+                            app.getViewport().getAlignment()
+                                    .getSequencesArray())
+                    : null;
+
+    int pdbFileCount = 0;
+    String param;
+    do
+    {
+      if (pdbFileCount > 0)
+      {
+        param = app.getParameter("PDBFILE" + pdbFileCount);
+      }
+      else
+      {
+        param = app.getParameter("PDBFILE");
+      }
+
+      if (param != null)
+      {
+        PDBEntry pdb = new PDBEntry();
+
+        String seqstring;
+        SequenceI[] seqs = null;
+        String[] chains = null;
+
+        StringTokenizer st = new StringTokenizer(param, " ");
+
+        if (st.countTokens() < 2)
+        {
+          String sequence = app.getParameter("PDBSEQ");
+          if (sequence != null)
+          {
+            seqs = new SequenceI[] { matcher == null
+                    ? (Sequence) app.getViewport().getAlignment()
+                            .findName(sequence)
+                    : matcher.findIdMatch(sequence) };
+          }
+
+        }
+        else
+        {
+          param = st.nextToken();
+          List<SequenceI> tmp = new ArrayList<>();
+          List<String> tmp2 = new ArrayList<>();
+
+          while (st.hasMoreTokens())
+          {
+            seqstring = st.nextToken();
+            StringTokenizer st2 = new StringTokenizer(seqstring, "=");
+            if (st2.countTokens() > 1)
+            {
+              // This is the chain
+              tmp2.add(st2.nextToken());
+              seqstring = st2.nextToken();
+            }
+            tmp.add(matcher == null
+                    ? (Sequence) app.getViewport().getAlignment()
+                            .findName(seqstring)
+                    : matcher.findIdMatch(seqstring));
+          }
+
+          seqs = tmp.toArray(new SequenceI[tmp.size()]);
+          if (tmp2.size() == tmp.size())
+          {
+            chains = tmp2.toArray(new String[tmp2.size()]);
+          }
+        }
+        pdb.setId(param);
+        ret[0] = param;
+        DataSourceType protocol = resolveFileProtocol(app, ret);
+        // TODO check JAL-357 for files in a jar (CLASSLOADER)
+        pdb.setFile(ret[0]);
+
+        if (seqs != null)
+        {
+          for (int i = 0; i < seqs.length; i++)
+          {
+            if (seqs[i] != null)
+            {
+              ((Sequence) seqs[i]).addPDBId(pdb);
+              StructureSelectionManager
+                      .getStructureSelectionManager(
+                              (StructureSelectionManagerProvider) app)
+                      .registerPDBEntry(pdb);
+            }
+            else
+            {
+              if (debug)
+              {
+                // this may not really be a problem but we give a warning
+                // anyway
+                System.err.println(
+                        "Warning: Possible input parsing error: Null sequence for attachment of PDB (sequence "
+                                + i + ")");
+              }
+            }
+          }
+
+          if (doAlign)
+          {
+            pdbs.addElement(new Object[] { pdb, seqs, chains, protocol });
+          }
+          else
+          {
+            app.newStructureView(pdb, seqs, chains, protocol);
+          }
+        }
+      }
+
+      pdbFileCount++;
+    } while (param != null || pdbFileCount < 10);
+    if (pdbs.size() > 0)
+    {
+      SequenceI[][] seqs = new SequenceI[pdbs.size()][];
+      PDBEntry[] pdb = new PDBEntry[pdbs.size()];
+      String[][] chains = new String[pdbs.size()][];
+      String[] protocols = new String[pdbs.size()];
+      for (int pdbsi = 0, pdbsiSize = pdbs
+              .size(); pdbsi < pdbsiSize; pdbsi++)
+      {
+        Object[] o = pdbs.elementAt(pdbsi);
+        pdb[pdbsi] = (PDBEntry) o[0];
+        seqs[pdbsi] = (SequenceI[]) o[1];
+        chains[pdbsi] = (String[]) o[2];
+        protocols[pdbsi] = (String) o[3];
+      }
+      app.alignedStructureView(pdb, seqs, chains, protocols);
+      result = true;
+    }
+    return result;
+  }
+
+  /**
+   * Load in a Jnetfile if specified by parameter. Returns true if loaded, else
+   * false.
+   * 
+   * @param alignFrame
+   * @return
+   */
+  protected boolean loadJnetFile()
+  {
+    boolean result = false;
+    String param = app.getParameter("jnetfile");
+    if (param == null)
+    {
+      // jnet became jpred around 2016
+      param = app.getParameter("jpredfile");
+    }
+    if (param != null)
+    {
+      try
+      {
+        ret[0] = param;
+        DataSourceType protocol = resolveFileProtocol(app, ret);
+        JPredFile predictions = new JPredFile(ret[0], protocol);
+        JnetAnnotationMaker.add_annotation(predictions,
+                app.getViewport().getAlignment(), 0, false);
+        // false == do not add sequence profile from concise output
+        app.getViewport().getAlignment().setupJPredAlignment();
+        app.updateForAnnotations();
+        result = true;
+      } catch (Exception ex)
+      {
+        ex.printStackTrace();
+      }
+    }
+    return result;
+  }
+
+  /**
+   * Load annotations if specified by parameter. Returns true if loaded, else
+   * false.
+   * 
+   * @param alignFrame
+   * @return
+   */
+  protected boolean loadAnnotations()
+  {
+    boolean result = false;
+    String param = app.getParameter("annotations");
+    if (param != null)
+    {
+      ret[0] = param;
+      DataSourceType protocol = resolveFileProtocol(app, ret);
+      param = ret[0];
+      if (new AnnotationFile().annotateAlignmentView(app.getViewport(),
+              param, protocol))
+      {
+        app.updateForAnnotations();
+        result = true;
+      }
+      else
+      {
+        System.err
+                .println("Annotations were not added from annotation file '"
+                        + param + "'");
+      }
+    }
+    return result;
+  }
+
+  /**
+   * Load features file and view settings as specified by parameters. Returns
+   * true if features were loaded, else false.
+   * 
+   * @param alignFrame
+   * @return
+   */
+  protected boolean loadFeatures()
+  {
+    boolean result = false;
+    // ///////////////////////////
+    // modify display of features
+    // we do this before any features have been loaded, ensuring any hidden
+    // groups are hidden when features first displayed
+    //
+    // hide specific groups
+    //
+    String param = app.getParameter("hidefeaturegroups");
+    if (param != null)
+    {
+      app.setFeatureGroupState(separatorListToArray(param, separator),
+              false);
+      // app.setFeatureGroupStateOn(newAlignFrame, param, false);
+    }
+    // show specific groups
+    param = app.getParameter("showfeaturegroups");
+    if (param != null)
+    {
+      app.setFeatureGroupState(separatorListToArray(param, separator),
+              true);
+      // app.setFeatureGroupStateOn(newAlignFrame, param, true);
+    }
+    // and now load features
+    param = app.getParameter("features");
+    if (param != null)
+    {
+      ret[0] = param;
+      DataSourceType protocol = resolveFileProtocol(app, ret);
+
+      result = app.parseFeaturesFile(ret[0], protocol);
+    }
+
+    param = app.getParameter("showFeatureSettings");
+    if (param != null && param.equalsIgnoreCase("true"))
+    {
+      app.newFeatureSettings();
+    }
+    return result;
+  }
+
+  /**
+   * Load a score file if specified by parameter. Returns true if file was
+   * loaded, else false.
+   * 
+   * @param loaderFrame
+   */
+  protected boolean loadScoreFile()
+  {
+    boolean result = false;
+    String sScoreFile = app.getParameter("scoreFile");
+    if (sScoreFile != null && !"".equals(sScoreFile))
+    {
+      try
+      {
+        if (debug)
+        {
+          System.err.println(
+                  "Attempting to load T-COFFEE score file from the scoreFile parameter");
+        }
+        result = app.loadScoreFile(sScoreFile);
+        if (!result)
+        {
+          System.err.println(
+                  "Failed to parse T-COFFEE parameter as a valid score file ('"
+                          + sScoreFile + "')");
+        }
+      } catch (Exception e)
+      {
+        System.err.printf("Cannot read score file: '%s'. Cause: %s \n",
+                sScoreFile, e.getMessage());
+      }
+    }
+    return result;
+  }
+
+  String[] ret = new String[1];
+
+  /**
+   * Load a tree for the alignment if specified by parameter. Returns true if a
+   * tree was loaded, else false.
+   * 
+   * @param loaderFrame
+   * @return
+   */
+  protected boolean loadTree()
+  {
+    boolean result = false;
+    String treeFile = app.getParameter("tree");
+    if (treeFile == null)
+    {
+      treeFile = app.getParameter("treeFile");
+    }
+
+    if (treeFile != null)
+    {
+      try
+      {
+        ret[0] = treeFile;
+        NewickFile fin = new NewickFile(treeFile,
+                resolveFileProtocol(app, ret));
+        fin.parse();
+
+        if (fin.getTree() != null)
+        {
+          app.loadTree(fin, ret[0]);
+          result = true;
+          if (debug)
+          {
+            System.out.println("Successfully imported tree.");
+          }
+        }
+        else
+        {
+          if (debug)
+          {
+            System.out.println(
+                    "Tree parameter did not resolve to a valid tree.");
+          }
+        }
+      } catch (Exception ex)
+      {
+        ex.printStackTrace();
+      }
+    }
+    return result;
+  }
+
+  /**
+   * form a complete URL given a path to a resource and a reference location on
+   * the same server
+   * 
+   * @param targetPath
+   *          - an absolute path on the same server as localref or a document
+   *          located relative to localref
+   * @param localref
+   *          - a URL on the same server as url
+   * @return a complete URL for the resource located by url
+   */
+  public static String resolveUrlForLocalOrAbsolute(String targetPath,
+          URL localref)
+  {
+    String resolvedPath = "";
+    if (targetPath.startsWith("/"))
+    {
+      String codebase = localref.toString();
+      String localfile = localref.getFile();
+      resolvedPath = codebase.substring(0,
+              codebase.length() - localfile.length()) + targetPath;
+      return resolvedPath;
+    }
+
+    /*
+     * get URL path and strip off any trailing file e.g.
+     * www.jalview.org/examples/index.html#applets?a=b is trimmed to
+     * www.jalview.org/examples/
+     */
+    String urlPath = localref.toString();
+    String directoryPath = urlPath;
+    int lastSeparator = directoryPath.lastIndexOf("/");
+    if (lastSeparator > 0)
+    {
+      directoryPath = directoryPath.substring(0, lastSeparator + 1);
+    }
+
+    if (targetPath.startsWith("/"))
+    {
+      /*
+       * construct absolute URL to a file on the server - this is not allowed?
+       */
+      // String localfile = localref.getFile();
+      // resolvedPath = urlPath.substring(0,
+      // urlPath.length() - localfile.length())
+      // + targetPath;
+      resolvedPath = directoryPath + targetPath.substring(1);
+    }
+    else
+    {
+      resolvedPath = directoryPath + targetPath;
+    }
+    // if (debug)
+    // {
+    // System.err.println(
+    // "resolveUrlForLocalOrAbsolute returning " + resolvedPath);
+    // }
+    return resolvedPath;
+  }
+
+  /**
+   * parse the string into a list
+   * 
+   * @param list
+   * @param separator
+   * @return elements separated by separator
+   */
+  public static String[] separatorListToArray(String list, String separator)
+  {
+    // TODO use StringUtils version (slightly different...)
+    int seplen = separator.length();
+    if (list == null || list.equals("") || list.equals(separator))
+    {
+      return null;
+    }
+    Vector<String> jv = new Vector<>();
+    int cp = 0, pos;
+    while ((pos = list.indexOf(separator, cp)) > cp)
+    {
+      jv.addElement(list.substring(cp, pos));
+      cp = pos + seplen;
+    }
+    if (cp < list.length())
+    {
+      String c = list.substring(cp);
+      if (!c.equals(separator))
+      {
+        jv.addElement(c);
+      }
+    }
+    if (jv.size() > 0)
+    {
+      String[] v = new String[jv.size()];
+      for (int i = 0; i < v.length; i++)
+      {
+        v[i] = jv.elementAt(i);
+      }
+      jv.removeAllElements();
+      // if (debug)
+      // {
+      // System.err.println("Array from '" + separator
+      // + "' separated List:\n" + v.length);
+      // for (int i = 0; i < v.length; i++)
+      // {
+      // System.err.println("item " + i + " '" + v[i] + "'");
+      // }
+      // }
+      return v;
+    }
+    // if (debug)
+    // {
+    // System.err.println(
+    // "Empty Array from '" + separator + "' separated List");
+    // }
+    return null;
+  }
+
+  public static DataSourceType resolveFileProtocol(JalviewApp app,
+          String[] retPath)
+  {
+    String path = retPath[0];
+    /*
+     * is it paste data?
+     */
+    if (path.startsWith("PASTE"))
+    {
+      retPath[0] = path.substring(5);
+      return DataSourceType.PASTE;
+    }
+
+    /*
+     * is it a URL?
+     */
+    if (path.indexOf("://") >= 0)
+    {
+      return DataSourceType.URL;
+    }
+
+    /*
+     * try relative to document root
+     */
+    URL documentBase = app.getDocumentBase();
+    String withDocBase = resolveUrlForLocalOrAbsolute(path, documentBase);
+    if (HttpUtils.isValidUrl(withDocBase))
+    {
+      // if (debug)
+      // {
+      // System.err.println("Prepended document base '" + documentBase
+      // + "' to make: '" + withDocBase + "'");
+      // }
+      retPath[0] = withDocBase;
+      return DataSourceType.URL;
+    }
+
+    /*
+     * try relative to codebase (if different to document base)
+     */
+    URL codeBase = app.getCodeBase();
+    String withCodeBase = resolveUrlForLocalOrAbsolute(path, codeBase);
+    if (!withCodeBase.equals(withDocBase)
+            && HttpUtils.isValidUrl(withCodeBase))
+    {
+      // if (debug)
+      // {
+      // System.err.println("Prepended codebase '" + codeBase
+      // + "' to make: '" + withCodeBase + "'");
+      // }
+      retPath[0] = withCodeBase;
+      return DataSourceType.URL;
+    }
+
+    /*
+     * try locating by classloader; try this last so files in the directory
+     * are resolved using document base
+     */
+    if (inArchive(app.getClass(), path))
+    {
+      return DataSourceType.CLASSLOADER;
+    }
+    return null;
+  }
+
+  /**
+   * Discovers whether the given file is in the Applet Archive
+   * 
+   * @param f
+   *          String
+   * @return boolean
+   */
+  private static boolean inArchive(Class<?> c, String f)
+  {
+    // This might throw a security exception in certain browsers
+    // Netscape Communicator for instance.
+    try
+    {
+      boolean rtn = (c.getResourceAsStream("/" + f) != null);
+      // if (debug)
+      // {
+      // System.err.println("Resource '" + f + "' was "
+      // + (rtn ? "" : "not ") + "located by classloader.");
+      // }
+      return rtn;
+    } catch (Exception ex)
+    {
+      System.out.println("Exception checking resources: " + f + " " + ex);
+      return false;
+    }
+  }
+
+  public void callInitCallback()
+  {
+    String initjscallback = app.getParameter("oninit");
+    if (initjscallback == null)
+    {
+      return;
+    }
+    initjscallback = initjscallback.trim();
+    if (initjscallback.length() > 0)
+    {
+      // TODO
+    }
+  }
+
+  /**
+   * read sequence1...sequenceN as a raw alignment
+   * 
+   * @param jalviewApp
+   * @return
+   */
+  public String getPastedSequence(JalviewApp jalviewApp)
+  {
+    StringBuffer data = new StringBuffer("PASTE");
+    int i = 1;
+    String file = null;
+    while ((file = app.getParameter("sequence" + i)) != null)
+    {
+      data.append(file.toString() + "\n");
+      i++;
+    }
+    if (data.length() > 5)
+    {
+      file = data.toString();
+    }
+    return file;
+  }
+
+  /**
+   * concatenate the list with separator
+   * 
+   * @param list
+   * @param separator
+   * @return concatenated string
+   */
+  public static String arrayToSeparatorList(String[] list, String separator)
+  {
+    // TODO use StringUtils version
+    StringBuffer v = new StringBuffer();
+    if (list != null && list.length > 0)
+    {
+      for (int i = 0, iSize = list.length; i < iSize; i++)
+      {
+        if (list[i] != null)
+        {
+          if (i > 0)
+          {
+            v.append(separator);
+          }
+          v.append(list[i]);
+        }
+      }
+      // if (debug)
+      // {
+      // System.err
+      // .println("Returning '" + separator + "' separated List:\n");
+      // System.err.println(v);
+      // }
+      return v.toString();
+    }
+    // if (debug)
+    // {
+    // System.err.println(
+    // "Returning empty '" + separator + "' separated List\n");
+    // }
+    return "" + separator;
+  }
+
+  public String arrayToSeparatorList(String[] array)
+  {
+    return arrayToSeparatorList(array, separator);
+  }
+
+  public String getSelectedSequencesFrom(AlignFrame alf, String sep)
+  {
+    StringBuffer result = new StringBuffer("");
+    if (sep == null || sep.length() == 0)
+    {
+      sep = separator; // "+0x00AC;
+    }
+    AlignViewport v = alf.getViewport();
+    if (v.getSelectionGroup() != null)
+    {
+      SequenceI[] seqs = v.getSelectionGroup()
+              .getSequencesInOrder(v.getAlignment());
+
+      for (int i = 0; i < seqs.length; i++)
+      {
+        result.append(seqs[i].getName());
+        result.append(sep);
+      }
+    }
+
+    return result.toString();
+  }
+
+  public void setFeatureGroupStateOn(final AlignFrame alf,
+          final String groups, boolean state)
+  {
+    java.awt.EventQueue.invokeLater(new Runnable()
+    {
+      @Override
+      public void run()
+      {
+        alf.setFeatureGroupState(
+                separatorListToArray(groups, separator), state);
+      }
+    });
+  }
+
+  public String getFeatureGroupsOfStateOn(AlignFrame alf, boolean visible)
+  {
+    return arrayToSeparatorList(
+            alf.getFeatureGroupsOfState(visible));
+  }
+
+  public void scrollViewToIn(final AlignFrame alf, final String topRow,
+          final String leftHandColumn)
+  {
+    // TODO test
+    java.awt.EventQueue.invokeLater(new Runnable()
+    {
+      @Override
+      public void run()
+      {
+        try
+        {
+          alf.scrollTo(Integer.valueOf(topRow).intValue(),
+                  Integer.valueOf(leftHandColumn).intValue());
+
+        } catch (Exception ex)
+        {
+          System.err.println("Couldn't parse integer arguments (topRow='"
+                  + topRow + "' and leftHandColumn='" + leftHandColumn
+                  + "')");
+          ex.printStackTrace();
+        }
+      }
+    });
+  }
+
+  public void scrollViewToRowIn(final AlignFrame alf, final String topRow)
+  {
+    // TODO test
+
+    java.awt.EventQueue.invokeLater(new Runnable()
+    {
+      @Override
+      public void run()
+      {
+        try
+        {
+          alf.scrollToRow(Integer.valueOf(topRow).intValue());
+
+        } catch (Exception ex)
+        {
+          System.err.println("Couldn't parse integer arguments (topRow='"
+                  + topRow + "')");
+          ex.printStackTrace();
+        }
+
+      }
+    });
+  }
+
+  public void scrollViewToColumnIn(final AlignFrame alf,
+          final String leftHandColumn)
+  {
+    // TODO test
+    java.awt.EventQueue.invokeLater(new Runnable()
+    {
+
+      @Override
+      public void run()
+      {
+        try
+        {
+          alf
+                  .scrollToColumn(Integer.valueOf(leftHandColumn).intValue());
+
+        } catch (Exception ex)
+        {
+          System.err.println(
+                  "Couldn't parse integer arguments (leftHandColumn='"
+                          + leftHandColumn + "')");
+          ex.printStackTrace();
+        }
+      }
+    });
+
+  }
+
+  public boolean addPdbFile(AlignFrame alf, String sequenceId,
+          String pdbEntryString, String pdbFile)
+  {
+    AlignFrame alFrame = alf;
+    SequenceI toaddpdb = alFrame.getViewport().getAlignment()
+            .findName(sequenceId);
+    boolean needtoadd = false;
+    if (toaddpdb != null)
+    {
+      Vector<PDBEntry> pdbe = toaddpdb.getAllPDBEntries();
+      PDBEntry pdbentry = null;
+      if (pdbe != null && pdbe.size() > 0)
+      {
+        for (int pe = 0, peSize = pdbe.size(); pe < peSize; pe++)
+        {
+          pdbentry = pdbe.elementAt(pe);
+          if (!pdbentry.getId().equals(pdbEntryString)
+                  && !pdbentry.getFile().equals(pdbFile))
+          {
+            pdbentry = null;
+          }
+          else
+          {
+            continue;
+          }
+        }
+      }
+      if (pdbentry == null)
+      {
+        pdbentry = new PDBEntry();
+        pdbentry.setId(pdbEntryString);
+        pdbentry.setFile(pdbFile);
+        needtoadd = true; // add this new entry to sequence.
+      }
+      // resolve data source
+      // TODO: this code should be a refactored to an io package
+      DataSourceType protocol = AppletFormatAdapter.resolveProtocol(pdbFile,
+              FileFormat.PDB);
+      if (protocol == null)
+      {
+        return false;
+      }
+      if (needtoadd)
+      {
+        pdbentry.setProperty("protocol", protocol);
+        toaddpdb.addPDBId(pdbentry);
+        alFrame.alignPanel.getStructureSelectionManager()
+                .registerPDBEntry(pdbentry);
+      }
+    }
+    return true;
+  }
+
+  public AlignFrame loadAlignment(String text, int width, int height,
+          String title)
+  {
+    AlignmentI al = null;
+
+    try
+    {
+      FileFormatI format = new IdentifyFile().identify(text,
+              DataSourceType.PASTE);
+      al = new AppletFormatAdapter().readFile(text, DataSourceType.PASTE,
+              format);
+      if (al.getHeight() > 0)
+      {
+        return new AlignFrame(al, width, height, title);
+      }
+    } catch (IOException ex)
+    {
+      ex.printStackTrace();
+    }
+    return null;
+  }
+
+  public String getFeatureGroupsOn(AlignFrame alf)
+  {
+    return arrayToSeparatorList(
+            alf.getFeatureGroups());
+  }
+
+  public void highlightIn(final AlignFrame alf, final String sequenceId,
+          final String position, final String alignedPosition)
+  {
+    // TODO: could try to highlight in all alignments if alf==null
+    jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
+            alf.getViewport().getAlignment()
+                    .getSequencesArray());
+    final SequenceI sq = matcher.findIdMatch(sequenceId);
+    if (sq != null)
+    {
+      int apos = -1;
+      try
+      {
+        apos = Integer.valueOf(position).intValue();
+        apos--;
+      } catch (NumberFormatException ex)
+      {
+        return;
+      }
+      final int pos = apos;
+      // use vamsas listener to broadcast to all listeners in scope
+      if (alignedPosition != null && (alignedPosition.trim().length() == 0
+              || alignedPosition.toLowerCase().indexOf("false") > -1))
+      {
+        java.awt.EventQueue.invokeLater(new Runnable()
+        {
+          @Override
+          public void run()
+          {
+            StructureSelectionManager
+                    .getStructureSelectionManager(Desktop.getInstance())
+                    .mouseOverVamsasSequence(sq, sq.findIndex(pos), null);
+          }
+        });
+      }
+      else
+      {
+        java.awt.EventQueue.invokeLater(new Runnable()
+        {
+          @Override
+          public void run()
+          {
+            StructureSelectionManager
+                    .getStructureSelectionManager(Desktop.getInstance())
+                    .mouseOverVamsasSequence(sq, pos, null);
+          }
+        });
+      }
+    }
+  }
+
+  public void selectIn(final AlignFrame alf, String sequenceIds,
+          String columns, String sep)
+  {
+    if (sep == null || sep.length() == 0)
+    {
+      sep = separator;
+    }
+    else
+    {
+      if (debug)
+      {
+        System.err.println("Selecting region using separator string '"
+                + separator + "'");
+      }
+    }
+    // deparse fields
+    String[] ids = JalviewAppLoader.separatorListToArray(sequenceIds, sep);
+    String[] cols = JalviewAppLoader.separatorListToArray(columns, sep);
+    final SequenceGroup sel = new SequenceGroup();
+    final ColumnSelection csel = new ColumnSelection();
+    AlignmentI al = alf.getViewport().getAlignment();
+    jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
+            alf.getViewport().getAlignment()
+                    .getSequencesArray());
+    int start = 0, end = al.getWidth(), alw = al.getWidth();
+    boolean seqsfound = true;
+    if (ids != null && ids.length > 0)
+    {
+      seqsfound = false;
+      for (int i = 0; i < ids.length; i++)
+      {
+        if (ids[i].trim().length() == 0)
+        {
+          continue;
+        }
+        SequenceI sq = matcher.findIdMatch(ids[i]);
+        if (sq != null)
+        {
+          seqsfound = true;
+          sel.addSequence(sq, false);
+        }
+      }
+    }
+    boolean inseqpos = false;
+    if (cols != null && cols.length > 0)
+    {
+      boolean seset = false;
+      for (int i = 0; i < cols.length; i++)
+      {
+        String cl = cols[i].trim();
+        if (cl.length() == 0)
+        {
+          continue;
+        }
+        int p;
+        if ((p = cl.indexOf("-")) > -1)
+        {
+          int from = -1, to = -1;
+          try
+          {
+            from = Integer.valueOf(cl.substring(0, p)).intValue();
+            from--;
+          } catch (NumberFormatException ex)
+          {
+            System.err.println(
+                    "ERROR: Couldn't parse first integer in range element column selection string '"
+                            + cl + "' - format is 'from-to'");
+            return;
+          }
+          try
+          {
+            to = Integer.valueOf(cl.substring(p + 1)).intValue();
+            to--;
+          } catch (NumberFormatException ex)
+          {
+            System.err.println(
+                    "ERROR: Couldn't parse second integer in range element column selection string '"
+                            + cl + "' - format is 'from-to'");
+            return;
+          }
+          if (from >= 0 && to >= 0)
+          {
+            // valid range
+            if (from < to)
+            {
+              int t = to;
+              to = from;
+              to = t;
+            }
+            if (!seset)
+            {
+              start = from;
+              end = to;
+              seset = true;
+            }
+            else
+            {
+              // comment to prevent range extension
+              if (start > from)
+              {
+                start = from;
+              }
+              if (end < to)
+              {
+                end = to;
+              }
+            }
+            for (int r = from; r <= to; r++)
+            {
+              if (r >= 0 && r < alw)
+              {
+                csel.addElement(r);
+              }
+            }
+            if (debug)
+            {
+              System.err.println("Range '" + cl + "' deparsed as [" + from
+                      + "," + to + "]");
+            }
+          }
+          else
+          {
+            System.err.println("ERROR: Invalid Range '" + cl
+                    + "' deparsed as [" + from + "," + to + "]");
+          }
+        }
+        else
+        {
+          int r = -1;
+          try
+          {
+            r = Integer.valueOf(cl).intValue();
+            r--;
+          } catch (NumberFormatException ex)
+          {
+            if (cl.toLowerCase().equals("sequence"))
+            {
+              // we are in the dataset sequence's coordinate frame.
+              inseqpos = true;
+            }
+            else
+            {
+              System.err.println(
+                      "ERROR: Couldn't parse integer from point selection element of column selection string '"
+                              + cl + "'");
+              return;
+            }
+          }
+          if (r >= 0 && r <= alw)
+          {
+            if (!seset)
+            {
+              start = r;
+              end = r;
+              seset = true;
+            }
+            else
+            {
+              // comment to prevent range extension
+              if (start > r)
+              {
+                start = r;
+              }
+              if (end < r)
+              {
+                end = r;
+              }
+            }
+            csel.addElement(r);
+            if (debug)
+            {
+              System.err.println("Point selection '" + cl
+                      + "' deparsed as [" + r + "]");
+            }
+          }
+          else
+          {
+            System.err.println("ERROR: Invalid Point selection '" + cl
+                    + "' deparsed as [" + r + "]");
+          }
+        }
+      }
+    }
+    if (seqsfound)
+    {
+      // we only propagate the selection when it was the null selection, or the
+      // given sequences were found in the alignment.
+      if (inseqpos && sel.getSize() > 0)
+      {
+        // assume first sequence provides reference frame ?
+        SequenceI rs = sel.getSequenceAt(0);
+        start = rs.findIndex(start);
+        end = rs.findIndex(end);
+        List<Integer> cs = new ArrayList<>(csel.getSelected());
+        csel.clear();
+        for (Integer selectedCol : cs)
+        {
+          csel.addElement(rs.findIndex(selectedCol));
+        }
+      }
+      sel.setStartRes(start);
+      sel.setEndRes(end);
+      EventQueue.invokeLater(new Runnable()
+      {
+        @Override
+        public void run()
+        {
+          alf.select(sel, csel, alf
+                  .getCurrentView().getAlignment().getHiddenColumns());
+        }
+      });
+    }
+  }
+
+  public String getAlignmentOrderFrom(AlignFrame alf, String sep)
+  {
+    AlignmentI alorder = alf.getViewport().getAlignment();
+    String[] order = new String[alorder.getHeight()];
+    for (int i = 0; i < order.length; i++)
+    {
+      order[i] = alorder.getSequenceAt(i).getName();
+    }
+    return arrayToSeparatorList(order, sep);
+  }
+
+  public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
+          String format, String suffix)
+  {
+    try
+    {
+      AlignViewport vp = alf.getViewport();
+      FileFormatI theFormat = FileFormats.getInstance().forName(format);
+      boolean seqlimits = (suffix == null
+              || suffix.equalsIgnoreCase("true"));
+      if (vp.getSelectionGroup() != null)
+      {
+        // JBPNote: getSelectionAsNewSequence behaviour has changed - this
+        // method now returns a full copy of sequence data
+        // TODO consider using getSequenceSelection instead here
+        String reply = new AppletFormatAdapter().formatSequences(theFormat,
+                new Alignment(vp.getSelectionAsNewSequence()),
+                seqlimits);
+        return reply;
+      }
+    } catch (IllegalArgumentException ex)
+    {
+      ex.printStackTrace();
+      return "Error retrieving alignment, possibly invalid format specifier: "
+              + format;
+    }
+    return "";
+  }
+
+  public String orderAlignmentBy(AlignFrame alf, String order,
+          String undoName, String sep)
+  {
+    if (sep == null || sep.length() == 0)
+    {
+      sep = separator;
+    }
+    String[] ids = JalviewAppLoader.separatorListToArray(order, sep);
+    SequenceI[] sqs = null;
+    if (ids != null && ids.length > 0)
+    {
+      jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
+              alf.getViewport().getAlignment()
+                      .getSequencesArray());
+      int s = 0;
+      sqs = new SequenceI[ids.length];
+      for (int i = 0; i < ids.length; i++)
+      {
+        if (ids[i].trim().length() == 0)
+        {
+          continue;
+        }
+        SequenceI sq = matcher.findIdMatch(ids[i]);
+        if (sq != null)
+        {
+          sqs[s++] = sq;
+        }
+      }
+      if (s > 0)
+      {
+        SequenceI[] sqq = new SequenceI[s];
+        System.arraycopy(sqs, 0, sqq, 0, s);
+        sqs = sqq;
+      }
+      else
+      {
+        sqs = null;
+      }
+    }
+    if (sqs == null)
+    {
+      return "";
+    }
+    ;
+    final AlignmentOrder aorder = new AlignmentOrder(sqs);
+
+    if (undoName != null && undoName.trim().length() == 0)
+    {
+      undoName = null;
+    }
+    final String _undoName = undoName;
+    // TODO: deal with synchronization here: cannot raise any events until after
+    // this has returned.
+    return alf.sortBy(aorder, _undoName) ? "true" : "";
+  }
+
+  public String getAlignmentFrom(AlignFrame alf, String format,
+          String suffix)
+  {
+    try
+    {
+      boolean seqlimits = (suffix == null
+              || suffix.equalsIgnoreCase("true"));
+
+      FileFormatI theFormat = FileFormats.getInstance().forName(format);
+      String reply = new AppletFormatAdapter().formatSequences(theFormat,
+              alf.getViewport().getAlignment(), seqlimits);
+      return reply;
+    } catch (IllegalArgumentException ex)
+    {
+      ex.printStackTrace();
+      return "Error retrieving alignment, possibly invalid format specifier: "
+              + format;
+    }
+  }
+
+  public void loadAnnotationFrom(AlignFrame alf, String annotation)
+  {
+    if (new AnnotationFile().annotateAlignmentView(
+            alf.getViewport(), annotation,
+            DataSourceType.PASTE))
+    {
+      alf.alignPanel.fontChanged();
+      alf.alignPanel.setScrollValues(0, 0);
+    }
+    else
+    {
+      alf.parseFeaturesFile(annotation,
+              DataSourceType.PASTE);
+    }
+  }
+
+  public boolean loadFeaturesFrom(AlignFrame alf, String features,
+          boolean autoenabledisplay)
+  {
+    boolean ret = alf.parseFeaturesFile(features,
+            DataSourceType.PASTE);
+    if (!ret)
+    {
+      return false;
+    }
+    if (autoenabledisplay)
+    {
+      alf.getViewport().setShowSequenceFeatures(true);
+      // this next was for a checkbox in JalviewLite
+      // ((AlignFrame) alf).getViewport().sequenceFeatures.setState(true);
+    }
+    return true;
+  }
+
+  /**
+   * JavaScript interface to print the alignment frame
+   * 
+   * @param alf
+   * @param format
+   *          "jalview" or "gff" with or without ";includeComplement" or
+   *          ";includeNonpositional"; default with no ";" is
+   *          ";includeNonpositional"
+   * @return
+   */
+  public String getFeaturesFrom(AlignFrame alf, String format)
+  {
+    AlignFrame f = (alf);
+
+    String features;
+    FeaturesFile formatter = new FeaturesFile();
+    format = format.toLowerCase();
+    if (format.indexOf(";") < 0)
+      format += ";includenonpositional";
+    boolean nonpos = format.indexOf(";includenonpositional") > 0;
+    boolean compl = format.indexOf(";includecomplement") >= 0;
+    if (format.startsWith("jalview"))
+    {
+      features = formatter.printJalviewFormat(
+              f.getViewport().getAlignment().getSequencesArray(),
+              f.alignPanel.getFeatureRenderer(), nonpos, compl);
+    }
+    else
+    {
+      features = formatter.printGffFormat(
+              f.getViewport().getAlignment().getSequencesArray(),
+              f.alignPanel.getFeatureRenderer(), nonpos, compl);
+    }
+
+    if (features == null)
+    {
+      features = "";
+    }
+    return features;
+
+  }
+
+  public String getAnnotationFrom(AlignFrame alf)
+  {
+    AlignFrame f = alf;
+    String annotation = new AnnotationFile()
+            .printAnnotationsForView(f.getViewport());
+    return annotation;
+  }
+
+  // public AlignFrame newViewFrom(AlignFrame alf, String name)
+  // {
+  // return (AlignFrame) alf.newView(name, true);
+  // }
+  //
+  public String[] separatorListToArray(String list)
+  {
+    return separatorListToArray(list, separator);
+  }
+
+  public Object[] getSelectionForListener(AlignFrame currentFrame,
+          SequenceGroup seqsel, ColumnSelection colsel,
+          HiddenColumns hidden, SelectionSource source, Object alignFrame)
+  {
+    // System.err.println("Testing selection event relay to
+    // jsfunction:"+_listener);
+    String setid = "";
+    AlignFrame src = (AlignFrame) alignFrame;
+    if (source != null)
+    {
+      if (source instanceof AlignViewport
+              && currentFrame.getViewport() == source)
+      {
+        // should be valid if it just generated an event!
+        src = currentFrame;
+
+      }
+    }
+    String[] seqs = new String[] {};
+    String[] cols = new String[] {};
+    int strt = 0, end = (src == null) ? -1
+            : src.alignPanel.av.getAlignment().getWidth();
+    if (seqsel != null && seqsel.getSize() > 0)
+    {
+      seqs = new String[seqsel.getSize()];
+      for (int i = 0; i < seqs.length; i++)
+      {
+        seqs[i] = seqsel.getSequenceAt(i).getName();
+      }
+      if (strt < seqsel.getStartRes())
+      {
+        strt = seqsel.getStartRes();
+      }
+      if (end == -1 || end > seqsel.getEndRes())
+      {
+        end = seqsel.getEndRes();
+      }
+    }
+    if (colsel != null && !colsel.isEmpty())
+    {
+      if (end == -1)
+      {
+        end = colsel.getMax() + 1;
+      }
+      cols = new String[colsel.getSelected().size()];
+      for (int i = 0; i < cols.length; i++)
+      {
+        cols[i] = "" + (1 + colsel.getSelected().get(i).intValue());
+      }
+    }
+    else
+    {
+      if (seqsel != null && seqsel.getSize() > 0)
+      {
+        // send a valid range, otherwise we send the empty selection
+        cols = new String[2];
+        cols[0] = "" + (1 + strt) + "-" + (1 + end);
+      }
+    }
+    return new Object[] { src, setid, arrayToSeparatorList(seqs),
+        arrayToSeparatorList(cols) };
+  }
+
+}
\ No newline at end of file
index ec00647..ba2c1d3 100644 (file)
@@ -23,6 +23,7 @@ package jalview.gui;
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Component;
+import java.awt.Dimension;
 import java.awt.Rectangle;
 import java.awt.Toolkit;
 import java.awt.datatransfer.Clipboard;
@@ -3368,12 +3369,38 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
 
     JInternalFrame frame = new JInternalFrame();
-    final OverviewPanel overview = new OverviewPanel(alignPanel);
+    
+    
+
+    // BH 2019.07.26 we allow for an embedded
+    // undecorated overview with defined size
+    frame.setName(Jalview.getAppID("overview"));
+    //
+    Dimension dim = Platform.getDimIfEmbedded(frame, -1, -1);
+    if (dim != null && dim.width == 0)
+    {
+      dim = null; // hidden, not embedded
+    }
+    OverviewPanel overview = new OverviewPanel(alignPanel, dim);
+
     frame.setContentPane(overview);
+    if (dim == null)
+    {
+      dim = new Dimension();
+      // was frame.getSize(), but that is 0,0 at this point;
+    }
+    else
+    {
+      // we are imbedding, and so we have an undecorated frame
+      // and we can set the the frame dimensions accordingly.
+    }
+    // allowing for unresizable option using, style="resize:none"
+    boolean resizable = (Platform.getEmbeddedAttribute(frame,
+            "resize") != "none");
     Desktop.addInternalFrame(frame, MessageManager
             .formatMessage("label.overview_params", new Object[]
-            { this.getTitle() }), true, frame.getWidth(), frame.getHeight(),
-            true, true);
+            { this.getTitle() }), true, dim.width, dim.height, resizable,
+            true);
     frame.pack();
     frame.setLayer(JLayeredPane.PALETTE_LAYER);
     frame.addInternalFrameListener(
@@ -3732,7 +3759,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
     frameTitle += this.title;
 
-    Desktop.addInternalFrame(tp, frameTitle, 600, 500);
+    Dimension dim = Platform.getDimIfEmbedded(tp, 600, 500);
+    Desktop.addInternalFrame(tp, frameTitle, dim.width, dim.height);
   }
 
   /**
@@ -4084,15 +4112,24 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
       if (nf.getTree() != null)
       {
         tp = new TreePanel(alignPanel, nf, treeTitle, input);
-
-        tp.setSize(w, h);
+        Dimension dim = Platform.getDimIfEmbedded(tp, -1, -1);
+        if (dim == null)
+        {
+          dim = new Dimension(w, h);
+        }
+        else
+        {
+          // no offset, either
+          x = 0;
+        }
+        tp.setSize(dim.width, dim.height);
 
         if (x > 0 && y > 0)
         {
           tp.setLocation(x, y);
         }
 
-        Desktop.addInternalFrame(tp, treeTitle, w, h);
+        Desktop.addInternalFrame(tp, treeTitle, dim.width, dim.height);
       }
     } catch (Exception ex)
     {
index eaf99be..1b85dd5 100644 (file)
@@ -209,7 +209,7 @@ public class Desktop extends jalview.jbgui.GDesktop
    * 
    * @return
    */
-  public static Object getInstance()
+  public static Desktop getInstance()
   {
     return instance;
   }
@@ -881,8 +881,8 @@ public class Desktop extends jalview.jbgui.GDesktop
     frame.setMaximizable(resizable);
     frame.setIconifiable(resizable);
     frame.setOpaque(Platform.isJS());
-
-    if (frame.getX() < 1 && frame.getY() < 1)
+    boolean isEmbedded = (Platform.getDimIfEmbedded(frame, -1, -1) != null);
+    if (!isEmbedded && frame.getX() < 1 && frame.getY() < 1)
     {
       frame.setLocation(xOffset * openFrameCount,
               yOffset * ((openFrameCount - 1) % 10) + yOffset);
index a5aaf7c..cf15aa1 100755 (executable)
@@ -73,34 +73,41 @@ public class OverviewPanel extends JPanel
 
   protected boolean draggingBox = false;
 
+  private Dimension dim;
+  
+  private boolean showProgress = !Platform.isJS();
+
   protected ProgressPanel progressPanel;
 
+  
   /**
-   * Creates a new OverviewPanel object.
-   * 
-   * @param alPanel
-   *          The alignment panel which is shown in the overview panel
+   * Creates the appropriate type of OverviewDimensions, with the desired size
    */
-  public OverviewPanel(AlignmentPanel alPanel)
+  private void createOverviewDimensions()
   {
-    this.av = alPanel.av;
-    this.ap = alPanel;
-
-    showHidden = Cache.getDefault(Preferences.SHOW_OV_HIDDEN_AT_START,
-            false);
+    boolean showAnnotation = (av.isShowAnnotation()
+            && av.getAlignmentConservationAnnotation() != null);
     if (showHidden)
     {
-      od = new OverviewDimensionsShowHidden(av.getRanges(),
-            (av.isShowAnnotation()
-                    && av.getAlignmentConservationAnnotation() != null));
+      od = new OverviewDimensionsShowHidden(av.getRanges(), showAnnotation,
+              dim);
     }
     else
     {
-      od = new OverviewDimensionsHideHidden(av.getRanges(),
-              (av.isShowAnnotation()
-                      && av.getAlignmentConservationAnnotation() != null));
+      od = new OverviewDimensionsHideHidden(av.getRanges(), showAnnotation,
+              dim);
     }
+  }
 
+  public OverviewPanel(AlignmentPanel alPanel, Dimension dim)
+  {
+    this.av = alPanel.av;
+    this.ap = alPanel;
+    this.dim = dim;
+
+    showHidden = Cache.getDefault(Preferences.SHOW_OV_HIDDEN_AT_START,
+            false);
+    createOverviewDimensions();
     setLayout(new BorderLayout());
     progressPanel = new ProgressPanel(OverviewRenderer.UPDATE,
             MessageManager.getString("label.oview_calc"), getWidth());
@@ -285,20 +292,8 @@ public class OverviewPanel extends JPanel
    */
   protected void toggleHiddenColumns()
   {
-    if (showHidden)
-    {
-      showHidden = false;
-      od = new OverviewDimensionsHideHidden(av.getRanges(),
-              (av.isShowAnnotation()
-                      && av.getAlignmentConservationAnnotation() != null));
-    }
-    else
-    {
-      showHidden = true;
-      od = new OverviewDimensionsShowHidden(av.getRanges(),
-              (av.isShowAnnotation()
-                      && av.getAlignmentConservationAnnotation() != null));
-    }
+    showHidden = !showHidden;
+    createOverviewDimensions();
     oviewCanvas.resetOviewDims(od);
     updateOverviewImage();
     setBoxPosition();
index 96a8b0d..5eca00f 100644 (file)
@@ -36,6 +36,7 @@ import jalview.jbgui.GPCAPanel;
 import jalview.math.RotatableMatrix.Axis;
 import jalview.util.ImageMaker;
 import jalview.util.MessageManager;
+import jalview.util.Platform;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.viewmodel.PCAModel;
 
@@ -200,10 +201,7 @@ public class PCAPanel extends GPCAPanel
     repaint();
     if (getParent() == null)
     {
-      Desktop.addInternalFrame(this,
-              MessageManager.formatMessage("label.calc_title", "PCA",
-                      getPcaModel().getScoreModelName()),
-              475, 450);
+      addToDesktop(this, getPcaModel().getScoreModelName());
       this.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
     }
     working = false;
@@ -762,4 +760,12 @@ public class PCAPanel extends GPCAPanel
     getRotatableCanvas().ap = panel;
     PaintRefresher.Register(PCAPanel.this, panel.av.getSequenceSetId());
   }
+
+  public static void addToDesktop(PCAPanel panel, String modelName)
+  {
+    Dimension dim = Platform.getDimIfEmbedded(panel, 475, 450);
+    Desktop.addInternalFrame(panel, MessageManager.formatMessage(
+            "label.calc_title", "PCA", modelName), dim.width,
+            dim.height);
+  }
 }
index 3aa433e..ac55911 100755 (executable)
@@ -20,6 +20,7 @@
  */
 package jalview.io;
 
+import java.awt.Dimension;
 import java.io.File;
 import java.io.IOException;
 import java.util.StringTokenizer;
@@ -46,6 +47,7 @@ import jalview.project.Jalview2XML;
 import jalview.schemes.ColourSchemeI;
 import jalview.structure.StructureSelectionManager;
 import jalview.util.MessageManager;
+import jalview.util.Platform;
 import jalview.ws.utils.UrlDownloadClient;
 
 public class FileLoader implements Runnable
@@ -480,8 +482,12 @@ public class FileLoader implements Runnable
               // status in Jalview 3
               // TODO: define 'virtual desktop' for benefit of headless scripts
               // that perform queries to find the 'current working alignment'
-              Desktop.addInternalFrame(alignFrame, title,
+              
+              Dimension dim = Platform.getDimIfEmbedded(alignFrame,
                       AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
+              alignFrame.setSize(dim);
+              Desktop.addInternalFrame(alignFrame, title, dim.width,
+                      dim.height);
             }
 
             try
index 6685c67..1eb0fb9 100755 (executable)
@@ -25,6 +25,7 @@ import jalview.analysis.GeneticCodeI;
 import jalview.analysis.GeneticCodes;
 import jalview.api.SplitContainerI;
 import jalview.bin.Cache;
+import jalview.bin.Jalview;
 import jalview.gui.JvSwingUtils;
 import jalview.gui.Preferences;
 import jalview.io.FileFormats;
@@ -220,7 +221,8 @@ public class GAlignFrame extends JInternalFrame
     {
 
       // for Web-page embedding using id=align-frame-div
-      setName("jalview-alignment");
+      setName(Jalview.getAppID("alignment"));
+
 
       jbInit();
       setJMenuBar(alignFrameMenuBar);
index e4a5905..6793663 100755 (executable)
@@ -21,6 +21,7 @@
 package jalview.jbgui;
 
 import jalview.api.AlignmentViewPanel;
+import jalview.bin.Jalview;
 import jalview.io.FileFormatException;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
@@ -139,7 +140,8 @@ public class GDesktop extends JFrame
    */
   private void jbInit() throws Exception
   {
-    setName("jalview-desktop");
+
+    setName(Jalview.getAppID("desktop"));
     FileMenu.setText(MessageManager.getString("action.file"));
     HelpMenu.setText(MessageManager.getString("action.help"));
     inputLocalFileMenuItem
index a6498d2..74b5afd 100755 (executable)
@@ -20,6 +20,7 @@
  */
 package jalview.jbgui;
 
+import jalview.bin.Jalview;
 import jalview.util.ImageMaker.TYPE;
 import jalview.util.MessageManager;
 
@@ -88,7 +89,7 @@ public class GPCAPanel extends JInternalFrame
 
   private void jbInit() throws Exception
   {
-    setName("jalview-pca");
+    setName(Jalview.getAppID("pca"));
     this.getContentPane().setLayout(new BorderLayout());
     JPanel jPanel2 = new JPanel();
     jPanel2.setLayout(new FlowLayout());
index dfee3e2..e16d63a 100644 (file)
@@ -21,6 +21,7 @@
 package jalview.jbgui;
 
 import jalview.api.structures.JalviewStructureDisplayI;
+import jalview.bin.Jalview;
 import jalview.gui.ColourMenuHelper.ColourChangeListener;
 import jalview.util.ImageMaker.TYPE;
 import jalview.util.MessageManager;
@@ -89,7 +90,7 @@ public abstract class GStructureViewer extends JInternalFrame
   private void jbInit() throws Exception
   {
 
-    setName("jalview-structureviewer");
+    setName(Jalview.getAppID("structureviewer"));
 
     JMenuBar menuBar = new JMenuBar();
     this.setJMenuBar(menuBar);
index d184e76..0f9c2a2 100755 (executable)
@@ -20,6 +20,7 @@
  */
 package jalview.jbgui;
 
+import jalview.bin.Jalview;
 import jalview.util.ImageMaker.TYPE;
 import jalview.util.MessageManager;
 
@@ -92,7 +93,7 @@ public class GTreePanel extends JInternalFrame
 
   private void jbInit() throws Exception
   {
-    setName("jalview-tree");
+    setName(Jalview.getAppID("tree"));
     this.getContentPane().setLayout(borderLayout1);
     this.setBackground(Color.white);
     this.setFont(new java.awt.Font("Verdana", 0, 12));
index 6340e64..751b297 100644 (file)
@@ -151,6 +151,7 @@ import jalview.xml.binding.jalview.ThresholdType;
 import jalview.xml.binding.jalview.VAMSAS;
 
 import java.awt.Color;
+import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.Rectangle;
 import java.io.BufferedReader;
@@ -5215,8 +5216,9 @@ public class Jalview2XML
     String complementaryViewId = view.getComplementId();
     if (complementaryViewId == null)
     {
-      Desktop.addInternalFrame(af, view.getTitle(),
+      Dimension dim = Platform.getDimIfEmbedded(af,
               safeInt(view.getWidth()), safeInt(view.getHeight()));
+      Desktop.addInternalFrame(af, view.getTitle(), dim.width, dim.height);
       // recompute any autoannotation
       af.alignPanel.updateAnnotation(false, true);
       reorderAutoannotation(af, al, autoAlan);
@@ -6349,9 +6351,7 @@ public class Jalview2XML
           panel.getRotatableCanvas().getAxisEndPoints()[i] = new Point(
                   axis.getXPos(), axis.getYPos(), axis.getZPos());
         }
-
-        Desktop.addInternalFrame(panel, MessageManager.formatMessage(
-                "label.calc_title", "PCA", modelName), 475, 450);
+        PCAPanel.addToDesktop(panel, modelName);
       }
     } catch (Exception ex)
     {
index 0235081..c153dc1 100644 (file)
@@ -26,6 +26,7 @@ import jalview.datamodel.AlignmentI;
 import jalview.datamodel.HiddenColumns;
 import jalview.datamodel.HiddenSequences;
 
+import java.awt.Dimension;
 import java.awt.Graphics;
 
 public abstract class OverviewDimensions
@@ -71,15 +72,22 @@ public abstract class OverviewDimensions
    *          true if the annotation panel is to be shown, false otherwise
    */
   public OverviewDimensions(ViewportRanges ranges,
-          boolean showAnnotationPanel)
+          boolean showAnnotationPanel, Dimension dim)
   {
+    if (!showAnnotationPanel)
+    {
+      graphHeight = 0;
+    }
+
     // scale the initial size of overviewpanel to shape of alignment
     float initialScale = (float) ranges.getAbsoluteAlignmentWidth()
             / (float) ranges.getAbsoluteAlignmentHeight();
 
-    if (!showAnnotationPanel)
+    if (dim != null)
     {
-      graphHeight = 0;
+      width = dim.width;
+      sequencesHeight = dim.height;
+      return;
     }
 
     if (ranges.getAbsoluteAlignmentWidth() > ranges
index de90a21..598b989 100644 (file)
@@ -20,6 +20,8 @@
  */
 package jalview.viewmodel;
 
+import java.awt.Dimension;
+
 import jalview.api.AlignmentColsCollectionI;
 import jalview.api.AlignmentRowsCollectionI;
 import jalview.datamodel.AlignmentI;
@@ -38,10 +40,21 @@ public class OverviewDimensionsHideHidden extends OverviewDimensions
   private int ydiff; // when dragging, difference in alignment units between
                      // start sequence and original mouse click position
 
+  /**
+   * for testng only
+   * 
+   * @param vpranges
+   * @param showAnnotationPanel
+   */  
+  @Deprecated
+  public OverviewDimensionsHideHidden(ViewportRanges vpranges, boolean showAnnotationPanel) {
+    this(vpranges, showAnnotationPanel, null);
+  }
+
   public OverviewDimensionsHideHidden(ViewportRanges vpranges,
-          boolean showAnnotationPanel)
+          boolean showAnnotationPanel, Dimension dim)
   {
-    super(vpranges, showAnnotationPanel);
+    super(vpranges, showAnnotationPanel, dim);
     ranges = vpranges;
     resetAlignmentDims();
   }
index 3aa6e1b..a4f21f0 100644 (file)
@@ -20,6 +20,8 @@
  */
 package jalview.viewmodel;
 
+import java.awt.Dimension;
+
 import jalview.api.AlignmentColsCollectionI;
 import jalview.api.AlignmentRowsCollectionI;
 import jalview.datamodel.AlignmentI;
@@ -38,6 +40,18 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions
   private int ydiff; // when dragging, difference in alignment units between
                      // start sequence and original mouse click position
 
+  
+  /**
+   * for testng only
+   * 
+   * @param vpranges
+   * @param showAnnotationPanel
+   */  
+  @Deprecated
+  public OverviewDimensionsShowHidden(ViewportRanges vpranges, boolean showAnnotationPanel) {
+    this(vpranges, showAnnotationPanel, null);
+  }
+
   /**
    * Create an OverviewDimensions object
    * 
@@ -47,9 +61,9 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions
    *          true if the annotation panel is to be shown, false otherwise
    */
   public OverviewDimensionsShowHidden(ViewportRanges vpranges,
-          boolean showAnnotationPanel)
+          boolean showAnnotationPanel, Dimension dim)
   {
-    super(vpranges, showAnnotationPanel);
+    super(vpranges, showAnnotationPanel, dim);
     ranges = vpranges;
     resetAlignmentDims();
   }