X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FJalviewFileChooser.java;h=7c3cf9289a00b72f6accf37b3f115499f1377d51;hb=db80eb8e1acf352e72a33e1e3825d40f7c6e4046;hp=192948d551356b25930de886bf65eb65af92e285;hpb=4db555a8f689e05652674009967a968021d6b340;p=jalview.git diff --git a/src/jalview/io/JalviewFileChooser.java b/src/jalview/io/JalviewFileChooser.java index 192948d..7c3cf92 100755 --- a/src/jalview/io/JalviewFileChooser.java +++ b/src/jalview/io/JalviewFileChooser.java @@ -30,6 +30,8 @@ import java.awt.Component; 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; @@ -38,7 +40,9 @@ import java.util.List; 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; @@ -58,6 +62,14 @@ import javax.swing.plaf.basic.BasicFileChooserUI; 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 * @@ -139,6 +151,12 @@ public class JalviewFileChooser extends JFileChooser 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) { @@ -147,7 +165,7 @@ public class JalviewFileChooser extends JFileChooser { formats.add(new String[] { extensions[i], descs[i] }); } - init(formats, selected, allFiles); + init(formats, selected, allFiles, allowBackupFiles); } else { @@ -181,6 +199,12 @@ public class JalviewFileChooser extends JFileChooser */ void init(List formats, String selected, boolean allFiles) { + init(formats, selected, allFiles, false); + } + + void init(List formats, String selected, boolean allFiles, + boolean allowBackupFiles) + { JalviewFileFilter chosen = null; @@ -191,6 +215,10 @@ public class JalviewFileChooser extends JFileChooser 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])) { @@ -203,7 +231,57 @@ public class JalviewFileChooser extends JFileChooser 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