001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002 *
003 * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
004 *
005 * "Hilbert II" is free software; you can redistribute
006 * it and/or modify it under the terms of the GNU General Public
007 * License as published by the Free Software Foundation; either
008 * version 2 of the License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU General Public License for more details.
014 */
015
016 package org.qedeq.gui.se.pane;
017
018 import java.io.File;
019 import java.io.IOException;
020
021 import org.qedeq.base.io.IoUtility;
022 import org.qedeq.kernel.bo.KernelContext;
023 import org.qedeq.kernel.se.config.QedeqConfig;
024
025 /**
026 * This class gives a type save access to the GUI properties of the application.
027 *
028 * @author Michael Meyling
029 */
030 public final class QedeqGuiConfig extends QedeqConfig {
031
032 /** The one and only instance. */
033 private static QedeqGuiConfig instance = null;
034
035 /**
036 * Get instance of config access. Method {@link #init} must have been called before.
037 *
038 * @return singleton, which is responsible the config access
039 * @throws IllegalStateException if {@link #setup} wasn't called before this method call
040 */
041 public static QedeqGuiConfig getInstance() {
042 if (instance == null) {
043 throw new IllegalStateException(QedeqGuiConfig.class.getName()
044 + " not initialized, call init before!");
045 }
046 return instance;
047 }
048
049 /**
050 * Load config file from start directory. This method must be called at the beginning.
051 * Look at {link IoUtility#getStartDirectory(String)} with parameter <code>qedeq</code>
052 *
053 * @param configFile Config file.
054 * @param basisDirectory Start directory of application. Basis for all relative paths.
055 * @throws IOException Config file not found or readable.
056 */
057 public static void init(final File configFile, final File basisDirectory) throws IOException {
058 instance = new QedeqGuiConfig(configFile,
059 "This file is part of the project *Hilbert II* - http://www.qedeq.org",
060 basisDirectory);
061 }
062
063 /**
064 * Constructor.
065 *
066 * @param configFile Config file.
067 * @param description Config file description
068 * @param basisDirectory Start directory of application. Basis for all relative paths.
069 * @throws IOException Config file couldn't be loaded.
070 */
071 private QedeqGuiConfig(final File configFile,
072 final String description, final File basisDirectory) throws IOException {
073 super(configFile, description, basisDirectory);
074 }
075
076
077 /**
078 * Should the log window scroll automatically to the last line?
079 *
080 * @return Automatic scroll for log window?
081 */
082 public final boolean isAutomaticLogScroll() {
083 return "true".equals(getKeyValue("automaticLogScroll", "true"));
084 }
085
086 /**
087 * Should the log window scroll automatically to the last line?
088 *
089 * @param value Automatic scroll for log window?
090 */
091 public final void setAutomaticLogScroll(final boolean value) {
092 setKeyValue("automaticLogScroll", (value ? "true" : "false"));
093 }
094
095 /**
096 * Get icon size. Default is "16x16".
097 *
098 * @return Icon size.
099 */
100 public final String getIconSize() {
101 return getKeyValue("iconSize", "16x16");
102 }
103
104 /**
105 * Set icon size.
106 *
107 * @param value Icon size value. Something like "16x16".
108 */
109 public final void setIconSize(final String value) {
110 setKeyValue("iconSize", value);
111 }
112
113 /**
114 * Get look and feel setting. Default is "PlasticXP".
115 * Might also be a direct class name.
116 * Supported keys are "Windows", "Plastic", "Plastic3D", "PlasticXP".
117 *
118 * @return Windows look and feel.
119 */
120 public final String getLookAndFeel() {
121 return getKeyValue("lookAndFeel", "PlasticXP");
122 }
123
124 /**
125 * Set look and feel setting.
126 * Supported keys are "Windows", "Plastic", "Plastic3D", "PlasticXP".
127 *
128 * @param value Look and feel key, or class name.
129 */
130 public final void setLookAndFeel(final String value) {
131 setKeyValue("lookAndFeel", value);
132 }
133
134 /**
135 * Get autostart html mode.
136 *
137 * @return list of modules.
138 */
139 public final boolean isAutoStartHtmlBrowser() {
140 return "true".equals(
141 getKeyValue("autoStartHtmlBrowser", "true"));
142 }
143
144 /**
145 * Set auto start HTML browser.
146 *
147 * @param mode Auto start?
148 */
149 public final void setAutoStartHtmlBrowser(final boolean mode) {
150 setKeyValue("autoStartHtmlBrowser", (mode ? "true" : "false"));
151 }
152
153 /**
154 * Get direct response mode.
155 *
156 * @return Direct response mode.
157 */
158 public final boolean isDirectResponse() {
159 return "true".equals(
160 getKeyValue("directResponse", "true"));
161 }
162
163 /**
164 * Set direct response mode.
165 *
166 * @param mode enable direct response?
167 */
168 public final void setDirectResponse(final boolean mode) {
169 setKeyValue("directResponse", (mode ? "true" : "false"));
170 }
171
172 /**
173 * Get start directory for file browser.
174 *
175 * @return Directory.
176 */
177 public final File getFileBrowserStartDirecty() {
178 final File dflt = (IoUtility.isWebStarted() ? KernelContext.getInstance().getConfig()
179 .getBasisDirectory() : new File("./sample"));
180
181 final String dir = getKeyValue("fileBrowserStartDirectory");
182 if (dir == null || dir.length() <= 0) {
183 return dflt;
184 }
185 return new File(dir);
186 }
187
188 /**
189 * Set start directory for file browser.
190 *
191 * @param directory Start directory.
192 */
193 public final void setFileBrowserStartDirecty(final File directory) {
194 setKeyValue("fileBrowserStartDirectory", directory.toString());
195 }
196
197 }
|