You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PreferencesDialog.java 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /*
  2. * Copyright (c) 2006-2007 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.ui.dialogs;
  23. import java.util.Map;
  24. import java.util.Properties;
  25. import javax.swing.UIManager;
  26. import javax.swing.UIManager.LookAndFeelInfo;
  27. import com.dmdirc.Config;
  28. import com.dmdirc.ui.components.PreferencesInterface;
  29. import com.dmdirc.ui.components.PreferencesPanel;
  30. /**
  31. * Allows the user to modify global client preferences.
  32. */
  33. public final class PreferencesDialog implements PreferencesInterface {
  34. /**
  35. * A version number for this class. It should be changed whenever the class
  36. * structure is changed (or anything else that would prevent serialized
  37. * objects being unserialized with the new class).
  38. */
  39. private static final long serialVersionUID = 6;
  40. /** A previously created instance of PreferencesDialog. */
  41. private static PreferencesDialog me;
  42. /** preferences panel. */
  43. private PreferencesPanel preferencesPanel;
  44. /**
  45. * Creates a new instance of PreferencesDialog.
  46. */
  47. private PreferencesDialog() {
  48. }
  49. /** Creates the dialog if one doesn't exist, and displays it. */
  50. public static synchronized void showPreferencesDialog() {
  51. if (me == null) {
  52. me = new PreferencesDialog();
  53. }
  54. me.initComponents();
  55. me.preferencesPanel.requestFocus();
  56. }
  57. /**
  58. * Initialises GUI components.
  59. */
  60. private void initComponents() {
  61. preferencesPanel = new PreferencesPanel(this);
  62. initGeneralTab();
  63. initUITab();
  64. initTreeViewTab();
  65. initNotificationsTab();
  66. initInputTab();
  67. initLoggingTab();
  68. initAdvancedTab();
  69. preferencesPanel.display();
  70. }
  71. /**
  72. * Initialises the preferences tab.
  73. */
  74. private void initGeneralTab() {
  75. final String general = "General";
  76. final String messages = "Messages";
  77. final String windows = "Windows";
  78. preferencesPanel.addCategory(general, "");
  79. preferencesPanel.addCategory(general, messages, "");
  80. preferencesPanel.addCategory(general, windows, "");
  81. preferencesPanel.addCheckboxOption(general, "ui.antialias",
  82. "System anti-alias: ", "", Config.getOptionBool("ui", "antialias"));
  83. preferencesPanel.addCheckboxOption(general, "server.friendlymodes",
  84. "Friendly modes: ", "", Config.getOptionBool("server", "friendlymodes"));
  85. preferencesPanel.addCheckboxOption(general, "general.hidequeries",
  86. "Hide queries : ", "", Config.getOptionBool("general", "hidequeries"));
  87. preferencesPanel.addSpinnerOption(general, "general.reconnectdelay",
  88. "Reconnect delay: ", "", Config.getOptionInt("general", "reconnectdelay", 30));
  89. preferencesPanel.addCheckboxOption(general, "general.reconnectonconnectfailure",
  90. "Reconnect on failure: ", "", Config.getOptionBool("general", "reconnectonconnectfailure"));
  91. preferencesPanel.addCheckboxOption(general, "general.reconnectondisconnect",
  92. "Reconnect on disconnect: ", "", Config.getOptionBool("general", "reconnectondisconnect"));
  93. preferencesPanel.addCheckboxOption(general, "general.showcolourdialog",
  94. "Show colour dialog: ", "", Config.getOptionBool("general", "showcolourdialog"));
  95. preferencesPanel.addSpinnerOption(general, "general.whotime",
  96. "Who request interval (ms): ", "",
  97. Config.getOptionInt("general", "whotime", 600000),
  98. 10000, Integer.MAX_VALUE, 10000);
  99. preferencesPanel.addSpinnerOption(general, "server.pingtimeout",
  100. "Server timeout (ms): ", "", Config.getOptionInt("server", "pingtimeout", 60000),
  101. 5000, Integer.MAX_VALUE, 5000);
  102. preferencesPanel.addCheckboxOption(general, "channel.sendwho",
  103. "Send channel WHOs: ", "", Config.getOptionBool("channel", "sendwho"));
  104. preferencesPanel.addTextfieldOption(messages, "general.closemessage",
  105. "Close message: ", "", Config.getOption("general", "closemessage"));
  106. preferencesPanel.addTextfieldOption(messages, "general.partmessage",
  107. "Part message: ", "", Config.getOption("general", "partmessage"));
  108. preferencesPanel.addTextfieldOption(messages, "general.quitmessage",
  109. "Quit message: ", "", Config.getOption("general", "quitmessage"));
  110. preferencesPanel.addTextfieldOption(messages, "general.cyclemessage",
  111. "Cycle message: ", "", Config.getOption("general", "cyclemessage"));
  112. preferencesPanel.addTextfieldOption(messages, "general.kickmessage",
  113. "Kick message: ", "", Config.getOption("general", "kickmessage"));
  114. preferencesPanel.addTextfieldOption(messages, "general.reconnectmessage",
  115. "Reconnect message: ", "", Config.getOption("general", "reconnectmessage"));
  116. preferencesPanel.addCheckboxOption(windows, "general.closechannelsonquit",
  117. "Close channels on quit: ", "", Config.getOptionBool("general", "closechannelsonquit"));
  118. preferencesPanel.addCheckboxOption(windows, "general.closechannelsondisconnect",
  119. "Close channels on disconnect: ", "", Config.getOptionBool("general", "closechannelsondisconnect"));
  120. preferencesPanel.addCheckboxOption(windows, "general.closequeriesonquit",
  121. "Close queries on quit: ", "", Config.getOptionBool("general", "closequeriesonquit"));
  122. preferencesPanel.addCheckboxOption(windows, "general.closequeriesondisconnect",
  123. "Close queries on disconnect: ", "", Config.getOptionBool("general", "closequeriesondisconnect"));
  124. }
  125. /**
  126. * Initialises the UI tab.
  127. */
  128. private void initUITab() {
  129. final String tabName = "GUI";
  130. preferencesPanel.addCategory(tabName, "");
  131. preferencesPanel.addCheckboxOption(tabName, "ui.maximisewindows",
  132. "Auto-Maximise windows: ", "",
  133. Config.getOptionBool("ui", "maximisewindows"));
  134. preferencesPanel.addColourOption(tabName, "ui.backgroundcolour",
  135. "Window background colour: ", "",
  136. Config.getOption("ui", "backgroundcolour"), true, false);
  137. preferencesPanel.addColourOption(tabName, "ui.foregroundcolour",
  138. "Window foreground colour: ", "",
  139. Config.getOption("ui", "foregroundcolour"), true, false);
  140. preferencesPanel.addCheckboxOption(tabName, "ui.sortByMode",
  141. "Nicklist sort by mode: ", "",
  142. Config.getOptionBool("ui", "sortByMode"));
  143. preferencesPanel.addCheckboxOption(tabName, "ui.sortByCase",
  144. "Nicklist sort by case: ", "",
  145. Config.getOptionBool("ui", "sortByCase"));
  146. preferencesPanel.addCheckboxOption(tabName, "channel.splitusermodes",
  147. "Split user modes: ", "",
  148. Config.getOptionBool("channel", "splitusermodes"));
  149. preferencesPanel.addCheckboxOption(tabName, "ui.quickCopy",
  150. "Quick Copy: ", "",
  151. Config.getOptionBool("ui", "quickCopy"));
  152. preferencesPanel.addSpinnerOption(tabName, "ui.pasteProtectionLimit",
  153. "Paste protection trigger: ", "",
  154. Config.getOptionInt("ui", "pasteProtectionLimit", 1));
  155. preferencesPanel.addCheckboxOption(tabName, "ui.awayindicator",
  156. "Away indicator: ", "Shows an away indicator in the input field.",
  157. Config.getOptionBool("ui", "awayindicator"));
  158. preferencesPanel.addCheckboxOption(tabName, "nicklist.altBackground",
  159. "Alternating nicklist", "",
  160. Config.getOptionBool("nicklist", "altBackground"));
  161. preferencesPanel.addColourOption(tabName, "nicklist.altBackgroundColour",
  162. "Alternate nicklist colour: ", "",
  163. Config.getOption("nicklist", "altBackgroundColour", "f0f0f0"),
  164. false, true);
  165. }
  166. /**
  167. * Initialises the TreeView tab.
  168. */
  169. private void initTreeViewTab() {
  170. final String tabName = "Treeview";
  171. preferencesPanel.addCategory(tabName, "");
  172. preferencesPanel.addCheckboxOption(tabName, "ui.treeviewRolloverEnabled",
  173. "Rollover enabled: ", "",
  174. Config.getOptionBool("ui", "treeviewRolloverEnabled"));
  175. preferencesPanel.addColourOption(tabName, "ui.treeviewRolloverColour",
  176. "Rollover colour: ", "", Config.getOption("ui", "treeviewRolloverColour"),
  177. true, true);
  178. preferencesPanel.addCheckboxOption(tabName, "treeview.sortwindows",
  179. "Sort windows: ", "",
  180. Config.getOptionBool("treeview", "sortwindows"));
  181. preferencesPanel.addCheckboxOption(tabName, "treeview.sortservers",
  182. "Sort servers: ", "",
  183. Config.getOptionBool("treeview", "sortservers"));
  184. }
  185. /**
  186. * Initialises the Notifications tab.
  187. */
  188. private void initNotificationsTab() {
  189. final String tabName = "Notifications";
  190. preferencesPanel.addCategory(tabName, "");
  191. final String[] windowOptions
  192. = new String[] {"all", "active", "server", };
  193. preferencesPanel.addComboboxOption(tabName, "notifications.socketClosed",
  194. "Socket closed: ", "", windowOptions,
  195. Config.getOption("notifications", "socketClosed"), false);
  196. preferencesPanel.addComboboxOption(tabName, "notifications.privateNotice",
  197. "Private notice: ", "", windowOptions,
  198. Config.getOption("notifications", "privateNotice"), false);
  199. preferencesPanel.addComboboxOption(tabName, "notifications.privateCTCP",
  200. "CTCP request: ", "", windowOptions,
  201. Config.getOption("notifications", "privateCTCP"), false);
  202. preferencesPanel.addComboboxOption(tabName, "notifications.privateCTCPreply",
  203. "CTCP reply: ", "", windowOptions,
  204. Config.getOption("notifications", "privateCTCPreply"), false);
  205. preferencesPanel.addComboboxOption(tabName, "notifications.connectError",
  206. "Connect error: ", "", windowOptions,
  207. Config.getOption("notifications", "connectError"), false);
  208. preferencesPanel.addComboboxOption(tabName, "notifications.connectRetry",
  209. "Connect retry: ", "", windowOptions,
  210. Config.getOption("notifications", "connectRetry"), false);
  211. preferencesPanel.addComboboxOption(tabName, "notifications.stonedServer",
  212. "Stoned server: ", "", windowOptions,
  213. Config.getOption("notifications", "stonedServer"), false);
  214. }
  215. /**
  216. * Initialises the input tab.
  217. */
  218. private void initInputTab() {
  219. final String tabName = "Input";
  220. preferencesPanel.addCategory(tabName, "");
  221. preferencesPanel.addTextfieldOption(tabName, "general.commandchar",
  222. "Command character: ", "", Config.getCommandChar());
  223. preferencesPanel.addCheckboxOption(tabName, "tabcompletion.casesensitive",
  224. "Case-sensitive tab completion: ", "",
  225. Config.getOptionBool("tabcompletion", "casesensitive"));
  226. }
  227. /**
  228. * Initialises the logging tab.
  229. */
  230. private void initLoggingTab() {
  231. final String tabName = "Error Handling";
  232. preferencesPanel.addCategory(tabName, "");
  233. preferencesPanel.addCheckboxOption(tabName, "general.autoSubmitErrors",
  234. "Automatically submit errors: ", "",
  235. Config.getOptionBool("general", "autoSubmitErrors"));
  236. preferencesPanel.addComboboxOption(tabName, "logging.dateFormat",
  237. "Date format: ", "", new String[]
  238. {"EEE, d MMM yyyy HH:mm:ss Z", "d MMM yyyy HH:mm:ss", },
  239. Config.getOption("logging", "dateFormat"), true);
  240. preferencesPanel.addCheckboxOption(tabName, "logging.programLogging",
  241. "Program logs: ", "",
  242. Config.getOptionBool("logging", "programLogging"));
  243. preferencesPanel.addCheckboxOption(tabName, "logging.debugLogging",
  244. "Debug logs: ", "",
  245. Config.getOptionBool("logging", "debugLogging"));
  246. preferencesPanel.addCheckboxOption(tabName, "logging.debugLoggingSysOut",
  247. "Debug console output: ", "",
  248. Config.getOptionBool("logging", "debugLoggingSysOut"));
  249. }
  250. /**
  251. * Initialises the advanced tab.
  252. */
  253. private void initAdvancedTab() {
  254. final String tabName = "Advanced";
  255. preferencesPanel.addCategory(tabName, "");
  256. final LookAndFeelInfo[] plaf = UIManager.getInstalledLookAndFeels();
  257. final String[] lafs = new String[plaf.length];
  258. int i = 0;
  259. for (LookAndFeelInfo laf : plaf) {
  260. lafs[i++] = laf.getName();
  261. }
  262. preferencesPanel.addComboboxOption(tabName, "ui.lookandfeel",
  263. "Look and feel: ", "", lafs,
  264. Config.getOption("ui", "lookandfeel"), false);
  265. preferencesPanel.addCheckboxOption(tabName, "ui.showversion",
  266. "Show version: ", "",
  267. Config.getOptionBool("ui", "showversion"));
  268. preferencesPanel.addSpinnerOption(tabName, "ui.inputbuffersize",
  269. "Input bufer size (lines): ", "",
  270. Config.getOptionInt("ui", "inputbuffersize", 50));
  271. preferencesPanel.addSpinnerOption(tabName, "ui.frameBufferSize",
  272. "Frame buffer size (characters): ", "",
  273. Config.getOptionInt("ui", "frameBufferSize", Integer.MAX_VALUE));
  274. preferencesPanel.addTextfieldOption(tabName, "general.browser",
  275. "Browser: ", "", Config.getOption("general", "browser"));
  276. }
  277. /** {@inheritDoc}. */
  278. public void configClosed(final Properties properties) {
  279. for (Map.Entry<Object, Object> entry : properties.entrySet()) {
  280. final String[] args = ((String) entry.getKey()).split("\\.");
  281. Config.setOption(args[0], args[1], (String) entry.getValue());
  282. }
  283. preferencesPanel = null;
  284. }
  285. }