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