01: // This file is part of KeY - Integrated Deductive Software Design
02: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
03: // Universitaet Koblenz-Landau, Germany
04: // Chalmers University of Technology, Sweden
05: //
06: // The KeY system is protected by the GNU General Public License.
07: // See LICENSE.TXT for details.
08: //
09: //
10:
11: package de.uka.ilkd.key.gui;
12:
13: import java.util.Iterator;
14: import java.util.LinkedList;
15: import java.util.Properties;
16:
17: import de.uka.ilkd.key.gui.configuration.Settings;
18: import de.uka.ilkd.key.gui.configuration.SettingsListener;
19:
20: public class ModelSourceSettings implements Settings {
21:
22: private static final String MODEL_SOURCE_KEY = "[Model]Source";
23:
24: private LinkedList listenerList = new LinkedList();
25: private String modelSource = "1";
26: private String modelSourceNew;
27: private boolean changed;
28:
29: public ModelSourceSettings() {
30: restore();
31: }
32:
33: public String getModelSource() {
34: return modelSource;
35: }
36:
37: /** restores old values */
38: public void restore() {
39: modelSourceNew = modelSource;
40: }
41:
42: public void store() {
43: modelSource = modelSourceNew;
44: fireSettingsChanged();
45: }
46:
47: public void setModelSource(String value) {
48: modelSourceNew = value;
49: }
50:
51: /** gets a Properties object and has to perform the necessary
52: * steps in order to change this object in a way that it
53: * represents the stored settings
54: */
55: public void readSettings(Properties props) {
56: String source = props.getProperty(MODEL_SOURCE_KEY);
57: if (source == null)
58: modelSource = "1";
59: else
60: modelSource = source;
61: restore();
62: }
63:
64: public void writeSettings(Properties props) {
65: props.setProperty(MODEL_SOURCE_KEY, modelSourceNew);
66: }
67:
68: public void setChanged(boolean arg) {
69: changed = arg;
70: }
71:
72: /** sends the message that the state of this setting has been
73: * changed to its registered listeners (not thread-safe)
74: */
75: protected void fireSettingsChanged() {
76: Iterator it = listenerList.iterator();
77: while (it.hasNext()) {
78: ((SettingsListener) it.next())
79: .settingsChanged(new GUIEvent(this ));
80: }
81: }
82:
83: /** adds a listener to the settings object
84: * @param l the listener
85: */
86: public void addSettingsListener(SettingsListener l) {
87: listenerList.add(l);
88: }
89:
90: }
|