1 21 22 package org.armedbear.j; 23 24 import gnu.regexp.RE; 25 import gnu.regexp.REException; 26 import java.lang.reflect.Method ; 27 28 public final class ModeListEntry 29 { 30 private final int id; 31 private final String displayName; 32 private final String className; 33 private final boolean selectable; 34 private final String defaultFiles; 35 private Mode mode; 36 37 public ModeListEntry(int id, String displayName, String className, 38 boolean selectable, String defaultFiles) 39 { 40 this.id = id; 41 this.displayName = displayName; 42 this.className = className; 43 this.selectable = selectable; 44 this.defaultFiles = defaultFiles; 45 } 46 47 public final int getId() 48 { 49 return id; 50 } 51 52 public final String getDisplayName() 53 { 54 return displayName; 55 } 56 57 public final String getClassName() 58 { 59 return className; 60 } 61 62 public final boolean isSelectable() 63 { 64 return selectable; 65 } 66 67 public Mode getMode(boolean create) 68 { 69 if (mode == null && create) { 70 if (className != null) { 71 try { 72 Class c = Class.forName("org.armedbear.j.".concat(className)); 73 Method method = c.getMethod("getMode", new Class [0]); 74 mode = (Mode) method.invoke(null, new Object [0]); 75 } 76 catch (Throwable t) { 77 Log.error(t); 78 } 79 } 80 } 81 return mode; 82 } 83 84 public boolean accepts(String filename) 85 { 86 if (defaultFiles == null) 87 return false; 88 final String key = className.concat(".").concat(Property.FILES.key()); 89 final String userFiles = Editor.preferences().getStringProperty(key); 90 RE filesRE = null; 91 if (userFiles != null) { 92 if (userFiles.trim().length() == 0) 93 return false; 94 try { 95 filesRE = new RE(userFiles, RE.REG_ICASE); 96 } 97 catch (REException e) { 98 Log.error(e); 99 } 100 } else { 101 try { 102 filesRE = new RE(defaultFiles, RE.REG_ICASE); 103 } 104 catch (REException e) { 105 Log.error(e); 106 } 107 } 108 if (filesRE != null && filesRE.isMatch(filename)) 109 return true; 110 else 111 return false; 112 } 113 114 public String toString() 115 { 116 return displayName; 117 } 118 } 119 | Popular Tags |