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: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.java.hints.options;
042:
043: import java.util.prefs.Preferences;
044: import org.netbeans.modules.java.hints.spi.AbstractHint;
045:
046: /**
047: *
048: * @author Petr Hrebejk
049: * @author Jan Lahoda
050: */
051: public class HintsSettings {
052:
053: // Only used for categories (disabled state in options dialog)
054: static final AbstractHint.HintSeverity SEVERITY_DEFAUT = AbstractHint.HintSeverity.WARNING;
055: static final boolean IN_TASK_LIST_DEFAULT = true;
056:
057: public static HintsAccessor HINTS_ACCESSOR;
058:
059: static final String ENABLED_KEY = "enabled"; // NOI18N
060: static final String SEVERITY_KEY = "severity"; // NOI18N
061: static final String IN_TASK_LIST_KEY = "inTaskList"; // NOI18N
062:
063: private static final String DEFAULT_PROFILE = "default"; // NOI18N
064:
065: private HintsSettings() {
066: }
067:
068: public static String getCurrentProfileId() {
069: return DEFAULT_PROFILE;
070: }
071:
072: /** For current profile
073: */
074: public static boolean isEnabled(AbstractHint hint) {
075: Preferences p = hint.getPreferences(HintsSettings
076: .getCurrentProfileId());
077: return isEnabled(hint, p);
078: }
079:
080: /** For current profile
081: */
082: public static boolean isShowInTaskList(AbstractHint hint) {
083: Preferences p = hint.getPreferences(HintsSettings
084: .getCurrentProfileId());
085: return isShowInTaskList(hint, p);
086: }
087:
088: public static boolean isEnabled(AbstractHint hint,
089: Preferences preferences) {
090: return preferences.getBoolean(ENABLED_KEY, HINTS_ACCESSOR
091: .isEnabledDefault(hint));
092: }
093:
094: public static void setEnabled(Preferences p, boolean value) {
095: p.putBoolean(ENABLED_KEY, value);
096: }
097:
098: public static boolean isShowInTaskList(AbstractHint hint,
099: Preferences preferences) {
100: Preferences p = hint.getPreferences(HintsSettings
101: .getCurrentProfileId());
102: return preferences.getBoolean(IN_TASK_LIST_KEY, HINTS_ACCESSOR
103: .isShowInTaskListDefault(hint));
104: }
105:
106: public static void setShowInTaskList(Preferences p, boolean value) {
107: p.putBoolean(IN_TASK_LIST_KEY, value);
108: }
109:
110: public static AbstractHint.HintSeverity getSeverity(
111: AbstractHint hint, Preferences preferences) {
112: String s = preferences.get(SEVERITY_KEY, null);
113: return s == null ? HINTS_ACCESSOR.severiryDefault(hint)
114: : AbstractHint.HintSeverity.valueOf(s);
115: }
116:
117: public static void setSeverity(Preferences p,
118: AbstractHint.HintSeverity severity) {
119: p.put(SEVERITY_KEY, severity.name());
120: }
121:
122: public static String[] getSuppressedBy(AbstractHint ah) {
123: return HINTS_ACCESSOR.getSuppressBy(ah);
124: }
125:
126: public static interface HintsAccessor {
127:
128: public boolean isEnabledDefault(AbstractHint hint);
129:
130: public boolean isShowInTaskListDefault(AbstractHint hint);
131:
132: public AbstractHint.HintSeverity severiryDefault(
133: AbstractHint hint);
134:
135: public String[] getSuppressBy(AbstractHint hint);
136: }
137:
138: }
|