1 33 34 package edu.rice.cs.drjava.ui; 35 36 import java.io.File ; 37 import javax.swing.filechooser.FileFilter ; 38 import edu.rice.cs.drjava.DrJava; 39 import edu.rice.cs.drjava.DrJavaRoot; 40 import edu.rice.cs.drjava.config.OptionConstants; 41 42 43 46 public class JavaSourceFilter extends FileFilter { 47 48 49 public boolean accept(File f) { 50 if (f.isDirectory()) { 51 return true; 52 } 53 String extension = getExtension(f); 54 if (extension != null) { 55 switch (DrJava.getConfig().getSetting(OptionConstants.LANGUAGE_LEVEL)) { 56 case (DrJavaRoot.FULL_JAVA): return (extension.equals("java") || extension.equals("j")); 57 case (DrJavaRoot.ELEMENTARY_LEVEL): return extension.equals("dj0"); 58 case (DrJavaRoot.INTERMEDIATE_LEVEL): return extension.equals("dj1"); 59 case (DrJavaRoot.ADVANCED_LEVEL): return extension.equals("dj2"); 60 } 61 } 62 return false; 63 } 64 65 66 public String getDescription() { 67 switch (DrJava.getConfig().getSetting(OptionConstants.LANGUAGE_LEVEL)) { 68 case (DrJavaRoot.FULL_JAVA): return "Java source files"; 69 case (DrJavaRoot.ELEMENTARY_LEVEL): return "Elementary source files (.dj0)"; 70 case (DrJavaRoot.INTERMEDIATE_LEVEL): return "Intermediate source files (.dj1)"; 71 case (DrJavaRoot.ADVANCED_LEVEL): return "Advanced source files (.dj2)"; 72 } 73 return "Java source files"; 74 } 75 76 77 public static String getExtension(File f) { 78 String ext = null; 79 String s = f.getName(); 80 int i = s.lastIndexOf('.'); 81 if (i > 0 && i < s.length() - 1) { 82 ext = s.substring(i + 1).toLowerCase(); 83 } 84 return ext; 85 } 86 } 87 88 89 90 | Popular Tags |