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 IntConfiguration {
045: private IntConfiguration master;
046: private int def;
047: private String[] names;
048: private String[] options;
049:
050: private int value;
051: private boolean modified;
052: private boolean dirty = false;
053:
054: public IntConfiguration(IntConfiguration master, int def,
055: String[] names, String[] options) {
056: this .master = master;
057: this .def = def;
058: this .names = names;
059: this .options = options;
060: reset();
061: }
062:
063: /** Needed for CompilerSetConfiguration to maintain compatibility */
064: protected IntConfiguration() {
065: }
066:
067: public void setValue(int value) {
068: this .value = value;
069: if (master != null)
070: setModified(true);
071: else
072: setModified(value != getDefault());
073: }
074:
075: public void setValue(String s) {
076: if (s != null) {
077: for (int i = 0; i < names.length; i++) {
078: if (s.equals(names[i])) {
079: setValue(i);
080: break;
081: }
082: }
083: }
084: }
085:
086: public int getValue() {
087: if (master != null && !getModified())
088: return master.getValue();
089: else
090: return value;
091: }
092:
093: public void setModified(boolean b) {
094: this .modified = b;
095: }
096:
097: public boolean getModified() {
098: return modified;
099: }
100:
101: public void setDirty(boolean dirty) {
102: this .dirty = dirty;
103: }
104:
105: public boolean getDirty() {
106: return dirty;
107: }
108:
109: public int getDefault() {
110: return def;
111: }
112:
113: public void reset() {
114: value = getDefault();
115: setModified(false);
116: }
117:
118: public String getName() {
119: if (getValue() < names.length)
120: return names[getValue()];
121: else
122: return "???"; // FIXUP // NOI18N
123: }
124:
125: public String[] getNames() {
126: return names;
127: }
128:
129: public String getOption() {
130: return options[getValue()] + " "; // NOI18N
131: }
132:
133: // Clone and Assign
134: public void assign(IntConfiguration conf) {
135: dirty = getValue() != conf.getValue();
136: setValue(conf.getValue());
137: setModified(conf.getModified());
138: }
139:
140: public Object clone() {
141: IntConfiguration clone = new IntConfiguration(master, def,
142: names, options);
143: clone.setValue(getValue());
144: clone.setModified(getModified());
145: return clone;
146: }
147: }
|