Skip to content
Snippets Groups Projects
Commit e65db808 authored by tcarver's avatar tcarver
Browse files

implement a file filter for BAM/VCF and allow for multiple file

selection
parent a61c6c63
No related branches found
No related tags found
No related merge requests found
...@@ -29,6 +29,7 @@ import javax.swing.JPanel; ...@@ -29,6 +29,7 @@ import javax.swing.JPanel;
import javax.swing.JTextField; import javax.swing.JTextField;
import uk.ac.sanger.artemis.components.StickyFileChooser; import uk.ac.sanger.artemis.components.StickyFileChooser;
import uk.ac.sanger.artemis.components.variant.VCFview;
/** /**
* File selection panel to allow input of DNA sequences * File selection panel to allow input of DNA sequences
...@@ -66,14 +67,14 @@ public class FileSelectionDialog extends JDialog ...@@ -66,14 +67,14 @@ public class FileSelectionDialog extends JDialog
{ {
super(f, program+" :: Select Files", true); super(f, program+" :: Select Files", true);
addBamField(fileType); addBamField(fileType, null);
JButton addMoreFiles = new JButton("Add More"); JButton addMoreFiles = new JButton("Add More");
addMoreFiles.addActionListener(new ActionListener() addMoreFiles.addActionListener(new ActionListener()
{ {
public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e)
{ {
addBamField(fileType); addBamField(fileType, null);
} }
}); });
...@@ -90,7 +91,7 @@ public class FileSelectionDialog extends JDialog ...@@ -90,7 +91,7 @@ public class FileSelectionDialog extends JDialog
c.gridy = ++row; c.gridy = ++row;
dialog.add(referenceField, c); dialog.add(referenceField, c);
JButton selectReference = new JButton("Select..."); JButton selectReference = new JButton("Select...");
addActionListener(selectReference, referenceField); addActionListener(selectReference, referenceField, fileType);
c.gridx = 1; c.gridx = 1;
dialog.add(selectReference, c); dialog.add(selectReference, c);
} }
...@@ -120,11 +121,13 @@ public class FileSelectionDialog extends JDialog ...@@ -120,11 +121,13 @@ public class FileSelectionDialog extends JDialog
* Add a text field to the dialog for adding in a path * Add a text field to the dialog for adding in a path
* to a BAM file. * to a BAM file.
*/ */
private void addBamField(String fileType) private void addBamField(String fileType, String fileName)
{ {
JTextField bamField = new JTextField(30); JTextField bamField = new JTextField(30);
bamFields.add(bamField); bamFields.add(bamField);
if(fileName != null)
bamField.setText(fileName);
bamField.setPreferredSize( bamField.setPreferredSize(
new Dimension(200,bamField.getPreferredSize().height)); new Dimension(200,bamField.getPreferredSize().height));
c.gridy = row; c.gridy = row;
...@@ -135,7 +138,7 @@ public class FileSelectionDialog extends JDialog ...@@ -135,7 +138,7 @@ public class FileSelectionDialog extends JDialog
dialog.add(bamField, c); dialog.add(bamField, c);
c.gridx = 1; c.gridx = 1;
JButton selectBam = new JButton("Select..."); JButton selectBam = new JButton("Select...");
addActionListener(selectBam, bamField); addActionListener(selectBam, bamField, fileType);
dialog.add(selectBam, c); dialog.add(selectBam, c);
pack(); pack();
...@@ -145,19 +148,51 @@ public class FileSelectionDialog extends JDialog ...@@ -145,19 +148,51 @@ public class FileSelectionDialog extends JDialog
* Add action listener to a button. * Add action listener to a button.
* @param fileSelectionButton * @param fileSelectionButton
* @param tfield * @param tfield
* @param fileType
*/ */
private void addActionListener(final JButton fileSelectionButton, private void addActionListener(final JButton fileSelectionButton,
final JTextField tfield) final JTextField tfield,
final String fileType)
{ {
final javax.swing.filechooser.FileFilter filter =
new javax.swing.filechooser.FileFilter()
{
public boolean accept(final File file)
{
if(file.isDirectory() ||
file.getName().matches(VCFview.VCFFILE_SUFFIX) ||
file.getName().matches(BamView.BAM_SUFFIX))
return true;
return false;
}
public String getDescription()
{
return "BAM / VCF files";
}
};
fileSelectionButton.addActionListener(new ActionListener() fileSelectionButton.addActionListener(new ActionListener()
{ {
public void actionPerformed(ActionEvent e) public void actionPerformed(ActionEvent e)
{ {
StickyFileChooser fileChooser = new StickyFileChooser(); StickyFileChooser fileChooser = new StickyFileChooser();
fileChooser.setMultiSelectionEnabled(true);
fileChooser.setFileFilter(filter);
int status = fileChooser.showOpenDialog(null); int status = fileChooser.showOpenDialog(null);
if(status == StickyFileChooser.CANCEL_OPTION) if(status == StickyFileChooser.CANCEL_OPTION)
return; return;
tfield.setText(fileChooser.getSelectedFile().getAbsolutePath());
File[] files = fileChooser.getSelectedFiles();
tfield.setText(files[0].getAbsolutePath());
if(files.length > 1)
{
for(int i=1; i<files.length; i++)
addBamField(fileType, files[i].getAbsolutePath());
}
} }
}); });
} }
...@@ -319,4 +354,5 @@ public class FileSelectionDialog extends JDialog ...@@ -319,4 +354,5 @@ public class FileSelectionDialog extends JDialog
{ {
return referenceField.getText(); return referenceField.getText();
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment