3253 reconciled with develop
[jalview.git] / src / jalview / gui / Preferences.java
index 777ab48..6d46ce7 100755 (executable)
@@ -25,6 +25,7 @@ import jalview.bin.Cache;
 import jalview.gui.Help.HelpId;
 import jalview.gui.StructureViewer.ViewerType;
 import jalview.io.BackupFiles;
+import jalview.io.BackupFilesPresetEntry;
 import jalview.io.FileFormatI;
 import jalview.io.JalviewFileChooser;
 import jalview.io.JalviewFileView;
@@ -84,10 +85,51 @@ import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
 @SuppressWarnings("serial")
 public class Preferences extends GPreferences
 {
-  public static final String ADD_SS_ANN = "ADD_SS_ANN";
+
+  // original to develop
+
+  public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
+
+  public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
+
+  public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
+
+  public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
+
+  public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
 
   public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN";
 
+  public static final String ADD_SS_ANN = "ADD_SS_ANN";
+
+  public static final String USE_RNAVIEW = "USE_RNAVIEW";
+
+  public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
+
+  public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
+
+  public static final String CHIMERA_PATH = "CHIMERA_PATH";
+
+  public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
+
+  public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
+
+  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;
+
+  // new for applet
+
   public static final String ALLOW_UNPUBLISHED_PDB_QUERYING = "ALLOW_UNPUBLISHED_PDB_QUERYING";
 
   public static final String ANNOTATIONCOLOUR_MAX = "ANNOTATIONCOLOUR_MAX";
@@ -100,20 +142,12 @@ public class Preferences extends GPreferences
 
   public static final String AUTOASSOCIATE_PDBANDSEQS = "AUTOASSOCIATE_PDBANDSEQS";
 
-  public static final String CENTRE_COLUMN_LABELS = "CENTRE_COLUMN_LABELS";
+  public static final String BLOSUM62_PCA_FOR_NUCLEOTIDE = "BLOSUM62_PCA_FOR_NUCLEOTIDE";
 
-  public static final String CHIMERA_PATH = "CHIMERA_PATH";
+  public static final String CENTRE_COLUMN_LABELS = "CENTRE_COLUMN_LABELS";
 
   public static final String DBREFFETCH_USEPICR = "DBREFFETCH_USEPICR";
 
-  public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR";
-
-  public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC";
-
-  public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT";
-
-  public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME";
-
   public static final String FIGURE_AUTOIDWIDTH = "FIGURE_AUTOIDWIDTH";
 
   public static final String FIGURE_FIXEDIDWIDTH = "FIGURE_FIXEDIDWIDTH";
@@ -126,12 +160,8 @@ public class Preferences extends GPreferences
 
   public static final String FONT_STYLE = "FONT_STYLE";
 
-  public static final String GAP_COLOUR = "GAP_COLOUR";
-
   public static final String GAP_SYMBOL = "GAP_SYMBOL";
 
-  public static final String HIDDEN_COLOUR = "HIDDEN_COLOUR";
-
   public static final String HIDE_INTRONS = "HIDE_INTRONS";
 
   public static final String ID_ITALICS = "ID_ITALICS";
@@ -156,12 +186,8 @@ public class Preferences extends GPreferences
 
   public static final String RIGHT_ALIGN_IDS = "RIGHT_ALIGN_IDS";
 
-  public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA";
-
   public static final String SHOW_ANNOTATIONS = "SHOW_ANNOTATIONS";
 
-  public static final String SHOW_AUTOCALC_ABOVE = "SHOW_AUTOCALC_ABOVE";
-
   public static final String SHOW_CONSENSUS = "SHOW_CONSENSUS";
 
   public static final String SHOW_CONSENSUS_HISTOGRAM = "SHOW_CONSENSUS_HISTOGRAM";
@@ -176,13 +202,13 @@ public class Preferences extends GPreferences
 
   public static final String SHOW_GROUP_CONSERVATION = "SHOW_GROUP_CONSERVATION";
 
-  public static final String SHOW_JVSUFFIX = "SHOW_JVSUFFIX";
+  public static final String SHOW_IDENTITY = "SHOW_IDENTITY";
 
-  public static final String SHOW_NPFEATS_TOOLTIP = "SHOW_NPFEATS_TOOLTIP";
+  public static final String SHOW_FULLSCREEN = "SHOW_FULLSCREEN";
 
-  public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY";
+  public static final String SHOW_JVSUFFIX = "SHOW_JVSUFFIX";
 
-  public static final String SHOW_OV_HIDDEN_AT_START = "SHOW_OV_HIDDEN_AT_START";
+  public static final String SHOW_NPFEATS_TOOLTIP = "SHOW_NPFEATS_TOOLTIP";
 
   public static final String SHOW_OVERVIEW = "SHOW_OVERVIEW";
 
@@ -192,32 +218,21 @@ public class Preferences extends GPreferences
 
   public static final String SORT_ALIGNMENT = "SORT_ALIGNMENT";
 
-  public static final String SORT_ANNOTATIONS = "SORT_ANNOTATIONS";
-
   public static final String SORT_BY_TREE = "SORT_BY_TREE";
 
-  public static final String STRUCT_FROM_PDB = "STRUCT_FROM_PDB";
-
-  public static final String STRUCTURE_DISPLAY = "STRUCTURE_DISPLAY";
-
   public static final String STRUCTURE_DIMENSIONS = "STRUCTURE_DIMENSIONS";
 
   public static final String UNIPROT_DOMAIN = "UNIPROT_DOMAIN";
 
   public static final String USE_FULL_SO = "USE_FULL_SO";
 
-  public static final String USE_LEGACY_GAP = "USE_LEGACY_GAP";
-
-  public static final String USE_RNAVIEW = "USE_RNAVIEW";
-
   public static final String USER_DEFINED_COLOURS = "USER_DEFINED_COLOURS";
 
   public static final String WRAP_ALIGNMENT = "WRAP_ALIGNMENT";
 
 
-  private static final int MIN_FONT_SIZE = 1;
-
-  private static final int MAX_FONT_SIZE = 30;
+  public static final Dimension DEFAULT_STRUCTURE_DIMENSIONS = new Dimension(
+          600, 600);
 
   /**
    * Holds name and link separated with | character. Sequence ID must be
@@ -237,15 +252,6 @@ public class Preferences extends GPreferences
 
   public static final List<String> groupURLLinks; // not implemented
 
-  public static final String BLOSUM62_PCA_FOR_NUCLEOTIDE = "BLOSUM62_PCA_FOR_NUCLEOTIDE";
-
-  public static final String SHOW_IDENTITY = "SHOW_IDENTITY";
-
-  public static final String SHOW_FULLSCREEN = "SHOW_FULLSCREEN";
-
-  public static final Dimension DEFAULT_STRUCTURE_DIMENSIONS = new Dimension(
-          600, 600);
-
   static
   {
     // get links selected to be in the menu (SEQUENCE_LINKS)
@@ -798,16 +804,17 @@ public class Preferences extends GPreferences
             protColour.getSelectedItem().toString());
     Cache.setPropertyNoSave(DEFAULT_COLOUR_NUC,
             nucColour.getSelectedItem().toString());
-    Cache.setColourProperty(ANNOTATIONCOLOUR_MIN,
+    Cache.setColourPropertyNoSave(ANNOTATIONCOLOUR_MIN,
             minColour.getBackground());
-    Cache.setColourProperty(ANNOTATIONCOLOUR_MAX,
+    Cache.setColourPropertyNoSave(ANNOTATIONCOLOUR_MAX,
             maxColour.getBackground());
 
     /*
      * Save Overview settings
      */
-    Cache.setColourProperty(GAP_COLOUR, gapColour.getBackground());
-    Cache.setColourProperty(HIDDEN_COLOUR, hiddenColour.getBackground());
+    Cache.setColourPropertyNoSave(GAP_COLOUR, gapColour.getBackground());
+    Cache.setColourPropertyNoSave(HIDDEN_COLOUR,
+            hiddenColour.getBackground());
     Cache.setPropertyNoSave(USE_LEGACY_GAP,
             Boolean.toString(useLegacyGap.isSelected()));
     Cache.setPropertyNoSave(SHOW_OV_HIDDEN_AT_START,
@@ -935,7 +942,9 @@ public class Preferences extends GPreferences
             Boolean.toString(modellerOutput.isSelected()));
     Cache.setPropertyNoSave("EXPORT_EMBBED_BIOJSON",
             Boolean.toString(embbedBioJSON.isSelected()));
-    Cache.setPropertyNoSave(FIGURE_AUTOIDWIDTH,
+    jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected();
+
+    Cache.setPropertyNoSave("FIGURE_AUTOIDWIDTH",
             Boolean.toString(autoIdWidth.isSelected()));
     userIdWidth_actionPerformed();
     Cache.setPropertyNoSave("FIGURE_FIXEDIDWIDTH", userIdWidth.getText());
@@ -953,27 +962,31 @@ public class Preferences extends GPreferences
     if (!Platform.isJS())
     {
       wsPrefs.updateAndRefreshWsMenuConfig(false);
+    }
+
       /*
        * Save Backups settings
        */
-      Cache.setPropertyNoSave(BackupFiles.CONFIRM_DELETE_OLD,
-              Boolean.toString(backupfilesConfirmDelete.isSelected()));
-      Cache.setPropertyNoSave(BackupFiles.ENABLED,
+    Cache.setPropertyNoSave(BackupFiles.ENABLED,
               Boolean.toString(enableBackupFiles.isSelected()));
-      Cache.setPropertyNoSave(BackupFiles.NO_MAX,
-              Boolean.toString(backupfilesKeepAll.isSelected()));
-      Cache.setPropertyNoSave(BackupFiles.REVERSE_ORDER,
-              Boolean.toString(suffixReverse.isSelected()));
-      Cache.setPropertyNoSave(BackupFiles.SUFFIX, suffixTemplate.getText());
-      Cache.setPropertyNoSave(BackupFiles.ROLL_MAX, Integer
-              .toString(getSpinnerInt(backupfilesRollMaxSpinner, 4)));
-      Cache.setPropertyNoSave(BackupFiles.SUFFIX_DIGITS,
-              Integer.toString(getSpinnerInt(suffixDigitsSpinner, 3)));
-      Cache.setPropertyNoSave(BackupFiles.NS + "_PRESET", Integer
-              .toString(getComboIntStringKey(backupfilesPresetsCombo)));
+    int preset = getComboIntStringKey(backupfilesPresetsCombo);
+    Cache.setPropertyNoSave(BackupFiles.NS + "_PRESET",
+            Integer.toString(preset));
 
+    if (preset == BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM)
+    {
+      BackupFilesPresetEntry customBFPE = getBackupfilesCurrentEntry();
+      BackupFilesPresetEntry.backupfilesPresetEntriesValues.put(
+              BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM, customBFPE);
+      Cache.setPropertyNoSave(BackupFilesPresetEntry.CUSTOMCONFIG,
+              customBFPE.toString());
     }
 
+    BackupFilesPresetEntry savedBFPE = BackupFilesPresetEntry.backupfilesPresetEntriesValues
+            .get(preset);
+    Cache.setPropertyNoSave(BackupFilesPresetEntry.SAVEDCONFIG,
+            savedBFPE.toString());
+
     Cache.saveProperties();
     Desktop.getInstance().doConfigureStructurePrefs();
     try
@@ -1045,7 +1058,8 @@ public class Preferences extends GPreferences
   }
 
   /**
-   * DOCUMENT ME!
+   * Opens a file browser, and if a file is chosen, sets its path as the text of
+   * the 'startup file' text field
    */
   @Override
   public void startupFileTextfield_mouseClicked()
@@ -1065,8 +1079,10 @@ public class Preferences extends GPreferences
       FileFormatI format = chooser.getSelectedFormat();
       if (format != null)
       {
-        Cache.setPropertyNoSave("DEFAULT_FILE_FORMAT",
-                format.getName());
+        /*
+         * saving properties to file is deferred to the 'OK' action
+         */
+        Cache.setPropertyNoSave("DEFAULT_FILE_FORMAT", format.getName());
       }
       startupFileTextfield
               .setText(chooser.getSelectedFile().getAbsolutePath());
@@ -1499,36 +1515,40 @@ public class Preferences extends GPreferences
     {
       ListSelectionModel lsm = (ListSelectionModel) e.getSource();
 
-      int index = lsm.getMinSelectionIndex();
-      if (index == -1)
-      {
-        // no selection, so disable delete/edit buttons
-        editLink.setEnabled(false);
-        deleteLink.setEnabled(false);
-        return;
-      }
-      int modelIndex = linkUrlTable.convertRowIndexToModel(index);
+      updateValueChanged(lsm.getMinSelectionIndex());
+    }
+  }
 
-      // enable/disable edit and delete link buttons
-      if (((UrlLinkTableModel) linkUrlTable.getModel())
-              .isRowDeletable(modelIndex))
-      {
-        deleteLink.setEnabled(true);
-      }
-      else
-      {
-        deleteLink.setEnabled(false);
-      }
+  public void updateValueChanged(int index)
+  {
+    if (index == -1)
+    {
+      // no selection, so disable delete/edit buttons
+      editLink.setEnabled(false);
+      deleteLink.setEnabled(false);
+      return;
+    }
+    int modelIndex = linkUrlTable.convertRowIndexToModel(index);
 
-      if (((UrlLinkTableModel) linkUrlTable.getModel())
-              .isRowEditable(modelIndex))
-      {
-        editLink.setEnabled(true);
-      }
-      else
-      {
-        editLink.setEnabled(false);
-      }
+    // enable/disable edit and delete link buttons
+    if (((UrlLinkTableModel) linkUrlTable.getModel())
+            .isRowDeletable(modelIndex))
+    {
+      deleteLink.setEnabled(true);
+    }
+    else
+    {
+      deleteLink.setEnabled(false);
+    }
+
+    if (((UrlLinkTableModel) linkUrlTable.getModel())
+            .isRowEditable(modelIndex))
+    {
+      editLink.setEnabled(true);
+    }
+    else
+    {
+      editLink.setEnabled(false);
     }
   }
 }