1 19 20 package org.netbeans.modules.options.generaleditor; 21 22 import java.lang.reflect.Method ; 23 import java.util.Iterator ; 24 import java.util.Map ; 25 import java.util.Set ; 26 import org.netbeans.api.editor.mimelookup.MimeLookup; 27 import org.netbeans.api.editor.mimelookup.MimePath; 28 import org.netbeans.editor.SettingsNames; 29 import org.netbeans.modules.editor.options.BaseOptions; 30 import org.netbeans.modules.editor.settings.storage.api.EditorSettings; 31 32 33 public class Model { 34 35 37 boolean isShowCodeFolding () { 38 return getFoldingParameter (SettingsNames.CODE_FOLDING_ENABLE, true); 39 } 40 41 boolean isFoldImports () { 42 return getFoldingParameter ("code-folding-collapse-import", false); 43 } 44 45 boolean isFoldInitialComment () { 46 return getFoldingParameter ("code-folding-collapse-initial-comment", false); 47 } 48 49 boolean isFoldInnerClasses () { 50 return getFoldingParameter ("code-folding-collapse-innerclass", false); 51 } 52 53 boolean isFoldJavaDocComments () { 54 return getFoldingParameter ("code-folding-collapse-javadoc", false); 55 } 56 57 boolean isFoldMethods () { 58 return getFoldingParameter ("code-folding-collapse-method", false); 59 } 60 61 void setFoldingOptions ( 62 boolean showCodeFolding, 63 boolean foldImports, 64 boolean foldInitialComent, 65 boolean foldInnerClasses, 66 boolean foldJavaDoc, 67 boolean foldMethods 68 ) { 69 if (javaOptions == null) 70 javaOptions = getOptions ("text/x-java"); 71 if (javaOptions == null) return; 72 Map javaFoldingMap = javaOptions.getCodeFoldingProps (); 73 74 javaFoldingMap.put ( 75 SettingsNames.CODE_FOLDING_ENABLE, 76 Boolean.valueOf (showCodeFolding) 77 ); 78 javaFoldingMap.put ( 79 "code-folding-collapse-import", 80 Boolean.valueOf (foldImports) 81 ); 82 javaFoldingMap.put ( 83 "code-folding-collapse-initial-comment", 84 Boolean.valueOf (foldInitialComent) 85 ); 86 javaFoldingMap.put ( 87 "code-folding-collapse-innerclass", 88 Boolean.valueOf (foldInnerClasses) 89 ); 90 javaFoldingMap.put ( 91 "code-folding-collapse-javadoc", 92 Boolean.valueOf (foldJavaDoc) 93 ); 94 javaFoldingMap.put ( 95 "code-folding-collapse-method", 96 Boolean.valueOf (foldMethods) 97 ); 98 javaOptions.setCodeFoldingProps (javaFoldingMap); 99 100 Set mimeTypes = EditorSettings.getDefault().getMimeTypes(); 101 for(Iterator i = mimeTypes.iterator(); i.hasNext(); ) { 102 String mimeType = (String ) i.next(); 103 BaseOptions baseOptions = (BaseOptions) MimeLookup.getLookup(MimePath.parse(mimeType)).lookup(BaseOptions.class); 104 105 if (baseOptions == null) { 106 continue; 107 } 108 109 Map m = baseOptions.getCodeFoldingProps (); 110 m.put ( 111 SettingsNames.CODE_FOLDING_ENABLE, 112 Boolean.valueOf (showCodeFolding) 113 ); 114 baseOptions.setCodeFoldingProps (m); 115 } 116 } 117 118 119 121 boolean isPairCharacterCompletion () { 122 return getParameter ("getPairCharactersCompletion", true); 123 } 124 125 boolean isCompletionAutoPopup () { 126 return getParameter ("getCompletionAutoPopup", true); 127 } 128 129 boolean isShowDeprecatedMembers () { 130 return getParameter ("getShowDeprecatedMembers", true); 131 } 132 133 boolean isCompletionInstantSubstitution () { 134 return getParameter ("getCompletionInstantSubstitution", true); 135 } 136 137 boolean isCompletionCaseSensitive () { 138 return getParameter ("getCompletionCaseSensitive", true); 139 } 140 141 void setCompletionOptions ( 142 boolean pairCharacterCompletion, 143 boolean completionAutoPopup, 144 boolean showDeprecatedMembers, 145 boolean completionInstantSubstitution, 146 boolean completionCaseSensitive 147 ) { 148 Set mimeTypes = EditorSettings.getDefault().getMimeTypes(); 149 for(Iterator i = mimeTypes.iterator(); i.hasNext(); ) { 150 String mimeType = (String ) i.next(); 151 BaseOptions baseOptions = (BaseOptions) MimeLookup.getLookup(MimePath.parse(mimeType)).lookup(BaseOptions.class); 152 153 if (baseOptions == null) { 154 continue; 155 } 156 157 try { 158 Method method = baseOptions.getClass ().getMethod ( 159 "setPairCharactersCompletion", 160 new Class [] {Boolean.TYPE} 161 ); 162 method.invoke ( 163 baseOptions, 164 new Object [] {Boolean.valueOf (pairCharacterCompletion)} 165 ); 166 } catch (Exception ex) { 167 } 168 try { 169 Method method = baseOptions.getClass ().getMethod ( 170 "setCompletionAutoPopup", 171 new Class [] {Boolean.TYPE} 172 ); 173 method.invoke ( 174 baseOptions, 175 new Object [] {Boolean.valueOf (completionAutoPopup)} 176 ); 177 } catch (Exception ex) { 178 } 179 try { 180 Method method = baseOptions.getClass ().getMethod ( 181 "setShowDeprecatedMembers", 182 new Class [] {Boolean.TYPE} 183 ); 184 method.invoke ( 185 baseOptions, 186 new Object [] {Boolean.valueOf (showDeprecatedMembers)} 187 ); 188 } catch (Exception ex) { 189 } 190 try { 191 Method method = baseOptions.getClass ().getMethod ( 192 "setCompletionInstantSubstitution", 193 new Class [] {Boolean.TYPE} 194 ); 195 method.invoke ( 196 baseOptions, 197 new Object [] {Boolean.valueOf (completionInstantSubstitution)} 198 ); 199 } catch (Exception ex) { 200 } 201 try { 202 Method method = baseOptions.getClass ().getMethod ( 203 "setCompletionCaseSensitive", 204 new Class [] {Boolean.TYPE} 205 ); 206 method.invoke ( 207 baseOptions, 208 new Object [] {Boolean.valueOf (completionCaseSensitive)} 209 ); 210 } catch (Exception ex) { 211 } 212 } 213 } 214 215 216 218 private boolean getFoldingParameter ( 219 String parameterName, 220 boolean defaultValue 221 ) { 222 BaseOptions options = getOptions ("text/x-java"); 223 if (options == null) 224 options = getOptions ("text/plain"); 225 if (options == null) return defaultValue; 226 Map javaFoldingMap = options.getCodeFoldingProps (); 227 Boolean b = (Boolean ) javaFoldingMap.get (parameterName); 228 if (b != null) return b.booleanValue (); 229 return defaultValue; 230 } 231 232 private BaseOptions javaOptions; 233 234 private boolean getParameter (String parameterName, boolean defaultValue) { 235 if (javaOptions == null) { 236 javaOptions = getOptions ("text/x-java"); 237 if (javaOptions == null) 238 javaOptions = getOptions ("text/plain"); 239 } 240 if (javaOptions == null) return defaultValue; 241 try { 242 Method method = javaOptions.getClass ().getMethod ( 243 parameterName, 244 new Class [0] 245 ); 246 return ((Boolean ) method.invoke (javaOptions, new Object [0])). 247 booleanValue (); 248 } catch (Exception ex) { 249 } 250 return defaultValue; 251 } 252 253 private static BaseOptions getOptions (String mimeType) { 254 return (BaseOptions) MimeLookup.getLookup(MimePath.parse(mimeType)).lookup(BaseOptions.class); 255 } 256 } 257 258 259 | Popular Tags |