ExampleFileFilter.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
10 package com.generalrobotix.ui.view.tdview;
11 
12 /*
13  * @(#)ExampleFileFilter.java 1.9 99/04/23
14  *
15  * Copyright (c) 1998, 1999 by Sun Microsystems, Inc. All Rights Reserved.
16  *
17  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
18  * modify and redistribute this software in source and binary code form,
19  * provided that i) this copyright notice and license appear on all copies of
20  * the software; and ii) Licensee does not utilize the software in a manner
21  * which is disparaging to Sun.
22  *
23  * This software is provided "AS IS," without a warranty of any kind. ALL
24  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
25  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
26  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
27  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
28  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
29  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
30  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
31  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
32  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGES.
34  *
35  * This software is not designed or intended for use in on-line control of
36  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
37  * the design, construction, operation or maintenance of any nuclear
38  * facility. Licensee represents and warrants that it will not use or
39  * redistribute the Software for such purposes.
40  */
41 
42 
43 import java.io.File;
44 import java.util.Hashtable;
45 import java.util.Enumeration;
46 import javax.swing.filechooser.*;
47 
67 public class ExampleFileFilter extends FileFilter {
68 
69 // private static String TYPE_UNKNOWN = "Type Unknown";
70 // private static String HIDDEN_FILE = "Hidden File";
71 
72  private Hashtable<String, ExampleFileFilter> filters = null;
73  private String description = null;
74  private String fullDescription = null;
75  private boolean useExtensionsInDescription = true;
76 
83  public ExampleFileFilter() {
84  this.filters = new Hashtable<String, ExampleFileFilter>();
85  }
86 
93  public ExampleFileFilter(String extension) {
94  this(extension,null);
95  }
96 
106  public ExampleFileFilter(String extension, String description) {
107  this();
108  if(extension!=null) addExtension(extension);
109  if(description!=null) setDescription(description);
110  }
111 
121  public ExampleFileFilter(String[] filters) {
122  this(filters, null);
123  }
124 
133  public ExampleFileFilter(String[] filters, String description) {
134  this();
135  for (int i = 0; i < filters.length; i++) {
136  // add filters one by one
137  addExtension(filters[i]);
138  }
139  if(description!=null) setDescription(description);
140  }
141 
151  public boolean accept(File f) {
152  if(f != null) {
153  if(f.isDirectory()) {
154  return true;
155  }
156  String extension = getExtension(f);
157  if(extension != null && filters.get(getExtension(f)) != null) {
158  return true;
159  };
160  }
161  return false;
162  }
163 
170  public String getExtension(File f) {
171  if(f != null) {
172  String filename = f.getName();
173  int i = filename.lastIndexOf('.');
174  if(i>0 && i<filename.length()-1) {
175  return filename.substring(i+1).toLowerCase();
176  };
177  }
178  return null;
179  }
180 
193  public void addExtension(String extension) {
194  if(filters == null) {
195  filters = new Hashtable<String, ExampleFileFilter>(5);
196  }
197  filters.put(extension.toLowerCase(), this);
198  fullDescription = null;
199  }
200 
201 
211  public String getDescription() {
212  if(fullDescription == null) {
213  if(description == null || isExtensionListInDescription()) {
214  fullDescription = description==null ? "(" : description + " (";
215  // build the description from the extension list
216  Enumeration<String> extensions = filters.keys();
217  if(extensions != null) {
218  fullDescription += "." + (String) extensions.nextElement();
219  while (extensions.hasMoreElements()) {
220  fullDescription += ", " + (String) extensions.nextElement();
221  }
222  }
223  fullDescription += ")";
224  } else {
225  fullDescription = description;
226  }
227  }
228  return fullDescription;
229  }
230 
239  public void setDescription(String description) {
240  this.description = description;
241  fullDescription = null;
242  }
243 
255  public void setExtensionListInDescription(boolean b) {
256  useExtensionsInDescription = b;
257  fullDescription = null;
258  }
259 
271  public boolean isExtensionListInDescription() {
273  }
274 }
char * filename
Definition: cdjpeg.h:133
#define null
our own NULL pointer
Definition: IceTypes.h:57
png_uint_32 i
Definition: png.h:2735
long b
Definition: jpegint.h:371
Hashtable< String, ExampleFileFilter > filters
ExampleFileFilter(String[] filters, String description)
ExampleFileFilter(String extension, String description)


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:21