JAL-3878 update branch from 2.12 merge from 2.11.2
[jalview.git] / src / jalview / gui / Preferences.java
index 6fd7b7a..19d929e 100755 (executable)
@@ -20,7 +20,6 @@
  */
 package jalview.gui;
 
-
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Component;
@@ -59,7 +58,11 @@ import jalview.hmmer.HmmerCommand;
 import jalview.util.FileUtils;
 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
 import jalview.bin.Cache;
+import jalview.bin.Console;
+import jalview.bin.MemorySetting;
 import jalview.ext.pymol.PymolManager;
 import jalview.gui.Help.HelpId;
 import jalview.gui.StructureViewer.ViewerType;
@@ -88,7 +91,6 @@ import jalview.ws.sifts.SiftsSettings;
  * @author $author$
  * @version $Revision$
  */
-
 public class Preferences extends GPreferences implements ApplicationSingletonI
 {
   // suggested list delimiter character
@@ -174,7 +176,6 @@ public class Preferences extends GPreferences implements ApplicationSingletonI
   public static final String PAD_GAPS = "PAD_GAPS";
 
   public static final String PDB_DOWNLOAD_FORMAT = "PDB_DOWNLOAD_FORMAT";
-
   public static final String PYMOL_PATH = "PYMOL_PATH";
 
   public static final String QUESTIONNAIRE = "QUESTIONNAIRE";
@@ -246,6 +247,7 @@ public class Preferences extends GPreferences implements ApplicationSingletonI
   private String previousProxyType;
 
   private static Preferences INSTANCE = null; // add "final"
+
   /**
    * Holds name and link separated with | character. Sequence ID must be
    * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$
@@ -351,6 +353,7 @@ public class Preferences extends GPreferences implements ApplicationSingletonI
       this.setMessage(message);
     this.frame.show();
   }
+
   /**
    * Creates a new Preferences object.
    */
@@ -576,6 +579,7 @@ public class Preferences extends GPreferences implements ApplicationSingletonI
     addSecondaryStructure.setEnabled(structSelected);
     addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, true));
     addTempFactor.setEnabled(structSelected);
+
     /*
      * set choice of structure viewer, and path if saved as a preference;
      * default to Jmol (first choice) if an unexpected value is found
@@ -609,7 +613,7 @@ public class Preferences extends GPreferences implements ApplicationSingletonI
       }
     } catch (IllegalArgumentException e)
     {
-      Cache.log.error("Unknown structure viewer type: " + viewerType
+      Console.error("Unknown structure viewer type: " + viewerType
               + ", defaulting to Jmol");
       type = ViewerType.JMOL;
     }
@@ -623,26 +627,27 @@ public class Preferences extends GPreferences implements ApplicationSingletonI
         if (validateViewerPath())
         {
           String path = structureViewerPath.getText();
-          try {
-          ViewerType type = ViewerType.valueOf(viewerType);
-          switch (type)
+          try
+          {
+            ViewerType type = ViewerType.valueOf(viewerType);
+            switch (type)
+            {
+            case JMOL:
+              break;
+            case CHIMERA:
+              Cache.setProperty(CHIMERA_PATH, path);
+              break;
+            case CHIMERAX:
+              Cache.setProperty(CHIMERAX_PATH, path);
+              break;
+            case PYMOL:
+              Cache.setProperty(PYMOL_PATH, path);
+              break;
+            }
+          } catch (IllegalArgumentException x)
           {
-          case JMOL:
-            break;
-          case CHIMERA:
-            Cache.setProperty(CHIMERA_PATH, path);
-            break;
-          case CHIMERAX:
-            Cache.setProperty(CHIMERAX_PATH, path);
-            break;
-          case PYMOL:
-            Cache.setProperty(PYMOL_PATH, path);
-            break;
+            Console.error("Failed to set path - unknown viewer type", x);
           }
-        } catch (IllegalArgumentException x)
-        {
-          Cache.log.error("Failed to set path - unknown viewer type",x);
-        }
         }
       }
     });
@@ -797,7 +802,7 @@ public class Preferences extends GPreferences implements ApplicationSingletonI
       proxyType.setSelected(customProxy.getModel(), true);
       break;
     default:
-      Cache.log.warn(
+      Console.warn(
               "Incorrect PROXY_TYPE - should be 'none' (clear proxy properties), 'false' (system settings), 'true' (custom settings): "
                       + proxyTypeString);
     }
@@ -856,6 +861,7 @@ public class Preferences extends GPreferences implements ApplicationSingletonI
 
     annotations_actionPerformed(null); // update the display of the annotation
                                        // settings
+
     
     
     /*
@@ -877,6 +883,7 @@ public class Preferences extends GPreferences implements ApplicationSingletonI
     comboBox.addItem(promptEachTimeOpt);
     comboBox.addItem(lineArtOpt);
     comboBox.addItem(textOpt);
+
     
     /*
      * JalviewJS doesn't support Lineart so force it to Text
@@ -915,6 +922,7 @@ public class Preferences extends GPreferences implements ApplicationSingletonI
      * Set proxy settings first (to be before web services refresh)
      */
     saveProxySettings();
+
     /*
      * Save Visual settings
      */
@@ -1197,15 +1205,14 @@ public class Preferences extends GPreferences implements ApplicationSingletonI
     Cache.setPropertyNoSave(BackupFiles.ENABLED,
             Boolean.toString(enableBackupFiles.isSelected()));
     int preset = getComboIntStringKey(backupfilesPresetsCombo);
-    Cache.applicationProperties.setProperty(BackupFiles.NS + "_PRESET", Integer.toString(preset));
+    Cache.setPropertyNoSave(BackupFiles.NS + "_PRESET", Integer.toString(preset));
 
     if (preset == BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM)
     {
       BackupFilesPresetEntry customBFPE = getBackupfilesCurrentEntry();
       BackupFilesPresetEntry.backupfilesPresetEntriesValues.put(
               BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM, customBFPE);
-      Cache.applicationProperties
-              .setProperty(BackupFilesPresetEntry.CUSTOMCONFIG,
+      Cache.setPropertyNoSave(BackupFilesPresetEntry.CUSTOMCONFIG,
                       customBFPE.toString());
     }
 
@@ -1214,6 +1221,20 @@ public class Preferences extends GPreferences implements ApplicationSingletonI
     Cache.setPropertyNoSave(
             BackupFilesPresetEntry.SAVEDCONFIG, savedBFPE.toString());
 
+    /*
+     * Save Memory Settings
+     */
+    Cache.setPropertyNoSave(
+            MemorySetting.CUSTOMISED_SETTINGS,
+            Boolean.toString(customiseMemorySetting.isSelected()));
+    Cache.setPropertyNoSave(MemorySetting.MEMORY_JVMMEMPC,
+            Integer.toString(jvmMemoryPercentSlider.getValue()));
+    Cache.setPropertyNoSave(MemorySetting.MEMORY_JVMMEMMAX,
+            jvmMemoryMaxTextField.getText());
+
+    /*
+     * save and close Preferences
+     */
     Cache.saveProperties();
     Desktop.getInstance().doConfigureStructurePrefs();
     try
@@ -1223,6 +1244,7 @@ public class Preferences extends GPreferences implements ApplicationSingletonI
     {
     }
   }
+
   public void saveProxySettings()
   {
     String newProxyType = customProxy.isSelected() ? Cache.PROXYTYPE_CUSTOM
@@ -1242,7 +1264,7 @@ public class Preferences extends GPreferences implements ApplicationSingletonI
             || !newProxyType.equals(previousProxyType))
     {
       // force a re-lookup of ws if proxytype is custom or has changed
-      wsPrefs.update++;
+      wsPrefs.refreshWs_actionPerformed(null);
     }
     previousProxyType = newProxyType;
   }
@@ -1424,7 +1446,7 @@ public class Preferences extends GPreferences implements ApplicationSingletonI
     if (index == -1)
     {
       // button no longer enabled if row is not selected
-      Cache.log.debug("Edit with no row selected in linkUrlTable");
+      Console.debug("Edit with no row selected in linkUrlTable");
       return;
     }
 
@@ -1476,7 +1498,7 @@ public class Preferences extends GPreferences implements ApplicationSingletonI
     if (index == -1)
     {
       // button no longer enabled if row is not selected
-      Cache.log.debug("Delete with no row selected in linkUrlTable");
+      Console.debug("Delete with no row selected in linkUrlTable");
       return;
     }
     else
@@ -1760,6 +1782,7 @@ public class Preferences extends GPreferences implements ApplicationSingletonI
         break;
       }
     }
+
     if (!found)
     {
       String[] options = { "OK", "Help" };
@@ -1768,6 +1791,7 @@ public class Preferences extends GPreferences implements ApplicationSingletonI
                       MessageManager.getString("label.viewer_missing")),
               "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE,
               null, options, options[0]);
+
       if (showHelp == JvOptionPane.NO_OPTION)
       {
         this.selectTab(Preferences.TabRef.STRUCTURE_TAB, null);