001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * If you wish your version of this file to be governed by only the CDDL
025: * or only the GPL Version 2, indicate your decision by adding
026: * "[Contributor] elects to include this software in this distribution
027: * under the [CDDL or GPL Version 2] license." If you do not indicate a
028: * single choice of license, a recipient has the option to distribute
029: * your version of this file under either the CDDL, the GPL Version 2 or
030: * to extend the choice of license to its licensees as provided above.
031: * However, if you add GPL Version 2 code and therefore, elected the GPL
032: * Version 2 license, then the option applies only if the new code is
033: * made subject to such option by the copyright holder.
034: *
035: * Contributor(s):
036: *
037: * Portions Copyrighted 2008 Sun Microsystems, Inc.
038: */
039:
040: package org.netbeans.modules.cnd.editor.options;
041:
042: import java.util.HashMap;
043: import java.util.Map;
044: import java.util.prefs.AbstractPreferences;
045: import java.util.prefs.BackingStoreException;
046: import java.util.prefs.Preferences;
047: import org.netbeans.modules.cnd.editor.api.CodeStyle;
048: import org.openide.util.Exceptions;
049:
050: public class PreviewPreferences extends AbstractPreferences {
051:
052: private Map<String, Object> map = new HashMap<String, Object>();
053: private final CodeStyle.Language language;
054: private final String styleId;
055:
056: public PreviewPreferences(Preferences master,
057: CodeStyle.Language language, String styleId) {
058: super (null, ""); // NOI18N
059: this .language = language;
060: this .styleId = styleId;
061: try {
062: for (String key : master.keys()) {
063: Object o = EditorOptions.getDefault(language, styleId,
064: key);
065: if (o instanceof Boolean) {
066: putBoolean(key, master.getBoolean(key, (Boolean) o));
067: } else if (o instanceof Integer) {
068: putInt(key, master.getInt(key, (Integer) o));
069: } else {
070: map.put(key, master.get(key, o.toString()));
071: }
072: }
073: } catch (BackingStoreException ex) {
074: Exceptions.printStackTrace(ex);
075: }
076: }
077:
078: public CodeStyle.Language getLanguage() {
079: return language;
080: }
081:
082: public String getStyleId() {
083: return styleId;
084: }
085:
086: protected void putSpi(String key, String value) {
087: map.put(key, value);
088: }
089:
090: protected String getSpi(String key) {
091: return (String) map.get(key);
092: }
093:
094: protected void removeSpi(String key) {
095: map.remove(key);
096: }
097:
098: protected void removeNodeSpi() throws BackingStoreException {
099: throw new UnsupportedOperationException("Not supported yet."); // NOI18N
100: }
101:
102: protected String[] keysSpi() throws BackingStoreException {
103: String[] array = new String[map.keySet().size()];
104: return map.keySet().toArray(array);
105: }
106:
107: protected String[] childrenNamesSpi() throws BackingStoreException {
108: throw new UnsupportedOperationException("Not supported yet."); // NOI18N
109: }
110:
111: protected AbstractPreferences childSpi(String name) {
112: throw new UnsupportedOperationException("Not supported yet."); // NOI18N
113: }
114:
115: protected void syncSpi() throws BackingStoreException {
116: throw new UnsupportedOperationException("Not supported yet."); // NOI18N
117: }
118:
119: protected void flushSpi() throws BackingStoreException {
120: throw new UnsupportedOperationException("Not supported yet."); // NOI18N
121: }
122: }
|