spatialfilefilter.java

来自「Java source code for the Ant Colony Opti」· Java 代码 · 共 54 行

JAVA
54
字号
package jwo.jpss.spatial.gui;

import javax.swing.filechooser.*;
import java.io.File;
			
//  **************************************************************
/** Provides a file filter to allow only spatial files to be 
  * to be displayed in a JFileChooser.
  * @author  Jo Wood.
  * @version 1.3, 11th October, 2001.
  */
//  **************************************************************

public class SpatialFileFilter extends FileFilter
{       
    // ---------------------- Class variables -------------------

    private static final String[] extensions = {"gis","grd","txt","xml"};

    // ------------------- Implemented Methods ------------------
    
    /** Filters only file extensions of known spatial file formats.
      * @param file File to consider displaying.
      * @return true if file has a recognised spatial filename extension.
      */
    public boolean accept(File file) 
    {
        if (file.isDirectory()) 
            return true;
        
        // Find file name extension.
        String fileName = file.getName();
        int i = fileName.lastIndexOf('.');

        if ((i > 0) && (i < fileName.length()-1))
        {
            String ext = fileName.substring(i+1);
            for (int extNum=0; extNum<extensions.length; extNum++)
            {
                if (ext.equalsIgnoreCase(extensions[extNum]))
                    return true;
             }
        }
        return false;
    }
    
    /** Reports the description of this filter for the file chooser.
      * @return Description of this filter.
      */
    public String getDescription() 
    {
        return new String("Spatial files");
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?