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: * Portions Copyrighted 2007 Sun Microsystems, Inc.
027: */
028: package org.netbeans.modules.php.rt.utils;
029:
030: import java.util.prefs.PreferenceChangeListener;
031: import java.util.prefs.Preferences;
032: import org.openide.util.NbPreferences;
033:
034: /**
035: *
036: * @author avk
037: */
038: public class ServerActionsPreferences {
039:
040: private static final int FILE_OVERWRITE_YES = 1; // NOI18N
041: private static final int FILE_OVERWRITE_NO = 0; // NOI18N
042: private static final int FILE_OVERWRITE_ASK_ME = 2; // NOI18N
043:
044: private static final ServerActionsPreferences INSTANCE = new ServerActionsPreferences();
045:
046: private static final String FILE_UPLOAD_BEFORE_RUN = "upload-file-before-run"; // NOI18N
047:
048: private static final String FILE_OVERWRITE = "overwrite-file"; // NOI18N
049:
050: private ServerActionsPreferences() {
051: }
052:
053: public static ServerActionsPreferences getInstance() {
054: return INSTANCE;
055: }
056:
057: public void setUploadBeforeRun(final boolean upload) {
058: getPreferences().putBoolean(FILE_UPLOAD_BEFORE_RUN, upload);
059: }
060:
061: public boolean getUploadBeforeRun() {
062: return getPreferences()
063: .getBoolean(FILE_UPLOAD_BEFORE_RUN, true);
064: }
065:
066: public void setFileOverwrite(final Boolean overwrite) {
067: int value = FILE_OVERWRITE_ASK_ME;
068: if (overwrite != null) {
069: value = overwrite.booleanValue() ? FILE_OVERWRITE_YES
070: : FILE_OVERWRITE_NO;
071: }
072: getPreferences().putInt(FILE_OVERWRITE, value);
073: }
074:
075: public Boolean getFileOverwrite() {
076: int value = getPreferences().getInt(FILE_OVERWRITE,
077: FILE_OVERWRITE_ASK_ME);
078: if (value == FILE_OVERWRITE_NO) {
079: return new Boolean(false);
080: } else if (value == FILE_OVERWRITE_YES) {
081: return new Boolean(true);
082: } else {
083: return null;
084: }
085: }
086:
087: public void addPreferenceChangeListener(PreferenceChangeListener pcl) {
088: getPreferences().addPreferenceChangeListener(pcl);
089: }
090:
091: public void removePreferenceChangeListener(
092: PreferenceChangeListener pcl) {
093: getPreferences().removePreferenceChangeListener(pcl);
094: }
095:
096: private Preferences getPreferences() {
097: return NbPreferences.forModule(ServerActionsPreferences.class);
098: }
099:
100: }
|