*/
package jalview.jbgui;
+import jalview.bin.Cache;
import jalview.fts.core.FTSDataColumnPreferences;
import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource;
import jalview.fts.service.pdb.PDBFTSRestClient;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
+import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
}
/**
+ * Load the saved Backups options EXCEPT "Enabled" and "Scheme"
+ */
+
+ protected void loadLastSavedBackupsOptions()
+ {
+ enableBackupFiles
+ .setSelected(Cache.getDefault(BackupFiles.ENABLED, true));
+ setComboIntStringKey(backupfilesPresetsCombo,
+ Cache.getDefault(BackupFiles.NS + "_PRESET", 1));
+ suffixTemplate.setText(Cache.getDefault(BackupFiles.SUFFIX,
+ ".bak" + BackupFiles.NUM_PLACEHOLDER));
+ 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, 3));
+ backupfilesConfirmDelete.setSelected(
+ Cache.getDefault(BackupFiles.CONFIRM_DELETE_OLD, true));
+
+ backupsOptionsSetEnabled();
+ updateBackupFilesExampleLabel();
+ }
+
+ /**
* Initialises the Backups tabbed panel.
*
* @return
{
boolean selected = enableBackupFiles.isSelected();
// enable other options only when the first is checked
- backupsOptionsSetEnabled(selected);
+ backupsOptionsSetEnabled();
}
});
// whole suffix panel next row
gbc.gridx = 0;
gbc.gridy = 2;
- backupsTab.add(suffixPanel, gbc);
+ backupsTab.add(keepfilesPanel, gbc);
// keep files panel
gbc.gridy = 3;
- backupsTab.add(keepfilesPanel, gbc);
+ backupsTab.add(suffixPanel, gbc);
- /*
- // whole examples panel next row
- gbc.gridy = 3;
- backupsTab.add(exampleFilesPanel, gbc);
-
// fill empty space
gbc.gridy = 4;
gbc.weighty = 1.0;
backupsTab.add(new JPanel(), gbc);
- */
- backupsOptionsSetEnabled(enableBackupFiles.isSelected());
+ backupsOptionsSetEnabled();
return backupsTab;
}
new IntKeyStringValueEntry(2,
MessageManager.getString("label.single_file")),
new IntKeyStringValueEntry(3,
- MessageManager.getString("label.keep_everything")),
+ MessageManager.getString("label.keep_all_versions")),
new IntKeyStringValueEntry(4,
MessageManager.getString("label.rolled_backups")),
// ...
+ new IntKeyStringValueEntry(255,
+ MessageManager.getString("label.previously_saved_scheme")),
// IMPORTANT, keep "Custom" entry with key 0 (even though it appears last)
new IntKeyStringValueEntry(0,
- MessageManager.getString("label.custom")) };
+ MessageManager.getString("label.customise")) };
private final Map<Integer, BackupFilesPresetEntry> backupfilesPresetEntriesValues = new HashMap<Integer, BackupFilesPresetEntry>()
{
{
- put(1, new BackupFilesPresetEntry(".v" + BackupFiles.NUM_PLACEHOLDER,
- 3, false, false, 4, false));
+ put(1, new BackupFilesPresetEntry(
+ ".bak" + BackupFiles.NUM_PLACEHOLDER, 3, false, false, 3,
+ false));
put(2, new BackupFilesPresetEntry("~", 1, false, false, 1, false));
put(3, new BackupFilesPresetEntry(".v" + BackupFiles.NUM_PLACEHOLDER,
3, false, true, 10, true));
private JPanel initBackupsTabPresetsPanel()
{
presetsPanel.setBorder(
- new TitledBorder(MessageManager.getString("label.presets")));
+ new TitledBorder(MessageManager.getString("label.schemes")));
for (int i = 0; i < backupfilesPresetEntries.length; i++)
{
backupfilesPresetsCombo.addItem(backupfilesPresetEntries[i]);
}
+ // put "Previously saved scheme" item in italics (it's not really
+ // selectable, as such -- it deselects itself when selected) and
+ // "Customise" in bold
+ backupfilesPresetsCombo
+ .setRenderer(new BackupFilesPresetsComboBoxRenderer());
backupfilesPresetsCombo.addActionListener(new ActionListener()
{
@Override
.getSelectedItem();
int key = entry.getKey();
String value = entry.getValue();
- boolean custom = key == 0;
+ // 0 reserved for "Custom" and 255 reserved or "Previously saved scheme"
+ boolean special = key == 0 || key == 255;
- if (custom)
+ if (special)
{
- // backupsSetCustomOptions();
+ if (key == 0)
+ {
+ // backupsSetCustomOptions();
+ }
+ else if (key == 255)
+ {
+ loadLastSavedBackupsOptions();
+ // switch to "Customise" scheme? probably not
+ // setComboIntStringKey(backupfilesPresetsCombo, 0);
+ }
}
else
{
}
else
{
- System.out.println("Preset '" + value + "' not implemented yet");
+ System.out.println("Preset '" + value + "' not implemented");
}
}
+ backupfilesCustomOptionsSetEnabled();
updateBackupFilesExampleLabel();
- backupsCustomOptionsSetEnabled(custom);
}
protected int getComboIntStringKey(JComboBox c)
private JPanel initBackupsTabSuffixPanel()
{
suffixPanel.setBorder(new TitledBorder(
- MessageManager.getString("label.suffix_format")));
+ MessageManager.getString("label.backup_filenames")));
suffixPanel.setLayout(new GridBagLayout());
suffixTemplateLabel
- .setText(MessageManager.getString("label.suffix_template"));
+ .setText(MessageManager.getString("label.append_to_filename"));
suffixTemplateLabel.setHorizontalAlignment(SwingConstants.LEFT);
suffixTemplateLabel.setFont(LABEL_FONT);
final String tooltip = JvSwingUtils.wrapTooltip(true,
- MessageManager.getString("label.suffix_template_tooltip"));
+ MessageManager.getString("label.append_to_filename_tooltip"));
suffixTemplate.setToolTipText(tooltip);
suffixTemplate.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
updateBackupFilesExampleLabel();
+ backupfilesCustomOptionsSetEnabled();
}
});
public void keyReleased(KeyEvent e)
{
updateBackupFilesExampleLabel();
+ backupfilesCustomOptionsSetEnabled();
}
@Override
{
}
- // disable use of ':'
+ // disable use of ':' or '/' or '\'
@Override
public void keyTyped(KeyEvent e)
{
char c = e.getKeyChar();
- if (c == ':')
+ if (c == ':' || c == '/' || c == '\\')
{
- // don't process ':'
+ // don't process ':' or '/' or '\'
e.consume();
}
}
return suffixPanel;
}
- private void backupfilesKeepAllEnabled(boolean enabled)
- {
- backupfilesKeepAll.setEnabled(enabled);
- keepRollMaxOptionsEnabled();
- }
-
private JPanel initBackupsTabKeepFilesPanel()
{
keepfilesPanel.setBorder(
JPanel jp = new JPanel();
jp.setLayout(new FlowLayout());
oldBackupFilesLabel
- .setText(MessageManager.getString("label.old_backup_files"));
+ .setText(MessageManager
+ .getString("label.autodelete_old_backup_files"));
oldBackupFilesLabel.setFont(LABEL_FONT);
oldBackupFilesLabel.setHorizontalAlignment(SwingConstants.LEFT);
jp.add(oldBackupFilesLabel);
private JPanel initBackupsTabFilenameExamplesPanel()
{
- String title = MessageManager.getString("label.example_filenames");
+ String title = MessageManager
+ .getString("label.summary_of_backups_scheme");
TitledBorder tb = new TitledBorder(title);
// tb.setTitleFont(LABEL_FONT);
exampleFilesPanel.setBorder(tb);
{
int exampleindex = 12;
String base = MessageManager.getString("label.filename");
- if (base == null || base.length() > 0)
+ if (base == null || base.length() == 0)
{
- base = "filename.fa";
+ base = "file_name.fa";
}
+ boolean reverse = suffixReverse.isSelected();
+ boolean keepAll = backupfilesKeepAll.isSelected();
+ int rollMax = 4;
String suffix = suffixTemplate.getText();
int digits = 3;
- try
- {
- suffixDigitsSpinner.commitEdit();
- digits = (Integer) suffixDigitsSpinner.getValue();
- digits = digits < 1 ? 1 : digits;
- } catch (Exception e)
+
+ backupfilesExampleLabel.setFont(LABEL_FONT_ITALIC);
+ if (suffix == null || suffix.length() == 0)
{
- System.out.println(
- "Failed casting (Integer) suffixTemplateSpinner.getValue()");
+ backupfilesExampleLabel
+ .setText(MessageManager.getString("label.no_backup_files"));
+ backupfilesExampleLabel.setFont(LABEL_FONT_BOLD);
+ return;
}
- boolean reverse = suffixReverse.isSelected();
- boolean keepAll = backupfilesKeepAll.isSelected();
- int rollMax = 4;
+
try
{
backupfilesRollMaxSpinner.commitEdit();
"Failed casting (Integer) backupfilesRollMaxSpinner.getValue()");
}
+ if (suffix.indexOf(BackupFiles.NUM_PLACEHOLDER) == -1)
+ {
+ rollMax = 1;
+ }
+
+ try
+ {
+ suffixDigitsSpinner.commitEdit();
+ digits = (Integer) suffixDigitsSpinner.getValue();
+ digits = digits < 1 ? 1 : digits;
+ } catch (Exception e)
+ {
+ System.out.println(
+ "Failed casting (Integer) suffixTemplateSpinner.getValue()");
+ }
+
int lowersurround = 2;
int uppersurround = 0;
StringBuilder exampleSB = new StringBuilder();
return i;
}
- protected void keepRollMaxOptionsEnabled()
+ private void keepRollMaxOptionsEnabled()
{
- keepRollMaxOptionsEnabled(backupfilesKeepAll.isEnabled());
+ boolean enabled = backupfilesKeepAll.isEnabled()
+ && !backupfilesKeepAll.isSelected();
+ oldBackupFilesLabel.setEnabled(enabled);
+ backupfilesRollMaxSpinner.setEnabled(enabled);
+ backupfilesConfirmDelete.setEnabled(enabled);
}
- protected void keepRollMaxOptionsEnabled(boolean tryEnabled)
+ private void backupfilesKeepAllSetEnabled(boolean tryEnabled)
{
- boolean enabled = tryEnabled && !backupfilesKeepAll.isSelected();
+ boolean enabled = tryEnabled && enableBackupFiles.isSelected()
+ && getComboIntStringKey(backupfilesPresetsCombo) == 0
+ && suffixTemplate.getText()
+ .indexOf(BackupFiles.NUM_PLACEHOLDER) > -1;
+ keepfilesPanel.setEnabled(enabled);
+ backupfilesKeepAll.setEnabled(enabled);
oldBackupFilesLabel.setEnabled(enabled);
- backupfilesRollMaxSpinner.setEnabled(enabled);
- backupfilesConfirmDelete.setEnabled(enabled);
+ keepRollMaxOptionsEnabled();
}
- protected void backupsCustomOptionsSetEnabled(boolean enabled)
+ private void backupfilesSuffixTemplateDigitsSetEnabled()
{
- backupsOptionsSetEnabled(enabled, false);
+ boolean enabled = suffixTemplate.isEnabled() && suffixTemplate.getText()
+ .indexOf(BackupFiles.NUM_PLACEHOLDER) > -1;
+ suffixDigitsLabel.setEnabled(enabled);
+ suffixDigitsSpinner.setEnabled(enabled);
+ suffixReverse.setEnabled(enabled);
}
- protected void backupsOptionsSetEnabled(boolean enabled)
+ private void backupfilesSuffixTemplateSetEnabled(boolean tryEnabled)
{
- backupsOptionsSetEnabled(enabled, true);
+ boolean enabled = tryEnabled && enableBackupFiles.isSelected()
+ && getComboIntStringKey(backupfilesPresetsCombo) == 0;
+ suffixPanel.setEnabled(enabled);
+ suffixTemplateLabel.setEnabled(enabled);
+ suffixTemplate.setEnabled(enabled);
+ backupfilesSuffixTemplateDigitsSetEnabled();
}
- protected void backupsOptionsSetEnabled(boolean enabled, boolean all)
+ protected void backupfilesCustomOptionsSetEnabled()
{
+ int scheme = getComboIntStringKey(backupfilesPresetsCombo);
+ boolean enabled = scheme == 0 && enableBackupFiles.isSelected();
- if (all)
- {
- presetsPanel.setEnabled(enabled);
- exampleFilesPanel.setEnabled(enabled);
+ backupfilesSuffixTemplateSetEnabled(enabled);
+ backupfilesKeepAllSetEnabled(enabled);
+ }
- backupfilesPresetsCombo.setEnabled(enabled);
- backupfilesExampleLabel.setEnabled(enabled);
- }
- suffixPanel.setEnabled(enabled);
- keepfilesPanel.setEnabled(enabled);
+ private void backupfilesSummarySetEnabled()
+ {
+ boolean enabled = enableBackupFiles.isSelected();
+ backupfilesExampleLabel.setEnabled(enabled);
+ exampleFilesPanel.setEnabled(enabled);
+ }
- suffixTemplate.setEnabled(enabled);
- suffixTemplateLabel.setEnabled(enabled);
- suffixDigitsLabel.setEnabled(enabled);
- suffixDigitsSpinner.setEnabled(enabled);
- suffixReverse.setEnabled(enabled);
- oldBackupFilesLabel.setEnabled(enabled);
- backupfilesKeepAllEnabled(enabled);
+ private void backupfilesPresetsSetEnabled()
+ {
+ boolean enabled = enableBackupFiles.isSelected();
+ presetsPanel.setEnabled(enabled);
+ backupfilesPresetsCombo.setEnabled(enabled);
+ }
- if (enabled && all)
- {
- backupsTabUpdatePresets();
- }
+ protected void backupsOptionsSetEnabled()
+ {
+ backupfilesPresetsSetEnabled();
+ backupfilesSummarySetEnabled();
+ backupfilesCustomOptionsSetEnabled();
}
protected void backupsSetOptions(String suffix, int digits,
this.confirmDelete = confirmDelete;
}
}
+
+class BackupFilesPresetsComboBoxRenderer extends DefaultListCellRenderer
+{
+ @Override
+ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
+ super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
+
+ try {
+ IntKeyStringValueEntry e = (IntKeyStringValueEntry) value;
+ if (e.getKey() == 255)
+ {
+ // "Previously saved scheme" item
+ this.setFont(this.getFont().deriveFont(Font.ITALIC));
+ }
+ else if (e.getKey() == 0)
+ {
+ // "Customise" item
+ this.setFont(this.getFont().deriveFont(Font.BOLD));
+ }
+ } catch (Exception e) {
+ return this;
+ }
+
+ return this;
+ }
+}
\ No newline at end of file