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;
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;
protected JCheckBox enableBackupFiles = new JCheckBox();
+ protected JPanel presetsPanel = new JPanel();
+
+ protected JComboBox<IntKeyStringValueEntry> backupfilesPresetsCombo = new JComboBox<>();
+
protected JPanel suffixPanel = new JPanel();
protected JPanel keepfilesPanel = new JPanel();
protected JalviewBooleanRadioButtons backupfilesKeepAll = new JalviewBooleanRadioButtons();
- protected JSpinner backupfilesRollMaxSpinner = new JSpinner();
+ public JSpinner backupfilesRollMaxSpinner = new JSpinner();
protected JLabel oldBackupFilesLabel = new JLabel();
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.fill = GridBagConstraints.NONE;
+ initBackupsTabPresetsPanel();
initBackupsTabSuffixPanel();
initBackupsTabKeepFilesPanel();
initBackupsTabFilenameExamplesPanel();
// 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);
/*
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<Integer, BackupFilesPresetEntry> backupfilesPresetEntriesValues = new HashMap<Integer, BackupFilesPresetEntry>()
+ {{
+ 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<IntKeyStringValueEntry> 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")));
return suffixPanel;
}
+ private void backupfilesKeepAllEnabled(boolean enabled)
+ {
+ backupfilesKeepAll.setEnabled(enabled);
+ keepRollMaxOptionsEnabled();
+ }
+
private JPanel initBackupsTabKeepFilesPanel()
{
keepfilesPanel.setBorder(
public void actionPerformed(ActionEvent e)
{
boolean selected = backupfilesKeepAll.isSelected();
- keepRollMaxOptionsEnabled(!selected);
+ keepRollMaxOptionsEnabled();
updateBackupFilesExampleLabel();
}
});
MessageManager.getString("label.confirm_delete"),
MessageManager.getString("label.auto_delete"));
// update the enabled section
- keepRollMaxOptionsEnabled(!backupfilesKeepAll.isSelected());
+ keepRollMaxOptionsEnabled();
GridBagConstraints kgbc = new GridBagConstraints();
}
- public static int getSpinnerInt(JSpinner s, int def)
+ protected static int getSpinnerInt(JSpinner s, int def)
{
int i = def;
try
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()
}
}
+
+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;
+ }
+}