From: Ben Soares Date: Wed, 23 Jan 2019 20:33:20 +0000 (+0000) Subject: JAL-3141 Added Presets options in the Backups Preferences pane, with several presets... X-Git-Tag: Release_2_11_0~17^2~97^2~20 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=c860648463c56ba9f75e9d239e2f56edea8e31e7;p=jalview.git JAL-3141 Added Presets options in the Backups Preferences pane, with several presets available and sensible 'Default' option chosen first time. --- diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 2e9390b..960e40f 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1385,3 +1385,9 @@ label.braced_oldest = (oldest) label.braced_newest = (most recent) label.configuration = Configuration label.configure_feature_tooltip = Click to configure variable colour or filters +label.presets = Presets +label.custom = Custom +label.default = Default +label.single_file = Single backup +label.keep_everything = Keep everything +label.rolled_backups = Rolled backup files diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index 824dae3..acadc8e 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -1386,3 +1386,9 @@ label.braced_oldest = (mas antiguo) label.braced_newest = (mas nuevo) label.configuration = ConfiguraciĆ³n label.configure_feature_tooltip = Haga clic para configurar el color o los filtros +label.presets = PreconfiguraciĆ³n +label.custom = Personalizado +label.default = Defecto +label.single_file = Solo uno respaldo +label.keep_everything = Mantenga todos +label.rolled_backups = Ciclos resaldos diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index bee6a73..c8f8b25 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -566,7 +566,9 @@ public class Preferences extends GPreferences .setValue(Cache.getDefault(BackupFiles.ROLL_MAX, 4)); backupfilesConfirmDelete.setSelected( Cache.getDefault(BackupFiles.CONFIRM_DELETE_OLD, true)); + setComboIntStringKey(backupfilesPresetsCombo, Cache.getDefault(BackupFiles.NS+"_PRESET", 0)); backupsOptionsSetEnabled(enableBackupFiles.isSelected()); + updateBackupFilesExampleLabel(); /* suffixPanel.setPreferredSize( @@ -843,6 +845,8 @@ public class Preferences extends GPreferences Integer.toString(getSpinnerInt(backupfilesRollMaxSpinner, 4))); Cache.applicationProperties.setProperty(BackupFiles.SUFFIX_DIGITS, Integer.toString(getSpinnerInt(suffixDigitsSpinner, 3))); + Cache.applicationProperties.setProperty(BackupFiles.NS+"_PRESET", + Integer.toString(getComboIntStringKey(backupfilesPresetsCombo))); Cache.saveProperties(); Desktop.instance.doConfigureStructurePrefs(); diff --git a/src/jalview/io/BackupFiles.java b/src/jalview/io/BackupFiles.java index 5f40cb4..aafe8f2 100644 --- a/src/jalview/io/BackupFiles.java +++ b/src/jalview/io/BackupFiles.java @@ -28,7 +28,7 @@ public class BackupFiles { // labels for saved params in Cache and .jalview_properties - private static final String NS = "BACKUPFILES"; + public static final String NS = "BACKUPFILES"; public static final String ENABLED = NS + "_ENABLED"; diff --git a/src/jalview/jbgui/GPreferences.java b/src/jalview/jbgui/GPreferences.java index 4aabd1c..58737ee 100755 --- a/src/jalview/jbgui/GPreferences.java +++ b/src/jalview/jbgui/GPreferences.java @@ -27,6 +27,7 @@ import jalview.gui.JalviewBooleanRadioButtons; import jalview.gui.JvSwingUtils; import jalview.gui.StructureViewer.ViewerType; import jalview.io.BackupFilenameFilter; +import jalview.io.BackupFiles; import jalview.util.MessageManager; import java.awt.BorderLayout; @@ -48,6 +49,9 @@ import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; import javax.swing.AbstractCellEditor; import javax.swing.BorderFactory; @@ -289,6 +293,10 @@ public class GPreferences extends JPanel protected JCheckBox enableBackupFiles = new JCheckBox(); + protected JPanel presetsPanel = new JPanel(); + + protected JComboBox backupfilesPresetsCombo = new JComboBox<>(); + protected JPanel suffixPanel = new JPanel(); protected JPanel keepfilesPanel = new JPanel(); @@ -307,7 +315,7 @@ public class GPreferences extends JPanel protected JalviewBooleanRadioButtons backupfilesKeepAll = new JalviewBooleanRadioButtons(); - protected JSpinner backupfilesRollMaxSpinner = new JSpinner(); + public JSpinner backupfilesRollMaxSpinner = new JSpinner(); protected JLabel oldBackupFilesLabel = new JLabel(); @@ -1702,6 +1710,7 @@ public class GPreferences extends JPanel gbc.anchor = GridBagConstraints.NORTHWEST; gbc.fill = GridBagConstraints.NONE; + initBackupsTabPresetsPanel(); initBackupsTabSuffixPanel(); initBackupsTabKeepFilesPanel(); initBackupsTabFilenameExamplesPanel(); @@ -1723,24 +1732,32 @@ public class GPreferences extends JPanel // enable checkbox 1 row gbc.gridwidth = 1; + gbc.gridx = 0; gbc.gridy = 0; backupsTab.add(enableBackupFiles, gbc); + gbc.gridx = 1; gbc.weightx = 1.0; + gbc.gridheight = 2; //gbc.anchor = GridBagConstraints.NORTHEAST; //gbc.fill = GridBagConstraints.HORIZONTAL; backupsTab.add(exampleFilesPanel, gbc); + gbc.gridx = 0; + gbc.gridy = 1; + backupsTab.add(presetsPanel, gbc); + gbc.anchor = GridBagConstraints.NORTHWEST; gbc.fill = GridBagConstraints.NONE; gbc.gridwidth = 2; + gbc.gridheight = 1; // whole suffix panel next row gbc.gridx = 0; - gbc.gridy = 1; + gbc.gridy = 2; backupsTab.add(suffixPanel, gbc); // keep files panel - gbc.gridy = 2; + gbc.gridy = 3; backupsTab.add(keepfilesPanel, gbc); /* @@ -1758,8 +1775,96 @@ public class GPreferences extends JPanel return backupsTab; } + private final IntKeyStringValueEntry[] backupfilesPresetEntries = + { + new IntKeyStringValueEntry(1, MessageManager.getString("label.default")), + new IntKeyStringValueEntry(2, MessageManager.getString("label.single_file")), + new IntKeyStringValueEntry(3, MessageManager.getString("label.keep_everything")), + new IntKeyStringValueEntry(4, MessageManager.getString("label.rolled_backups")), + // ... + // IMPORTANT, keep "Custom" entry with key 0 (even though it appears last) + new IntKeyStringValueEntry(0, MessageManager.getString("label.custom")) + }; + + private final Map backupfilesPresetEntriesValues = new HashMap() + {{ + put(1, new BackupFilesPresetEntry(".v"+BackupFiles.NUM_PLACEHOLDER, 3, false, false, 4, false)); + put(2, new BackupFilesPresetEntry("~", 1, false, false, 1, false)); + put(3, new BackupFilesPresetEntry(".v"+BackupFiles.NUM_PLACEHOLDER, 3, false, true, 10, true)); + put(4, new BackupFilesPresetEntry("_bak."+BackupFiles.NUM_PLACEHOLDER, 1, true, false, 9, false)); + }}; + + private JPanel initBackupsTabPresetsPanel() + { + presetsPanel.setBorder(new TitledBorder( + MessageManager.getString("label.presets"))); + + for (int i = 0; i < backupfilesPresetEntries.length; i++) + { + backupfilesPresetsCombo.addItem(backupfilesPresetEntries[i]); + } - public JPanel initBackupsTabSuffixPanel() + backupfilesPresetsCombo.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + backupsTabUpdatePresets(); + } + } + ); + + presetsPanel.add(backupfilesPresetsCombo); + return presetsPanel; + } + + private void backupsTabUpdatePresets() + { + IntKeyStringValueEntry entry = (IntKeyStringValueEntry) backupfilesPresetsCombo.getSelectedItem(); + int key = entry.getKey(); + String value = entry.getValue(); + boolean custom = key==0; + + if (custom) + { + //backupsSetCustomOptions(); + } else + { + if (backupfilesPresetEntriesValues.containsKey(key)) + { + backupsSetOptions(backupfilesPresetEntriesValues.get(key)); + } else { + System.out.println("Preset '"+value+"' not implemented yet"); + } + } + + updateBackupFilesExampleLabel(); + backupsCustomOptionsSetEnabled(custom); + } + + protected int getComboIntStringKey(JComboBox c) + { + IntKeyStringValueEntry e = (IntKeyStringValueEntry) c.getSelectedItem(); + return e!=null?e.getKey():0; + } + + protected void setComboIntStringKey(JComboBox c, int key) + { + for (int i=0; i < c.getItemCount(); i++) + { + IntKeyStringValueEntry e = c.getItemAt(i); + int k = e.getKey(); + String v = e.getValue(); + if (e.getKey() == key) + { + c.setSelectedIndex(i); + break; + } + } + backupsTabUpdatePresets(); + } + + private JPanel initBackupsTabSuffixPanel() { suffixPanel.setBorder(new TitledBorder( MessageManager.getString("label.suffix_format"))); @@ -1881,6 +1986,12 @@ public class GPreferences extends JPanel return suffixPanel; } + private void backupfilesKeepAllEnabled(boolean enabled) + { + backupfilesKeepAll.setEnabled(enabled); + keepRollMaxOptionsEnabled(); + } + private JPanel initBackupsTabKeepFilesPanel() { keepfilesPanel.setBorder( @@ -1905,7 +2016,7 @@ public class GPreferences extends JPanel public void actionPerformed(ActionEvent e) { boolean selected = backupfilesKeepAll.isSelected(); - keepRollMaxOptionsEnabled(!selected); + keepRollMaxOptionsEnabled(); updateBackupFilesExampleLabel(); } }); @@ -1925,7 +2036,7 @@ public class GPreferences extends JPanel MessageManager.getString("label.confirm_delete"), MessageManager.getString("label.auto_delete")); // update the enabled section - keepRollMaxOptionsEnabled(!backupfilesKeepAll.isSelected()); + keepRollMaxOptionsEnabled(); GridBagConstraints kgbc = new GridBagConstraints(); @@ -2190,7 +2301,7 @@ public class GPreferences extends JPanel } - public static int getSpinnerInt(JSpinner s, int def) + protected static int getSpinnerInt(JSpinner s, int def) { int i = def; try @@ -2204,32 +2315,70 @@ public class GPreferences extends JPanel return i; } - private void keepRollMaxOptionsEnabled(boolean enabled) + protected void keepRollMaxOptionsEnabled() { + keepRollMaxOptionsEnabled(backupfilesKeepAll.isEnabled()); + } + + protected void keepRollMaxOptionsEnabled(boolean tryEnabled) + { + boolean enabled = tryEnabled && !backupfilesKeepAll.isSelected(); oldBackupFilesLabel.setEnabled(enabled); backupfilesRollMaxSpinner.setEnabled(enabled); backupfilesConfirmDelete.setEnabled(enabled); + } + protected void backupsCustomOptionsSetEnabled(boolean enabled) + { + backupsOptionsSetEnabled(enabled, false); } protected void backupsOptionsSetEnabled(boolean enabled) { + backupsOptionsSetEnabled(enabled, true); + } + + protected void backupsOptionsSetEnabled(boolean enabled, boolean all) + { + + if (all) + { + presetsPanel.setEnabled(enabled); + exampleFilesPanel.setEnabled(enabled); + + backupfilesPresetsCombo.setEnabled(enabled); + backupfilesExampleLabel.setEnabled(enabled); + } suffixPanel.setEnabled(enabled); keepfilesPanel.setEnabled(enabled); - exampleFilesPanel.setEnabled(enabled); suffixTemplate.setEnabled(enabled); suffixTemplateLabel.setEnabled(enabled); suffixDigitsLabel.setEnabled(enabled); suffixDigitsSpinner.setEnabled(enabled); suffixReverse.setEnabled(enabled); - backupfilesKeepAll.setEnabled(enabled); - backupfilesRollMaxSpinner.setEnabled(enabled); oldBackupFilesLabel.setEnabled(enabled); - backupfilesConfirmDelete.setEnabled(enabled); - backupfilesExampleLabel.setEnabled(enabled); + backupfilesKeepAllEnabled(enabled); + + if (enabled && all) + { + backupsTabUpdatePresets(); + } + } - keepRollMaxOptionsEnabled(enabled && !backupfilesKeepAll.isSelected()); + protected void backupsSetOptions(String suffix, int digits, boolean reverse, boolean keepAll, int rollMax, boolean confirmDelete) + { + suffixTemplate.setText(suffix); + suffixDigitsSpinner.setValue(digits); + suffixReverse.setSelected(reverse); + backupfilesKeepAll.setSelected(keepAll); + backupfilesRollMaxSpinner.setValue(rollMax); + backupfilesConfirmDelete.setSelected(confirmDelete); + } + + protected void backupsSetOptions(BackupFilesPresetEntry p) + { + backupsSetOptions(p.suffix, p.digits, p.reverse, p.keepAll, p.rollMax, p.confirmDelete); } protected void autoIdWidth_actionPerformed() @@ -2417,3 +2566,44 @@ public class GPreferences extends JPanel } } + +class IntKeyStringValueEntry { + int k; + String v; + public IntKeyStringValueEntry(int k, String v) + { + this.k = k; + this.v = v; + } + @Override + public String toString() + { + return this.getValue(); + } + public int getKey() + { + return k; + } + public String getValue() + { + return v; + } +} + +class BackupFilesPresetEntry { + String suffix; + int digits; + boolean reverse; + boolean keepAll; + int rollMax; + boolean confirmDelete; + public BackupFilesPresetEntry(String suffix, int digits, boolean reverse, boolean keepAll, int rollMax, boolean confirmDelete) + { + this.suffix = suffix; + this.digits = digits; + this.reverse = reverse; + this.keepAll = keepAll; + this.rollMax = rollMax; + this.confirmDelete = confirmDelete; + } +}