📄 cplusplusfilefilter.java
字号:
/*
* 03/12/2004
*
* CPlusPlusFileFilter - A FileFilter that filters everything except C/C++
* related files.
* Copyright (C) 2004 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.*;
/**
* A file filter for <code>JFileChooser</code>s that filters everything except
* for C/C++ related files.
*
* @author Robert Futrell
* @version 1.0
*/
public class CPlusPlusFileFilter extends FileFilter {
/*****************************************************************************/
/**
* Decides whether or not a file is "accepted" (i.e., visible in
* a <code>JFileChooser</code> with this filter enabled). Accepts
* all directories and all <code>.c</code>, <code>.cpp</code>,
* <code>.cxx</code>, and <code>.h</code> files.
*
* @param f A file to check for whether or not it passes this filter.
* @return Whether or not f passes this filter.
*/
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();
// Now, accept the file ONLY if it is a .txt file.
if (extension!=null &&
(extension.equals("c") || extension.equals("cpp") ||
extension.equals("cxx") || extension.equals("h")))
return true;
// Any other files are not accepted by this filter.
return false;
}
/*****************************************************************************/
/**
* Gets the description of this filter. This is the message displayed in
* the "Files of type" part of the <code>JFileChooser</code>.
*
* @return The description of this filter.
*/
public String getDescription() {
return "C/C++ Source Files (*.c, *.cpp, *.cxx, *.h)";
}
/*****************************************************************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -