1 19 20 package org.netbeans.modules.xml.schema.ui.basic; 21 22 import java.io.IOException ; 23 import java.io.ObjectInput ; 24 import org.openide.util.HelpCtx; 25 import org.openide.util.NbBundle; 26 import org.openide.util.NbPreferences; 27 28 33 public class SchemaSettings { 34 35 private static SchemaSettings INSTANCE = new SchemaSettings(); 36 37 public static final String PROP_VIEW_MODE = "viewMode"; 38 39 public static final String PROP_LANGUAGE = "language"; 40 41 44 public static enum ViewMode { 45 TREE, COLUMN 46 }; 47 48 private SchemaSettings() { 49 setDefaults(); 50 } 51 52 public String displayName() { 53 return NbBundle.getMessage(SchemaSettings.class, 54 "CTL_SchemaSettings_name"); 55 } 56 57 62 public static SchemaSettings getDefault() { 63 return INSTANCE; 64 } 65 66 public HelpCtx getHelpCtx() { 67 return HelpCtx.DEFAULT_HELP; 68 } 69 70 75 public ViewMode getViewMode() { 76 String mode = (String ) getProperty(PROP_VIEW_MODE); 77 if(mode == null) 78 return ViewMode.COLUMN; 79 80 return ViewMode.valueOf(mode); 81 } 82 83 public void readExternal(ObjectInput in) throws 84 IOException , ClassNotFoundException { 85 setDefaults(); 88 } 89 90 93 private void setDefaults() { 94 if (getProperty(PROP_VIEW_MODE) == null) { 95 putProperty(PROP_VIEW_MODE, ViewMode.COLUMN.toString()); 96 } 97 } 98 99 104 public void setViewMode(ViewMode mode) { 105 putProperty(PROP_VIEW_MODE, mode.toString()); 107 } 108 109 114 public String getLanguage() { 115 return (String ) getProperty(PROP_LANGUAGE); 116 } 117 118 123 public void setLanguage(String language) { 124 putProperty(PROP_LANGUAGE, language); 126 } 127 128 protected final String putProperty(String key, String value) { 129 String retval = NbPreferences.forModule(SchemaSettings.class).get(key, null); 130 if (value != null) { 131 NbPreferences.forModule(SchemaSettings.class).put(key, value); 132 } else { 133 NbPreferences.forModule(SchemaSettings.class).remove(key); 134 } 135 return retval; 136 } 137 138 protected final String getProperty(String key) { 139 return NbPreferences.forModule(SchemaSettings.class).get(key, ViewMode.COLUMN.toString()); 140 } 141 } 142 | Popular Tags |