]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/ModuleEditor/src/org/tianocore/common/IFileFilter.java
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@671 6f19259b...
[mirror_edk2.git] / Tools / Source / ModuleEditor / src / org / tianocore / common / IFileFilter.java
1 /** @file
2
3 The file is used to override FileFilter to provides customized interfaces
4
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 package org.tianocore.common;
17
18 import java.io.File;
19
20 import javax.swing.filechooser.FileFilter;
21
22 /**
23 The class is used to override FileFilter to provides customized interfaces
24
25 @since ModuleEditor 1.0
26
27 **/
28 public class IFileFilter extends FileFilter {
29
30 private String strExt;
31
32 /**
33 Reserved for test
34
35 @param args
36
37 **/
38 public static void main(String[] args) {
39 // TODO Auto-generated method stub
40
41 }
42
43 /**
44 This is the default constructor
45
46 @param ext
47
48 **/
49 public IFileFilter(String ext) {
50 this.strExt = ext;
51 }
52
53 /* (non-Javadoc)
54 * @see javax.swing.filechooser.FileFilter#accept(java.io.File)
55 *
56 * Override method "accept"
57 *
58 */
59 public boolean accept(File file) {
60 if (file.isDirectory()) {
61 return true;
62 }
63 String strFileName = file.getName();
64 int intIndex = strFileName.lastIndexOf('.');
65 if (intIndex > 0 && intIndex < strFileName.length() - 1) {
66 String strExtension = strFileName.substring(intIndex + 1).toLowerCase();
67 if (strExtension.equals(strExt))
68 return true;
69 }
70 return false;
71 }
72
73 /* (non-Javadoc)
74 * @see javax.swing.filechooser.FileFilter#getDescription()
75 *
76 * Override method "getDescription" to config description via different file type
77 *
78 */
79 public String getDescription() {
80 if (strExt.equals("msa"))
81 return "Module Surface Area File(*.msa)";
82 if (strExt.equals("mbd"))
83 return "Module Build Description File(*.mbd)";
84 return "";
85 }
86
87 }