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.

SwingPreferencesModel.java 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc.addons.ui_swing;
  18. import com.dmdirc.config.prefs.PluginPreferencesCategory;
  19. import com.dmdirc.config.prefs.PreferencesCategory;
  20. import com.dmdirc.config.prefs.PreferencesSetting;
  21. import com.dmdirc.config.prefs.PreferencesType;
  22. import com.dmdirc.config.provider.AggregateConfigProvider;
  23. import com.dmdirc.config.provider.ConfigProvider;
  24. import com.dmdirc.plugins.PluginInfo;
  25. import com.dmdirc.util.validators.NumericalValidator;
  26. import java.util.HashMap;
  27. import java.util.Map;
  28. import javax.swing.UIManager;
  29. /**
  30. * Manages the swing UI preferences.
  31. */
  32. public class SwingPreferencesModel {
  33. private final PluginInfo pluginInfo;
  34. private final String domain;
  35. private final AggregateConfigProvider globalConfig;
  36. private final ConfigProvider globalIdentity;
  37. public SwingPreferencesModel(final PluginInfo pluginInfo,
  38. final String domain,
  39. final AggregateConfigProvider globalConfig,
  40. final ConfigProvider globalIdentity) {
  41. this.pluginInfo = pluginInfo;
  42. this.domain = domain;
  43. this.globalConfig = globalConfig;
  44. this.globalIdentity = globalIdentity;
  45. }
  46. /**
  47. * Creates the Swing UI category.
  48. *
  49. * @return Swing UI preferences category
  50. */
  51. public PreferencesCategory getSwingUICategory() {
  52. return createGeneralCategory();
  53. }
  54. /**
  55. * Creates the "Advanced" category.
  56. *
  57. * @return Newly created preferences category
  58. */
  59. private PreferencesCategory createGeneralCategory() {
  60. final PreferencesCategory general = new PluginPreferencesCategory(
  61. pluginInfo, "Swing UI", "These config options apply "
  62. + "only to the swing UI.", "category-gui");
  63. final Map<String, String> lafs = new HashMap<>();
  64. final Map<String, String> framemanagers = new HashMap<>();
  65. final Map<String, String> fmpositions = new HashMap<>();
  66. // TODO: When we can inject nicely, use a service locator to find all implementations.
  67. framemanagers.put(
  68. "com.dmdirc.addons.ui_swing.framemanager.tree.TreeFrameManagerProvider",
  69. "Treeview");
  70. framemanagers.put(
  71. "com.dmdirc.addons.ui_swing.framemanager.buttonbar.ButtonBarProvider",
  72. "Button bar");
  73. fmpositions.put("top", "Top");
  74. fmpositions.put("bottom", "Bottom");
  75. fmpositions.put("left", "Left");
  76. fmpositions.put("right", "Right");
  77. final UIManager.LookAndFeelInfo[] plaf = UIManager.getInstalledLookAndFeels();
  78. lafs.put("Native", "Native");
  79. for (final UIManager.LookAndFeelInfo laf : plaf) {
  80. lafs.put(laf.getName(), laf.getName());
  81. }
  82. general.addSetting(new PreferencesSetting("ui", "lookandfeel",
  83. "Look and feel", "The Java look and feel to use", lafs,
  84. globalConfig, globalIdentity).setRestartNeeded());
  85. general.addSetting(new PreferencesSetting("ui", "framemanager",
  86. "Window manager", "Which window manager should be used?",
  87. framemanagers,
  88. globalConfig, globalIdentity).setRestartNeeded());
  89. general.addSetting(new PreferencesSetting("ui", "framemanagerPosition",
  90. "Window manager position", "Where should the window "
  91. + "manager be positioned?", fmpositions,
  92. globalConfig, globalIdentity).setRestartNeeded());
  93. general.addSetting(new PreferencesSetting(PreferencesType.FONT,
  94. "ui", "textPaneFontName", "Textpane font",
  95. "Font for the textpane",
  96. globalConfig, globalIdentity).setRestartNeeded());
  97. general.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
  98. "ui", "textPaneFontSize", "Textpane font size",
  99. "Font size for the textpane",
  100. globalConfig, globalIdentity).setRestartNeeded());
  101. general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  102. "ui", "sortrootwindows", "Sort root windows",
  103. "Sort child windows in the frame managers?",
  104. globalConfig, globalIdentity));
  105. general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  106. "ui", "sortchildwindows", "Sort child windows",
  107. "Sort root windows in the frame managers?",
  108. globalConfig, globalIdentity));
  109. general.addSubCategory(createNicklistCategory());
  110. general.addSubCategory(createTreeViewCategory());
  111. general.addSubCategory(createAdvancedCategory());
  112. return general;
  113. }
  114. /**
  115. * Creates the "Advanced" category.
  116. *
  117. * @return Newly created preferences category
  118. */
  119. private PreferencesCategory createAdvancedCategory() {
  120. final PreferencesCategory advanced = new PluginPreferencesCategory(
  121. pluginInfo, "Advanced", "");
  122. advanced.addSetting(new PreferencesSetting(
  123. PreferencesType.INTEGER, new NumericalValidator(10, -1),
  124. "ui", "frameBufferSize",
  125. "Window buffer size", "The maximum number of lines in a "
  126. + "window buffer", globalConfig, globalIdentity));
  127. advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  128. domain, "mdiBarVisibility", "MDI Bar Visibility",
  129. "Controls the visibility of the MDI bar",
  130. globalConfig, globalIdentity));
  131. advanced.addSetting(
  132. new PreferencesSetting(PreferencesType.BOOLEAN, "ui",
  133. "useOneTouchExpandable", "Use one touch expandable split "
  134. + "panes?", "Use one touch expandable arrows for "
  135. + "collapsing/expanding the split panes",
  136. globalConfig, globalIdentity));
  137. advanced.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
  138. domain, "windowMenuItems", "Window menu item count",
  139. "Number of items to show in the window menu",
  140. globalConfig, globalIdentity));
  141. advanced.addSetting(
  142. new PreferencesSetting(PreferencesType.INTEGER, domain,
  143. "windowMenuScrollInterval", "Window menu scroll interval",
  144. "Number of milliseconds to pause when autoscrolling in the "
  145. + "window menu",
  146. globalConfig, globalIdentity));
  147. advanced.addSetting(
  148. new PreferencesSetting(PreferencesType.BOOLEAN, domain,
  149. "showtopicbar", "Show topic bar",
  150. "Shows a graphical topic bar in channels.",
  151. globalConfig, globalIdentity));
  152. advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  153. domain,
  154. "shownicklist", "Show nicklist?",
  155. "Do you want the nicklist visible",
  156. globalConfig, globalIdentity));
  157. advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  158. domain, "showfulltopic", "Show full topic in topic bar?",
  159. "Do you want to show the full topic in the topic bar or just"
  160. + "first line?",
  161. globalConfig, globalIdentity));
  162. advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  163. domain, "hideEmptyTopicBar", "Hide empty topic bar?",
  164. "Do you want to hide the topic bar when there is no topic",
  165. globalConfig, globalIdentity));
  166. advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  167. domain, "textpanelinenotification",
  168. "New line notification", "Do you want to be notified about new "
  169. + "lines whilst scrolled up?",
  170. globalConfig, globalIdentity));
  171. return advanced;
  172. }
  173. /**
  174. * Creates the "Treeview" category.
  175. *
  176. * @return Newly created preferences category
  177. */
  178. private PreferencesCategory createTreeViewCategory() {
  179. final PreferencesCategory treeview = new PluginPreferencesCategory(
  180. pluginInfo, "Treeview", "", "treeview");
  181. treeview.addSetting(new PreferencesSetting(
  182. PreferencesType.OPTIONALCOLOUR,
  183. "treeview", "backgroundcolour", "Treeview background colour",
  184. "Background colour to use for the treeview",
  185. globalConfig, globalIdentity));
  186. treeview.addSetting(new PreferencesSetting(
  187. PreferencesType.OPTIONALCOLOUR,
  188. "treeview", "foregroundcolour", "Treeview foreground colour",
  189. "Foreground colour to use for the treeview",
  190. globalConfig, globalIdentity));
  191. treeview.addSetting(new PreferencesSetting(
  192. PreferencesType.OPTIONALCOLOUR,
  193. "ui", "treeviewRolloverColour", "Treeview rollover colour",
  194. "Background colour to use when the mouse cursor is over a "
  195. + "node",
  196. globalConfig, globalIdentity));
  197. treeview.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  198. "ui", "treeviewActiveBold", "Active node bold",
  199. "Make the active node bold?",
  200. globalConfig, globalIdentity));
  201. treeview.addSetting(new PreferencesSetting(
  202. PreferencesType.OPTIONALCOLOUR,
  203. "ui", "treeviewActiveBackground", "Active node background",
  204. "Background colour to use for active treeview node",
  205. globalConfig, globalIdentity));
  206. treeview.addSetting(new PreferencesSetting(
  207. PreferencesType.OPTIONALCOLOUR,
  208. "ui", "treeviewActiveForeground", "Active node foreground",
  209. "Foreground colour to use for active treeview node",
  210. globalConfig, globalIdentity));
  211. treeview.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  212. domain, "showtreeexpands", "Show expand/collapse handles",
  213. "Do you want to show tree view collapse/expand handles",
  214. globalConfig, globalIdentity));
  215. return treeview;
  216. }
  217. /**
  218. * Creates the "Nicklist" category.
  219. *
  220. * @return Newly created preferences category
  221. */
  222. private PreferencesCategory createNicklistCategory() {
  223. final PreferencesCategory nicklist = new PluginPreferencesCategory(
  224. pluginInfo, "Nicklist", "", "nicklist");
  225. nicklist.addSetting(new PreferencesSetting(
  226. PreferencesType.OPTIONALCOLOUR,
  227. "ui", "nicklistbackgroundcolour", "Nicklist background colour",
  228. "Background colour to use for the nicklist",
  229. globalConfig, globalIdentity));
  230. nicklist.addSetting(new PreferencesSetting(
  231. PreferencesType.OPTIONALCOLOUR,
  232. "ui", "nicklistforegroundcolour", "Nicklist foreground colour",
  233. "Foreground colour to use for the nicklist",
  234. globalConfig, globalIdentity));
  235. nicklist.addSetting(new PreferencesSetting(
  236. PreferencesType.OPTIONALCOLOUR,
  237. "ui", "nickListAltBackgroundColour",
  238. "Alternate background colour",
  239. "Background colour to use for every other nicklist entry",
  240. globalConfig, globalIdentity));
  241. nicklist.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  242. "nicklist", "sortByMode", "Sort nicklist by user mode",
  243. "Sort nicknames by the modes that they have?",
  244. globalConfig, globalIdentity));
  245. nicklist.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  246. "nicklist", "sortByCase", "Sort nicklist by case",
  247. "Sort nicknames in a case-sensitive manner?",
  248. globalConfig, globalIdentity));
  249. return nicklist;
  250. }
  251. }