JAL-1695 parameter controls whether SplitFrame is enabled
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 13 Apr 2015 14:56:31 +0000 (15:56 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 13 Apr 2015 14:56:31 +0000 (15:56 +0100)
src/jalview/appletgui/CutAndPasteTransfer.java
src/jalview/bin/JalviewLite.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/AlignViewport.java

index 036bbe3..d33e0cc 100644 (file)
@@ -230,7 +230,13 @@ public class CutAndPasteTransfer extends Panel implements ActionListener,
     if (al != null)
     {
       al.setDataset(null); // set dataset on alignment/sequences
-      if (openSplitFrame(al, format))
+
+      /*
+       * SplitFrame option dependent on applet parameter for now.
+       */
+      boolean allowSplitFrame = alignFrame.viewport.applet
+              .getDefaultParameter("enableSplitFrame", false);
+      if (allowSplitFrame && openSplitFrame(al, format))
       {
         return;
       }
index c0a8d73..cb9d893 100644 (file)
  */
 package jalview.bin;
 
+import java.applet.Applet;
+import java.awt.Button;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.EventQueue;
+import java.awt.Font;
+import java.awt.Frame;
+import java.awt.Graphics;
+import java.awt.event.ActionEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+import netscape.javascript.JSException;
+import netscape.javascript.JSObject;
+
 import jalview.api.StructureSelectionManagerProvider;
 import jalview.appletgui.AlignFrame;
 import jalview.appletgui.AlignViewport;
@@ -48,30 +72,6 @@ import jalview.structure.SelectionListener;
 import jalview.structure.StructureSelectionManager;
 import jalview.util.MessageManager;
 
-import java.applet.Applet;
-import java.awt.Button;
-import java.awt.Color;
-import java.awt.Component;
-import java.awt.EventQueue;
-import java.awt.Font;
-import java.awt.Frame;
-import java.awt.Graphics;
-import java.awt.event.ActionEvent;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.URL;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.StringTokenizer;
-import java.util.Vector;
-
-import netscape.javascript.JSException;
-import netscape.javascript.JSObject;
-
 /**
  * Jalview Applet. Runs in Java 1.18 runtime
  * 
@@ -1459,7 +1459,10 @@ public class JalviewLite extends Applet implements
         file = data.toString();
       }
     }
-    file2 = getParameter("file2");
+    if ("true".equalsIgnoreCase(getParameter("enableSplitFrame")))
+    {
+      file2 = getParameter("file2");
+    }
 
     embedded = TRUE.equalsIgnoreCase(getParameter("embedded"));
     if (embedded)
index bb8eec3..fcf4301 100644 (file)
@@ -140,6 +140,7 @@ import jalview.schemes.TaylorColourScheme;
 import jalview.schemes.TurnColourScheme;
 import jalview.schemes.UserColourScheme;
 import jalview.schemes.ZappoColourScheme;
+import jalview.structure.StructureSelectionManager;
 import jalview.util.MessageManager;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.ws.jws1.Discoverer;
@@ -4781,8 +4782,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               sprods[s].updatePDBIds();
             }
             Alignment al = new Alignment(sprods);
-            Set<AlignedCodonFrame> cf = prods.getCodonFrames();
             al.setDataset(ds);
+
+            /*
+             * Copy dna-to-protein mappings to new alignment
+             */
+            // TODO 1: no mappings are set up for EMBL product
+            // TODO 2: if they were, should add them to protein alignment, not
+            // dna
+            Set<AlignedCodonFrame> cf = prods.getCodonFrames();
             for (AlignedCodonFrame acf : cf)
             {
               al.addCodonFrame(acf);
@@ -4794,12 +4802,33 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
                     + getTitle();
             naf.setTitle(newtitle);
 
-            // remove this flag once confirmed we want a split view
-            boolean asSplitFrame = true;
+            // temporary flag until SplitFrame is released
+            boolean asSplitFrame = Cache.getDefault(
+                    Preferences.ENABLE_SPLIT_FRAME, false);
             if (asSplitFrame)
             {
-              final Alignment copyAlignment = new Alignment(new Alignment(
-                      AlignFrame.this.viewport.getSequenceSelection()));
+              /*
+               * Make a copy of this alignment (sharing the same dataset
+               * sequences). If we are DNA, drop introns and update mappings
+               */
+              AlignmentI copyAlignment = null;
+              final SequenceI[] sequenceSelection = AlignFrame.this.viewport
+                      .getSequenceSelection();
+              if (dna)
+              {
+                copyAlignment = AlignmentUtils.makeExonAlignment(
+                        sequenceSelection, cf);
+                al.getCodonFrames().clear();
+                al.getCodonFrames().addAll(cf);
+                final StructureSelectionManager ssm = StructureSelectionManager
+                        .getStructureSelectionManager(Desktop.instance);
+                ssm.addMappings(cf);
+              }
+              else
+              {
+                copyAlignment = new Alignment(new Alignment(
+                        sequenceSelection));
+              }
               AlignFrame copyThis = new AlignFrame(copyAlignment,
                       AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
               copyThis.setTitle(AlignFrame.this.getTitle());
@@ -4907,9 +4936,17 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               "label.translation_of_params", new Object[]
               { this.getTitle() });
       af.setTitle(newTitle);
-      final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
-      viewport.openSplitFrame(af, new Alignment(seqs), al.getCodonFrames());
-      // Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH, DEFAULT_HEIGHT);
+      if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, false))
+      {
+        final SequenceI[] seqs = viewport.getSelectionAsNewSequence();
+        viewport.openSplitFrame(af, new Alignment(seqs),
+                al.getCodonFrames());
+      }
+      else
+      {
+        Desktop.addInternalFrame(af, newTitle, DEFAULT_WIDTH,
+                DEFAULT_HEIGHT);
+      }
     }
   }
 
index 5e477c7..c59d201 100644 (file)
@@ -243,7 +243,7 @@ public class AlignViewport extends AlignmentViewport implements
     showAutocalculatedAbove = Cache.getDefault(
             Preferences.SHOW_AUTOCALC_ABOVE, false);
     viewStyle.setScaleProteinAsCdna(Cache.getDefault(
-            Preferences.SCALE_PROTEIN_TO_CDNA, false));
+            Preferences.SCALE_PROTEIN_TO_CDNA, true));
   }
 
   void init()
@@ -798,16 +798,23 @@ public class AlignViewport extends AlignmentViewport implements
     // TODO: create undo object for this JAL-1101
 
     /*
-     * If one alignment is protein and one nucleotide, with at least one
-     * sequence name in common, offer to open a linked alignment.
+     * If any cDNA/protein mappings can be made between the alignments, offer to
+     * open a linked alignment with split frame option.
      */
-    if (AlignmentUtils.isMappable(al, getAlignment()))
+    if (Cache.getDefault(Preferences.ENABLE_SPLIT_FRAME, false))
     {
-      if (openLinkedAlignment(al, title))
+      if (AlignmentUtils.isMappable(al, getAlignment()))
       {
-        return;
+        if (openLinkedAlignment(al, title))
+        {
+          return;
+        }
       }
     }
+
+    /*
+     * No mappings, or offer declined - add sequences to this alignment
+     */
     // TODO: JAL-407 regardless of above - identical sequences (based on ID and
     // provenance) should share the same dataset sequence
 
@@ -815,19 +822,18 @@ public class AlignViewport extends AlignmentViewport implements
     {
       getAlignment().addSequence(al.getSequenceAt(i));
     }
-    // TODO this call was done by SequenceFetcher but not FileLoader or
-    // CutAndPasteTransfer. Is it needed?
-    // JBPComment: this repositions the view to show the new sequences
-    // JBPComment: so it is needed for UX
+
     setEndSeq(getAlignment().getHeight());
     firePropertyChange("alignment", null, getAlignment().getSequences());
   }
 
   /**
    * Show a dialog with the option to open and link (cDNA <-> protein) as a new
-   * alignment. Returns true if the new alignment was opened, false if not,
-   * because the user declined the offer.
+   * alignment, either as a standalone alignment or in a split frame. Returns
+   * true if the new alignment was opened, false if not, because the user
+   * declined the offer.
    * 
+   * @param al
    * @param title
    */
   protected boolean openLinkedAlignment(AlignmentI al, String title)