JAL-2435 further adjustments to behaviour in split screen
[jalview.git] / src / jalview / appletgui / FontChooser.java
index 727aa88..96dfc20 100644 (file)
@@ -20,7 +20,6 @@
  */
 package jalview.appletgui;
 
-import jalview.api.ViewStyleI;
 import jalview.util.MessageManager;
 
 import java.awt.BorderLayout;
@@ -71,10 +70,20 @@ public class FontChooser extends Panel implements ItemListener
 
   private Font oldFont;
 
+  private Font oldComplementFont;
+
   private int oldCharWidth = 0;
 
+  /*
+   * the state of 'scale protein to cDNA' on opening the dialog
+   */
   private boolean oldScaleProtein = false;
 
+  /*
+   * the state of 'same font for protein and cDNA' on opening the dialog
+   */
+  boolean oldMirrorFont;
+
   private Font lastSelected = null;
 
   private int lastSelStyle = 0;
@@ -184,6 +193,29 @@ public class FontChooser extends Panel implements ItemListener
     {
       scaleAsCdna_actionPerformed();
     }
+    else if (source == fontAsCdna)
+    {
+      mirrorFont_actionPerformed();
+    }
+  }
+
+  /**
+   * Action on checking or unchecking 'use same font across split screen'
+   * option. When checked, the font settings are copied to the other half of the
+   * split screen. When unchecked, the other half is restored to its initial
+   * settings.
+   */
+  protected void mirrorFont_actionPerformed()
+  {
+    boolean selected = fontAsCdna.getState();
+    ap.av.setProteinFontAsCdna(selected);
+    ap.av.getCodingComplement().setProteinFontAsCdna(selected);
+
+    if (!selected)
+    {
+      ap.av.getCodingComplement().setFont(oldComplementFont, true);
+    }
+    changeFont();
   }
 
   /**
@@ -210,19 +242,23 @@ public class FontChooser extends Panel implements ItemListener
     if (ap != null)
     {
       ap.av.setScaleProteinAsCdna(oldScaleProtein);
+      ap.av.setProteinFontAsCdna(oldMirrorFont);
+
       if (ap.av.getCodingComplement() != null)
       {
         ap.av.getCodingComplement().setScaleProteinAsCdna(oldScaleProtein);
-        ap.av.getCodingComplement().setFont(oldFont, true);
-        ap.alignFrame.getSplitFrame().repaint();
+        ap.av.getCodingComplement().setProteinFontAsCdna(oldMirrorFont);
+        ap.av.getCodingComplement().setFont(oldComplementFont, true);
+        SplitFrame splitFrame = ap.alignFrame.getSplitFrame();
+        splitFrame.adjustLayout();
+        splitFrame.getComplement(ap.alignFrame).alignPanel.fontChanged();
+        splitFrame.repaint();
       }
 
       ap.av.setFont(oldFont, true);
-      ViewStyleI style = ap.av.getViewStyle();
-      if (style.getCharWidth() != oldCharWidth)
+      if (ap.av.getCharWidth() != oldCharWidth)
       {
-        style.setCharWidth(oldCharWidth);
-        ap.av.setViewStyle(style);
+        ap.av.setCharWidth(oldCharWidth);
       }
       ap.paintAlignment(true);
     }
@@ -288,11 +324,15 @@ public class FontChooser extends Panel implements ItemListener
       /*
        * and change font in other half of split frame if any
        */
-      if (inSplitFrame && fontAsCdna.getState())
+      if (inSplitFrame)
       {
-        ap.av.getCodingComplement().setFont(newFont, true);
+        if (fontAsCdna.getState())
+        {
+          ap.av.getCodingComplement().setFont(newFont, true);
+        }
         SplitFrame splitFrame = ap.alignFrame.getSplitFrame();
         splitFrame.adjustLayout();
+        splitFrame.getComplement(ap.alignFrame).alignPanel.fontChanged();
         splitFrame.repaint();
       }
     }
@@ -363,7 +403,8 @@ public class FontChooser extends Panel implements ItemListener
 
     fontAsCdna.setLabel(MessageManager.getString("label.font_as_cdna"));
     fontAsCdna.setFont(VERDANA_11PT);
-    fontAsCdna.setState(true);
+    fontAsCdna.addItemListener(this);
+    fontAsCdna.setState(ap.av.isProteinFontAsCdna());
 
     ok.setFont(VERDANA_11PT);
     ok.setLabel(MessageManager.getString("action.ok"));
@@ -425,6 +466,8 @@ public class FontChooser extends Panel implements ItemListener
     if (ap.alignFrame.getSplitFrame() != null)
     {
       inSplitFrame = true;
+      oldComplementFont = ((AlignViewport) ap.av.getCodingComplement())
+              .getFont();
       this.add(scalePanel, BorderLayout.CENTER);
     }
     this.add(okCancelPanel, BorderLayout.SOUTH);
@@ -439,9 +482,7 @@ public class FontChooser extends Panel implements ItemListener
     ap.av.setScaleProteinAsCdna(scaleAsCdna.getState());
     ap.av.getCodingComplement().setScaleProteinAsCdna(
             scaleAsCdna.getState());
-    ap.alignFrame.getSplitFrame().adjustLayout();
-    ap.paintAlignment(true);
-    ap.alignFrame.getSplitFrame().repaint();
+    changeFont();
   }
 
 }