Merge branch 'develop' into Jalview-JS/develop
[jalview.git] / src / jalview / gui / Preferences.java
index e1c6089..04b83a3 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;
@@ -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());
@@ -552,30 +547,40 @@ public class Preferences extends GPreferences
     /*
      * Set Backups tab defaults
      */
-    enableBackupFiles
-            .setSelected(Cache.getDefault(BackupFiles.ENABLED, true));
-    suffixTemplate.setText(Cache.getDefault(BackupFiles.SUFFIX,
-            "-v" + BackupFiles.getNumPlaceHolder()));
-    suffixDigitsSpinner
-            .setValue(Cache.getDefault(BackupFiles.SUFFIX_DIGITS, 3));
-    suffixReverse.setSelected(
-            Cache.getDefault(BackupFiles.REVERSE_ORDER, false));
-    backupfilesKeepAll
-            .setSelected(Cache.getDefault(BackupFiles.NO_MAX, false));
-    backupfilesRollMaxSpinner
-            .setValue(Cache.getDefault(BackupFiles.ROLL_MAX, 4));
-    backupfilesConfirmDelete.setSelected(
-            Cache.getDefault(BackupFiles.CONFIRM_DELETE_OLD, true));
-    backupsOptionsSetEnabled(enableBackupFiles.isSelected());
-    /*
-    suffixPanel.setPreferredSize(
-            new Dimension(width, suffixPanel.getHeight()));
-    keepfilesPanel.setPreferredSize(
-            new Dimension(width, keepfilesPanel.getHeight()));
-    exampleFilesPanel.setPreferredSize(
-            new Dimension(width, exampleFilesPanel.getHeight()));
-            */
+    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);
+    }
   }
 
   /**
@@ -714,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
@@ -823,25 +832,33 @@ 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.CONFIRM_DELETE_OLD,
-            Boolean.toString(backupfilesConfirmDelete.isSelected()));
     Cache.applicationProperties.setProperty(BackupFiles.ENABLED,
             Boolean.toString(enableBackupFiles.isSelected()));
-    Cache.applicationProperties.setProperty(BackupFiles.NO_MAX,
-            Boolean.toString(backupfilesKeepAll.isSelected()));
-    Cache.applicationProperties.setProperty(BackupFiles.REVERSE_ORDER,
-            Boolean.toString(suffixReverse.isSelected()));
-    Cache.applicationProperties.setProperty(BackupFiles.SUFFIX,
-            suffixTemplate.getText());
-    Cache.applicationProperties.setProperty(BackupFiles.ROLL_MAX,
-            Integer.toString(getSpinnerInt(backupfilesRollMaxSpinner, 4)));
-    Cache.applicationProperties.setProperty(BackupFiles.SUFFIX_DIGITS,
-            Integer.toString(getSpinnerInt(suffixDigitsSpinner, 3)));
+    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();
@@ -882,6 +899,7 @@ public class Preferences extends GPreferences
   @Override
   public void startupFileTextfield_mouseClicked()
   {
+    // TODO: JAL-3048 not needed for Jalview-JS
     String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
     JalviewFileChooser chooser = JalviewFileChooser
             .forRead(Cache.getProperty("LAST_DIRECTORY"), fileFormat);
@@ -915,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)
     {
@@ -1055,17 +1076,25 @@ public class Preferences extends GPreferences
   @Override
   public void defaultBrowser_mouseClicked(MouseEvent e)
   {
-    JFileChooser chooser = new JFileChooser(".");
-    chooser.setDialogTitle(
-            MessageManager.getString("label.select_default_browser"));
+    // TODO: JAL-3048 not needed for j2s
+    if (!Platform.isJS()) // BH 2019
+    /**
+     * Java only
+     * 
+     * @j2sIgnore
+     */
+    {
+      JFileChooser chooser = new JFileChooser(".");
+      chooser.setDialogTitle(
+              MessageManager.getString("label.select_default_browser"));
 
-    int value = chooser.showOpenDialog(this);
+      int value = chooser.showOpenDialog(this);
 
-    if (value == JFileChooser.APPROVE_OPTION)
-    {
-      defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
+      if (value == JFileChooser.APPROVE_OPTION)
+      {
+        defaultBrowser.setText(chooser.getSelectedFile().getAbsolutePath());
+      }
     }
-
   }
 
   /*
@@ -1090,27 +1119,17 @@ public class Preferences extends GPreferences
   @Override
   public void minColour_actionPerformed(JPanel panel)
   {
-    Color col = JColorChooser.showDialog(this,
+    JalviewColourChooser.showColourChooser(this,
             MessageManager.getString("label.select_colour_minimum_value"),
-            minColour.getBackground());
-    if (col != null)
-    {
-      panel.setBackground(col);
-    }
-    panel.repaint();
+            panel);
   }
 
   @Override
   public void maxColour_actionPerformed(JPanel panel)
   {
-    Color col = JColorChooser.showDialog(this,
+    JalviewColourChooser.showColourChooser(this,
             MessageManager.getString("label.select_colour_maximum_value"),
-            maxColour.getBackground());
-    if (col != null)
-    {
-      panel.setBackground(col);
-    }
-    panel.repaint();
+            panel);
   }
 
   @Override
@@ -1118,28 +1137,18 @@ public class Preferences extends GPreferences
   {
     if (!useLegacyGap.isSelected())
     {
-      Color col = JColorChooser.showDialog(this,
+      JalviewColourChooser.showColourChooser(this,
               MessageManager.getString("label.select_gap_colour"),
-              gapColour.getBackground());
-      if (col != null)
-      {
-        gap.setBackground(col);
-      }
-      gap.repaint();
+              gap);
     }
   }
 
   @Override
   public void hiddenColour_actionPerformed(JPanel hidden)
   {
-    Color col = JColorChooser.showDialog(this,
+    JalviewColourChooser.showColourChooser(this,
             MessageManager.getString("label.select_hidden_colour"),
-            hiddenColour.getBackground());
-    if (col != null)
-    {
-      hidden.setBackground(col);
-    }
-    hidden.repaint();
+            hidden);
   }
 
   @Override
@@ -1165,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);
   }
@@ -1187,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("");
     }
   }