2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.util.HashMap;
25 import java.util.StringTokenizer;
27 import jalview.bin.Cache;
28 import jalview.bin.Console;
29 import jalview.util.MessageManager;
31 public class BackupFilesPresetEntry
36 public static final int DIGITSMIN = 1;
38 public static final int DIGITSMAX = 6;
42 public boolean reverse;
44 public boolean keepAll;
46 public static final int ROLLMAXMIN = 1;
48 public static final int ROLLMAXMAX = 999;
52 public boolean confirmDelete;
54 public static final String SAVEDCONFIG = BackupFiles.NS + "_SAVED";
56 public static final String CUSTOMCONFIG = BackupFiles.NS + "_CUSTOM";
58 private static final String stringDelim = "\t";
60 public static final int BACKUPFILESSCHEMECUSTOM = 0;
62 public static final int BACKUPFILESSCHEMEDEFAULT = 1;
64 public BackupFilesPresetEntry(String suffix, int digits, boolean reverse,
65 boolean keepAll, int rollMax, boolean confirmDelete)
67 this.suffix = suffix == null ? "" : suffix;
68 this.digits = digits < DIGITSMIN ? DIGITSMIN
69 : (digits > DIGITSMAX ? DIGITSMAX : digits);
70 this.reverse = reverse;
71 this.keepAll = keepAll;
72 this.rollMax = rollMax < ROLLMAXMIN ? ROLLMAXMIN
73 : (rollMax > ROLLMAXMAX ? ROLLMAXMAX : rollMax);
74 this.confirmDelete = confirmDelete;
77 public boolean equals(BackupFilesPresetEntry compare)
79 return suffix.equals(compare.suffix) && digits == compare.digits
80 && reverse == compare.reverse && keepAll == compare.keepAll
81 && rollMax == compare.rollMax
82 && confirmDelete == compare.confirmDelete;
86 public String toString()
88 StringBuilder sb = new StringBuilder();
90 sb.append(stringDelim);
92 sb.append(stringDelim);
94 sb.append(stringDelim);
96 sb.append(stringDelim);
98 sb.append(stringDelim);
99 sb.append(confirmDelete);
100 return sb.toString();
103 public static BackupFilesPresetEntry createBackupFilesPresetEntry(
110 StringTokenizer st = new StringTokenizer(line, stringDelim);
111 String suffix = null;
113 boolean reverse = false;
114 boolean keepAll = false;
116 boolean confirmDelete = false;
120 suffix = st.nextToken();
121 digits = Integer.valueOf(st.nextToken());
122 reverse = Boolean.valueOf(st.nextToken());
123 keepAll = Boolean.valueOf(st.nextToken());
124 rollMax = Integer.valueOf(st.nextToken());
125 confirmDelete = Boolean.valueOf(st.nextToken());
126 } catch (Exception e)
128 Console.error("Error parsing backupfiles scheme '" + line + "'");
131 return new BackupFilesPresetEntry(suffix, digits, reverse, keepAll,
132 rollMax, confirmDelete);
135 public static BackupFilesPresetEntry getSavedBackupEntry()
137 String savedPresetString = Cache
138 .getDefault(BackupFilesPresetEntry.SAVEDCONFIG, null);
139 BackupFilesPresetEntry savedPreset = BackupFilesPresetEntry
140 .createBackupFilesPresetEntry(savedPresetString);
141 if (savedPreset == null)
143 savedPreset = backupfilesPresetEntriesValues
144 .get(BACKUPFILESSCHEMEDEFAULT);
149 public static final IntKeyStringValueEntry[] backupfilesPresetEntries = {
150 new IntKeyStringValueEntry(BACKUPFILESSCHEMEDEFAULT,
151 MessageManager.getString("label.default")),
152 new IntKeyStringValueEntry(2,
153 MessageManager.getString("label.single_file")),
154 new IntKeyStringValueEntry(3,
155 MessageManager.getString("label.keep_all_versions")),
156 new IntKeyStringValueEntry(4,
157 MessageManager.getString("label.rolled_backups")),
159 // IMPORTANT, keep "Custom" entry with key 0 (even though it appears last)
160 new IntKeyStringValueEntry(BACKUPFILESSCHEMECUSTOM,
161 MessageManager.getString("label.custom")) };
163 public static final String[] backupfilesPresetEntryDescriptions = {
164 MessageManager.getString("label.default_description"),
165 MessageManager.getString("label.single_file_description"),
166 MessageManager.getString("label.keep_all_versions_description"),
167 MessageManager.getString("label.rolled_backups_description"),
168 MessageManager.getString("label.custom_description") };
170 public static final Map<Integer, BackupFilesPresetEntry> backupfilesPresetEntriesValues = new HashMap<Integer, BackupFilesPresetEntry>()
175 private static final long serialVersionUID = 125L;
178 put(1, new BackupFilesPresetEntry(
179 ".bak" + BackupFiles.NUM_PLACEHOLDER, 3, false, false, 3,
181 put(2, new BackupFilesPresetEntry("~", 1, false, false, 1, false));
182 put(3, new BackupFilesPresetEntry(".v" + BackupFiles.NUM_PLACEHOLDER,
183 3, false, true, 10, true));
184 put(4, new BackupFilesPresetEntry(
185 "_bak." + BackupFiles.NUM_PLACEHOLDER, 1, true, false, 9,
188 // This gets replaced by GPreferences
189 put(BACKUPFILESSCHEMECUSTOM,
190 new BackupFilesPresetEntry("", 0, false, false, 0, false));