Merge branch 'develop' into features/JAL-845splitPaneMergeDevelop
[jalview.git] / src / jalview / appletgui / AlignFrame.java
index aa7aed3..ba90075 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -23,6 +23,7 @@ package jalview.appletgui;
 import jalview.analysis.AlignmentSorter;
 import jalview.api.AlignViewControllerGuiI;
 import jalview.api.AlignViewControllerI;
+import jalview.api.AlignViewportI;
 import jalview.api.FeatureRenderer;
 import jalview.api.SequenceStructureBinding;
 import jalview.bin.JalviewLite;
@@ -64,6 +65,7 @@ import jalview.schemes.TurnColourScheme;
 import jalview.schemes.ZappoColourScheme;
 import jalview.structure.StructureSelectionManager;
 import jalview.structures.models.AAStructureBindingModel;
+import jalview.util.MappingUtils;
 import jalview.util.MessageManager;
 
 import java.awt.BorderLayout;
@@ -92,6 +94,7 @@ import java.io.IOException;
 import java.net.URL;
 import java.net.URLEncoder;
 import java.util.Arrays;
+import java.util.Deque;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
@@ -1216,7 +1219,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     Frame frame = new Frame();
     frame.add(cap);
     jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
-            "label.alignment_output_command", new String[]
+            "label.alignment_output_command", new Object[]
             { e.getActionCommand() }), 600, 500);
     cap.setText(new AppletFormatAdapter().formatSequences(
             e.getActionCommand(), viewport.getAlignment(),
@@ -1315,7 +1318,12 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   {
     StringBuffer url = new StringBuffer(jalviewServletURL);
 
-    url.append("?open="
+    // allow servlet parameters to be passed in applet parameter
+    String firstSep = url.lastIndexOf("?") > url.lastIndexOf("/") ? "&"
+            : "?";
+    url.append(firstSep);
+
+    url.append("open="
             + appendProtocol(viewport.applet.getParameter("file")));
 
     if (viewport.applet.getParameter("features") != null)
@@ -1433,12 +1441,12 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   void updateEditMenuBar()
   {
 
-    if (viewport.historyList.size() > 0)
+    if (viewport.getHistoryList().size() > 0)
     {
       undoMenuItem.setEnabled(true);
-      CommandI command = (CommandI) viewport.historyList.peek();
+      CommandI command = viewport.getHistoryList().peek();
       undoMenuItem.setLabel(MessageManager.formatMessage(
-              "label.undo_command", new String[]
+              "label.undo_command", new Object[]
               { command.getDescription() }));
     }
     else
@@ -1447,13 +1455,13 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       undoMenuItem.setLabel(MessageManager.getString("action.undo"));
     }
 
-    if (viewport.redoList.size() > 0)
+    if (viewport.getRedoList().size() > 0)
     {
       redoMenuItem.setEnabled(true);
 
-      CommandI command = (CommandI) viewport.redoList.peek();
+      CommandI command = viewport.getRedoList().peek();
       redoMenuItem.setLabel(MessageManager.formatMessage(
-              "label.redo_command", new String[]
+              "label.redo_command", new Object[]
               { command.getDescription() }));
     }
     else
@@ -1471,8 +1479,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   {
     if (command.getSize() > 0)
     {
-      viewport.historyList.push(command);
-      viewport.redoList.removeAllElements();
+      viewport.addToHistoryList(command);
+      viewport.clearRedoList();
       updateEditMenuBar();
       viewport.updateHiddenColumns();
     }
@@ -1486,13 +1494,13 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
    */
   protected void undoMenuItem_actionPerformed()
   {
-    if (viewport.historyList.size() < 1)
+    if (viewport.getHistoryList().isEmpty())
     {
       return;
     }
 
-    CommandI command = (CommandI) viewport.historyList.pop();
-    viewport.redoList.push(command);
+    CommandI command = viewport.getHistoryList().pop();
+    viewport.addToRedoList(command);
     command.undoCommand(null);
 
     AlignViewport originalSource = getOriginatingSource(command);
@@ -1518,13 +1526,13 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
    */
   protected void redoMenuItem_actionPerformed()
   {
-    if (viewport.redoList.size() < 1)
+    if (viewport.getRedoList().isEmpty())
     {
       return;
     }
 
-    CommandI command = (CommandI) viewport.redoList.pop();
-    viewport.historyList.push(command);
+    CommandI command = viewport.getRedoList().pop();
+    viewport.addToHistoryList(command);
     command.doCommand(null);
 
     AlignViewport originalSource = getOriginatingSource(command);
@@ -1584,6 +1592,12 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     return originalSource;
   }
 
+  /**
+   * Move the currently selected sequences up or down one position in the
+   * alignment
+   * 
+   * @param up
+   */
   public void moveSelectedSequences(boolean up)
   {
     SequenceGroup sg = viewport.getSelectionGroup();
@@ -1594,6 +1608,21 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     viewport.getAlignment().moveSelectedSequencesByOne(sg,
             up ? null : viewport.getHiddenRepSequences(), up);
     alignPanel.paintAlignment(true);
+
+    /*
+     * Also move cDNA/protein complement sequences
+     */
+    AlignViewportI complement = viewport.getCodingComplement();
+    if (complement != null)
+    {
+      SequenceGroup mappedSelection = MappingUtils.mapSequenceGroup(sg,
+              viewport, complement);
+      complement.getAlignment().moveSelectedSequencesByOne(mappedSelection,
+              up ? null : complement.getHiddenRepSequences(), up);
+      // TODO need to trigger a repaint of the complementary panel - how?
+      // would prefer to handle in SplitFrame but it is not overriding key
+      // listener chiz
+    }
   }
 
   synchronized void slideSequences(boolean right, int size)
@@ -1681,11 +1710,12 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     }
 
     boolean appendHistoryItem = false;
-    if (viewport.historyList != null && viewport.historyList.size() > 0
-            && viewport.historyList.peek() instanceof SlideSequencesCommand)
+    Deque<CommandI> historyList = viewport.getHistoryList();
+    if (historyList != null && historyList.size() > 0
+            && historyList.peek() instanceof SlideSequencesCommand)
     {
       appendHistoryItem = ssc
-              .appendSlideCommand((SlideSequencesCommand) viewport.historyList
+              .appendSlideCommand((SlideSequencesCommand) historyList
                       .peek());
     }
 
@@ -2290,8 +2320,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 
     newaf.setTitle(title.toString());
 
-    newaf.viewport.historyList = viewport.historyList;
-    newaf.viewport.redoList = viewport.redoList;
+    newaf.viewport.setHistoryList(viewport.getHistoryList());
+    newaf.viewport.setRedoList(viewport.getRedoList());
     return newaf;
   }
 
@@ -3592,8 +3622,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     // view cannot be closed if its actually on the page
     fileMenu.remove(closeMenuItem);
     fileMenu.remove(3); // Remove Separator
-    embeddedMenu = makeEmbeddedPopupMenu(alignFrameMenuBar,
-            FONT_ARIAL_PLAIN_11, false, false); // use our own fonts.
+    // construct embedded menu, using default font
+    embeddedMenu = makeEmbeddedPopupMenu(alignFrameMenuBar, false, false);
     // and actually add the components to the applet area
     theApplet.setLayout(new BorderLayout());
     theApplet.add(embeddedMenu, BorderLayout.NORTH);