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 org.apache.log4j.Logger;
017:
018: import de.uka.ilkd.key.gui.GUIEvent;
019:
020: /**
021: * This class encapsulates information about:
022: * 1) relative font size in the prover view
023: * 2) the maximal number of lines a tooltip with instantiated SchemaVariables
024: * is allowed to have. If this number is exceeded no SchemaVariables get
025: * instantiated in the displayed tooltip.
026: * 3) wether intermediate proofsteps should be hidden in the proof tree view
027: */
028: public class ViewSettings implements Settings {
029: static Logger logger = Logger.getLogger(ViewSettings.class
030: .getName());
031: private static final String MAX_TOOLTIP_LINES_KEY = "[View]MaxTooltipLines";
032: private static final String SHOW_WHOLE_TACLET = "[View]ShowWholeTaclet";
033: private static final String FONT_INDEX = "[View]FontIndex";
034: private static final String HIDE_INTERMEDIATE_PROOFSTEPS = "[View]HideIntermediateProofsteps";
035:
036: /** default max number of displayed tooltip lines is 40 */
037: private int maxTooltipLines = 40;
038: /** do not print the find, varcond and heuristics part of taclets in
039: * the TacletMenu by default */
040: private boolean showWholeTaclet = false;
041: /** default fontsize */
042: private int sizeIndex = 2;
043: /** do not hide intermediate proofsteps by default */
044: private boolean hideIntermediateProofsteps = false;
045:
046: private LinkedList listenerList = new LinkedList();
047:
048: /**
049: * @return the current maxTooltipLines
050: */
051: public int getMaxTooltipLines() {
052: return maxTooltipLines;
053: }
054:
055: /**
056: * Sets maxTooltipLines
057: * @param b The new value for maxTooltipLines
058: */
059: public void setMaxTooltipLines(int b) {
060: if (b != maxTooltipLines) {
061: maxTooltipLines = b;
062: fireSettingsChanged();
063: }
064: }
065:
066: /**
067: * returns whether the Find and VarCond part of Taclets should be
068: * pretty-printed with instantiations of schema-variables or not
069: *
070: * @return true iff the find part should be pretty-printed instantiated
071: */
072: public boolean getShowWholeTaclet() {
073: return showWholeTaclet;
074: }
075:
076: /**
077: * Sets whether the Find and VarCond part of Taclets should be
078: * pretty-printed with instantiations of schema-variables or not
079: *
080: * @param b
081: * indicates whether the Find and VarCond part of Taclets should
082: * be pretty-printed with instantiations of schema-variables or
083: * not
084: */
085: public void setShowWholeTaclet(boolean b) {
086: if (b != showWholeTaclet) {
087: showWholeTaclet = b;
088: fireSettingsChanged();
089: }
090: }
091:
092: /**
093: * @return the current sizeIndex
094: */
095: public int sizeIndex() {
096: return sizeIndex;
097: }
098:
099: /**
100: * Sets FontIndex
101: * @param b The new value for SizeIndex
102: */
103: public void setFontIndex(int b) {
104: if (b != sizeIndex) {
105: sizeIndex = b;
106: fireSettingsChanged();
107: }
108: }
109:
110: /**
111: * @return true iff intermediate proofsteps should be hidden
112: */
113: public boolean getHideIntermediateProofsteps() {
114: return hideIntermediateProofsteps;
115: }
116:
117: /**
118: * @param hide Wether intermediate proofsteps should be hidden
119: */
120: public void setHideIntermediateProofsteps(boolean hide) {
121: if (hide != hideIntermediateProofsteps) {
122: hideIntermediateProofsteps = hide;
123: fireSettingsChanged();
124: }
125: }
126:
127: /** gets a Properties object and has to perform the necessary
128: * steps in order to change this object in a way that it
129: * represents the stored settings
130: * @param props the collection of properties
131: */
132: public void readSettings(Properties props) {
133: String val1 = props.getProperty(MAX_TOOLTIP_LINES_KEY);
134: String val2 = props.getProperty(FONT_INDEX);
135: String val3 = props.getProperty(SHOW_WHOLE_TACLET);
136: String val4 = props.getProperty(HIDE_INTERMEDIATE_PROOFSTEPS);
137: if (val1 != null) {
138: maxTooltipLines = Integer.valueOf(val1).intValue();
139: }
140: if (val2 != null) {
141: sizeIndex = Integer.valueOf(val2).intValue();
142: }
143: if (val3 != null) {
144: showWholeTaclet = Boolean.valueOf(val3).booleanValue();
145: }
146: if (val4 != null) {
147: hideIntermediateProofsteps = Boolean.valueOf(val4)
148: .booleanValue();
149: }
150: }
151:
152: /**
153: * implements the method required by the Settings interface. The settings
154: * are written to the given Properties object. Only entries of the form
155: * <key>=<value>(, <value>)* are allowed.
156: *
157: * @param props
158: * the Properties object where to write the settings as (key,
159: * value) pair
160: */
161: public void writeSettings(Properties props) {
162: props.setProperty(MAX_TOOLTIP_LINES_KEY, "" + maxTooltipLines);
163: props.setProperty(SHOW_WHOLE_TACLET, "" + showWholeTaclet);
164: props.setProperty(FONT_INDEX, "" + sizeIndex);
165: props.setProperty(HIDE_INTERMEDIATE_PROOFSTEPS, ""
166: + hideIntermediateProofsteps);
167: }
168:
169: /** sends the message that the state of this setting has been
170: * changed to its registered listeners (not thread-safe)
171: */
172: protected void fireSettingsChanged() {
173: Iterator it = listenerList.iterator();
174: while (it.hasNext()) {
175: ((SettingsListener) it.next())
176: .settingsChanged(new GUIEvent(this ));
177: }
178: }
179:
180: /**
181: * adds a listener to the settings object
182: * @param l the listener
183: */
184: public void addSettingsListener(SettingsListener l) {
185: listenerList.add(l);
186: }
187:
188: }
|