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:
011: package de.uka.ilkd.key.gui.configuration;
012:
013: import java.awt.Font;
014: import java.util.ArrayList;
015: import java.util.Iterator;
016: import java.util.List;
017:
018: import javax.swing.UIManager;
019:
020: /** this class is used to set some default gui properties */
021: public class Config {
022:
023: public static final Config DEFAULT = new Config();
024:
025: /** name of different fonts */
026: public static final String KEY_FONT_PROOF_TREE = "KEY_FONT_PROOF_TREE";
027: public static final String KEY_FONT_CURRENT_GOAL_VIEW = "KEY_FONT_CURRENT_GOAL_VIEW";
028: public static final String KEY_FONT_INNER_NODE_VIEW = "KEY_FONT_INNER_NODE_VIEW";
029: public static final String KEY_FONT_GOAL_LIST_VIEW = "KEY_FONT_GOAL_LIST_VIEW";
030: public static final String KEY_FONT_PROOF_LIST_VIEW = "KEY_FONT_PROOF_LIST_VIEW";
031:
032: /** An array of font sizes for the goal view */
033: private static final int[] sizes = new int[] { 10, 12, 14, 17, 20,
034: 24 };
035:
036: /** The index of the current size */
037: private int sizeIndex = ProofSettings.DEFAULT_SETTINGS
038: .getViewSettings().sizeIndex();
039:
040: /** cached ConfigChange event */
041: private ConfigChangeEvent configChangeEvent = new ConfigChangeEvent(
042: this );
043:
044: /** the listeners to this Config */
045: private List listenerList = new ArrayList(5);
046:
047: private Config() {
048: }
049:
050: public void larger() {
051: if (!isMaximumSize()) {
052: sizeIndex++;
053: ProofSettings.DEFAULT_SETTINGS.getViewSettings()
054: .setFontIndex(sizeIndex);
055: setDefaultFonts();
056: fireConfigChange();
057: }
058: }
059:
060: public void smaller() {
061: if (!isMinimumSize()) {
062: sizeIndex--;
063: ProofSettings.DEFAULT_SETTINGS.getViewSettings()
064: .setFontIndex(sizeIndex);
065: setDefaultFonts();
066: fireConfigChange();
067: }
068: }
069:
070: public boolean isMinimumSize() {
071: return sizeIndex == 0;
072: }
073:
074: public boolean isMaximumSize() {
075: return sizeIndex == sizes.length - 1;
076: }
077:
078: public void setDefaultFonts() {
079: UIManager.put(KEY_FONT_PROOF_TREE, new Font("Default",
080: Font.PLAIN, sizes[sizeIndex]));
081: UIManager.put(KEY_FONT_CURRENT_GOAL_VIEW, new Font(
082: "Monospaced", Font.PLAIN, sizes[sizeIndex]));
083: UIManager.put(KEY_FONT_INNER_NODE_VIEW, new Font("Monospaced",
084: Font.ITALIC, sizes[sizeIndex]));
085: UIManager.put(KEY_FONT_GOAL_LIST_VIEW, new Font("Default",
086: Font.PLAIN, sizes[2]));
087: UIManager.put(KEY_FONT_PROOF_LIST_VIEW, new Font("Default",
088: Font.PLAIN, sizes[2]));
089: }
090:
091: public void addConfigChangeListener(ConfigChangeListener listener) {
092: synchronized (listenerList) {
093: listenerList.add(listener);
094: }
095: }
096:
097: public void removeConfigChangeListener(ConfigChangeListener listener) {
098: synchronized (listenerList) {
099: listenerList.remove(listener);
100: }
101: }
102:
103: public synchronized void fireConfigChange() {
104: synchronized (listenerList) {
105: Iterator it = listenerList.iterator();
106: while (it.hasNext()) {
107: ((ConfigChangeListener) it.next())
108: .configChanged(configChangeEvent);
109: }
110: }
111: }
112:
113: }
|