JAL-1780 more support for export setting for flatfile output
[jalview.git] / src / jalview / appletgui / AlignFrame.java
index 3e919f6..4f7e2b9 100644 (file)
@@ -103,6 +103,7 @@ import jalview.structure.StructureSelectionManager;
 import jalview.structures.models.AAStructureBindingModel;
 import jalview.util.MappingUtils;
 import jalview.util.MessageManager;
+import jalview.viewmodel.AlignmentViewport;
 
 public class AlignFrame extends EmbmenuFrame implements ActionListener,
         ItemListener, KeyListener, AlignViewControllerGuiI
@@ -113,9 +114,10 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 
   public AlignViewport viewport;
 
-  int DEFAULT_WIDTH = 700;
+  // width and height may be overridden by applet parameters
+  int frameWidth = 700;
 
-  int DEFAULT_HEIGHT = 500;
+  int frameHeight = 500;
 
   String jalviewServletURL;
 
@@ -154,6 +156,20 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   public AlignFrame(AlignmentI al, JalviewLite applet,
           String title, boolean embedded, boolean addToDisplay)
   {
+    this(al, null, null, applet, title, embedded, addToDisplay);
+  }
+
+  public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
+          ColumnSelection columnSelection, JalviewLite applet,
+          String title, boolean embedded)
+  {
+    this(al, hiddenSeqs, columnSelection, applet, title, embedded, true);
+  }
+
+  public AlignFrame(AlignmentI al, SequenceI[] hiddenSeqs,
+          ColumnSelection columnSelection, JalviewLite applet,
+          String title, boolean embedded, boolean addToDisplay)
+  {
     if (applet != null)
     {
       jalviewServletURL = applet.getParameter("APPLICATION_URL");
@@ -176,19 +192,30 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
         if (param != null)
         {
           int width = Integer.parseInt(param);
-          DEFAULT_WIDTH = width;
+          frameWidth = width;
         }
         param = applet.getParameter("windowHeight");
         if (param != null)
         {
           int height = Integer.parseInt(param);
-          DEFAULT_HEIGHT = height;
+          frameHeight = height;
         }
       } catch (Exception ex)
       {
       }
     }
     viewport = new AlignViewport(al, applet);
+
+    if (hiddenSeqs != null && hiddenSeqs.length > 0)
+    {
+      viewport.hideSequence(hiddenSeqs);
+      viewport.setHasHiddenRows(true);
+    }
+    if (columnSelection != null)
+    {
+      viewport.setColumnSelection(columnSelection);
+    }
+
     alignPanel = new AlignmentPanel(this, viewport);
     avc = new jalview.controller.AlignViewController(this, viewport,
             alignPanel);
@@ -196,13 +223,14 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     viewport.updateConsensus(alignPanel);
 
     displayNonconservedMenuItem.setState(viewport.getShowUnconserved());
-    followMouseOverFlag.setState(viewport.getFollowHighlight());
+    followMouseOverFlag.setState(viewport.isFollowHighlight());
     showGroupConsensus.setState(viewport.isShowGroupConsensus());
     showGroupConservation.setState(viewport.isShowGroupConservation());
     showConsensusHistogram.setState(viewport.isShowConsensusHistogram());
     showSequenceLogo.setState(viewport.isShowSequenceLogo());
     normSequenceLogo.setState(viewport.isNormaliseSequenceLogo());
     applyToAllGroups.setState(viewport.getColourAppliesToAllGroups());
+    annotationPanelMenuItem.setState(viewport.isShowAnnotation());
     showAlignmentAnnotations.setState(viewport.isShowAnnotation());
     showSequenceAnnotations.setState(viewport.isShowAnnotation());
 
@@ -924,7 +952,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 
   private void mouseOverFlag_stateChanged()
   {
-    viewport.followHighlight = followMouseOverFlag.getState();
+    viewport.setFollowHighlight(followMouseOverFlag.getState());
     // TODO: could kick the scrollTo mechanism to reset view for current
     // searchresults.
   }
@@ -1310,7 +1338,10 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage(
             "label.alignment_output_command", new Object[]
             { e.getActionCommand() }), 600, 500);
-    cap.setText(new AppletFormatAdapter().formatSequences(
+
+    FeatureRenderer fr = this.alignPanel.cloneFeatureRenderer();
+    viewport.setFeatureRenderer(fr);
+    cap.setText(new AppletFormatAdapter(viewport).formatSequences(
             e.getActionCommand(), viewport.getAlignment(),
             viewport.getShowJVSuffix()));
   }
@@ -1592,7 +1623,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     viewport.addToRedoList(command);
     command.undoCommand(null);
 
-    AlignViewport originalSource = getOriginatingSource(command);
+    AlignmentViewport originalSource = getOriginatingSource(command);
     // JBPNote Test
     if (originalSource != viewport)
     {
@@ -1624,7 +1655,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     viewport.addToHistoryList(command);
     command.doCommand(null);
 
-    AlignViewport originalSource = getOriginatingSource(command);
+    AlignmentViewport originalSource = getOriginatingSource(command);
     // JBPNote Test
     if (originalSource != viewport)
     {
@@ -1640,9 +1671,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
             .getAlignment().getSequences());
   }
 
-  AlignViewport getOriginatingSource(CommandI command)
+  AlignmentViewport getOriginatingSource(CommandI command)
   {
-    AlignViewport originalSource = null;
+    AlignmentViewport originalSource = null;
     // For sequence removal and addition, we need to fire
     // the property change event FROM the viewport where the
     // original alignment was altered
@@ -1964,8 +1995,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
           }
         }
 
-        jalview.bin.JalviewLite.addFrame(af, newtitle, DEFAULT_WIDTH,
-                DEFAULT_HEIGHT);
+        jalview.bin.JalviewLite.addFrame(af, newtitle, frameWidth,
+                frameHeight);
       }
       else
       {
@@ -2539,7 +2570,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 
   }
 
-  void changeColour(ColourSchemeI cs)
+  public void changeColour(ColourSchemeI cs)
   {
     int threshold = 0;
 
@@ -3596,8 +3627,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     /*
      * Annotations menu
      */
-    // annotationsMenu.add(annotationPanelMenuItem);
-    // annotationsMenu.addSeparator();
+    annotationsMenu.add(annotationPanelMenuItem);
+    annotationsMenu.addSeparator();
     annotationsMenu.add(showAlignmentAnnotations);
     annotationsMenu.add(showSequenceAnnotations);
     annotationsMenu.add(sortAnnBySequence);
@@ -3738,6 +3769,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 
   private CheckboxMenuItem showAutoLast;
 
+  private SplitFrame splitFrame;
+
   /**
    * Attach the alignFrame panels after embedding menus, if necessary. This used
    * to be called setEmbedded, but is now creates the dropdown menus in a
@@ -3771,8 +3804,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       add(alignPanel, BorderLayout.CENTER);
       // and register with the applet so it can pass external API calls to us
       jalview.bin.JalviewLite.addFrame(this, this.getTitle(),
-              DEFAULT_WIDTH,
-              DEFAULT_HEIGHT);
+              frameWidth,
+              frameHeight);
     }
   }
 
@@ -4164,4 +4197,13 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     return false;
   }
 
+  public SplitFrame getSplitFrame()
+  {
+    return this.splitFrame;
+  }
+
+  public void setSplitFrame(SplitFrame sf)
+  {
+    this.splitFrame = sf;
+  }
 }