package miw2;
 
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
 
/**
 * Prolog file chooser with filter for prolog files.
 * @author Filip
 */
public class PlFileChooser {
 
    /**
     * Name of the file to load.
     */
    private static String fileName;
 
    /**
     * Default constructor of prolog file chooser Dialog.
     */
    public PlFileChooser(){
 
        PlFilter filter = new PlFilter();
        JFileChooser jfc = new JFileChooser();
        jfc.setFileFilter( filter);
        if(jfc.showOpenDialog(null)== JFileChooser.APPROVE_OPTION){
            fileName = jfc.getSelectedFile().toString();
        }
    }
 
    /**
     * Prolog files' filter.
     */
    private class PlFilter extends FileFilter{
 
        public boolean accept(File file) {
            if(file == null)return false;
            else if(file.isDirectory())return true;
 
            return file.getName().endsWith("pl");
        }
 
        @Override
        public String getDescription() {
            //throw new UnsupportedOperationException("Not supported yet.");
            return "prolog files";
        }
 
    }
 
    /**
     * Return prolog file name.
     * @return file name.
     */
    public String getFile(){
        return fileName;
    }
}
pl/miw/miw08_ruleruntimeg/plfilechooser.txt · ostatnio zmienione: 2017/07/17 08:08 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0