View Javadoc

1   package org.wcb.autohome.util;
2   
3   import java.io.File;
4   
5   /***
6    * Copyright (C) 1999  Walter Bogaardt
7    *
8    * This library is free software; you can redistribute it and/or
9    * modify it under the terms of the GNU Lesser General Public
10   * License as published by the Free Software Foundation; either
11   * version 2 of the License, or (at your option) any later version.
12   *
13   * This library is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16   * Lesser General Public License for more details.
17   *
18   * You should have received a copy of the GNU Lesser General Public
19   * License along with this library; if not, write to the Free Software
20   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
21   *
22   *  Project:   Home Automation Interface
23   *  Filename:  $Id: X10Filter.java,v 1.0 1999/09/14 23:42:04 wbogaardt
24   */
25  public class X10Filter extends javax.swing.filechooser.FileFilter {
26  
27      /***
28       * This determinse if the passed in file should be displayed.
29       * @param f File path and name
30       * @return true indicates display file
31       */
32      public boolean accept(File f) {
33          boolean accept = f.isDirectory();
34          if (!accept)
35          {
36              String suffix = getSuffix(f);
37              if (suffix != null)
38              {
39                  accept = suffix.equals("x10");
40              }
41          }
42          return accept;
43      }
44  
45      /***
46       * Gets the description of the filter for display in the
47       * file open dialog
48       * @return String of the displayable filter description
49       */
50      public String getDescription() {
51          return "X10 module files (*.x10)";
52      }
53  
54      /***
55       * Gets the suffix of the file.
56       * @param f The file name
57       * @return  String after the period.
58       */
59      private String getSuffix(File f) {
60          String s = f.getPath(), suffix = null;
61          int i = s.lastIndexOf('.');
62          if (i > 0 && i < s.length() - 1)
63          {
64              suffix = s.substring(i + 1).toLowerCase();
65          }
66          return suffix;
67      }
68  }