📄 imagefilefilter.java
字号:
/*
* 11/14/2003
*
* ImageFileFilter - A FileFilter that filters everything except image files
* processed by Swing (*.jpg, *.gif and *.png).
* Copyright (C) 2003 Robert Futrell
* email@address.com
* www.website.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.fife.ui.rtextfilechooser.filters;
import java.io.File;
import javax.swing.filechooser.FileFilter;
/**
* A file filter for <code>JFileChooser</code>s that filters everything except
* image files processed by Swing (<code>*.gif</code>, <code>*.jpg</code>, and
* <code>*.png</code>).
*
* @author Robert Futrell
* @version 1.0
*/
public class ImageFileFilter extends FileFilter {
/*****************************************************************************/
/**
* Accepts all gif, jpg, and png image files.
*
* @param f The file to check.
* @return Whether the file is an image file.
*/
public boolean accept(File f) {
// Accept the "file" if it is a directory.
if (f.isDirectory()) {
return true;
}
// Get the extension of the file.
String extension = null;
String s = f.getName();
int i = s.lastIndexOf('.');
if (i>0 && i<s.length()-1)
extension = s.substring(i+1).toLowerCase();
if (extension!=null &&
(extension.equals("gif") || extension.equals("jpg") ||
extension.equals("png")))
return true;
// Any other files are not accepted by this filter.
return false;
}
/*****************************************************************************/
/**
* Returns the description of this file filter.
*
* @return The description.
*/
public String getDescription() {
return "Supported Image Formats (*.gif, *.jpg)";
}
/*****************************************************************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -