1 19 package org.netbeans.modules.xml.core.settings; 20 21 22 23 import java.util.prefs.Preferences ; 24 import org.openide.nodes.BeanNode; 25 import org.openide.util.HelpCtx; 26 import org.openide.util.NbPreferences; 27 import org.openide.util.actions.SystemAction; 28 29 34 public class CoreSettings { 35 private static final CoreSettings INSTANCE = new CoreSettings(); 36 public static final String PROP_AUTO_PARSING_DELAY = "autoParsingDelay"; public static final String PROP_DEFAULT_ACTION = "defaultAction"; public static final String PROP_PREFERED_SHORT_EMPTY_ELEMENT = "preferedShortEmptyElement"; 40 private static Preferences getPreferences() { 41 return NbPreferences.forModule(CoreSettings.class); 42 } 43 44 public static CoreSettings getDefault () { 45 return INSTANCE; 46 } 47 48 private CoreSettings () {} 49 53 54 public String displayName () { 55 String displayName = Util.THIS.getString ("CTL_XML_option"); 56 57 if ( Util.THIS.isLoggable() ) Util.THIS.debug ("CoreSettings::displayName = " + displayName); 59 return displayName; 60 } 61 62 63 public HelpCtx getHelpCtx() { 64 return HelpCtx.DEFAULT_HELP; 66 } 67 68 72 75 public int getAutoParsingDelay () { 76 int autoParsingDelay = getPreferences().getInt(PROP_AUTO_PARSING_DELAY, 3000); 77 if ( Util.THIS.isLoggable() ) Util.THIS.debug ("CoreSettings::getAutoParsingDelay: " + autoParsingDelay); 79 return autoParsingDelay; 80 } 81 82 85 public void setAutoParsingDelay (int delay) { 86 if ( Util.THIS.isLoggable() ) Util.THIS.debug ("CoreSettings::setAutoParsingDelay: " + delay); 88 if (delay < 0) 89 throw new IllegalArgumentException (); 90 91 getPreferences().putInt(PROP_AUTO_PARSING_DELAY, delay); 92 } 93 94 95 102 public String getDefaultAction() { 103 return getPreferences().get(PROP_DEFAULT_ACTION, null); 104 } 105 106 109 public void setDefaultAction(String defaultAction) { 110 getPreferences().put(PROP_DEFAULT_ACTION, defaultAction); 111 } 112 113 118 public SystemAction getDefaultAction(SystemAction actions[], SystemAction systemDefault) { 119 String defaultAction = getDefaultAction(); 120 if (defaultAction == null) return systemDefault; 121 if (actions == null) return systemDefault; 122 123 for (int i=0; i<actions.length; i++) { 125 SystemAction next = (SystemAction) actions[i]; 126 if (next == null) continue; 127 Class klass = next.getClass(); 128 String name = klass.getName(); 129 if (name.equals(defaultAction)) { 130 return next; 131 } 132 } 133 134 return systemDefault; 135 } 136 137 140 public boolean isPreferedShortEmptyElement() { 141 return getPreferences().getBoolean(PROP_PREFERED_SHORT_EMPTY_ELEMENT, false); 142 } 143 144 147 public void setPreferedShortEmptyElement(boolean pref) { 148 getPreferences().putBoolean(PROP_PREFERED_SHORT_EMPTY_ELEMENT, pref); 149 } 150 151 private static BeanNode createViewNode() throws java.beans.IntrospectionException { 152 return new BeanNode(CoreSettings.getDefault()); 153 } 154 } 155 | Popular Tags |