⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 extensionfilefilter.java

📁 用java编写的IDE程序示例
💻 JAVA
字号:
/*
 * Created on 2004-5-26
 */
package yuchifang.javaIDE.util;

import java.io.File;
import java.util.ArrayList;

import javax.swing.filechooser.FileFilter;

/**
 * @author yuchifang
 */
/**
   This file filter matches all files with a given set of
   extensions.
*/
public class ExtensionFileFilter extends FileFilter
{
  private ArrayList extensions = new ArrayList();
  private String description = "";

  /**
     Sets a description for the file set that this file filter
     recognizes.
     @param aDescription a description for the file set
  */
  public void setDescription(String aDescription)
  {
    description = aDescription;
  }

  /**
     Returns a description for the file set that this file
     filter recognizes.
     @return a description for the file set
  */
  public String getDescription()
  {
    return description;
  }

  public boolean accept(File f)
  {
    if (f.isDirectory())
      return true;

    String name = f.getName().toLowerCase();

    // check if the file name ends with any of the extensions
    for (int i = 0; i < extensions.size(); i++)
    {
      if (name.endsWith((String) extensions.get(i)))
        return true;
    }

    return false;
  }

  /**
     Adds an extension that this file filter recognizes.
     @param extension a file extension (such as ".txt" or "txt")
  */
  public void addExtension(String extension)
  {
    if (!extension.startsWith("."))
      extension = "." + extension;

    extensions.add(extension.toLowerCase());
  }
}

⌨️ 快捷键说明

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