PageRenderTime 18ms CodeModel.GetById 11ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/edu/uncc/parsets/gui/CombinedFileNameFilter.java

https://code.google.com/p/parsets/
Java | 59 lines | 17 code | 8 blank | 34 comment | 1 complexity | 15b45a2e0993187d7676ed7dd6637ec6 MD5 | raw file
 1package edu.uncc.parsets.gui;
 2
 3import java.io.File;
 4import java.io.FilenameFilter;
 5
 6import javax.swing.filechooser.FileFilter;
 7
 8/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
 9 * Copyright (c) 2009, Robert Kosara, Caroline Ziemkiewicz,
10 *                     and others (see Authors.txt for full list)
11 * All rights reserved.
12 * 
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions are met:
15 * 
16 *    * Redistributions of source code must retain the above copyright
17 *      notice, this list of conditions and the following disclaimer.
18 *    * Redistributions in binary form must reproduce the above copyright
19 *      notice, this list of conditions and the following disclaimer in the
20 *      documentation and/or other materials provided with the distribution.
21 *    * Neither the name of UNC Charlotte nor the names of its contributors
22 *      may be used to endorse or promote products derived from this software
23 *      without specific prior written permission.
24 *      
25 * THIS SOFTWARE IS PROVIDED BY ITS AUTHORS ''AS IS'' AND ANY
26 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
29 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
36
37/**
38 * Combine {@link FileFilter} and {@link FilenameFilter} for universal use in
39 * Swing and AWT file dialogs. Subclasses only need to override
40 * {@link #getDescription()} and {@link #getExtension()} to accept only
41 * files.
42 */
43public abstract class CombinedFileNameFilter extends FileFilter implements FilenameFilter {
44
45	@Override
46	public boolean accept(File f) {
47		return accept(f.getParentFile(), f.getName()) || f.isDirectory();
48	}
49
50	@Override
51	public boolean accept(File dir, String name) {
52		return name.endsWith(getExtension());
53	}
54
55	@Override
56	public abstract String getDescription();
57
58	public abstract String getExtension();
59}