3 import jalview.bin.Cache;
4 import jalview.util.MessageManager;
6 import java.util.HashMap;
8 import java.util.StringTokenizer;
10 public class BackupFilesPresetEntry
15 public static final int DIGITSMIN = 1;
17 public static final int DIGITSMAX = 6;
21 public boolean reverse;
23 public boolean keepAll;
25 public static final int ROLLMAXMIN = 1;
27 public static final int ROLLMAXMAX = 999;
31 public boolean confirmDelete;
33 public static final String SAVEDCONFIG = BackupFiles.NS + "_SAVED";
35 public static final String CUSTOMCONFIG = BackupFiles.NS + "_CUSTOM";
37 private static final String stringDelim = "\t";
39 public static final int BACKUPFILESSCHEMECUSTOM = 0;
41 public static final int BACKUPFILESSCHEMEDEFAULT = 1;
43 public BackupFilesPresetEntry(String suffix, int digits, boolean reverse,
44 boolean keepAll, int rollMax, boolean confirmDelete)
46 this.suffix = suffix == null ? "" : suffix;
47 this.digits = digits < DIGITSMIN ? DIGITSMIN
48 : (digits > DIGITSMAX ? DIGITSMAX : digits);
49 this.reverse = reverse;
50 this.keepAll = keepAll;
51 this.rollMax = rollMax < ROLLMAXMIN ? ROLLMAXMIN
52 : (rollMax > ROLLMAXMAX ? ROLLMAXMAX : rollMax);
53 this.confirmDelete = confirmDelete;
56 public boolean equals(BackupFilesPresetEntry compare)
58 return suffix.equals(compare.suffix) && digits == compare.digits
59 && reverse == compare.reverse && keepAll == compare.keepAll
60 && rollMax == compare.rollMax
61 && confirmDelete == compare.confirmDelete;
65 public String toString()
67 StringBuilder sb = new StringBuilder();
69 sb.append(stringDelim);
71 sb.append(stringDelim);
73 sb.append(stringDelim);
75 sb.append(stringDelim);
77 sb.append(stringDelim);
78 sb.append(confirmDelete);
82 public static BackupFilesPresetEntry createBackupFilesPresetEntry(
89 StringTokenizer st = new StringTokenizer(line, stringDelim);
92 boolean reverse = false;
93 boolean keepAll = false;
95 boolean confirmDelete = false;
99 suffix = st.nextToken();
100 digits = Integer.valueOf(st.nextToken());
101 reverse = Boolean.valueOf(st.nextToken());
102 keepAll = Boolean.valueOf(st.nextToken());
103 rollMax = Integer.valueOf(st.nextToken());
104 confirmDelete = Boolean.valueOf(st.nextToken());
105 } catch (Exception e)
107 Cache.log.error("Error parsing backupfiles scheme '" + line + "'");
110 return new BackupFilesPresetEntry(suffix, digits, reverse, keepAll,
111 rollMax, confirmDelete);
114 public static BackupFilesPresetEntry getSavedBackupEntry()
116 String savedPresetString = Cache
117 .getDefault(BackupFilesPresetEntry.SAVEDCONFIG, null);
118 BackupFilesPresetEntry savedPreset = BackupFilesPresetEntry
119 .createBackupFilesPresetEntry(savedPresetString);
120 if (savedPreset == null)
122 savedPreset = backupfilesPresetEntriesValues
123 .get(BACKUPFILESSCHEMEDEFAULT);
128 public static final IntKeyStringValueEntry[] backupfilesPresetEntries = {
129 new IntKeyStringValueEntry(BACKUPFILESSCHEMEDEFAULT,
130 MessageManager.getString("label.default")),
131 new IntKeyStringValueEntry(2,
132 MessageManager.getString("label.single_file")),
133 new IntKeyStringValueEntry(3,
134 MessageManager.getString("label.keep_all_versions")),
135 new IntKeyStringValueEntry(4,
136 MessageManager.getString("label.rolled_backups")),
138 // IMPORTANT, keep "Custom" entry with key 0 (even though it appears last)
139 new IntKeyStringValueEntry(BACKUPFILESSCHEMECUSTOM,
140 MessageManager.getString("label.custom")) };
142 public static final String[] backupfilesPresetEntryDescriptions = {
143 MessageManager.getString("label.default_description"),
144 MessageManager.getString("label.single_file_description"),
145 MessageManager.getString("label.keep_all_versions_description"),
146 MessageManager.getString("label.rolled_backups_description"),
147 MessageManager.getString("label.custom_description") };
149 public static final Map<Integer, BackupFilesPresetEntry> backupfilesPresetEntriesValues = new HashMap<Integer, BackupFilesPresetEntry>()
154 private static final long serialVersionUID = 125L;
157 put(1, new BackupFilesPresetEntry(
158 ".bak" + BackupFiles.NUM_PLACEHOLDER, 3, false, false, 3,
160 put(2, new BackupFilesPresetEntry("~", 1, false, false, 1, false));
161 put(3, new BackupFilesPresetEntry(".v" + BackupFiles.NUM_PLACEHOLDER,
162 3, false, true, 10, true));
163 put(4, new BackupFilesPresetEntry(
164 "_bak." + BackupFiles.NUM_PLACEHOLDER, 1, true, false, 9,
167 // This gets replaced by GPreferences
168 put(BACKUPFILESSCHEMECUSTOM,
169 new BackupFilesPresetEntry("", 0, false, false, 0, false));