3253-omnibus save
[jalview.git] / src / jalview / bin / JalviewAppLoader.java
index 921ccdf..834a30f 100644 (file)
@@ -7,6 +7,7 @@ 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;
@@ -17,6 +18,7 @@ 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;
@@ -24,11 +26,11 @@ 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;
@@ -784,7 +786,7 @@ public class JalviewAppLoader
   public void setFeatureGroupStateOn(final AlignFrameI alf,
           final String groups, boolean state)
   {
-    java.awt.EventQueue.invokeLater(new Runnable()
+    Jalview.execRunnable(new Runnable()
     {
       @Override
       public void run()
@@ -804,7 +806,7 @@ public class JalviewAppLoader
   public void scrollViewToIn(final AlignFrameI alf, final String topRow,
           final String leftHandColumn)
   {
-    java.awt.EventQueue.invokeLater(new Runnable()
+    Jalview.execRunnable(new Runnable()
     {
       @Override
       public void run()
@@ -828,7 +830,7 @@ public class JalviewAppLoader
   public void scrollViewToRowIn(final AlignFrameI alf, final String topRow)
   {
 
-    java.awt.EventQueue.invokeLater(new Runnable()
+    Jalview.execRunnable(new Runnable()
     {
       @Override
       public void run()
@@ -851,7 +853,7 @@ public class JalviewAppLoader
   public void scrollViewToColumnIn(final AlignFrameI alf,
           final String leftHandColumn)
   {
-    java.awt.EventQueue.invokeLater(new Runnable()
+    Jalview.execRunnable(new Runnable()
     {
 
       @Override
@@ -979,7 +981,7 @@ public class JalviewAppLoader
       if (alignedPosition != null && (alignedPosition.trim().length() == 0
               || alignedPosition.toLowerCase().indexOf("false") > -1))
       {
-        java.awt.EventQueue.invokeLater(new Runnable()
+        Jalview.execRunnable(new Runnable()
         {
           @Override
           public void run()
@@ -992,7 +994,7 @@ public class JalviewAppLoader
       }
       else
       {
-        java.awt.EventQueue.invokeLater(new Runnable()
+        Jalview.execRunnable(new Runnable()
         {
           @Override
           public void run()
@@ -1208,7 +1210,7 @@ public class JalviewAppLoader
       }
       sel.setStartRes(start);
       sel.setEndRes(end);
-      EventQueue.invokeLater(new Runnable()
+      Jalview.execRunnable(new Runnable()
       {
         @Override
         public void run()
@@ -1302,7 +1304,6 @@ public class JalviewAppLoader
     {
       return "";
     }
-    ;
     final AlignmentOrder aorder = new AlignmentOrder(sqs);
 
     if (undoName != null && undoName.trim().length() == 0)
@@ -1335,4 +1336,149 @@ public class JalviewAppLoader
     }
   }
 
+  public void loadAnnotationFrom(AlignFrameI alf, String annotation)
+  {
+    if (new AnnotationFile().annotateAlignmentView(
+            ((AlignFrame) alf).getViewport(), annotation,
+            DataSourceType.PASTE))
+    {
+      ((AlignFrame) alf).alignPanel.fontChanged();
+      ((AlignFrame) alf).alignPanel.setScrollValues(0, 0);
+    }
+    else
+    {
+      ((AlignFrame) alf).parseFeaturesFile(annotation,
+              DataSourceType.PASTE);
+    }
+  }
+
+  public boolean loadFeaturesFrom(AlignFrameI alf, String features,
+          boolean autoenabledisplay)
+  {
+    boolean ret = ((AlignFrame) alf).parseFeaturesFile(features,
+            DataSourceType.PASTE);
+    if (!ret)
+    {
+      return false;
+    }
+    if (autoenabledisplay)
+    {
+      ((AlignFrame) alf).getViewport().setShowSequenceFeatures(true);
+      // this next was for a checkbox in JalviewLite
+      // ((AlignFrame) alf).getViewport().sequenceFeatures.setState(true);
+    }
+    return true;
+  }
+
+  public String getFeaturesFrom(AlignFrameI alf, String format,
+          boolean includeNonpositionsFeatures, boolean includeComplement)
+  {
+    AlignFrame f = ((AlignFrame) alf);
+
+    String features;
+    FeaturesFile formatter = new FeaturesFile();
+    if (format.equalsIgnoreCase("Jalview"))
+    {
+      features = formatter.printJalviewFormat(
+              f.getViewport().getAlignment().getSequencesArray(),
+              f.alignPanel.getFeatureRenderer(),
+              includeNonpositionsFeatures, includeComplement);
+    }
+    else
+    {
+      features = formatter.printGffFormat(
+              f.getViewport().getAlignment().getSequencesArray(),
+              f.alignPanel.getFeatureRenderer(),
+              includeNonpositionsFeatures, includeComplement);
+    }
+
+    if (features == null)
+    {
+      features = "";
+    }
+    return features;
+
+  }
+
+  public String getAnnotationFrom(AlignFrameI alf)
+  {
+    AlignFrame f = (AlignFrame) alf;
+    String annotation = new AnnotationFile()
+            .printAnnotationsForView(f.getViewport());
+    return annotation;
+  }
+
+  public AlignFrameI newViewFrom(AlignFrameI alf, String name)
+  {
+    return (AlignFrameI) ((AlignFrame) alf).newView(name, true);
+  }
+
+  public String[] separatorListToArray(String list)
+  {
+    return separatorListToArray(list, separator);
+  }
+
+  public Object[] getSelectionForListener(AlignFrameI 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
+              && ((AlignFrame) currentFrame).getViewport() == source)
+      {
+        // should be valid if it just generated an event!
+        src = (AlignFrame) 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