?? fortranfilefilter.java
字號:
/*
* 03/23/2005
*
* FortranFileFilter.java - File filter for Fortran files.
* Copyright (C) 2005 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
* Fortran files.
*
* @author Robert Futrell
* @version 1.0
*/
public class FortranFileFilter extends FileFilter {
private String description;
private static final String[] extensions = { "f",
"for",
"fort",
"f77",
"f90"
};
/*****************************************************************************/
/**
* Constructor.
*/
public FortranFileFilter() {
super();
StringBuffer buffer = new StringBuffer();
int extensionCount = extensions.length;
for (int i=0; i<extensionCount-1; i++)
buffer.append("*.").append(extensions[i]).append(", ");
buffer.append(extensions[extensionCount-1]).append(")");
description = "Fortran Source Files (" + buffer.toString();
}
/*****************************************************************************/
/**
* Accepts all directories and all Fortran files.
*/
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 Fortran file.
return extension!=null && isFortranExtension(extension);
}
/*****************************************************************************/
// The description of this filter.
public String getDescription() {
return description;
}
/*****************************************************************************/
/**
* Returns whether or not the given extension is a "Fortran" extension.
*
* @param ext The extension.
* @return Whether a file with that extension is a Fortran source file.
*/
private static final boolean isFortranExtension(String ext) {
int extensionCount = extensions.length;
for (int i=0; i<extensionCount; i++)
if (extensions[i].equals(ext))
return true;
return false;
}
/*****************************************************************************/
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -