JAL-1690 fix NPE on Cancel when not in split frame
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 22 Apr 2015 12:21:59 +0000 (13:21 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 22 Apr 2015 12:21:59 +0000 (13:21 +0100)
src/jalview/gui/FontChooser.java

index 5e13781..381fbe3 100755 (executable)
@@ -94,8 +94,10 @@ public class FontChooser extends GFontChooser
      * Enable 'scale protein as cDNA' in a SplitFrame view. The selection is
      * stored in the ViewStyle of both dna and protein Viewport
      */
+    scaleAsCdna.setEnabled(false);
     if (ap.av.getCodingComplement() != null)
     {
+      scaleAsCdna.setEnabled(true);
       scaleAsCdna.setVisible(true);
       scaleAsCdna.setSelected(ap.av.isScaleProteinAsCdna());
     }
@@ -243,15 +245,19 @@ public class FontChooser extends GFontChooser
             .getStringBounds("I", getGraphics()).getWidth();
     if (mw < 1 || iw < 1)
     {
-      fontName.setSelectedItem(lastSelected.getName());
-      fontStyle.setSelectedIndex(lastSelStyle);
-      fontSize.setSelectedItem(lastSelSize);
-      monospaced.setSelected(lastSelMono);
       JOptionPane
               .showInternalMessageDialog(
                       this,
                       MessageManager.getString("label.font_doesnt_have_letters_defined"),
                       MessageManager.getString("label.invalid_font"), JOptionPane.WARNING_MESSAGE);
+      /*
+       * Restore previous values - size first to avoid recursive calls to this
+       * point!
+       */
+      fontSize.setSelectedItem(lastSelSize);
+      fontName.setSelectedItem(lastSelected.getName());
+      fontStyle.setSelectedIndex(lastSelStyle);
+      monospaced.setSelected(lastSelMono);
       return;
     }
     if (tp != null)