| 1 | // Copyright 2004-2007 Jean-Francois Poilpret |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package net.sourceforge.hivegui.component; |
| 16 | |
| 17 | import java.io.File; |
| 18 | |
| 19 | import javax.swing.filechooser.FileFilter; |
| 20 | |
| 21 | public class ExtensionFileFilter extends FileFilter |
| 22 | { |
| 23 | public ExtensionFileFilter(String extension, String description) |
| 24 | { |
| 25 | if (extension.startsWith(".")) |
| 26 | { |
| 27 | _extension = extension; |
| 28 | } |
| 29 | else |
| 30 | { |
| 31 | _extension = "." + extension; |
| 32 | } |
| 33 | _description = description; |
| 34 | } |
| 35 | |
| 36 | @Override public boolean accept(File f) |
| 37 | { |
| 38 | if (f.isDirectory()) |
| 39 | { |
| 40 | return true; |
| 41 | } |
| 42 | else |
| 43 | { |
| 44 | return f.getName().endsWith(_extension); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | @Override public String getDescription() |
| 49 | { |
| 50 | return _description; |
| 51 | } |
| 52 | |
| 53 | public String getExtension() |
| 54 | { |
| 55 | return _extension.substring(1); |
| 56 | } |
| 57 | |
| 58 | private final String _extension; |
| 59 | private final String _description; |
| 60 | } |