001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 * Created on Sep 28, 2009
021 * Author: Andreas Prlic
022 *
023 */
024
025package org.biojava.nbio.structure.align.gui;
026
027import org.biojava.nbio.structure.align.util.UserConfiguration;
028import org.biojava.nbio.structure.align.webstart.WebStartMain;
029
030import javax.swing.*;
031import java.awt.event.ActionEvent;
032import java.io.File;
033
034
035/** Ask the user to provide a directory containting PDB files.
036 * Sets the idr in the provided textField.
037 * @author Andreas Prlic
038 *
039 */
040public class ChooseDirAction extends AbstractAction{
041
042        JTextField textField;
043        UserConfiguration config;
044        public ChooseDirAction (JTextField textField, UserConfiguration config){
045                super("Choose");
046                this.config = config;
047                this.textField = textField;
048        }
049        public static final long serialVersionUID = 0l;
050        // This method is called when the button is pressed
051        @Override
052        public void actionPerformed(ActionEvent evt) {
053                // Perform action...
054                JFileChooser chooser = new JFileChooser();
055                String txt = textField.getText();
056
057                if ( config == null) {
058                        System.out.println("config == null, calling getWebStartConfig...");
059                        config = WebStartMain.getWebStartConfig();
060                }
061                if ( txt != null){
062                        chooser.setCurrentDirectory(new java.io.File(txt));
063                        config.setPdbFilePath(txt);
064
065                }
066                chooser.setDialogTitle("Choose directory that contains your PDB files");
067                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
068                //
069                // disable the "All files" option.
070                //
071                chooser.setAcceptAllFileFilterUsed(false);
072                //
073
074
075//              In response to a button click:
076                int returnVal = chooser.showOpenDialog(null);
077                if ( returnVal == JFileChooser.APPROVE_OPTION) {
078                        File file = chooser.getSelectedFile();
079                        textField.setText(file.getAbsolutePath());
080                        textField.repaint();
081                }
082
083        }
084}