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: import de.uka.ilkd.key.rule.UpdateSimplifier;
018:
019: /** This class encapsulates the information about the active
020: * update simplifier settings
021: */
022: public class SimultaneousUpdateSimplifierSettings implements Settings {
023:
024: private static final String DELETE_EFFECTLESS_KEY = "[SimultaneousUpdateSimplifier]DeleteEffectLessLocations";
025: private static final String EAGER_MODE_KEY = "[SimultaneousUpdateSimplifier]EagerSimplification";
026:
027: private boolean delete_effectless_updates = true;
028: private boolean eagerMode = true;
029:
030: private UpdateSimplifier sus;
031:
032: private LinkedList listenerList = new LinkedList();
033:
034: public SimultaneousUpdateSimplifierSettings() {
035: updateSimplifier();
036: }
037:
038: //
039: private void updateSimplifier() {
040: sus = new UpdateSimplifier(deleteEffectlessUpdates(),
041: eagerMode());
042: }
043:
044: // getter
045: public boolean deleteEffectlessUpdates() {
046: return delete_effectless_updates;
047: }
048:
049: public boolean eagerMode() {
050: return eagerMode;
051: }
052:
053: // setter
054:
055: public void setDeleteEffectlessUpdates(boolean b) {
056: if (delete_effectless_updates != b) {
057: delete_effectless_updates = b;
058: fireSettingsChanged();
059: }
060: }
061:
062: public void setEagerMode(boolean b) {
063: if (eagerMode != b) {
064: eagerMode = b;
065: fireSettingsChanged();
066: }
067: }
068:
069: //
070: public UpdateSimplifier getSimplifier() {
071: return sus;
072: }
073:
074: /** gets a Properties object and has to perform the necessary
075: * steps in order to change this object in a way that it
076: * represents the stored settings
077: */
078: public void readSettings(Properties props) {
079: String deleteEffectlessString = props
080: .getProperty(DELETE_EFFECTLESS_KEY);
081: String eagerModeString = props.getProperty(EAGER_MODE_KEY);
082:
083: if (deleteEffectlessString != null) {
084: delete_effectless_updates = Boolean.valueOf(
085: deleteEffectlessString).booleanValue();
086: }
087: if (eagerModeString != null) {
088: eagerMode = Boolean.valueOf(eagerModeString).booleanValue();
089: }
090:
091: }
092:
093: /** implements the method required by the Settings interface. The
094: * settings are written to the given Properties object. Only entries of the form
095: * <key> = <value> (,<value>)* are allowed.
096: * @param props the Properties object where to write the settings as (key, value) pair
097: */
098: public void writeSettings(Properties props) {
099: props.setProperty(DELETE_EFFECTLESS_KEY, ""
100: + delete_effectless_updates);
101: props.setProperty(EAGER_MODE_KEY, "" + eagerMode);
102: }
103:
104: /** sends the message that the state of this setting has been
105: * changed to its registered listeners (not thread-safe)
106: */
107: protected void fireSettingsChanged() {
108: updateSimplifier();
109:
110: Iterator it = listenerList.iterator();
111: while (it.hasNext()) {
112: ((SettingsListener) it.next())
113: .settingsChanged(new GUIEvent(this ));
114: }
115: }
116:
117: /** adds a listener to the settings object
118: * @param l the listener
119: */
120: public void addSettingsListener(SettingsListener l) {
121: listenerList.add(l);
122: }
123:
124: }
|