1 19 20 21 package org.netbeans.modules.i18n; 22 23 24 import java.io.File ; 25 import java.io.File ; 26 import java.util.ArrayList ; 27 import java.util.List ; 28 import java.util.logging.Level ; 29 import java.util.logging.Logger ; 30 import java.util.prefs.Preferences ; 31 32 import org.openide.filesystems.FileObject; 33 import org.openide.filesystems.FileStateInvalidException; 34 import org.openide.filesystems.FileSystem; 35 import org.openide.filesystems.FileSystem; 36 import org.openide.filesystems.FileUtil; 37 import org.openide.loaders.DataObject; 38 import org.openide.util.HelpCtx; 39 import org.openide.loaders.DataObjectNotFoundException; 40 import org.openide.nodes.BeanNode; 41 import org.openide.util.NbPreferences; 42 43 48 public class I18nOptions { 49 private static final I18nOptions INSTANCE = new I18nOptions(); 50 51 53 public static final String PROP_ADVANCED_WIZARD = "advancedWizard"; 55 57 public static final String PROP_INIT_JAVA_CODE = "initJavaCode"; 59 61 public static final String PROP_REPLACE_JAVA_CODE = "replaceJavaCode"; 63 66 public static final String PROP_REGULAR_EXPRESSION = "regularExpression"; 68 71 public static final String PROP_I18N_REGULAR_EXPRESSION = "i18nRegularExpression"; 73 75 public static final String PROP_REPLACE_RESOURCE_VALUE = "replaceResourceValue"; 77 79 public static final String PROP_LAST_RESOURCE2 = "lastResource2"; 81 82 84 private I18nOptions() {} 85 86 public static I18nOptions getDefault() { 87 return INSTANCE; 88 } 89 90 private static Preferences getPreferences() { 91 return NbPreferences.forModule(I18nOptions.class); 92 } 93 94 95 public String displayName() { 96 return I18nUtil.getBundle().getString("LBL_Internationalization"); 97 } 98 99 100 public boolean isAdvancedWizard() { 101 return getPreferences().getBoolean(PROP_ADVANCED_WIZARD,false); 103 } 104 105 106 public void setAdvancedWizard(boolean generateField) { 107 getPreferences().putBoolean(PROP_ADVANCED_WIZARD,generateField); 109 } 110 111 112 public String getInitJavaCode() { 113 return getPreferences().get(PROP_INIT_JAVA_CODE,(String )I18nUtil.getInitFormatItems().get(0)); 114 } 115 116 117 public void setInitJavaCode(String initJavaCode) { 118 getPreferences().put(PROP_INIT_JAVA_CODE,initJavaCode); 119 } 120 121 122 public String getReplaceJavaCode() { 123 return getPreferences().get(PROP_REPLACE_JAVA_CODE,(String )I18nUtil.getDefaultReplaceFormat(false)); 125 } 126 127 128 public void setReplaceJavaCode(String replaceJavaCode) { 129 getPreferences().put(PROP_REPLACE_JAVA_CODE,replaceJavaCode); 130 } 131 132 134 public String getRegularExpression() { 135 return getPreferences().get(PROP_REGULAR_EXPRESSION,(String )I18nUtil.getRegExpItems().get(0)); 136 } 137 138 140 public void setRegularExpression(String regExp) { 141 getPreferences().put(PROP_REGULAR_EXPRESSION,regExp); 142 } 143 144 146 public String getI18nRegularExpression() { 147 return getPreferences().get(PROP_I18N_REGULAR_EXPRESSION,(String )I18nUtil.getI18nRegExpItems().get(0)); 148 } 149 150 152 public void setI18nRegularExpression(String regExp) { 153 getPreferences().put(PROP_I18N_REGULAR_EXPRESSION,regExp); 154 } 155 156 157 public boolean isReplaceResourceValue() { 158 return getPreferences().getBoolean(PROP_REPLACE_RESOURCE_VALUE,false); 159 } 160 161 162 public void setReplaceResourceValue(boolean replaceResourceValue) { 163 getPreferences().putBoolean(PROP_REPLACE_RESOURCE_VALUE,replaceResourceValue); 164 } 165 166 167 public DataObject getLastResource2() { 168 String path = getPreferences().get(PROP_LAST_RESOURCE2,null); 169 FileObject f = (path != null) ? findFileObject(path) : null; 170 if ((f != null) && !f.isFolder() && f.isValid()) { 171 try { 172 return DataObject.find(f); 173 } catch (DataObjectNotFoundException e) { 174 175 getPreferences().remove(PROP_LAST_RESOURCE2); 176 } 177 } 178 return null; 179 } 180 181 182 public void setLastResource2(DataObject lastResource) { 183 if(lastResource == null) 185 return; 186 187 getPreferences().put(PROP_LAST_RESOURCE2,lastResource.getPrimaryFile().getPath()); 188 } 189 190 193 public HelpCtx getHelpCtx () { 194 return new HelpCtx (I18nOptions.class); 195 } 196 197 private static FileSystem[] getFileSystems() { 198 List retval = new ArrayList (); 199 File [] all = File.listRoots(); 200 for (int i = 0; i < all.length; i++) { 201 File file = all[i]; 202 FileObject fo = FileUtil.toFileObject(file); 203 if (fo != null) { 204 try { 205 retval.add(fo.getFileSystem()); 206 } catch (FileStateInvalidException ex) { 207 Logger.getLogger(I18nOptions.class.getName()).log(Level.INFO, null, ex); 208 } 209 } 210 } 211 return (FileSystem[])retval.toArray(new FileSystem[retval.size()]); 212 } 213 214 private static FileObject findFileObject(String path) { 215 FileObject retval = null; 216 FileSystem[] fss = getFileSystems(); 217 for (int i = 0; retval == null && i < fss.length; i++) { 218 FileSystem fileSystem = fss[i]; 219 retval = fileSystem.findResource(path); 220 } 221 return retval; 222 } 223 224 private static BeanNode createViewNode() throws java.beans.IntrospectionException { 225 return new BeanNode(I18nOptions.getDefault()); 226 } 227 } 228 | Popular Tags |