Merge branch 'Release_2_8_3_Branch' of https://source.jalview.org/git/jalview into...
[jalview.git] / src / jalview / gui / FontChooser.java
index fc66965..5e13781 100755 (executable)
  */
 package jalview.gui;
 
-import jalview.bin.Cache;
-import jalview.jbgui.GFontChooser;
-import jalview.util.MessageManager;
-
 import java.awt.Font;
 import java.awt.FontMetrics;
 import java.awt.event.ActionEvent;
@@ -32,6 +28,10 @@ import javax.swing.JInternalFrame;
 import javax.swing.JLayeredPane;
 import javax.swing.JOptionPane;
 
+import jalview.bin.Cache;
+import jalview.jbgui.GFontChooser;
+import jalview.util.MessageManager;
+
 /**
  * DOCUMENT ME!
  * 
@@ -46,6 +46,8 @@ public class FontChooser extends GFontChooser
 
   Font oldFont;
 
+  boolean oldProteinScale;
+
   boolean init = true;
 
   JInternalFrame frame;
@@ -75,6 +77,8 @@ public class FontChooser extends GFontChooser
   public FontChooser(AlignmentPanel ap)
   {
     oldFont = ap.av.getFont();
+    oldProteinScale = ap.av.isScaleProteinAsCdna();
+
     this.ap = ap;
     init();
   }
@@ -86,16 +90,26 @@ public class FontChooser extends GFontChooser
 
     smoothFont.setSelected(ap.av.antiAlias);
 
+    /*
+     * Enable 'scale protein as cDNA' in a SplitFrame view. The selection is
+     * stored in the ViewStyle of both dna and protein Viewport
+     */
+    if (ap.av.getCodingComplement() != null)
+    {
+      scaleAsCdna.setVisible(true);
+      scaleAsCdna.setSelected(ap.av.isScaleProteinAsCdna());
+    }
+
     if (tp != null)
     {
       Desktop.addInternalFrame(frame,
               MessageManager.getString("action.change_font_tree_panel"),
-              340, 170, false);
+              400, 200, false);
     }
     else
     {
       Desktop.addInternalFrame(frame,
-              MessageManager.getString("action.change_font"), 340, 170,
+              MessageManager.getString("action.change_font"), 380, 200,
               false);
     }
 
@@ -111,7 +125,7 @@ public class FontChooser extends GFontChooser
 
     for (int i = 1; i < 51; i++)
     {
-      fontSize.addItem(i + "");
+      fontSize.addItem(i);
     }
 
     fontStyle.addItem("plain");
@@ -119,7 +133,7 @@ public class FontChooser extends GFontChooser
     fontStyle.addItem("italic");
 
     fontName.setSelectedItem(oldFont.getName());
-    fontSize.setSelectedItem(oldFont.getSize() + "");
+    fontSize.setSelectedItem(oldFont.getSize());
     fontStyle.setSelectedIndex(oldFont.getStyle());
 
     FontMetrics fm = getGraphics().getFontMetrics(oldFont);
@@ -172,14 +186,20 @@ public class FontChooser extends GFontChooser
     if (ap != null)
     {
       ap.av.setFont(oldFont, true);
+      ap.av.setScaleProteinAsCdna(oldProteinScale);
       ap.paintAlignment(true);
+      if (scaleAsCdna.isEnabled())
+      {
+        ap.av.setScaleProteinAsCdna(oldProteinScale);
+        ap.av.getCodingComplement().setScaleProteinAsCdna(oldProteinScale);
+      }
     }
     else if (tp != null)
     {
       tp.setTreeFont(oldFont);
     }
     fontName.setSelectedItem(oldFont.getName());
-    fontSize.setSelectedItem(oldFont.getSize() + "");
+    fontSize.setSelectedItem(oldFont.getSize());
     fontStyle.setSelectedIndex(oldFont.getStyle());
 
     try
@@ -216,8 +236,8 @@ public class FontChooser extends GFontChooser
     }
 
     Font newFont = new Font(fontName.getSelectedItem().toString(),
-            fontStyle.getSelectedIndex(), Integer.parseInt(fontSize
-                    .getSelectedItem().toString()));
+            fontStyle.getSelectedIndex(),
+            (Integer) fontSize.getSelectedItem());
     FontMetrics fm = getGraphics().getFontMetrics(newFont);
     double mw = fm.getStringBounds("M", getGraphics()).getWidth(), iw = fm
             .getStringBounds("I", getGraphics()).getWidth();
@@ -225,7 +245,7 @@ public class FontChooser extends GFontChooser
     {
       fontName.setSelectedItem(lastSelected.getName());
       fontStyle.setSelectedIndex(lastSelStyle);
-      fontSize.setSelectedItem("" + lastSelSize);
+      fontSize.setSelectedItem(lastSelSize);
       monospaced.setSelected(lastSelMono);
       JOptionPane
               .showInternalMessageDialog(
@@ -298,10 +318,10 @@ public class FontChooser extends GFontChooser
   }
 
   /**
-   * DOCUMENT ME!
+   * Make selected settings the defaults by storing them (via Cache class) in
+   * the .jalview_properties file (the file is only written when Jalview exits)
    * 
    * @param e
-   *          DOCUMENT ME!
    */
   public void defaultButton_actionPerformed(ActionEvent e)
   {
@@ -310,5 +330,25 @@ public class FontChooser extends GFontChooser
     Cache.setProperty("FONT_SIZE", fontSize.getSelectedItem().toString());
     Cache.setProperty("ANTI_ALIAS",
             Boolean.toString(smoothFont.isSelected()));
+    Cache.setProperty(Preferences.SCALE_PROTEIN_TO_CDNA,
+            Boolean.toString(scaleAsCdna.isSelected()));
+  }
+
+  /**
+   * Turn on/off scaling of protein characters to 3 times the width of cDNA
+   * characters
+   */
+  @Override
+  protected void scaleAsCdna_actionPerformed(ActionEvent e)
+  {
+    ap.av.setScaleProteinAsCdna(scaleAsCdna.isSelected());
+    ap.av.getCodingComplement().setScaleProteinAsCdna(
+            scaleAsCdna.isSelected());
+    final SplitFrame splitFrame = (SplitFrame) ap.alignFrame
+            .getSplitViewContainer();
+    splitFrame.adjustLayout();
+    splitFrame.repaint();
+    // ap.paintAlignment(true);
+    // TODO would like to repaint
   }
 }