View Javadoc

1   package org.ximtec.igesture.tool.util;
2   
3   import java.io.File;
4   
5   public enum FileType {
6     
7     compressedWorkbench("igz", "iGesture Workspace Compressed"),
8     xstreamWorkbench("igx", "iGesture Workspace XStream"),
9     db4oWorkbench("igd", "iGesture Workspace db4o"),
10    gestureSet("igs", "iGesture Gesture Set"),
11    testSet("igt", "iGesture Test Set"),
12    algorithmConfiguration("igc", "iGesture Recogniser Configuration"),
13    pdf ("pdf", "Portable Document Format"),
14    igb("igb", "iGesture Batch Configuration"),
15    deviceConfiguration("igdc","iGesture Device Configuration");
16    
17    private String extension;
18    private String description;
19    private ExtensionFileFilter filter;
20    
21    /**
22     * Constructor
23     * @param extension
24     * @param description
25     */
26    private FileType(String extension, String description){
27      this.extension = extension;
28      this.description = description;
29      this.filter = new ExtensionFileFilter(this.extension, this.description);
30    }
31    
32    /**
33     * Returns the file type extension
34     * @return the file type extension
35     */
36    public String getExtension(){
37      return this.extension;
38    }
39    
40    /**
41     * Returns the file type description
42     * @return the file type description
43     */
44    public String getDescription(){
45      return this.description;
46    }
47  
48    /**
49     * Returns the extension file filter 
50     * @return the extension file filter 
51     */
52    public ExtensionFileFilter getFilter(){
53      return this.filter;
54    }
55    
56    /**
57     * Adds the extension if it is not already there.
58     * @param file
59     * @return file with extension
60     */
61    public File addExtension(File file){
62      if(file != null && !file.getName().endsWith(this.extension) ){
63        File parent = file.getParentFile();
64        return new File(parent, String.format("%s.%s", file.getName(), extension));
65      }
66      
67      return file;
68    }
69  }