JAL-1807 still testing
[jalviewjs.git] / unused / appletgui / SplitFrame.java
index 1baeb5d..356c44e 100644 (file)
-package jalview.appletgui;
-
-import jalview.analysis.AlignmentUtils;
-import jalview.api.AlignmentViewPanel;
-import jalview.api.ViewStyleI;
-import jalview.bin.JalviewLite;
-import jalview.datamodel.AlignmentI;
-import jalview.structure.StructureSelectionManager;
-import jalview.viewmodel.AlignmentViewport;
-
-import java.awt.BorderLayout;
-import java.awt.Dimension;
-import java.awt.GridLayout;
-
-import javax.swing.JPanel;
-
-public class SplitFrame extends EmbmenuFrame
-{
-  private static final long serialVersionUID = 1L;
-
-  private AlignFrame topFrame;
-
-  private AlignFrame bottomFrame;
-
-  private JPanel outermost;
-  
-
-  /**
-   * Constructor
-   */
-  public SplitFrame(AlignFrame af1, AlignFrame af2)
-  {
-    topFrame = af1;
-    bottomFrame = af2;
-    init();
-  }
-
-  /**
-   * Creates a Panel containing two Panels, and adds the first and second
-   * AlignFrame's components to each. At this stage we have not yet committed to
-   * whether the enclosing panel will be added to this frame, for display as a
-   * separate frame, or added to the applet (embedded mode).
-   */
-  public void init()
-  {
-    constructSplit();
-
-    /*
-     * Try to make and add dna/protein sequence mappings
-     */
-    final AlignViewport topViewport = topFrame.viewport;
-    final AlignViewport bottomViewport = bottomFrame.viewport;
-    final AlignmentI topAlignment = topViewport.getAlignment();
-    final AlignmentI bottomAlignment = bottomViewport.getAlignment();
-    AlignmentViewport cdna = topAlignment.isNucleotide() ? topViewport
-            : (bottomAlignment.isNucleotide() ? bottomViewport : null);
-    AlignmentViewport protein = !topAlignment.isNucleotide() ? topViewport
-            : (!bottomAlignment.isNucleotide() ? bottomViewport : null);
-
-    boolean mapped = AlignmentUtils.mapProteinToCdna(
-            protein.getAlignment(), cdna.getAlignment());
-    if (mapped)
-    {
-      final StructureSelectionManager ssm = StructureSelectionManager
-              .getStructureSelectionManager(topViewport.applet);
-      ssm.addMappings(protein.getAlignment().getCodonFrames());
-      topViewport.setCodingComplement(bottomViewport);
-      ssm.addCommandListener(cdna);
-      ssm.addCommandListener(protein);
-    }
-
-    /*
-     * Now mappings exist, can compute cDNA consensus on protein alignment
-     */
-    protein.initComplementConsensus();
-    AlignmentViewPanel ap = topAlignment.isNucleotide() ? bottomFrame.alignPanel
-            : topFrame.alignPanel;
-    protein.updateConsensus(ap);
-
-    adjustLayout();
-  }
-
-  /**
-   * 
-   */
-  protected void constructSplit()
-  {
-    setMenuBar(null);
-    outermost = new JPanel(new GridLayout(2, 1));
-
-    JPanel topPanel = new JPanel();
-    JPanel bottomPanel = new JPanel();
-    outermost.add(topPanel);
-    outermost.add(bottomPanel);
-
-    addAlignFrameComponents(topFrame, topPanel);
-    addAlignFrameComponents(bottomFrame, bottomPanel);
-  }
-
-  /**
-   * Make any adjustments to the layout
-   */
-  protected void adjustLayout()
-  {
-    AlignmentViewport cdna = topFrame.getAlignViewport().getAlignment()
-            .isNucleotide() ? topFrame.viewport : bottomFrame.viewport;
-    AlignmentViewport protein = cdna == topFrame.viewport ? bottomFrame.viewport
-            : topFrame.viewport;
-
-    /*
-     * Ensure sequence ids are the same width for good alignment.
-     */
-    // TODO should do this via av.getViewStyle/setViewStyle
-    // however at present av.viewStyle is not set in IdPanel.fontChanged
-    int w1 = topFrame.alignPanel.idPanel.idCanvas.getWidth();
-    int w2 = bottomFrame.alignPanel.idPanel.idCanvas.getWidth();
-    int w3 = Math.max(w1, w2);
-    if (w1 != w3)
-    {
-      Dimension d = topFrame.alignPanel.idPanel.idCanvas.getSize();
-      topFrame.alignPanel.idPanel.idCanvas.setSize(new Dimension(w3,
-              d.height));
-    }
-    if (w2 != w3)
-    {
-      Dimension d = bottomFrame.alignPanel.idPanel.idCanvas.getSize();
-      bottomFrame.alignPanel.idPanel.idCanvas.setSize(new Dimension(w3,
-              d.height));
-    }
-
-    /*
-     * Scale protein to either 1 or 3 times character width of dna
-     */
-    if (protein != null && cdna != null)
-    {
-      ViewStyleI vs = protein.getViewStyle();
-      int scale = vs.isScaleProteinAsCdna() ? 3 : 1;
-      vs.setCharWidth(scale * cdna.getViewStyle().getCharWidth());
-      protein.setViewStyle(vs);
-    }
-  }
-
-       /**
-        * Add the menu bar, alignment panel and status bar from the AlignFrame to the
-        * panel. The menu bar is a panel 'reconstructed' from the AlignFrame's frame
-        * menu bar. This allows each half of the SplitFrame to have its own menu bar.
-        * 
-        * @param af
-        * @param panel
-        */
-       private void addAlignFrameComponents(AlignFrame af, JPanel panel) {
-               panel.setLayout(new BorderLayout());
-               JPanel menuPanel = af.makeEmbeddedPopupMenu(af.getJMenuBar(), true, false);
-               panel.add(menuPanel, BorderLayout.NORTH);
-               panel.add(af.statusBar, BorderLayout.SOUTH);
-               panel.add(af.alignPanel, BorderLayout.CENTER);
-
-               af.setSplitFrame(this);
-       }
-
-  /**
-   * Display the content panel either as a new frame or embedded in the applet.
-   * 
-   * @param embedded
-   * @param applet
-   */
-  public void addToDisplay(boolean embedded, JalviewLite applet)
-  {
-    createSplitFrameWindow(embedded, applet);
-    validate();
-    topFrame.alignPanel.adjustAnnotationHeight();
-    topFrame.alignPanel.paintAlignment(true);
-    bottomFrame.alignPanel.adjustAnnotationHeight();
-    bottomFrame.alignPanel.paintAlignment(true);
-  }
-
-  /**
-   * Either show the content panel in this frame as a new frame, or (if
-   * embed=true) add it to the applet container instead.
-   * 
-   * @param embed
-   * @param applet
-   */
-  protected void createSplitFrameWindow(boolean embed, JalviewLite applet)
-  {
-    if (embed)
-    {
-      applet.add(outermost);
-      applet.validate();
-    }
-    else
-    {
-      this.add(outermost);
-      int width = Math.max(topFrame.frameWidth, bottomFrame.frameWidth);
-      int height = topFrame.frameHeight + bottomFrame.frameHeight;
-      JalviewLite.addFrame(this, this.getTitle(), width, height);
-    }
-  }
-
-  /**
-   * Returns the contained AlignFrame complementary to the one given (or null if
-   * no match to top or bottom component).
-   * 
-   * @param af
-   * @return
-   */
-  public AlignFrame getComplement(AlignFrame af)
-  {
-    if (topFrame == af)
-    {
-      return bottomFrame;
-    }
-    else if (bottomFrame == af)
-    {
-      return topFrame;
-    }
-    return null;
-  }
-}
+package jalview.appletgui;\r
+\r
+import jalview.analysis.AlignmentUtils;\r
+import jalview.api.AlignmentViewPanel;\r
+import jalview.api.ViewStyleI;\r
+import jalview.bin.JalviewLite;\r
+import jalview.datamodel.AlignmentI;\r
+import jalview.structure.StructureSelectionManager;\r
+import jalview.viewmodel.AlignmentViewport;\r
+\r
+import java.awt.BorderLayout;\r
+import java.awt.Dimension;\r
+import java.awt.GridLayout;\r
+\r
+import javax.swing.JPanel;\r
+\r
+public class SplitFrame extends EmbmenuFrame\r
+{\r
+  private static final long serialVersionUID = 1L;\r
+\r
+  private AlignFrame topFrame;\r
+\r
+  private AlignFrame bottomFrame;\r
+\r
+  private JPanel outermost;\r
+  \r
+\r
+  /**\r
+   * Constructor\r
+   */\r
+  public SplitFrame(AlignFrame af1, AlignFrame af2)\r
+  {\r
+    topFrame = af1;\r
+    bottomFrame = af2;\r
+    init();\r
+  }\r
+\r
+  /**\r
+   * Creates a Panel containing two Panels, and adds the first and second\r
+   * AlignFrame's components to each. At this stage we have not yet committed to\r
+   * whether the enclosing panel will be added to this frame, for display as a\r
+   * separate frame, or added to the applet (embedded mode).\r
+   */\r
+  public void init()\r
+  {\r
+    constructSplit();\r
+\r
+    /*\r
+     * Try to make and add dna/protein sequence mappings\r
+     */\r
+    final AlignViewport topViewport = topFrame.viewport;\r
+    final AlignViewport bottomViewport = bottomFrame.viewport;\r
+    final AlignmentI topAlignment = topViewport.getAlignment();\r
+    final AlignmentI bottomAlignment = bottomViewport.getAlignment();\r
+    AlignmentViewport cdna = topAlignment.isNucleotide() ? topViewport\r
+            : (bottomAlignment.isNucleotide() ? bottomViewport : null);\r
+    AlignmentViewport protein = !topAlignment.isNucleotide() ? topViewport\r
+            : (!bottomAlignment.isNucleotide() ? bottomViewport : null);\r
+\r
+    boolean mapped = AlignmentUtils.mapProteinToCdna(\r
+            protein.getAlignment(), cdna.getAlignment());\r
+    if (mapped)\r
+    {\r
+      final StructureSelectionManager ssm = StructureSelectionManager\r
+              .getStructureSelectionManager(topViewport.applet);\r
+      ssm.addMappings(protein.getAlignment().getCodonFrames());\r
+      topViewport.setCodingComplement(bottomViewport);\r
+      ssm.addCommandListener(cdna);\r
+      ssm.addCommandListener(protein);\r
+    }\r
+\r
+    /*\r
+     * Now mappings exist, can compute cDNA consensus on protein alignment\r
+     */\r
+    protein.initComplementConsensus();\r
+    AlignmentViewPanel ap = topAlignment.isNucleotide() ? bottomFrame.alignPanel\r
+            : topFrame.alignPanel;\r
+    protein.updateConsensus(ap);\r
+\r
+    adjustLayout();\r
+  }\r
+\r
+  /**\r
+   * \r
+   */\r
+  protected void constructSplit()\r
+  {\r
+    setMenuBar(null);\r
+    outermost = new JPanel(new GridLayout(2, 1));\r
+\r
+    JPanel topPanel = new JPanel();\r
+    JPanel bottomPanel = new JPanel();\r
+    outermost.add(topPanel);\r
+    outermost.add(bottomPanel);\r
+\r
+    addAlignFrameComponents(topFrame, topPanel);\r
+    addAlignFrameComponents(bottomFrame, bottomPanel);\r
+  }\r
+\r
+  /**\r
+   * Make any adjustments to the layout\r
+   */\r
+  protected void adjustLayout()\r
+  {\r
+    AlignmentViewport cdna = topFrame.getAlignViewport().getAlignment()\r
+            .isNucleotide() ? topFrame.viewport : bottomFrame.viewport;\r
+    AlignmentViewport protein = cdna == topFrame.viewport ? bottomFrame.viewport\r
+            : topFrame.viewport;\r
+\r
+    /*\r
+     * Ensure sequence ids are the same width for good alignment.\r
+     */\r
+    // TODO should do this via av.getViewStyle/setViewStyle\r
+    // however at present av.viewStyle is not set in IdPanel.fontChanged\r
+    int w1 = topFrame.alignPanel.idPanel.idCanvas.getWidth();\r
+    int w2 = bottomFrame.alignPanel.idPanel.idCanvas.getWidth();\r
+    int w3 = Math.max(w1, w2);\r
+    if (w1 != w3)\r
+    {\r
+      Dimension d = topFrame.alignPanel.idPanel.idCanvas.getSize();\r
+      topFrame.alignPanel.idPanel.idCanvas.setSize(new Dimension(w3,\r
+              d.height));\r
+    }\r
+    if (w2 != w3)\r
+    {\r
+      Dimension d = bottomFrame.alignPanel.idPanel.idCanvas.getSize();\r
+      bottomFrame.alignPanel.idPanel.idCanvas.setSize(new Dimension(w3,\r
+              d.height));\r
+    }\r
+\r
+    /*\r
+     * Scale protein to either 1 or 3 times character width of dna\r
+     */\r
+    if (protein != null && cdna != null)\r
+    {\r
+      ViewStyleI vs = protein.getViewStyle();\r
+      int scale = vs.isScaleProteinAsCdna() ? 3 : 1;\r
+      vs.setCharWidth(scale * cdna.getViewStyle().getCharWidth());\r
+      protein.setViewStyle(vs);\r
+    }\r
+  }\r
+\r
+       /**\r
+        * Add the menu bar, alignment panel and status bar from the AlignFrame to the\r
+        * panel. The menu bar is a panel 'reconstructed' from the AlignFrame's frame\r
+        * menu bar. This allows each half of the SplitFrame to have its own menu bar.\r
+        * \r
+        * @param af\r
+        * @param panel\r
+        */\r
+       private void addAlignFrameComponents(AlignFrame af, JPanel panel) {\r
+               panel.setLayout(new BorderLayout());\r
+               JPanel menuPanel = af.makeEmbeddedPopupMenu(af.getJMenuBar(), true, false);\r
+               panel.add(menuPanel, BorderLayout.NORTH);\r
+               panel.add(af.statusBar, BorderLayout.SOUTH);\r
+               panel.add(af.alignPanel, BorderLayout.CENTER);\r
+\r
+               af.setSplitFrame(this);\r
+       }\r
+\r
+  /**\r
+   * Display the content panel either as a new frame or embedded in the applet.\r
+   * \r
+   * @param embedded\r
+   * @param applet\r
+   */\r
+  public void addToDisplay(boolean embedded, JalviewLite applet)\r
+  {\r
+    createSplitFrameWindow(embedded, applet);\r
+    validate();\r
+    topFrame.alignPanel.adjustAnnotationHeight();\r
+    topFrame.alignPanel.paintAlignment(true);\r
+    bottomFrame.alignPanel.adjustAnnotationHeight();\r
+    bottomFrame.alignPanel.paintAlignment(true);\r
+  }\r
+\r
+  /**\r
+   * Either show the content panel in this frame as a new frame, or (if\r
+   * embed=true) add it to the applet container instead.\r
+   * \r
+   * @param embed\r
+   * @param applet\r
+   */\r
+  protected void createSplitFrameWindow(boolean embed, JalviewLite applet)\r
+  {\r
+    if (embed)\r
+    {\r
+      applet.add(outermost);\r
+      applet.validate();\r
+    }\r
+    else\r
+    {\r
+      this.add(outermost);\r
+      int width = Math.max(topFrame.frameWidth, bottomFrame.frameWidth);\r
+      int height = topFrame.frameHeight + bottomFrame.frameHeight;\r
+      JalviewLite.addFrame(this, this.getTitle(), width, height);\r
+    }\r
+  }\r
+\r
+  /**\r
+   * Returns the contained AlignFrame complementary to the one given (or null if\r
+   * no match to top or bottom component).\r
+   * \r
+   * @param af\r
+   * @return\r
+   */\r
+  public AlignFrame getComplement(AlignFrame af)\r
+  {\r
+    if (topFrame == af)\r
+    {\r
+      return bottomFrame;\r
+    }\r
+    else if (bottomFrame == af)\r
+    {\r
+      return topFrame;\r
+    }\r
+    return null;\r
+  }\r
+}\r