Merge branch 'releases/Release_2_10_2b1_Branch'
[jalview.git] / src / jalview / gui / Preferences.java
index 6fdaa0d..6635dbe 100755 (executable)
@@ -54,7 +54,6 @@ import java.util.ArrayList;
 import java.util.List;
 
 import javax.help.HelpSetException;
-import javax.swing.JButton;
 import javax.swing.JColorChooser;
 import javax.swing.JFileChooser;
 import javax.swing.JInternalFrame;
@@ -110,6 +109,14 @@ public class Preferences extends GPreferences
 
   public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
 
+  public static final String SHOW_OV_HIDDEN_AT_START = "SHOW_OV_HIDDEN_AT_START";
+
+  public static final String USE_LEGACY_GAP = "USE_LEGACY_GAP";
+
+  public static final String GAP_COLOUR = "GAP_COLOUR";
+
+  public static final String HIDDEN_COLOUR = "HIDDEN_COLOUR";
+
   private static final int MIN_FONT_SIZE = 1;
 
   private static final int MAX_FONT_SIZE = 30;
@@ -308,10 +315,21 @@ public class Preferences extends GPreferences
             Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
     maxColour.setBackground(
             Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
+
+    /*
+     * Set overview panel defaults
+     */
     gapColour.setBackground(
-            Cache.getDefaultColour("GAP_COLOUR", Color.lightGray));
+            Cache.getDefaultColour(GAP_COLOUR,
+                    jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP));
     hiddenColour.setBackground(
-            Cache.getDefaultColour("HIDDEN_COLOUR", Color.darkGray));
+            Cache.getDefaultColour(HIDDEN_COLOUR,
+                    jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN));
+    useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false));
+    gapLabel.setEnabled(!useLegacyGap.isSelected());
+    gapColour.setEnabled(!useLegacyGap.isSelected());
+    showHiddenAtStart
+            .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, true));
 
     /*
      * Set Structure tab defaults.
@@ -636,6 +654,16 @@ public class Preferences extends GPreferences
             maxColour.getBackground());
 
     /*
+     * Save Overview settings
+     */
+    Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
+    Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
+    Cache.applicationProperties.setProperty(USE_LEGACY_GAP,
+            Boolean.toString(useLegacyGap.isSelected()));
+    Cache.applicationProperties.setProperty(SHOW_OV_HIDDEN_AT_START,
+            Boolean.toString(showHiddenAtStart.isSelected()));
+
+    /*
      * Save Structure settings
      */
     Cache.applicationProperties.setProperty(ADD_TEMPFACT_ANN,
@@ -1040,29 +1068,60 @@ public class Preferences extends GPreferences
   }
 
   @Override
-  public void gapColour_actionPerformed(JButton btn)
+  public void gapColour_actionPerformed(JPanel gap)
   {
-    Color col = JColorChooser.showDialog(this,
-            MessageManager.getString("label.select_gap_colour"),
-            gapColour.getForeground());
-    if (col != null)
+    if (!useLegacyGap.isSelected())
     {
-      btn.setForeground(col);
+      Color col = JColorChooser.showDialog(this,
+              MessageManager.getString("label.select_gap_colour"),
+              gapColour.getBackground());
+      if (col != null)
+      {
+        gap.setBackground(col);
+      }
+      gap.repaint();
     }
-    btn.repaint();
   }
 
   @Override
-  public void hiddenColour_actionPerformed(JButton btn)
+  public void hiddenColour_actionPerformed(JPanel hidden)
   {
     Color col = JColorChooser.showDialog(this,
             MessageManager.getString("label.select_hidden_colour"),
-            hiddenColour.getForeground());
+            hiddenColour.getBackground());
     if (col != null)
     {
-      btn.setForeground(col);
+      hidden.setBackground(col);
     }
-    btn.repaint();
+    hidden.repaint();
+  }
+
+  @Override
+  protected void useLegacyGaps_actionPerformed(ActionEvent e)
+  {
+    boolean enabled = useLegacyGap.isSelected();
+    if (enabled)
+    {
+      gapColour.setBackground(
+              jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_LEGACY_GAP);
+    }
+    else
+    {
+      gapColour.setBackground(
+              jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
+    }
+    gapColour.setEnabled(!enabled);
+    gapLabel.setEnabled(!enabled);
+  }
+
+  @Override
+  protected void resetOvDefaults_actionPerformed(ActionEvent e)
+  {
+    useLegacyGap.setSelected(false);
+    useLegacyGaps_actionPerformed(null);
+    showHiddenAtStart.setSelected(true);
+    hiddenColour.setBackground(
+            jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
   }
 
   @Override