Merge branch 'develop' into Jalview-JS/develop
[jalview.git] / src / jalview / gui / Preferences.java
index aeac55f..04b83a3 100755 (executable)
@@ -23,8 +23,9 @@ package jalview.gui;
 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
 import jalview.bin.Cache;
 import jalview.gui.Help.HelpId;
-import jalview.gui.JalviewColourChooser.ColourChooserListener;
 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;
@@ -55,7 +56,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import javax.help.HelpSetException;
-import javax.swing.JColorChooser;
+import javax.swing.JComboBox;
 import javax.swing.JFileChooser;
 import javax.swing.JInternalFrame;
 import javax.swing.JPanel;
@@ -189,11 +190,18 @@ public class Preferences extends GPreferences
     super();
     frame = new JInternalFrame();
     frame.setContentPane(this);
-    wsPrefs = new WsPreferences();
-    wsTab.add(wsPrefs, BorderLayout.CENTER);
+    if (!Platform.isJS())
+    /**
+     * Java only
+     * 
+     * @j2sIgnore
+     */
+    {
+      wsPrefs = new WsPreferences();
+      wsTab.add(wsPrefs, BorderLayout.CENTER);
+    }
     int width = 500, height = 450;
-    new jalview.util.Platform();
-    if (Platform.isAMac())
+    if (Platform.isAMacAndNotJS())
     {
       width = 570;
       height = 480;
@@ -252,7 +260,7 @@ public class Preferences extends GPreferences
     fontStyleCB.setSelectedItem(
             Cache.getDefault("FONT_STYLE", Font.PLAIN + ""));
 
-    smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false));
+    smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", true));
     scaleProteinToCdna
             .setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, false));
 
@@ -326,7 +334,7 @@ public class Preferences extends GPreferences
     gapLabel.setEnabled(!useLegacyGap.isSelected());
     gapColour.setEnabled(!useLegacyGap.isSelected());
     showHiddenAtStart
-            .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, true));
+            .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, false));
 
     /*
      * Set Structure tab defaults.
@@ -383,7 +391,8 @@ public class Preferences extends GPreferences
             new RowSorter.SortKey(m.getNameColumn(), SortOrder.ASCENDING));
 
     sorter.setSortKeys(sortKeys);
-    sorter.sort();
+    // BH 2018 setSortKeys will do the sort
+    // sorter.sort();
 
     // set up filtering
     ActionListener onReset;
@@ -502,23 +511,9 @@ public class Preferences extends GPreferences
     /*
      * Set Output tab defaults
      */
-    epsRendering.addItem(promptEachTimeOpt);
-    epsRendering.addItem(lineArtOpt);
-    epsRendering.addItem(textOpt);
-    String defaultEPS = Cache.getDefault("EPS_RENDERING",
-            "Prompt each time");
-    if (defaultEPS.equalsIgnoreCase("Text"))
-    {
-      epsRendering.setSelectedItem(textOpt);
-    }
-    else if (defaultEPS.equalsIgnoreCase("Lineart"))
-    {
-      epsRendering.setSelectedItem(lineArtOpt);
-    }
-    else
-    {
-      epsRendering.setSelectedItem(promptEachTimeOpt);
-    }
+    setupOutputCombo(epsRendering, "EPS_RENDERING");
+    setupOutputCombo(htmlRendering, "HTML_RENDERING");
+    setupOutputCombo(svgRendering, "SVG_RENDERING");
     autoIdWidth.setSelected(Cache.getDefault("FIGURE_AUTOIDWIDTH", false));
     userIdWidth.setEnabled(!autoIdWidth.isSelected());
     userIdWidthlabel.setEnabled(!autoIdWidth.isSelected());
@@ -547,6 +542,45 @@ public class Preferences extends GPreferences
 
     annotations_actionPerformed(null); // update the display of the annotation
                                        // settings
+    
+    
+    /*
+     * Set Backups tab defaults
+     */
+    loadLastSavedBackupsOptions();
+  }
+
+  /**
+   * A helper method that sets the items and initial selection in a character
+   * rendering option list (Prompt each time/Lineart/Text)
+   * 
+   * @param comboBox
+   * @param propertyKey
+   */
+  protected void setupOutputCombo(JComboBox<Object> comboBox,
+          String propertyKey)
+  {
+    comboBox.addItem(promptEachTimeOpt);
+    comboBox.addItem(lineArtOpt);
+    comboBox.addItem(textOpt);
+    
+    /*
+     * JalviewJS doesn't support Lineart so force it to Text
+     */
+    String defaultOption = Platform.isJS() ? "Text"
+            : Cache.getDefault(propertyKey, "Prompt each time");
+    if (defaultOption.equalsIgnoreCase("Text"))
+    {
+      comboBox.setSelectedItem(textOpt);
+    }
+    else if (defaultOption.equalsIgnoreCase("Lineart"))
+    {
+      comboBox.setSelectedItem(lineArtOpt);
+    }
+    else
+    {
+      comboBox.setSelectedItem(promptEachTimeOpt);
+    }
   }
 
   /**
@@ -685,6 +719,10 @@ public class Preferences extends GPreferences
      */
     Cache.applicationProperties.setProperty("EPS_RENDERING",
             ((OptionsParam) epsRendering.getSelectedItem()).getCode());
+    Cache.applicationProperties.setProperty("HTML_RENDERING",
+            ((OptionsParam) htmlRendering.getSelectedItem()).getCode());
+    Cache.applicationProperties.setProperty("SVG_RENDERING",
+            ((OptionsParam) svgRendering.getSelectedItem()).getCode());
 
     /*
      * Save Connections settings
@@ -794,7 +832,34 @@ public class Preferences extends GPreferences
     Cache.applicationProperties.setProperty("PAD_GAPS",
             Boolean.toString(padGaps.isSelected()));
 
-    wsPrefs.updateAndRefreshWsMenuConfig(false);
+    if (!Platform.isJS())
+    {
+      wsPrefs.updateAndRefreshWsMenuConfig(false);
+    }
+
+    /*
+     * Save Backups settings
+     */
+    Cache.applicationProperties.setProperty(BackupFiles.ENABLED,
+            Boolean.toString(enableBackupFiles.isSelected()));
+    int preset = getComboIntStringKey(backupfilesPresetsCombo);
+    Cache.applicationProperties.setProperty(BackupFiles.NS + "_PRESET", Integer.toString(preset));
+
+    if (preset == BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM)
+    {
+      BackupFilesPresetEntry customBFPE = getBackupfilesCurrentEntry();
+      BackupFilesPresetEntry.backupfilesPresetEntriesValues.put(
+              BackupFilesPresetEntry.BACKUPFILESSCHEMECUSTOM, customBFPE);
+      Cache.applicationProperties
+              .setProperty(BackupFilesPresetEntry.CUSTOMCONFIG,
+                      customBFPE.toString());
+    }
+
+    BackupFilesPresetEntry savedBFPE = BackupFilesPresetEntry.backupfilesPresetEntriesValues
+            .get(preset);
+    Cache.applicationProperties.setProperty(
+            BackupFilesPresetEntry.SAVEDCONFIG, savedBFPE.toString());
+
     Cache.saveProperties();
     Desktop.instance.doConfigureStructurePrefs();
     try
@@ -868,8 +933,11 @@ public class Preferences extends GPreferences
   {
     try
     {
-      wsPrefs.updateWsMenuConfig(true);
-      wsPrefs.refreshWs_actionPerformed(e);
+      if (!Platform.isJS())
+      {
+        wsPrefs.updateWsMenuConfig(true);
+        wsPrefs.refreshWs_actionPerformed(e);
+      }
       frame.setClosed(true);
     } catch (Exception ex)
     {
@@ -1009,8 +1077,11 @@ public class Preferences extends GPreferences
   public void defaultBrowser_mouseClicked(MouseEvent e)
   {
     // TODO: JAL-3048 not needed for j2s
-    /*
-     * @j2sNative
+    if (!Platform.isJS()) // BH 2019
+    /**
+     * Java only
+     * 
+     * @j2sIgnore
      */
     {
       JFileChooser chooser = new JFileChooser(".");
@@ -1103,7 +1174,7 @@ public class Preferences extends GPreferences
   {
     useLegacyGap.setSelected(false);
     useLegacyGaps_actionPerformed(null);
-    showHiddenAtStart.setSelected(true);
+    showHiddenAtStart.setSelected(false);
     hiddenColour.setBackground(
             jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
   }
@@ -1125,12 +1196,12 @@ public class Preferences extends GPreferences
       }
     } catch (NumberFormatException x)
     {
+      userIdWidth.setText("");
       JvOptionPane.showInternalMessageDialog(Desktop.desktop,
               MessageManager
                       .getString("warn.user_defined_width_requirements"),
               MessageManager.getString("label.invalid_id_column_width"),
               JvOptionPane.WARNING_MESSAGE);
-      userIdWidth.setText("");
     }
   }