File Source: PreferencesManager.java
/*
P/P * Method: com.dmdirc.config.prefs.PreferencesManager__static_init
*/
1 /*
2 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22 package com.dmdirc.config.prefs;
23
24 import com.dmdirc.Main;
25 import com.dmdirc.actions.ActionManager;
26 import com.dmdirc.actions.CoreActionType;
27 import com.dmdirc.config.prefs.validator.NumericalValidator;
28 import com.dmdirc.plugins.PluginManager;
29 import com.dmdirc.plugins.Service;
30 import com.dmdirc.util.ListenerList;
31
32 import java.util.ArrayList;
33 import java.util.HashMap;
34 import java.util.List;
35 import java.util.Map;
36
37 import javax.swing.UIManager;
38 import javax.swing.UIManager.LookAndFeelInfo;
39
40 /**
41 * Manages categories that should appear in the preferences dialog.
42 *
43 * @author chris
44 */
45 public class PreferencesManager {
46
47 /** A list of categories. */
48 private final List<PreferencesCategory> categories
49 = new ArrayList<PreferencesCategory>();
50
51 /** A list of listeners. */
52 private final ListenerList listeners = new ListenerList();
53
54 /**
55 * Creates a new instance of PreferencesManager.
56 */
/*
P/P * Method: void com.dmdirc.config.prefs.PreferencesManager()
*
* Preconditions:
* init'ed(com/dmdirc/config/IdentityManager.globalconfig)
* (soft) init'ed(com.dmdirc.config.ConfigManager$1__static_init.new int[](ConfigManager$1__static_init#1)[...])
*
* Presumptions:
* init'ed(com.dmdirc.actions.CoreActionType.CLIENT_PREFS_OPENED)
*
* Postconditions:
* com/dmdirc/config/IdentityManager.globalconfig != null
* java.lang.StringBuilder:toString(...)._tainted == 0
* new ArrayList(getSources#1) num objects == 0
* new ConfigManager(getGlobalConfig#1) num objects == 0
* new MapList(ConfigManager#1) num objects == 0
* this.categories == &new ArrayList(PreferencesManager#1)
* this.listeners == &new ListenerList(PreferencesManager#2)
* new ArrayList(PreferencesManager#1) num objects == 1
* new ListenerList(PreferencesManager#2) num objects == 1
* init'ed(new ConfigManager(getGlobalConfig#1).channel)
* ...
*/
57 public PreferencesManager() {
58 addDefaultCategories();
59
60 ActionManager.processEvent(CoreActionType.CLIENT_PREFS_OPENED, null, this);
61 }
62
63 /**
64 * Adds the specified category to the preferences manager.
65 *
66 * @param category The category to be added
67 */
68 public void addCategory(final PreferencesCategory category) {
/*
P/P * Method: void addCategory(PreferencesCategory)
*
* Preconditions:
* this.categories != null
*/
69 categories.add(category);
70 }
71
72 /**
73 * Retrieves a list of categories registered with the preferences manager.
74 *
75 * @return An ordered list of categories
76 */
77 public List<PreferencesCategory> getCategories() {
/*
P/P * Method: List getCategories()
*
* Postconditions:
* return_value == this.categories
* init'ed(return_value)
*/
78 return categories;
79 }
80
81 /**
82 * Finds and retrieves the category with the specified name.
83 *
84 * @param name The name (title) of the category to find.
85 * @return The appropriate category, or null if none was found
86 */
87 public PreferencesCategory getCategory(final String name) {
/*
P/P * Method: PreferencesCategory getCategory(String)
*
* Preconditions:
* this.categories != null
*
* Presumptions:
* category.title@88 != null
* java.util.Iterator:next(...)@88 != null
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* java.lang.String:equals(...)@89: {0}, {1}
* java.util.Iterator:hasNext(...)@88: {0}, {1}
*/
88 for (PreferencesCategory category : categories) {
89 if (category.getTitle().equals(name)) {
90 return category;
91 }
92 }
93
94 return null;
95 }
96
97 /**
98 * Saves all the settings in this manager.
99 *
100 * @return Is a restart needed after saving?
101 */
102 public boolean save() {
/*
P/P * Method: bool save()
*
* Preconditions:
* this.categories != null
* this.listeners != null
*
* Presumptions:
* java.util.Iterator:next(...)@106 != null
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@106: {0}, {1}
* save(...)@107: {0}, {1}
*/
103 fireSaveListeners();
104
105 boolean restart = false;
106 for (PreferencesCategory category : categories) {
107 if (category.save()) {
108 restart = true;
109 }
110 }
111
112 return restart;
113 }
114
115 /**
116 * Dismisses all the settings in this manager.
117 */
118 public void dismiss() {
/*
P/P * Method: void dismiss()
*
* Preconditions:
* this.categories != null
*
* Presumptions:
* category.settings@119 != null
* category.subcats@119 != null
* java.util.Iterator:next(...)@119 != null
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@119: {0}, {1}
*/
119 for (PreferencesCategory category : categories) {
120 category.dismiss();
121 }
122 }
123
124 /**
125 * Adds the default categories to this preferences manager.
126 */
127 private void addDefaultCategories() {
/*
P/P * Method: void addDefaultCategories()
*
* Preconditions:
* init'ed(com/dmdirc/config/IdentityManager.globalconfig)
* this.categories != null
* (soft) init'ed(com.dmdirc.config.ConfigManager$1__static_init.new int[](ConfigManager$1__static_init#1)[...])
*
* Postconditions:
* com/dmdirc/config/IdentityManager.globalconfig != null
* java.lang.StringBuilder:toString(...)._tainted == 0
* new ArrayList(getSources#1) num objects == 0
* new ConfigManager(getGlobalConfig#1) num objects == 0
* new MapList(ConfigManager#1) num objects == 0
* init'ed(new ConfigManager(getGlobalConfig#1).channel)
* init'ed(new ConfigManager(getGlobalConfig#1).ircd)
* init'ed(new ConfigManager(getGlobalConfig#1).listeners)
* init'ed(new ConfigManager(getGlobalConfig#1).network)
* init'ed(new ConfigManager(getGlobalConfig#1).server)
* ...
*/
128 addGeneralCategory();
129 addConnectionCategory();
130 addMessagesCategory();
131 addGuiCategory();
132 addPluginsCategory();
133 addUrlHandlerCategory();
134 addUpdatesCategory();
135 addAdvancedCategory();
136 }
137
138 /**
139 * Creates and adds the "General" category.
140 */
141 private void addGeneralCategory() {
/*
P/P * Method: void addGeneralCategory()
*
* Preconditions:
* init'ed(com/dmdirc/config/IdentityManager.globalconfig)
* this.categories != null
* (soft) init'ed(com.dmdirc.config.ConfigManager$1__static_init.new int[](ConfigManager$1__static_init#1)[...])
*
* Presumptions:
* com.dmdirc.plugins.PluginManager:getPluginManager(...)@176 != null
* com.dmdirc.plugins.PluginManager:getServicesByType(...)@176 != null
* java.util.Iterator:next(...)@176 != null
*
* Postconditions:
* com/dmdirc/config/IdentityManager.globalconfig != null
* java.lang.StringBuilder:toString(...)._tainted == 0
* new ArrayList(getSources#1) num objects == 0
* new ConfigManager(getGlobalConfig#1) num objects == 0
* new MapList(ConfigManager#1) num objects == 0
* new ArrayList(getSources#1) num objects <= 1
* new ConfigManager(getGlobalConfig#1) num objects == new ArrayList(getSources#1) num objects
* new MapList(ConfigManager#1) num objects == new ArrayList(getSources#1) num objects
* new ConfigManager(getGlobalConfig#1).channel == &java.lang.StringBuilder:toString(...)
* init'ed(new ConfigManager(getGlobalConfig#1).channel)
* ...
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@176: {0}, {1}
*/
142 final PreferencesCategory category = new PreferencesCategory("General", "");
143
144 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
145 "ui", "confirmQuit", "Confirm quit",
146 "Do you want to confirm closing the client?"));
147 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
148 "channel", "splitusermodes", "Split user modes",
149 "Show individual mode lines for each mode change that affects" +
150 " a user (e.g. op, devoice)"));
151 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
152 "channel", "sendwho", "Send channel WHOs",
153 "Request information (away state, hostname, etc) on channel " +
154 "users automatically"));
155 category.addSetting(new PreferencesSetting(PreferencesType.DURATION,
156 "general", "whotime", "Who request interval",
157 "How often to send WHO requests for a channel"));
158 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
159 "channel", "showmodeprefix", "Show mode prefix",
160 "Prefix users' names with their mode in channels"));
161 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
162 "server", "friendlymodes", "Friendly modes",
163 "Show friendly mode names"));
164 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
165 "general", "hidequeries", "Hide queries",
166 "Initially hide queries so that they don't steal focus"));
167 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
168 "ui", "awayindicator", "Away indicator",
169 "Shows an indicator in windows when you are marked as away"));
170 category.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
171 new NumericalValidator(0, 100), "ui", "pasteProtectionLimit",
172 "Paste protection trigger", "Confirm pasting of text that " +
173 "contains more than this many lines."));
174
175 final Map<String, String> taboptions = new HashMap<String, String>();
176 for (Service service : PluginManager.getPluginManager().getServicesByType("tabcompletion")) {
177 taboptions.put(service.getName(), service.getName());
178 }
179
180 category.addSetting(new PreferencesSetting("tabcompletion", "style",
181 "Tab completion style", "Determines the behaviour of " +
182 "the tab completer when there are multiple matches.", taboptions));
183
184 addCategory(category);
185 }
186
187 /**
188 * Creates and adds the "Connection" category.
189 */
190 private void addConnectionCategory() {
/*
P/P * Method: void addConnectionCategory()
*
* Preconditions:
* init'ed(com/dmdirc/config/IdentityManager.globalconfig)
* this.categories != null
* (soft) init'ed(com.dmdirc.config.ConfigManager$1__static_init.new int[](ConfigManager$1__static_init#1)[...])
*
* Postconditions:
* com/dmdirc/config/IdentityManager.globalconfig != null
* java.lang.StringBuilder:toString(...)._tainted == 0
* new ArrayList(getSources#1) num objects == 0
* new ConfigManager(getGlobalConfig#1) num objects == 0
* new MapList(ConfigManager#1) num objects == 0
* new ArrayList(getSources#1) num objects <= 1
* new ConfigManager(getGlobalConfig#1) num objects == new ArrayList(getSources#1) num objects
* new MapList(ConfigManager#1) num objects == new ArrayList(getSources#1) num objects
* new ConfigManager(getGlobalConfig#1).channel == &java.lang.StringBuilder:toString(...)
* init'ed(new ConfigManager(getGlobalConfig#1).channel)
* ...
*/
191 final PreferencesCategory category = new PreferencesCategory("Connection",
192 "", "category-connection");
193
194 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
195 "general", "closechannelsonquit", "Close channels on quit",
196 "Close channel windows when you quit the server?"));
197 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
198 "general", "closechannelsondisconnect",
199 "Close channels on disconnect", "Close channel windows when " +
200 "the server is disconnected?"));
201 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
202 "general", "closequeriesonquit", "Close queries on quit",
203 "Close query windows when you quit the server?"));
204 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
205 "general", "closequeriesondisconnect",
206 "Close queries on disconnect", "Close query windows when " +
207 "the server is disconnected?"));
208 category.addSetting(new PreferencesSetting(PreferencesType.DURATION,
209 "server", "pingtimer", "Ping warning time",
210 "How long to wait after a ping reply is sent before showing " +
211 "a warning message"));
212 category.addSetting(new PreferencesSetting(PreferencesType.DURATION,
213 "server", "pingtimeout", "Ping timeout",
214 "How long to wait for a server to reply to a PING request " +
215 "before assume it has died and disconnecting"));
216 category.addSetting(new PreferencesSetting(PreferencesType.DURATION,
217 "server", "pingfrequency", "Ping frequency",
218 "How often a PING request should be sent to the server (to " +
219 "check that it is still alive)"));
220 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
221 "general", "reconnectonconnectfailure", "Reconnect on failure",
222 "Attempt to reconnect if there is an error when connecting?"));
223 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
224 "general", "reconnectondisconnect", "Reconnect on disconnect",
225 "Attempt to reconnect if the server is disconnected?"));
226 category.addSetting(new PreferencesSetting(PreferencesType.DURATION,
227 "general", "reconnectdelay", "Reconnect delay",
228 "How long to wait before attempting to reconnect to a server"));
229 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
230 "general", "rejoinchannels", "Rejoin open channels",
231 "Rejoin open channels when reconnecting to a server?"));
232
233 addCategory(category);
234 }
235
236 /**
237 * Creates and adds the "Messages" category.
238 */
239 private void addMessagesCategory() {
/*
P/P * Method: void addMessagesCategory()
*
* Preconditions:
* init'ed(com/dmdirc/config/IdentityManager.globalconfig)
* this.categories != null
* (soft) init'ed(com.dmdirc.config.ConfigManager$1__static_init.new int[](ConfigManager$1__static_init#1)[...])
*
* Postconditions:
* com/dmdirc/config/IdentityManager.globalconfig != null
* java.lang.StringBuilder:toString(...)._tainted == 0
* new ArrayList(getSources#1) num objects == 0
* new ConfigManager(getGlobalConfig#1) num objects == 0
* new MapList(ConfigManager#1) num objects == 0
* new ArrayList(getSources#1) num objects <= 1
* new ConfigManager(getGlobalConfig#1) num objects == new ArrayList(getSources#1) num objects
* new MapList(ConfigManager#1) num objects == new ArrayList(getSources#1) num objects
* new ConfigManager(getGlobalConfig#1).channel == &java.lang.StringBuilder:toString(...)
* init'ed(new ConfigManager(getGlobalConfig#1).channel)
* ...
*/
240 final PreferencesCategory category = new PreferencesCategory("Messages",
241 "", "category-messages");
242
243 category.addSetting(new PreferencesSetting(PreferencesType.TEXT,
244 "general", "closemessage",
245 "Close message", "Default quit message to use when closing DMDirc"));
246 category.addSetting(new PreferencesSetting(PreferencesType.TEXT,
247 "general", "partmessage",
248 "Part message", "Default part message to use when leaving channels"));
249 category.addSetting(new PreferencesSetting(PreferencesType.TEXT,
250 "general", "quitmessage",
251 "Quit message", "Default quit message to use when disconnecting"));
252 category.addSetting(new PreferencesSetting(PreferencesType.TEXT,
253 "general", "cyclemessage",
254 "Cycle message", "Default part message to use when cycling channels"));
255 category.addSetting(new PreferencesSetting(PreferencesType.TEXT,
256 "general", "kickmessage",
257 "Kick message", "Default message to use when kicking people"));
258 category.addSetting(new PreferencesSetting(PreferencesType.TEXT,
259 "general", "reconnectmessage",
260 "Reconnect message", "Default quit message to use when reconnecting"));
261
262 addNotificationsCategory(category);
263 addCategory(category);
264 }
265
266 /**
267 * Creates and adds the "Notifications" category.
268 *
269 * @param parent The parent category.
270 */
271 private void addNotificationsCategory(final PreferencesCategory parent) {
/*
P/P * Method: void addNotificationsCategory(PreferencesCategory)
*
* Preconditions:
* init'ed(com/dmdirc/config/IdentityManager.globalconfig)
* parent != null
* init'ed(parent.isInline)
* parent.subcats != null
* (soft) init'ed(com.dmdirc.config.ConfigManager$1__static_init.new int[](ConfigManager$1__static_init#1)[...])
*
* Presumptions:
* category.isInline@293 == 1
*
* Postconditions:
* com/dmdirc/config/IdentityManager.globalconfig != null
* java.lang.StringBuilder:toString(...)._tainted == 0
* new ArrayList(getSources#1) num objects == 0
* new ConfigManager(getGlobalConfig#1) num objects == 0
* new MapList(ConfigManager#1) num objects == 0
* new ArrayList(getSources#1) num objects <= 1
* new ConfigManager(getGlobalConfig#1) num objects == new ArrayList(getSources#1) num objects
* new MapList(ConfigManager#1) num objects == new ArrayList(getSources#1) num objects
* new ConfigManager(getGlobalConfig#1).channel == &java.lang.StringBuilder:toString(...)
* init'ed(new ConfigManager(getGlobalConfig#1).channel)
* ...
*/
272 final PreferencesCategory category = new PreferencesCategory("Notifications", "");
273
274 final Map<String, String> options = new HashMap<String, String>();
275 final Map<String, String> whoisOptions = new HashMap<String, String>();
276 final Map<String, String> ctcprOptions = new HashMap<String, String>();
277 final Map<String, String> mapOptions = new HashMap<String, String>();
278
279 options.put("all", "All windows");
280 options.put("active", "Active window");
281 options.put("server", "Server window");
282 options.put("none", "Nowhere");
283
284 whoisOptions.putAll(options);
285 whoisOptions.put("lastcommand:(raw )?whois %4$s( %4$s)?", "Source of whois command");
286
287 ctcprOptions.putAll(options);
288 ctcprOptions.put("lastcommand:ctcp %1$s %4$S", "Source of ctcp command");
289
290 mapOptions.putAll(options);
291 mapOptions.put("window:Network Map", "Map window");
292
293 category.addSetting(new PreferencesSetting("notifications", "socketClosed",
294 "Socket closed", "Where to display socket closed notifications",
295 options));
296 category.addSetting(new PreferencesSetting("notifications", "privateNotice",
297 "Private notice", "Where to display private notices",
298 options));
299 category.addSetting(new PreferencesSetting("notifications", "privateCTCP",
300 "CTCP request", "Where to display CTCP request notifications",
301 options));
302 category.addSetting(new PreferencesSetting("notifications", "privateCTCPreply",
303 "CTCP reply", "Where to display CTCP replies",
304 ctcprOptions));
305 category.addSetting(new PreferencesSetting("notifications", "connectError",
306 "Connect error", "Where to display connect error notifications",
307 options));
308 category.addSetting(new PreferencesSetting("notifications", "connectRetry",
309 "Connect retry", "Where to display connect retry notifications",
310 options));
311 category.addSetting(new PreferencesSetting("notifications", "stonedServer",
312 "Stoned server", "Where to display stoned server notifications",
313 options));
314 category.addSetting(new PreferencesSetting("notifications", "whois",
315 "Whois output", "Where to display /whois output",
316 whoisOptions));
317 category.addSetting(new PreferencesSetting("notifications", "lusers",
318 "Lusers output", "Where to display /lusers output",
319 options));
320 category.addSetting(new PreferencesSetting("notifications", "map",
321 "Map output", "Where to display /map output",
322 mapOptions));
323 category.addSetting(new PreferencesSetting("notifications", "away",
324 "Away notification", "Where to display /away output",
325 options));
326 category.addSetting(new PreferencesSetting("notifications", "back",
327 "Back notification", "Where to display /away output",
328 options));
329
330 parent.addSubCategory(category);
331 }
332
333 /**
334 * Creates and adds the "Advanced" category.
335 */
336 private void addAdvancedCategory() {
/*
P/P * Method: void addAdvancedCategory()
*
* Preconditions:
* init'ed(com/dmdirc/config/IdentityManager.globalconfig)
* this.categories != null
* (soft) init'ed(com.dmdirc.config.ConfigManager$1__static_init.new int[](ConfigManager$1__static_init#1)[...])
*
* Postconditions:
* com/dmdirc/config/IdentityManager.globalconfig != null
* java.lang.StringBuilder:toString(...)._tainted == 0
* new ArrayList(getSources#1) num objects == 0
* new ConfigManager(getGlobalConfig#1) num objects == 0
* new MapList(ConfigManager#1) num objects == 0
* new ArrayList(getSources#1) num objects <= 1
* new ConfigManager(getGlobalConfig#1) num objects == new ArrayList(getSources#1) num objects
* new MapList(ConfigManager#1) num objects == new ArrayList(getSources#1) num objects
* new ConfigManager(getGlobalConfig#1).channel == &java.lang.StringBuilder:toString(...)
* init'ed(new ConfigManager(getGlobalConfig#1).channel)
* ...
*/
337 final PreferencesCategory category = new PreferencesCategory("Advanced",
338 "", "category-advanced");
339
340 final Map<String, String> options = new HashMap<String, String>();
341
342 options.put("alwaysShow", "Always show");
343 options.put("neverShow", "Never show");
344 options.put("showWhenMaximised", "Show only when windows maximised");
345
346 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
347 "browser", "uselaunchdelay", "Use browser launch delay",
348 "Enable delay between browser launches (to prevent mistakenly" +
349 " double clicking)?"));
350 category.addSetting(new PreferencesSetting(PreferencesType.DURATION,
351 "browser", "launchdelay", "Browser launch delay",
352 "Minimum time between opening of URLs"));
353 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
354 "general", "submitErrors", "Automatically submit errors",
355 "Automatically submit client errors to the developers?"));
356 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
357 "general", "logerrors", "Log errors to disk",
358 "Save copies of all errors to disk?"));
359 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
360 "tabcompletion", "casesensitive", "Case-sensitive tab completion",
361 "Respect case when tab completing?"));
362 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
363 "ui", "quickCopy", "Quick copy", "Automatically copy" +
364 " text that's selected when the mouse button is released?"));
365 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
366 "ui", "showversion", "Show version",
367 "Show DMDirc version in the titlebar?"));
368 category.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
369 new NumericalValidator(10, -1), "ui", "frameBufferSize",
370 "Window buffer size", "The maximum number of lines in a window" +
371 " buffer"));
372 category.addSetting(new PreferencesSetting("ui", "mdiBarVisibility",
373 "MDI Bar Visibility", "Controls the visibility of the MDI bar", options));
374 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN, "ui",
375 "useOneTouchExpandable", "Use one touch expandable split panes?",
376 "Use one touch expandable arrows for collapsing/expanding the split panes"));
377
378 addCategory(category);
379 }
380
381 /**
382 * Creates and adds the "GUI" category.
383 */
384 private void addGuiCategory() {
/*
P/P * Method: void addGuiCategory()
*
* Preconditions:
* init'ed(com/dmdirc/config/IdentityManager.globalconfig)
* this.categories != null
* (soft) init'ed(com.dmdirc.config.ConfigManager$1__static_init.new int[](ConfigManager$1__static_init#1)[...])
*
* Presumptions:
* arr$.length@399 <= 232-1
* arr$[i$]@399 != null
* javax.swing.UIManager:getInstalledLookAndFeels(...)@399 != null
*
* Postconditions:
* com/dmdirc/config/IdentityManager.globalconfig != null
* java.lang.StringBuilder:toString(...)._tainted == 0
* new ArrayList(getSources#1) num objects == 0
* new ConfigManager(getGlobalConfig#1) num objects == 0
* new MapList(ConfigManager#1) num objects == 0
* new ArrayList(getSources#1) num objects <= 1
* new ConfigManager(getGlobalConfig#1) num objects == new ArrayList(getSources#1) num objects
* new MapList(ConfigManager#1) num objects == new ArrayList(getSources#1) num objects
* new ConfigManager(getGlobalConfig#1).channel == &java.lang.StringBuilder:toString(...)
* init'ed(new ConfigManager(getGlobalConfig#1).channel)
* ...
*/
385 final Map<String, String> lafs = new HashMap<String, String>();
386 final Map<String, String> framemanagers = new HashMap<String, String>();
387 final Map<String, String> fmpositions = new HashMap<String, String>();
388 final PreferencesCategory category = new PreferencesCategory("GUI", "",
389 "category-gui");
390
391 framemanagers.put("com.dmdirc.ui.swing.framemanager.tree.TreeFrameManager", "Treeview");
392 framemanagers.put("com.dmdirc.ui.swing.framemanager.buttonbar.ButtonBar", "Button bar");
393
394 fmpositions.put("top", "Top");
395 fmpositions.put("bottom", "Bottom");
396 fmpositions.put("left", "Left");
397 fmpositions.put("right", "Right");
398
399 final LookAndFeelInfo[] plaf = UIManager.getInstalledLookAndFeels();
400 final String sysLafClass = UIManager.getSystemLookAndFeelClassName();
401
402 lafs.put("Native", "Native");
403 for (LookAndFeelInfo laf : plaf) {
404 lafs.put(laf.getName(), laf.getName());
405 }
406
407 category.addSetting(new PreferencesSetting(PreferencesType.COLOUR,
408 "ui", "backgroundcolour", "Background colour", "Default " +
409 "background colour to use"));
410 category.addSetting(new PreferencesSetting(PreferencesType.COLOUR,
411 "ui", "foregroundcolour", "Foreground colour", "Default " +
412 "foreground colour to use"));
413 category.addSetting(new PreferencesSetting(PreferencesType.OPTIONALCOLOUR,
414 "ui", "inputbackgroundcolour", "Input background colour",
415 "Default background colour to use for input fields"));
416 category.addSetting(new PreferencesSetting(PreferencesType.OPTIONALCOLOUR,
417 "ui", "inputforegroundcolour", "Input foreground colour",
418 "Default foreground colour to use for input fields"));
419 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
420 "general", "showcolourdialog", "Show colour dialog",
421 "Show colour picker dialog when using colour control codes?"));
422 category.addSetting(new PreferencesSetting("ui", "lookandfeel",
423 "Look and feel", "The Java look and feel to use",
424 lafs));
425 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
426 "ui", "antialias", "System anti-alias",
427 "Anti-alias all fonts?").setRestartNeeded());
428 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
429 "ui", "maximisewindows", "Auto-maximise windows",
430 "Automatically maximise newly opened windows?"));
431 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
432 "ui", "shownickcoloursintext", "Show nick colours in text area",
433 "Show nickname colours in text areas?"));
434 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
435 "ui", "shownickcoloursinnicklist", "Show nick colours in nicklists",
436 "Show nickname colours in channel nicklists?"));
437 category.addSetting(new PreferencesSetting("ui", "framemanager",
438 "Window manager", "Which window manager should be used?",
439 framemanagers).setRestartNeeded());
440 category.addSetting(new PreferencesSetting("ui", "framemanagerPosition",
441 "Window manager position", "Where should the window " +
442 "manager be positioned?", fmpositions).setRestartNeeded());
443 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
444 "ui", "stylelinks", "Style links", "Style links in text areas"));
445
446 addThemesCategory(category);
447 addNicklistCategory(category);
448 addTreeviewCategory(category);
449 addCategory(category);
450 }
451
452 /**
453 * Creates and adds the "Themes" category.
454 *
455 * @param parent The parent category
456 */
457 private void addThemesCategory(final PreferencesCategory parent) {
458 // TODO: Abstract the panel
459
/*
P/P * Method: void addThemesCategory(PreferencesCategory)
*
* Preconditions:
* parent != null
* init'ed(parent.isInline)
* parent.subcats != null
*
* Presumptions:
* com.dmdirc.Main:getUI(...)@460 != null
*/
460 parent.addSubCategory(new PreferencesCategory("Themes", "",
461 "category-addons", Main.getUI().getThemesPrefsPanel()));
462 }
463
464 /**
465 * Creates and adds the "Nicklist" category.
466 *
467 * @param parent The parent category
468 */
469 private void addNicklistCategory(final PreferencesCategory parent) {
/*
P/P * Method: void addNicklistCategory(PreferencesCategory)
*
* Preconditions:
* init'ed(com/dmdirc/config/IdentityManager.globalconfig)
* parent != null
* init'ed(parent.isInline)
* parent.subcats != null
* (soft) init'ed(com.dmdirc.config.ConfigManager$1__static_init.new int[](ConfigManager$1__static_init#1)[...])
*
* Presumptions:
* category.isInline@472 == 1
*
* Postconditions:
* com/dmdirc/config/IdentityManager.globalconfig != null
* java.lang.StringBuilder:toString(...)._tainted == 0
* new ArrayList(getSources#1) num objects == 0
* new ConfigManager(getGlobalConfig#1) num objects == 0
* new MapList(ConfigManager#1) num objects == 0
* new ArrayList(getSources#1) num objects <= 1
* new ConfigManager(getGlobalConfig#1) num objects == new ArrayList(getSources#1) num objects
* new MapList(ConfigManager#1) num objects == new ArrayList(getSources#1) num objects
* new ConfigManager(getGlobalConfig#1).channel == &java.lang.StringBuilder:toString(...)
* init'ed(new ConfigManager(getGlobalConfig#1).channel)
* ...
*/
470 final PreferencesCategory category = new PreferencesCategory("Nicklist", "");
471
472 category.addSetting(new PreferencesSetting(PreferencesType.OPTIONALCOLOUR,
473 "ui", "nicklistbackgroundcolour", "Nicklist background colour",
474 "Background colour to use for the nicklist"));
475 category.addSetting(new PreferencesSetting(PreferencesType.OPTIONALCOLOUR,
476 "ui", "nicklistforegroundcolour", "Nicklist foreground colour",
477 "Foreground colour to use for the nicklist"));
478 category.addSetting(new PreferencesSetting(PreferencesType.OPTIONALCOLOUR,
479 "ui", "nickListAltBackgroundColour", "Alternate background colour",
480 "Background colour to use for every other nicklist entry"));
481 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
482 "nicklist", "sortByMode", "Sort nicklist by user mode",
483 "Sort nicknames by the modes that they have?"));
484 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
485 "nicklist", "sortByCase", "Sort nicklist by case",
486 "Sort nicknames in a case-sensitive manner?"));
487
488 parent.addSubCategory(category);
489 }
490
491 /**
492 * Creates and adds the "Treeview" category.
493 *
494 * @param parent The parent category
495 */
496 private void addTreeviewCategory(final PreferencesCategory parent) {
/*
P/P * Method: void addTreeviewCategory(PreferencesCategory)
*
* Preconditions:
* init'ed(com/dmdirc/config/IdentityManager.globalconfig)
* parent != null
* init'ed(parent.isInline)
* parent.subcats != null
* (soft) init'ed(com.dmdirc.config.ConfigManager$1__static_init.new int[](ConfigManager$1__static_init#1)[...])
*
* Presumptions:
* category.isInline@499 == 1
*
* Postconditions:
* com/dmdirc/config/IdentityManager.globalconfig != null
* java.lang.StringBuilder:toString(...)._tainted == 0
* new ArrayList(getSources#1) num objects == 0
* new ConfigManager(getGlobalConfig#1) num objects == 0
* new MapList(ConfigManager#1) num objects == 0
* new ArrayList(getSources#1) num objects <= 1
* new ConfigManager(getGlobalConfig#1) num objects == new ArrayList(getSources#1) num objects
* new MapList(ConfigManager#1) num objects == new ArrayList(getSources#1) num objects
* new ConfigManager(getGlobalConfig#1).channel == &java.lang.StringBuilder:toString(...)
* init'ed(new ConfigManager(getGlobalConfig#1).channel)
* ...
*/
497 final PreferencesCategory category = new PreferencesCategory("Treeview", "");
498
499 category.addSetting(new PreferencesSetting(PreferencesType.OPTIONALCOLOUR,
500 "treeview", "backgroundcolour", "Treeview background colour",
501 "Background colour to use for the treeview"));
502 category.addSetting(new PreferencesSetting(PreferencesType.OPTIONALCOLOUR,
503 "treeview", "foregroundcolour", "Treeview foreground colour",
504 "Foreground colour to use for the treeview"));
505 category.addSetting(new PreferencesSetting(PreferencesType.OPTIONALCOLOUR,
506 "ui", "treeviewRolloverColour", "Treeview rollover colour",
507 "Background colour to use when the mouse cursor is over a node"));
508 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
509 "treeview", "sortwindows", "Sort windows",
510 "Sort windows belonging to servers in the treeview?"));
511 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
512 "treeview", "sortservers", "Sort servers",
513 "Sort servers in the treeview?"));
514 category.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
515 "ui", "treeviewActiveBold", "Active node bold",
516 "Make the active node bold?"));
517 category.addSetting(new PreferencesSetting(PreferencesType.OPTIONALCOLOUR,
518 "ui", "treeviewActiveBackground", "Active node background",
519 "Background colour to use for active treeview node"));
520 category.addSetting(new PreferencesSetting(PreferencesType.OPTIONALCOLOUR,
521 "ui", "treeviewActiveForeground", "Active node foreground",
522 "Foreground colour to use for active treeview node"));
523
524 parent.addSubCategory(category);
525 }
526
527 /**
528 * Creates and adds the "Plugins" category.
529 */
530 private void addPluginsCategory() {
531 // TODO: Abstract the panel
532
/*
P/P * Method: void addPluginsCategory()
*
* Preconditions:
* this.categories != null
*
* Presumptions:
* com.dmdirc.Main:getUI(...)@533 != null
*/
533 addCategory(new PreferencesCategory("Plugins", "", "category-addons",
534 Main.getUI().getPluginPrefsPanel()));
535 }
536
537 /**
538 * Creates and adds the "Updates" category.
539 */
540 private void addUpdatesCategory() {
541 // TODO: Abstract the panel
542
/*
P/P * Method: void addUpdatesCategory()
*
* Preconditions:
* this.categories != null
*
* Presumptions:
* com.dmdirc.Main:getUI(...)@543 != null
*/
543 addCategory(new PreferencesCategory("Updates", "", "category-updates",
544 Main.getUI().getUpdatesPrefsPanel()));
545 }
546
547 /**
548 * Creates and adds the "URL Handlers" category.
549 */
550 private void addUrlHandlerCategory() {
551 // TODO: Abstract the panel
552
/*
P/P * Method: void addUrlHandlerCategory()
*
* Preconditions:
* this.categories != null
*
* Presumptions:
* com.dmdirc.Main:getUI(...)@553 != null
*/
553 addCategory(new PreferencesCategory("URL Handlers",
554 "Configure how DMDirc handles different types of URLs",
555 "category-urlhandlers", Main.getUI().getUrlHandlersPrefsPanel()));
556 }
557
558 /**
559 * Registers the specified save listener with this manager.
560 *
561 * @param listener The listener to be registered
562 */
563 public void registerSaveListener(final PreferencesInterface listener) {
/*
P/P * Method: void registerSaveListener(PreferencesInterface)
*
* Preconditions:
* this.listeners != null
*/
564 listeners.add(PreferencesInterface.class, listener);
565 }
566
567 /**
568 * Fires the "save" methods of all registered listeners.
569 */
570 public void fireSaveListeners() {
/*
P/P * Method: void fireSaveListeners()
*
* Preconditions:
* this.categories != null
* this.listeners != null
*
* Presumptions:
* category.subcats@575 != null
* com.dmdirc.util.ListenerList:get(...)@571 != null
* java.util.Iterator:next(...)@571 != null
* java.util.Iterator:next(...)@575 != null
*
* Test Vectors:
* java.util.Iterator:hasNext(...)@571: {0}, {1}
* java.util.Iterator:hasNext(...)@575: {0}, {1}
*/
571 for (PreferencesInterface iface : listeners.get(PreferencesInterface.class)) {
572 iface.save();
573 }
574
575 for (PreferencesCategory category : categories) {
576 fireSaveListener(category);
577 }
578 }
579
580 /**
581 * Fires the save listener for any objects within the specified category.
582 *
583 * @param category The category to check
584 */
585 private void fireSaveListener(final PreferencesCategory category) {
/*
P/P * Method: void fireSaveListener(PreferencesCategory)
*
* Preconditions:
* category != null
* category.subcats != null
*
* Presumptions:
* java.util.Iterator:next(...)@590 != null
* subcategory.subcats@590 != null
*
* Test Vectors:
* category.object: Addr_Set{null}, Inverse{null}
* java.util.Iterator:hasNext(...)@590: {0}, {1}
*/
586 if (category.hasObject()) {
587 category.getObject().save();
588 }
589
590 for (PreferencesCategory subcategory : category.getSubcats()) {
591 fireSaveListener(subcategory);
592 }
593 }
594
595 /**
596 * Fires the CLIENT_PREFS_CLOSED action
597 *
598 * @since 0.6
599 */
600 public void close() {
/*
P/P * Method: void close()
*
* Presumptions:
* init'ed(com.dmdirc.actions.CoreActionType.CLIENT_PREFS_CLOSED)
*/
601 ActionManager.processEvent(CoreActionType.CLIENT_PREFS_CLOSED, null);
602 }
603
604 }
SofCheck Inspector Build Version : 2.17854
| PreferencesManager.java |
2009-Jun-25 01:54:24 |
| PreferencesManager.class |
2009-Sep-02 17:04:13 |