label.backupfiles_confirm_save_file = Confirm save file
label.backupfiles_confirm_save_file_backupfiles_roll_wrong = Something possibly went wrong with the backups of this file, write the new file anyway?
label.backups = Backups
+label.backup = Backup
label.backup_files = Backup Files
label.enable_backupfiles = Enable backup files
label.backup_filename_strategy = Backup filename strategy
label.keep_all_versions = Keep all versions
label.rolled_backups = Rolled backup files
label.previously_saved_scheme = Previously saved scheme
-label.no_backup_files = NO BACKUP FILES
\ No newline at end of file
+label.no_backup_files = NO BACKUP FILES
+label.include_backup_files = Include backup files
\ No newline at end of file
label.backupfiles_confirm_save_file = Confirmar guardar archivo
label.backupfiles_confirm_save_file_backupfiles_roll_wrong = Posiblemente algo está mal con los archivos de copia de seguridad. ¿Guardar el nuevo archivo?
label.backups = Respaldos
+label.backup = Respaldo
label.backup_files = Archivos de respaldos
label.enable_backupfiles = Habilitar archivos de respaldos
label.backup_filename_strategy = Estrategia de nombres de archivo de respaldos
label.keep_all_versions = Mantener todas las versiones
label.rolled_backups = Ciclos resaldos
label.previously_saved_scheme = Esquema previamente guardado
-label.no_backup_files = NO ARCHIVOS DE RESPALDOS
\ No newline at end of file
+label.no_backup_files = NO ARCHIVOS DE RESPALDOS
+label.include_backup_files = Incluir archivos de respaldos
\ No newline at end of file
"Jalview Project (old)" };
JalviewFileChooser chooser = new JalviewFileChooser(
Cache.getProperty("LAST_DIRECTORY"), suffix, desc,
- "Jalview Project");
+ "Jalview Project", true, true); // last two booleans: allFiles,
+ // allowBackupFiles
chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle(MessageManager.getString("label.restore_state"));
return bffp.isBackupFile();
}
- public static String getBackupFilename(int index, String base,
- String template, int digits)
- {
- String numString = String.format("%0" + digits + "d", index);
- String backupSuffix = template.replaceAll(BackupFiles.NUM_PLACEHOLDER,
- numString);
- String backupfilename = base + backupSuffix;
- return backupfilename;
- }
-
}
package jalview.io;
+import jalview.bin.Cache;
+
import java.io.File;
public class BackupFilenameParts
{
- String base;
+ private String base;
- String templateStart;
+ private String templateStart;
- int num;
+ private int num;
- int digits;
+ private int digits;
- String templateEnd;
+ private String templateEnd;
- boolean isBackupFile;
+ private boolean isBackupFile;
+
+ private BackupFilenameParts()
+ {
+ this.isBackupFile = false;
+ }
public BackupFilenameParts(File file, String base, String template,
int digits)
public BackupFilenameParts(String filename, String base, String template,
int suggesteddigits)
{
+ this(filename, base, template, suggesteddigits, false);
+ }
+
+ public BackupFilenameParts(String filename, String base, String template,
+ int suggesteddigits, boolean extensionMatch)
+ {
this.isBackupFile = false;
int numcharstart = template.indexOf(BackupFiles.NUM_PLACEHOLDER);
digits = suggesteddigits;
}
+ String savedFilename = "";
+ // if extensionOnly is set then reset the filename to the last occurrence of the extension+templateStart and try the match
+ if (extensionMatch)
+ {
+ // only trying to match from extension onwards
+
+ int extensioncharstart = filename
+ .lastIndexOf('.' + base + templateStart);
+ if (extensioncharstart == -1)
+ {
+ return;
+ }
+
+ savedFilename = filename.substring(0, extensioncharstart + 1); // include
+ // the "."
+ filename = filename.substring(extensioncharstart + 1);
+ }
+
+ // full filename match
+
// calculate minimum length of a backup filename
int minlength = base.length() + template.length()
- BackupFiles.NUM_PLACEHOLDER.length() + digits;
- if (!(filename.startsWith(base) && filename.length() >= minlength))
+ if (!(filename.startsWith(base + templateStart)
+ && filename.endsWith(templateEnd)
+ && filename.length() >= minlength))
{
// non-starter
return;
&& filename.endsWith(templateEnd)
&& numString.matches("[0-9]*"))
{
- this.base = base;
+ this.base = extensionMatch ? savedFilename + base : base;
this.templateStart = templateStart;
this.num = numString.length() > 0 ? Integer.parseInt(numString) : 0;
this.digits = digits;
}
+ public static BackupFilenameParts currentBackupFilenameParts(
+ String filename, String base, boolean extensionMatch)
+ {
+ BackupFilenameParts bfp = new BackupFilenameParts();
+ String template = Cache.getDefault(BackupFiles.SUFFIX, null);
+ if (template == null)
+ {
+ return bfp;
+ }
+ int digits;
+ try
+ {
+ digits = Integer
+ .parseInt(Cache.getDefault(BackupFiles.SUFFIX_DIGITS, null));
+ } catch (Exception e)
+ {
+ return bfp;
+ }
+ return new BackupFilenameParts(filename, base, template, digits,
+ extensionMatch);
+ }
+
public boolean isBackupFile()
{
return this.isBackupFile;
{
return this.num;
}
+
+ public static String getBackupFilename(int index, String base,
+ String template, int digits)
+ {
+ String numString = String.format("%0" + digits + "d", index);
+ String backupSuffix = template.replaceFirst(BackupFiles.NUM_PLACEHOLDER,
+ numString);
+ String backupfilename = base + backupSuffix;
+ return backupfilename;
+ }
}
{
// int n = tempMax - m;
String backupfilename = dir + File.separatorChar
- + BackupFilenameFilter.getBackupFilename(n, basename,
+ + BackupFilenameParts.getBackupFilename(n, basename,
suffix, digits);
File backupfile_n = new File(backupfilename);
// Let's make the new backup file!! yay, got there at last!
String latestBackupFilename = dir + File.separatorChar
- + BackupFilenameFilter.getBackupFilename(nextIndexNum, basename,
+ + BackupFilenameParts.getBackupFilename(nextIndexNum, basename,
suffix, digits);
File latestBackupFile = new File(latestBackupFilename);
ret = ret && file.renameTo(latestBackupFile);
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.HeadlessException;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.util.StringTokenizer;
import java.util.Vector;
+import javax.swing.BoxLayout;
import javax.swing.DefaultListCellRenderer;
+import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JList;
import javax.swing.JPanel;
public class JalviewFileChooser extends JFileChooser
{
/**
+ * backupfilesCheckBox = "Include backup files" checkbox includeBackupfiles =
+ * flag set by checkbox
+ */
+ private JCheckBox backupfilesCheckBox = null;
+
+ protected boolean includeBackupFiles = false;
+
+ /**
* Factory method to return a file chooser that offers readable alignment file
* formats
*
JalviewFileChooser(String dir, String[] extensions, String[] descs,
String selected, boolean allFiles)
{
+ this(dir, extensions, descs, selected, allFiles, false);
+ }
+
+ public JalviewFileChooser(String dir, String[] extensions, String[] descs,
+ String selected, boolean allFiles, boolean allowBackupFiles)
+ {
super(safePath(dir));
if (extensions.length == descs.length)
{
{
formats.add(new String[] { extensions[i], descs[i] });
}
- init(formats, selected, allFiles);
+ init(formats, selected, allFiles, allowBackupFiles);
}
else
{
*/
void init(List<String[]> formats, String selected, boolean allFiles)
{
+ init(formats, selected, allFiles, false);
+ }
+
+ void init(List<String[]> formats, String selected, boolean allFiles,
+ boolean allowBackupFiles)
+ {
JalviewFileFilter chosen = null;
for (String[] format : formats)
{
JalviewFileFilter jvf = new JalviewFileFilter(format[0], format[1]);
+ if (allowBackupFiles)
+ {
+ jvf.setParentJFC(this);
+ }
addChoosableFileFilter(jvf);
if ((selected != null) && selected.equalsIgnoreCase(format[1]))
{
setFileFilter(chosen);
}
- setAccessory(new RecentlyOpened());
+ if (allowBackupFiles)
+ {
+ JPanel multi = new JPanel();
+ multi.setLayout(new BoxLayout(multi, BoxLayout.PAGE_AXIS));
+ if (backupfilesCheckBox == null)
+ {
+ try {
+ includeBackupFiles = Boolean.parseBoolean(
+ Cache.getProperty(BackupFiles.NS + "_FC_INCLUDE"));
+ } catch (Exception e)
+ {
+ includeBackupFiles = false;
+ }
+ backupfilesCheckBox = new JCheckBox(
+ MessageManager.getString("label.include_backup_files"),
+ includeBackupFiles);
+ backupfilesCheckBox.setAlignmentX(Component.CENTER_ALIGNMENT);
+ JalviewFileChooser jfc = this;
+ backupfilesCheckBox.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ includeBackupFiles = backupfilesCheckBox.isSelected();
+ Cache.setProperty(BackupFiles.NS + "_FC_INCLUDE",
+ String.valueOf(includeBackupFiles));
+ jfc.rescanCurrentDirectory();
+ jfc.revalidate();
+ jfc.repaint();
+ // This is a kludge. Cannot find out how to get the file list to
+ // refresh!
+ /*
+ Object o = jfc.getClientProperty(
+ CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY);
+ jfc.firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY,
+ o, o);
+ */
+ }
+ });
+ }
+ multi.add(new RecentlyOpened());
+ multi.add(backupfilesCheckBox);
+ setAccessory(multi);
+ }
+ else
+ {
+ // set includeBackupFiles=false to avoid other file choosers from picking
+ // up backup files (Just In Case)
+ includeBackupFiles = false;
+ setAccessory(new RecentlyOpened());
+ }
}
@Override
private boolean useExtensionsInDescription = true;
+ private JalviewFileChooser parentJFC = null;
+
public JalviewFileFilter(String extension, String description)
{
StringTokenizer st = new StringTokenizer(extension, ",");
@Override
public boolean accept(File f)
{
+
if (f != null)
{
String extension = getExtension(f);
{
return true;
}
+
}
+ if (parentJFC != null && parentJFC.includeBackupFiles)
+ {
+ Iterator<String> it = filters.keySet().iterator();
+ while (it.hasNext())
+ {
+ String ext = it.next();
+
+ BackupFilenameParts bfp = BackupFilenameParts
+ .currentBackupFilenameParts(f.getName(), ext, true);
+ if (bfp.isBackupFile())
+ {
+ return true;
+ }
+ }
+ }
+
return false;
}
{
return useExtensionsInDescription;
}
+
+ protected void setParentJFC(JalviewFileChooser p)
+ {
+ this.parentJFC = p;
+ }
+
}
*/
package jalview.io;
+import jalview.util.MessageManager;
+
import java.io.File;
import java.net.URL;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import javax.swing.Icon;
public String getTypeDescription(File f)
{
String extension = getExtension(f);
+
String type = getDescriptionForExtension(extension);
+
if (extension != null)
{
if (extensions.containsKey(extension))
{
String extension = getExtension(f);
Icon icon = null;
+ String type = getDescriptionForExtension(extension);
+
+ if (type == null)
+ {
+ Iterator<String> it = extensions.keySet().iterator();
+ while (it.hasNext())
+ {
+ String ext = it.next();
+ BackupFilenameParts bfp = BackupFilenameParts
+ .currentBackupFilenameParts(f.getName(), ext, true);
+ if (bfp.isBackupFile())
+ {
+ extension = ext;
+ type = getDescriptionForExtension(extension)
+ + MessageManager.getString("label.backup");
+ break;
+ }
+ }
+ }
- if (getDescriptionForExtension(extension) != null)
+ if (type != null)
{
icon = getImageIcon("/images/file.png");
}
import jalview.gui.JalviewBooleanRadioButtons;
import jalview.gui.JvSwingUtils;
import jalview.gui.StructureViewer.ViewerType;
-import jalview.io.BackupFilenameFilter;
+import jalview.io.BackupFilenameParts;
import jalview.io.BackupFiles;
import jalview.util.MessageManager;
{
exampleSB.append("\n");
}
- exampleSB.append(BackupFilenameFilter.getBackupFilename(index,
+ exampleSB.append(BackupFilenameParts.getBackupFilename(index,
base, suffix, digits));
if (min == max)
{
{
exampleSB.append("\n");
}
- exampleSB.append(BackupFilenameFilter.getBackupFilename(index,
+ exampleSB.append(BackupFilenameParts.getBackupFilename(index,
base, suffix, digits));
if (min == max)
{