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:
042: package org.netbeans.modules.cnd.makeproject.api.configurations;
043:
044: public class BooleanConfiguration {
045: private BooleanConfiguration master;
046:
047: private boolean def;
048: private String falseValue;
049: private String trueValue;
050:
051: private boolean value;
052: private boolean modified;
053: private boolean dirty = false;
054:
055: public BooleanConfiguration(BooleanConfiguration master, boolean def) {
056: this .master = master;
057: this .def = def;
058: falseValue = ""; // NOI18N
059: trueValue = ""; // NOI18N
060: reset();
061: }
062:
063: public BooleanConfiguration(BooleanConfiguration master,
064: boolean def, String falseValue, String trueValue) {
065: this .master = master;
066: this .def = def;
067: this .falseValue = falseValue;
068: this .trueValue = trueValue;
069: reset();
070: }
071:
072: public void setValue(boolean b) {
073: this .value = b;
074: if (master != null)
075: setModified(true);
076: else
077: setModified(b != getDefault());
078: }
079:
080: public boolean getValue() {
081: if (master != null && !getModified())
082: return master.getValue();
083: else
084: return value;
085: }
086:
087: public void setModified(boolean b) {
088: this .modified = b;
089: }
090:
091: public boolean getModified() {
092: return modified;
093: }
094:
095: public void setDirty(boolean dirty) {
096: this .dirty = dirty;
097: }
098:
099: public boolean getDirty() {
100: return dirty;
101: }
102:
103: public boolean getDefault() {
104: return def;
105: }
106:
107: public void setDefault(boolean b) {
108: def = b;
109: setModified(value != def);
110: }
111:
112: public void reset() {
113: value = getDefault();
114: setModified(false);
115: }
116:
117: public String getOption() {
118: if (getValue())
119: return trueValue;
120: else
121: return falseValue;
122: }
123:
124: // Clone and Assign
125: public void assign(BooleanConfiguration conf) {
126: dirty |= conf.getValue() ^ getValue();
127: setValue(conf.getValue());
128: setModified(conf.getModified());
129: }
130:
131: public Object clone() {
132: BooleanConfiguration clone = new BooleanConfiguration(master,
133: def, falseValue, trueValue);
134: clone.setValue(getValue());
135: clone.setModified(getModified());
136: return clone;
137: }
138: }
|