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.util.MessageManager;
30 public class BackupFilesPresetEntry
35 public static final int DIGITSMIN = 1;
37 public static final int DIGITSMAX = 6;
41 public boolean reverse;
43 public boolean keepAll;
45 public static final int ROLLMAXMIN = 1;
47 public static final int ROLLMAXMAX = 999;
51 public boolean confirmDelete;
53 public static final String SAVEDCONFIG = BackupFiles.NS + "_SAVED";
55 public static final String CUSTOMCONFIG = BackupFiles.NS + "_CUSTOM";
57 private static final String stringDelim = "\t";
59 public static final int BACKUPFILESSCHEMECUSTOM = 0;
61 public static final int BACKUPFILESSCHEMEDEFAULT = 1;
63 public BackupFilesPresetEntry(String suffix, int digits, boolean reverse,
64 boolean keepAll, int rollMax, boolean confirmDelete)
66 this.suffix = suffix == null ? "" : suffix;
67 this.digits = digits < DIGITSMIN ? DIGITSMIN
68 : (digits > DIGITSMAX ? DIGITSMAX : digits);
69 this.reverse = reverse;
70 this.keepAll = keepAll;
71 this.rollMax = rollMax < ROLLMAXMIN ? ROLLMAXMIN
72 : (rollMax > ROLLMAXMAX ? ROLLMAXMAX : rollMax);
73 this.confirmDelete = confirmDelete;
76 public boolean equals(BackupFilesPresetEntry compare)
78 return suffix.equals(compare.suffix) && digits == compare.digits
79 && reverse == compare.reverse && keepAll == compare.keepAll
80 && rollMax == compare.rollMax
81 && confirmDelete == compare.confirmDelete;
85 public String toString()
87 StringBuilder sb = new StringBuilder();
89 sb.append(stringDelim);
91 sb.append(stringDelim);
93 sb.append(stringDelim);
95 sb.append(stringDelim);
97 sb.append(stringDelim);
98 sb.append(confirmDelete);
102 public static BackupFilesPresetEntry createBackupFilesPresetEntry(
109 StringTokenizer st = new StringTokenizer(line, stringDelim);
110 String suffix = null;
112 boolean reverse = false;
113 boolean keepAll = false;
115 boolean confirmDelete = false;
119 suffix = st.nextToken();
120 digits = Integer.valueOf(st.nextToken());
121 reverse = Boolean.valueOf(st.nextToken());
122 keepAll = Boolean.valueOf(st.nextToken());
123 rollMax = Integer.valueOf(st.nextToken());
124 confirmDelete = Boolean.valueOf(st.nextToken());
125 } catch (Exception e)
127 Cache.log.error("Error parsing backupfiles scheme '" + line + "'");
130 return new BackupFilesPresetEntry(suffix, digits, reverse, keepAll,
131 rollMax, confirmDelete);
134 public static BackupFilesPresetEntry getSavedBackupEntry()
136 String savedPresetString = Cache
137 .getDefault(BackupFilesPresetEntry.SAVEDCONFIG, null);
138 BackupFilesPresetEntry savedPreset = BackupFilesPresetEntry
139 .createBackupFilesPresetEntry(savedPresetString);
140 if (savedPreset == null)
142 savedPreset = backupfilesPresetEntriesValues
143 .get(BACKUPFILESSCHEMEDEFAULT);
148 public static final IntKeyStringValueEntry[] backupfilesPresetEntries = {
149 new IntKeyStringValueEntry(BACKUPFILESSCHEMEDEFAULT,
150 MessageManager.getString("label.default")),
151 new IntKeyStringValueEntry(2,
152 MessageManager.getString("label.single_file")),
153 new IntKeyStringValueEntry(3,
154 MessageManager.getString("label.keep_all_versions")),
155 new IntKeyStringValueEntry(4,
156 MessageManager.getString("label.rolled_backups")),
158 // IMPORTANT, keep "Custom" entry with key 0 (even though it appears last)
159 new IntKeyStringValueEntry(BACKUPFILESSCHEMECUSTOM,
160 MessageManager.getString("label.custom")) };
162 public static final String[] backupfilesPresetEntryDescriptions = {
163 MessageManager.getString("label.default_description"),
164 MessageManager.getString("label.single_file_description"),
165 MessageManager.getString("label.keep_all_versions_description"),
166 MessageManager.getString("label.rolled_backups_description"),
167 MessageManager.getString("label.custom_description") };
169 public static final Map<Integer, BackupFilesPresetEntry> backupfilesPresetEntriesValues = new HashMap<Integer, BackupFilesPresetEntry>()
174 private static final long serialVersionUID = 125L;
177 put(1, new BackupFilesPresetEntry(
178 ".bak" + BackupFiles.NUM_PLACEHOLDER, 3, false, false, 3,
180 put(2, new BackupFilesPresetEntry("~", 1, false, false, 1, false));
181 put(3, new BackupFilesPresetEntry(".v" + BackupFiles.NUM_PLACEHOLDER,
182 3, false, true, 10, true));
183 put(4, new BackupFilesPresetEntry(
184 "_bak." + BackupFiles.NUM_PLACEHOLDER, 1, true, false, 9,
187 // This gets replaced by GPreferences
188 put(BACKUPFILESSCHEMECUSTOM,
189 new BackupFilesPresetEntry("", 0, false, false, 0, false));