001    /*
002     * This file is part of McIDAS-V
003     *
004     * Copyright 2007-2013
005     * Space Science and Engineering Center (SSEC)
006     * University of Wisconsin - Madison
007     * 1225 W. Dayton Street, Madison, WI 53706, USA
008     * https://www.ssec.wisc.edu/mcidas
009     * 
010     * All Rights Reserved
011     * 
012     * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
013     * some McIDAS-V source code is based on IDV and VisAD source code.  
014     * 
015     * McIDAS-V is free software; you can redistribute it and/or modify
016     * it under the terms of the GNU Lesser Public License as published by
017     * the Free Software Foundation; either version 3 of the License, or
018     * (at your option) any later version.
019     * 
020     * McIDAS-V is distributed in the hope that it will be useful,
021     * but WITHOUT ANY WARRANTY; without even the implied warranty of
022     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
023     * GNU Lesser Public License for more details.
024     * 
025     * You should have received a copy of the GNU Lesser Public License
026     * along with this program.  If not, see http://www.gnu.org/licenses.
027     */
028    
029    package edu.wisc.ssec.mcidasv.chooser;
030    
031    import java.beans.PropertyChangeEvent;
032    import java.beans.PropertyChangeListener;
033    
034    import javax.swing.JFileChooser;
035    import javax.swing.filechooser.FileFilter;
036    import javax.swing.filechooser.FileNameExtensionFilter;
037    
038    import org.slf4j.Logger;
039    import org.slf4j.LoggerFactory;
040    
041    /**
042     * An extension of JFileChooser to handle Two-Line Element (TLE)
043     * files, for plotting satellite orbit tracks.
044     * 
045     * @author tommyj
046     *
047     */
048    
049    public class TLEFileChooser extends JFileChooser implements PropertyChangeListener {
050    
051            /**
052             * auto-generated default value
053             */
054            private static final long serialVersionUID = 1L;
055            private static final Logger logger = LoggerFactory.getLogger(TLEFileChooser.class);
056            
057            // the enclosing orbit track chooser
058            private PolarOrbitTrackChooser potc = null;
059            
060            /**
061         * Create the file chooser
062         *
063         * @param path   the initial path
064         */
065            
066        public TLEFileChooser(String path) {
067            super(path);
068            setControlButtonsAreShown(false);
069            setMultiSelectionEnabled(false);
070            FileFilter filter = new FileNameExtensionFilter("TLE files", "txt");
071            addChoosableFileFilter(filter);
072            setAcceptAllFileFilterUsed(false);
073            setFileFilter(filter);
074            addPropertyChangeListener(this);
075            logger.debug("TLEFileChooser constructor...");
076        }
077    
078        /**
079         * Approve the selection
080         */
081        
082        public void approveSelection() {
083            potc.doLoad();
084        }
085    
086            public void setPotc(PolarOrbitTrackChooser potc) {
087                    this.potc = potc;
088            }
089    
090            public PolarOrbitTrackChooser getPotc() {
091                    return potc;
092            }
093    
094            @Override
095            public void propertyChange(PropertyChangeEvent pce) {
096                    String propName = pce.getPropertyName();
097                    if (propName.equals(SELECTED_FILE_CHANGED_PROPERTY)) {
098                            // tell the chooser we have a file to load
099                            if (potc != null) {
100                                    if (this.accept(this.getSelectedFile())) {
101                                            logger.debug("File selected, enabling Add Source button...");
102                                            potc.enableFileLoad(true);
103                                    } else {
104                                            potc.enableFileLoad(false);
105                                    }
106                            } else {
107                                    logger.debug("null potc, wt?");
108                            }
109                    }
110            }
111    
112    }