001: // This file is part of KeY - Integrated Deductive Software Design
002: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
003: // Universitaet Koblenz-Landau, Germany
004: // Chalmers University of Technology, Sweden
005: //
006: // The KeY system is protected by the GNU General Public License.
007: // See LICENSE.TXT for details.
008: //
009: //
010: package de.uka.ilkd.key.gui.configuration;
011:
012: import java.util.Iterator;
013: import java.util.LinkedList;
014: import java.util.Properties;
015:
016: import de.uka.ilkd.key.gui.GUIEvent;
017:
018: /** This class encapsulates the information about the active
019: * Heuristics and the maximum amount of heuristics steps before an
020: * interactive step is required.
021: */
022: public class GeneralSettings implements Settings {
023:
024: private static final String STUPID_MODE_KEY = "[General]StupidMode";
025: private static final String PROOF_ASSISTANT_MODE_KEY = "[General]ProofAssistant";
026: private static final String SUGG_VARNAMES_KEY = "[General]SuggestiveVarNames";
027: private static final String OUTER_RENAMING_KEY = "[General]OuterRenaming";
028:
029: private static final String SOUND_NOTIFICATION_KEY = "[General]SoundNotification";
030: private static final String DND_DIRECTION_SENSITIVE_KEY = "[General]DnDDirectionSensitive";
031:
032: /** minimize interaction is on by default */
033: private boolean stupidMode = true;
034:
035: /** proof assistant is on by default */
036: private boolean proofAssistantMode = true;
037:
038: /** suggestive var names are off by default */
039: private boolean suggestiveVarNames = false;
040:
041: /** outer renaming is on by default */
042: private boolean outerRenaming = false;
043:
044: /** sound notification is on by default */
045: private boolean soundNotification = true;
046:
047: /** is drag and drop instantiation direction sensitive */
048: private boolean dndDirectionSensitive = true;
049:
050: private LinkedList listenerList = new LinkedList();
051:
052: // getter
053: public boolean stupidMode() {
054: return stupidMode;
055: }
056:
057: public boolean proofAssistantMode() {
058: return proofAssistantMode;
059: }
060:
061: public boolean suggestiveVarNames() {
062: return suggestiveVarNames;
063: }
064:
065: public boolean outerRenaming() {
066: return outerRenaming;
067: }
068:
069: public boolean soundNotification() {
070: return soundNotification;
071: }
072:
073: /**
074: * returns true if drag and drop shall be direction sensitive
075: */
076: public boolean isDndDirectionSensitive() {
077: return dndDirectionSensitive;
078: }
079:
080: // setter
081: public void setStupidMode(boolean b) {
082: if (stupidMode != b) {
083: stupidMode = b;
084: fireSettingsChanged();
085: }
086: }
087:
088: public void setProofAssistantMode(boolean b) {
089: if (proofAssistantMode != b) {
090: proofAssistantMode = b;
091: fireSettingsChanged();
092: }
093: }
094:
095: public void setSuggestiveVarNames(boolean b) {
096: if (suggestiveVarNames != b) {
097: suggestiveVarNames = b;
098: fireSettingsChanged();
099: }
100: }
101:
102: public void setOuterRenaming(boolean b) {
103: if (outerRenaming != b) {
104: outerRenaming = b;
105: fireSettingsChanged();
106: }
107: }
108:
109: public void setSoundNotification(boolean b) {
110: if (soundNotification != b) {
111: soundNotification = b;
112: fireSettingsChanged();
113: }
114: }
115:
116: public void setDnDDirectionSensitivity(boolean b) {
117: if (dndDirectionSensitive != b) {
118: dndDirectionSensitive = b;
119: fireSettingsChanged();
120: }
121: }
122:
123: /** gets a Properties object and has to perform the necessary
124: * steps in order to change this object in a way that it
125: * represents the stored settings
126: */
127: public void readSettings(Properties props) {
128: String val = props.getProperty(STUPID_MODE_KEY);
129: if (val != null) {
130: stupidMode = Boolean.valueOf(val).booleanValue();
131: }
132:
133: val = props.getProperty(PROOF_ASSISTANT_MODE_KEY);
134: if (val != null) {
135: proofAssistantMode = Boolean.valueOf(val).booleanValue();
136: }
137:
138: val = props.getProperty(SUGG_VARNAMES_KEY);
139: if (val != null) {
140: suggestiveVarNames = Boolean.valueOf(val).booleanValue();
141: }
142:
143: val = props.getProperty(OUTER_RENAMING_KEY);
144: if (val != null) {
145: outerRenaming = Boolean.valueOf(val).booleanValue();
146: }
147:
148: val = props.getProperty(SOUND_NOTIFICATION_KEY);
149: if (val != null) {
150: soundNotification = Boolean.valueOf(val).booleanValue();
151: }
152:
153: val = props.getProperty(DND_DIRECTION_SENSITIVE_KEY);
154: if (val != null) {
155: dndDirectionSensitive = Boolean.valueOf(val).booleanValue();
156: }
157:
158: }
159:
160: /** implements the method required by the Settings interface. The
161: * settings are written to the given Properties object. Only entries of the form
162: * <key> = <value> (,<value>)* are allowed.
163: * @param props the Properties object where to write the settings as (key, value) pair
164: */
165: public void writeSettings(Properties props) {
166: props.setProperty(STUPID_MODE_KEY, "" + stupidMode);
167: props.setProperty(PROOF_ASSISTANT_MODE_KEY, ""
168: + proofAssistantMode);
169: props.setProperty(SUGG_VARNAMES_KEY, "" + suggestiveVarNames);
170: props.setProperty(OUTER_RENAMING_KEY, "" + outerRenaming);
171: props.setProperty(SOUND_NOTIFICATION_KEY, ""
172: + soundNotification);
173: props.setProperty(DND_DIRECTION_SENSITIVE_KEY, ""
174: + dndDirectionSensitive);
175: }
176:
177: /** sends the message that the state of this setting has been
178: * changed to its registered listeners (not thread-safe)
179: */
180: protected void fireSettingsChanged() {
181: Iterator it = listenerList.iterator();
182: while (it.hasNext()) {
183: ((SettingsListener) it.next())
184: .settingsChanged(new GUIEvent(this ));
185: }
186: }
187:
188: /**
189: * adds a listener to the settings object
190: * @param l the listener
191: */
192: public void addSettingsListener(SettingsListener l) {
193: listenerList.add(l);
194: }
195:
196: }
|