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.

SwingController.java 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. /*
  2. * Copyright (c) 2006-2014 DMDirc Developers
  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.addons.ui_swing;
  23. import com.dmdirc.Channel;
  24. import com.dmdirc.Server;
  25. import com.dmdirc.ServerManager;
  26. import com.dmdirc.addons.ui_swing.commands.ChannelSettings;
  27. import com.dmdirc.addons.ui_swing.commands.Input;
  28. import com.dmdirc.addons.ui_swing.commands.PopInCommand;
  29. import com.dmdirc.addons.ui_swing.commands.PopOutCommand;
  30. import com.dmdirc.addons.ui_swing.commands.ServerSettings;
  31. import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
  32. import com.dmdirc.addons.ui_swing.dialogs.error.ErrorListDialog;
  33. import com.dmdirc.addons.ui_swing.injection.SwingModule;
  34. import com.dmdirc.config.prefs.PluginPreferencesCategory;
  35. import com.dmdirc.config.prefs.PreferencesCategory;
  36. import com.dmdirc.config.prefs.PreferencesDialogModel;
  37. import com.dmdirc.config.prefs.PreferencesSetting;
  38. import com.dmdirc.config.prefs.PreferencesType;
  39. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  40. import com.dmdirc.interfaces.config.ConfigProvider;
  41. import com.dmdirc.interfaces.config.IdentityController;
  42. import com.dmdirc.interfaces.ui.UIController;
  43. import com.dmdirc.interfaces.ui.Window;
  44. import com.dmdirc.logger.ErrorLevel;
  45. import com.dmdirc.logger.Logger;
  46. import com.dmdirc.plugins.Exported;
  47. import com.dmdirc.plugins.PluginInfo;
  48. import com.dmdirc.plugins.PluginManager;
  49. import com.dmdirc.plugins.implementations.BaseCommandPlugin;
  50. import com.dmdirc.ui.IconManager;
  51. import com.dmdirc.ui.messages.ColourManager;
  52. import com.dmdirc.updater.Version;
  53. import com.dmdirc.util.URLBuilder;
  54. import com.dmdirc.util.validators.NumericalValidator;
  55. import com.dmdirc.util.validators.OptionalValidator;
  56. import com.google.common.eventbus.EventBus;
  57. import java.awt.Font;
  58. import java.awt.GraphicsEnvironment;
  59. import java.net.URI;
  60. import java.util.ArrayList;
  61. import java.util.HashMap;
  62. import java.util.List;
  63. import java.util.Map;
  64. import java.util.concurrent.Callable;
  65. import javax.swing.JMenuItem;
  66. import javax.swing.SwingUtilities;
  67. import javax.swing.UIManager;
  68. import javax.swing.UIManager.LookAndFeelInfo;
  69. import javax.swing.UnsupportedLookAndFeelException;
  70. import net.miginfocom.layout.PlatformDefaults;
  71. import dagger.ObjectGraph;
  72. /**
  73. * Controls the main swing UI.
  74. */
  75. public class SwingController extends BaseCommandPlugin implements UIController {
  76. /** Top level window list. */
  77. private final List<java.awt.Window> windows;
  78. /** Error dialog. */
  79. private ErrorListDialog errorDialog;
  80. /** This plugin's plugin info object. */
  81. private final PluginInfo pluginInfo;
  82. /** Global config manager. */
  83. private final AggregateConfigProvider globalConfig;
  84. /** Global config identity. */
  85. private final ConfigProvider globalIdentity;
  86. /** Addon config identity. */
  87. private final ConfigProvider addonIdentity;
  88. /** Global Swing UI Icon manager. */
  89. private final IconManager iconManager;
  90. /** Plugin manager. */
  91. private final PluginManager pluginManager;
  92. /** Apple handler, deals with Mac specific code. */
  93. private final Apple apple;
  94. /** The colour manager to use to parse colours. */
  95. private final ColourManager colourManager;
  96. /** The manager we're using for dependencies. */
  97. private SwingManager swingManager;
  98. /** This plugin's settings domain. */
  99. private final String domain;
  100. /**
  101. * Instantiates a new SwingController.
  102. *
  103. * @param pluginInfo Plugin info
  104. * @param identityManager Identity Manager
  105. * @param pluginManager Plugin manager
  106. * @param serverManager Server manager to use for server information.
  107. * @param urlBuilder URL builder to use to resolve icons etc.
  108. * @param colourManager The colour manager to use to parse colours.
  109. * @param eventBus The bus to publish and subscribe to events on.
  110. */
  111. public SwingController(
  112. final PluginInfo pluginInfo,
  113. final IdentityController identityManager,
  114. final PluginManager pluginManager,
  115. final ServerManager serverManager,
  116. final URLBuilder urlBuilder,
  117. final ColourManager colourManager,
  118. final EventBus eventBus) {
  119. this.pluginInfo = pluginInfo;
  120. this.pluginManager = pluginManager;
  121. this.colourManager = colourManager;
  122. this.domain = pluginInfo.getDomain();
  123. globalConfig = identityManager.getGlobalConfiguration();
  124. globalIdentity = identityManager.getUserSettings();
  125. addonIdentity = identityManager.getAddonSettings();
  126. apple = new Apple(globalConfig, serverManager, eventBus);
  127. iconManager = new IconManager(globalConfig, urlBuilder);
  128. setAntiAlias();
  129. windows = new ArrayList<>();
  130. }
  131. @Deprecated
  132. public AggregateConfigProvider getGlobalConfig() {
  133. return globalConfig;
  134. }
  135. @Deprecated
  136. public IconManager getIconManager() {
  137. return iconManager;
  138. }
  139. @Deprecated
  140. public PluginManager getPluginManager() {
  141. return pluginManager;
  142. }
  143. @Deprecated
  144. public Apple getApple() {
  145. return apple;
  146. }
  147. @Deprecated
  148. public ColourManager getColourManager() {
  149. return colourManager;
  150. }
  151. /**
  152. * Make swing not use Anti Aliasing if the user doesn't want it.
  153. */
  154. public final void setAntiAlias() {
  155. // For this to work it *HAS* to be before anything else UI related.
  156. final boolean aaSetting = getGlobalConfig()
  157. .getOptionBool("ui", "antialias");
  158. System.setProperty("awt.useSystemAAFontSettings",
  159. Boolean.toString(aaSetting));
  160. System.setProperty("swing.aatext", Boolean.toString(aaSetting));
  161. }
  162. /**
  163. * Does the main frame exist?
  164. *
  165. * @return true iif mainframe exists
  166. */
  167. protected boolean hasMainFrame() {
  168. return swingManager != null;
  169. }
  170. /** {@inheritDoc} */
  171. @Override
  172. public void showFirstRunWizard() {
  173. swingManager.getFirstRunExecutor().showWizardAndWait();
  174. }
  175. /** {@inheritDoc} */
  176. @Override
  177. public void showChannelSettingsDialog(final Channel channel) {
  178. UIUtilities.invokeLater(new Runnable() {
  179. /** {@inheritDoc} */
  180. @Override
  181. public void run() {
  182. swingManager.getChannelSettingsDialogProvider().displayOrRequestFocus(channel);
  183. }
  184. });
  185. }
  186. /** {@inheritDoc} */
  187. @Override
  188. public void showServerSettingsDialog(final Server server) {
  189. UIUtilities.invokeLater(new Runnable() {
  190. /** {@inheritDoc} */
  191. @Override
  192. public void run() {
  193. swingManager.getServerSettingsDialogProvider().displayOrRequestFocus(server);
  194. }
  195. });
  196. }
  197. /**
  198. * @deprecated Callers should be given access to the provider.
  199. */
  200. @Deprecated
  201. public void closeServerSettingsDialog(final Server server) {
  202. UIUtilities.invokeLater(new Runnable() {
  203. /** {@inheritDoc} */
  204. @Override
  205. public void run() {
  206. swingManager.getServerSettingsDialogProvider().dispose(server);
  207. }
  208. });
  209. }
  210. /**
  211. * Updates the look and feel to the current config setting.
  212. */
  213. public void updateLookAndFeel() {
  214. try {
  215. UIManager.setLookAndFeel(UIUtilities.getLookAndFeel(
  216. getGlobalConfig().getOption("ui", "lookandfeel")));
  217. updateComponentTrees();
  218. } catch (ClassNotFoundException | InstantiationException |
  219. IllegalAccessException | UnsupportedLookAndFeelException ex) {
  220. Logger.userError(ErrorLevel.LOW,
  221. "Unable to change Look and Feel: " + ex.getMessage());
  222. }
  223. }
  224. /**
  225. * Updates the component trees of all known windows in the Swing UI.
  226. */
  227. public void updateComponentTrees() {
  228. final int state = UIUtilities.invokeAndWait(
  229. new Callable<Integer>() {
  230. /** {@inheritDoc} */
  231. @Override
  232. public Integer call() {
  233. return getMainFrame().getExtendedState();
  234. }
  235. });
  236. UIUtilities.invokeLater(new Runnable() {
  237. /** {@inheritDoc} */
  238. @Override
  239. public void run() {
  240. SwingUtilities.updateComponentTreeUI(errorDialog);
  241. }
  242. });
  243. for (final java.awt.Window window : getTopLevelWindows()) {
  244. UIUtilities.invokeLater(new Runnable() {
  245. /** {@inheritDoc} */
  246. @Override
  247. public void run() {
  248. SwingUtilities.updateComponentTreeUI(window);
  249. if (window != getMainFrame()) {
  250. window.pack();
  251. }
  252. }
  253. });
  254. }
  255. UIUtilities.invokeLater(new Runnable() {
  256. /** {@inheritDoc} */
  257. @Override
  258. public void run() {
  259. getMainFrame().setExtendedState(state);
  260. }
  261. });
  262. }
  263. /**
  264. * Initialises the global UI settings for the Swing UI.
  265. */
  266. private void initUISettings() {
  267. UIUtilities.invokeAndWait(new Runnable() {
  268. /** {@inheritDoc} */
  269. @Override
  270. public void run() {
  271. // This will do nothing on non OS X Systems
  272. if (Apple.isApple()) {
  273. apple.setUISettings();
  274. apple.setListener();
  275. }
  276. final Font defaultFont = new Font(Font.DIALOG, Font.TRUETYPE_FONT, 12);
  277. if (UIManager.getFont("TextField.font") == null) {
  278. UIManager.put("TextField.font", defaultFont);
  279. }
  280. if (UIManager.getFont("TextPane.font") == null) {
  281. UIManager.put("TextPane.font", defaultFont);
  282. }
  283. try {
  284. UIUtilities.initUISettings();
  285. UIManager.setLookAndFeel(UIUtilities.getLookAndFeel(
  286. getGlobalConfig().getOption("ui", "lookandfeel")));
  287. UIUtilities.setUIFont(new Font(getGlobalConfig()
  288. .getOption("ui", "textPaneFontName"), Font.PLAIN, 12));
  289. } catch (UnsupportedOperationException | UnsupportedLookAndFeelException |
  290. IllegalAccessException | InstantiationException | ClassNotFoundException ex) {
  291. Logger.userError(ErrorLevel.LOW, "Unable to set UI Settings");
  292. }
  293. if ("Metal".equals(UIManager.getLookAndFeel().getName())
  294. || Apple.isAppleUI()) {
  295. PlatformDefaults.setPlatform(PlatformDefaults.WINDOWS_XP);
  296. }
  297. }
  298. });
  299. }
  300. /** {@inheritDoc} */
  301. @Override
  302. public void showURLDialog(final URI url) {
  303. UIUtilities.invokeLater(new Runnable() {
  304. /** {@inheritDoc} */
  305. @Override
  306. public void run() {
  307. swingManager.getUrlDialogFactory().getURLDialog(url).display();
  308. }
  309. });
  310. }
  311. /** {@inheritDoc} */
  312. @Override
  313. public void showFeedbackNag() {
  314. UIUtilities.invokeLater(new Runnable() {
  315. /** {@inheritDoc} */
  316. @Override
  317. public void run() {
  318. swingManager.getFeedbackNagProvider().get();
  319. }
  320. });
  321. }
  322. /**
  323. * Shows the error dialog.
  324. */
  325. public void showErrorDialog() {
  326. errorDialog.display();
  327. }
  328. /**
  329. * Returns the current look and feel.
  330. *
  331. * @return Current look and feel
  332. */
  333. public static String getLookAndFeel() {
  334. return UIManager.getLookAndFeel().getName();
  335. }
  336. /** {@inheritDoc} */
  337. @Override
  338. public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
  339. super.load(pluginInfo, graph);
  340. // Init the UI settings before we start any DI, as we might create frames etc.
  341. initUISettings();
  342. setObjectGraph(graph.plus(new SwingModule(this, pluginInfo.getDomain())));
  343. getObjectGraph().validate();
  344. swingManager = getObjectGraph().get(SwingManager.class);
  345. registerCommand(ServerSettings.class, ServerSettings.INFO);
  346. registerCommand(ChannelSettings.class, ChannelSettings.INFO);
  347. registerCommand(Input.class, Input.INFO);
  348. registerCommand(PopOutCommand.class, PopOutCommand.INFO);
  349. registerCommand(PopInCommand.class, PopInCommand.INFO);
  350. }
  351. /** {@inheritDoc} */
  352. @Override
  353. public void onLoad() {
  354. if (GraphicsEnvironment.isHeadless()) {
  355. throw new IllegalStateException(
  356. "Swing UI can't be run in a headless environment");
  357. }
  358. swingManager.load();
  359. UIUtilities.invokeAndWait(new Runnable() {
  360. /** {@inheritDoc} */
  361. @Override
  362. public void run() {
  363. getMainFrame().setVisible(true);
  364. errorDialog = new ErrorListDialog(getMainFrame(), getIconManager());
  365. }
  366. });
  367. super.onLoad();
  368. }
  369. /** {@inheritDoc} */
  370. @Override
  371. public void onUnload() {
  372. swingManager.unload();
  373. errorDialog.dispose();
  374. for (final java.awt.Window window : getTopLevelWindows()) {
  375. window.dispose();
  376. }
  377. super.onUnload();
  378. }
  379. /** {@inheritDoc} */
  380. @Override
  381. public void domainUpdated() {
  382. addonIdentity.setOption("ui", "textPaneFontName",
  383. UIManager.getFont("TextPane.font").getFamily());
  384. addonIdentity.setOption("ui", "textPaneFontSize",
  385. UIManager.getFont("TextPane.font").getSize());
  386. }
  387. /** {@inheritDoc} */
  388. @Override
  389. public void showConfig(final PreferencesDialogModel manager) {
  390. manager.getCategory("GUI").addSubCategory(createGeneralCategory());
  391. }
  392. /**
  393. * Creates the "Advanced" category.
  394. *
  395. * @return Newly created preferences category
  396. */
  397. private PreferencesCategory createGeneralCategory() {
  398. final PreferencesCategory general = new PluginPreferencesCategory(
  399. pluginInfo, "Swing UI", "These config options apply "
  400. + "only to the swing UI.", "category-gui");
  401. final Map<String, String> lafs = new HashMap<>();
  402. final Map<String, String> framemanagers = new HashMap<>();
  403. final Map<String, String> fmpositions = new HashMap<>();
  404. framemanagers.put(
  405. "com.dmdirc.addons.ui_swing.framemanager.tree.TreeFrameManager",
  406. "Treeview");
  407. framemanagers.put(
  408. "com.dmdirc.addons.ui_swing.framemanager.buttonbar.ButtonBar",
  409. "Button bar");
  410. fmpositions.put("top", "Top");
  411. fmpositions.put("bottom", "Bottom");
  412. fmpositions.put("left", "Left");
  413. fmpositions.put("right", "Right");
  414. final LookAndFeelInfo[] plaf = UIManager.getInstalledLookAndFeels();
  415. lafs.put("Native", "Native");
  416. for (final LookAndFeelInfo laf : plaf) {
  417. lafs.put(laf.getName(), laf.getName());
  418. }
  419. general.addSetting(new PreferencesSetting("ui", "lookandfeel",
  420. "Look and feel", "The Java look and feel to use", lafs,
  421. globalConfig, globalIdentity));
  422. general.addSetting(new PreferencesSetting("ui", "framemanager",
  423. "Window manager", "Which window manager should be used?",
  424. framemanagers,
  425. globalConfig, globalIdentity));
  426. general.addSetting(new PreferencesSetting("ui", "framemanagerPosition",
  427. "Window manager position", "Where should the window "
  428. + "manager be positioned?", fmpositions,
  429. globalConfig, globalIdentity));
  430. general.addSetting(new PreferencesSetting(PreferencesType.FONT,
  431. "ui", "textPaneFontName", "Textpane font",
  432. "Font for the textpane",
  433. globalConfig, globalIdentity));
  434. general.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
  435. "ui", "textPaneFontSize", "Textpane font size",
  436. "Font size for the textpane",
  437. globalConfig, globalIdentity));
  438. general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  439. "ui", "sortrootwindows", "Sort root windows",
  440. "Sort child windows in the frame managers?",
  441. globalConfig, globalIdentity));
  442. general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  443. "ui", "sortchildwindows", "Sort child windows",
  444. "Sort root windows in the frame managers?",
  445. globalConfig, globalIdentity));
  446. general.addSubCategory(createNicklistCategory());
  447. general.addSubCategory(createTreeViewCategory());
  448. general.addSubCategory(createAdvancedCategory());
  449. return general;
  450. }
  451. /**
  452. * Creates the "Advanced" category.
  453. *
  454. * @return Newly created preferences category
  455. */
  456. private PreferencesCategory createAdvancedCategory() {
  457. final PreferencesCategory advanced = new PluginPreferencesCategory(
  458. pluginInfo, "Advanced", "");
  459. advanced.addSetting(new PreferencesSetting(
  460. PreferencesType.OPTIONALINTEGER,
  461. new OptionalValidator(new NumericalValidator(10, -1)),
  462. "ui", "frameBufferSize",
  463. "Window buffer size", "The maximum number of lines in a "
  464. + "window buffer", globalConfig, globalIdentity));
  465. advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  466. domain, "mdiBarVisibility", "MDI Bar Visibility",
  467. "Controls the visibility of the MDI bar",
  468. globalConfig, globalIdentity));
  469. advanced.addSetting(
  470. new PreferencesSetting(PreferencesType.BOOLEAN, "ui",
  471. "useOneTouchExpandable", "Use one touch expandable split "
  472. + "panes?", "Use one touch expandable arrows for "
  473. + "collapsing/expanding the split panes",
  474. globalConfig, globalIdentity));
  475. advanced.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
  476. domain, "windowMenuItems", "Window menu item count",
  477. "Number of items to show in the window menu",
  478. globalConfig, globalIdentity));
  479. advanced.addSetting(
  480. new PreferencesSetting(PreferencesType.INTEGER, domain,
  481. "windowMenuScrollInterval", "Window menu scroll interval",
  482. "Number of milliseconds to pause when autoscrolling in the "
  483. + "window menu",
  484. globalConfig, globalIdentity));
  485. advanced.addSetting(
  486. new PreferencesSetting(PreferencesType.BOOLEAN, domain,
  487. "showtopicbar", "Show topic bar",
  488. "Shows a graphical topic bar in channels.",
  489. globalConfig, globalIdentity));
  490. advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  491. domain,
  492. "shownicklist", "Show nicklist?",
  493. "Do you want the nicklist visible",
  494. globalConfig, globalIdentity));
  495. advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  496. domain, "showfulltopic", "Show full topic in topic bar?",
  497. "Do you want to show the full topic in the topic bar or just"
  498. + "first line?",
  499. globalConfig, globalIdentity));
  500. advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  501. domain, "hideEmptyTopicBar", "Hide empty topic bar?",
  502. "Do you want to hide the topic bar when there is no topic",
  503. globalConfig, globalIdentity));
  504. advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  505. domain, "textpanelinenotification",
  506. "New line notification", "Do you want to be notified about new "
  507. + "lines whilst scrolled up?",
  508. globalConfig, globalIdentity));
  509. return advanced;
  510. }
  511. /**
  512. * Creates the "Treeview" category.
  513. *
  514. * @return Newly created preferences category
  515. */
  516. private PreferencesCategory createTreeViewCategory() {
  517. final PreferencesCategory treeview = new PluginPreferencesCategory(
  518. pluginInfo, "Treeview", "", "treeview");
  519. treeview.addSetting(new PreferencesSetting(
  520. PreferencesType.OPTIONALCOLOUR,
  521. "treeview", "backgroundcolour", "Treeview background colour",
  522. "Background colour to use for the treeview",
  523. globalConfig, globalIdentity));
  524. treeview.addSetting(new PreferencesSetting(
  525. PreferencesType.OPTIONALCOLOUR,
  526. "treeview", "foregroundcolour", "Treeview foreground colour",
  527. "Foreground colour to use for the treeview",
  528. globalConfig, globalIdentity));
  529. treeview.addSetting(new PreferencesSetting(
  530. PreferencesType.OPTIONALCOLOUR,
  531. "ui", "treeviewRolloverColour", "Treeview rollover colour",
  532. "Background colour to use when the mouse cursor is over a "
  533. + "node",
  534. globalConfig, globalIdentity));
  535. treeview.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  536. "ui", "treeviewActiveBold", "Active node bold",
  537. "Make the active node bold?",
  538. globalConfig, globalIdentity));
  539. treeview.addSetting(new PreferencesSetting(
  540. PreferencesType.OPTIONALCOLOUR,
  541. "ui", "treeviewActiveBackground", "Active node background",
  542. "Background colour to use for active treeview node",
  543. globalConfig, globalIdentity));
  544. treeview.addSetting(new PreferencesSetting(
  545. PreferencesType.OPTIONALCOLOUR,
  546. "ui", "treeviewActiveForeground", "Active node foreground",
  547. "Foreground colour to use for active treeview node",
  548. globalConfig, globalIdentity));
  549. treeview.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  550. domain, "showtreeexpands", "Show expand/collapse handles",
  551. "Do you want to show tree view collapse/expand handles",
  552. globalConfig, globalIdentity));
  553. return treeview;
  554. }
  555. /**
  556. * Creates the "Nicklist" category.
  557. *
  558. * @return Newly created preferences category
  559. */
  560. private PreferencesCategory createNicklistCategory() {
  561. final PreferencesCategory nicklist = new PluginPreferencesCategory(
  562. pluginInfo, "Nicklist", "", "nicklist");
  563. nicklist.addSetting(new PreferencesSetting(
  564. PreferencesType.OPTIONALCOLOUR,
  565. "ui", "nicklistbackgroundcolour", "Nicklist background colour",
  566. "Background colour to use for the nicklist",
  567. globalConfig, globalIdentity));
  568. nicklist.addSetting(new PreferencesSetting(
  569. PreferencesType.OPTIONALCOLOUR,
  570. "ui", "nicklistforegroundcolour", "Nicklist foreground colour",
  571. "Foreground colour to use for the nicklist",
  572. globalConfig, globalIdentity));
  573. nicklist.addSetting(new PreferencesSetting(
  574. PreferencesType.OPTIONALCOLOUR,
  575. "ui", "nickListAltBackgroundColour",
  576. "Alternate background colour",
  577. "Background colour to use for every other nicklist entry",
  578. globalConfig, globalIdentity));
  579. nicklist.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  580. "nicklist", "sortByMode", "Sort nicklist by user mode",
  581. "Sort nicknames by the modes that they have?",
  582. globalConfig, globalIdentity));
  583. nicklist.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  584. "nicklist", "sortByCase", "Sort nicklist by case",
  585. "Sort nicknames in a case-sensitive manner?",
  586. globalConfig, globalIdentity));
  587. return nicklist;
  588. }
  589. /**
  590. * Adds a top level window to the window list.
  591. *
  592. * @param source New window
  593. */
  594. protected void addTopLevelWindow(final java.awt.Window source) {
  595. synchronized (windows) {
  596. windows.add(source);
  597. }
  598. }
  599. /**
  600. * Deletes a top level window to the window list.
  601. *
  602. * @param source Old window
  603. */
  604. protected void delTopLevelWindow(final java.awt.Window source) {
  605. synchronized (windows) {
  606. windows.remove(source);
  607. }
  608. }
  609. /**
  610. * Returns a list of top level windows.
  611. *
  612. * @return Top level window list
  613. */
  614. public List<java.awt.Window> getTopLevelWindows() {
  615. synchronized (windows) {
  616. return new ArrayList<>(windows);
  617. }
  618. }
  619. /**
  620. * Returns an instance of SwingController. This method is exported for use in other plugins.
  621. *
  622. * @return A reference to this SwingController.
  623. */
  624. @Exported
  625. public UIController getController() {
  626. return this;
  627. }
  628. /**
  629. * Adds the specified menu item to the named parent menu, creating the parent menu if required.
  630. *
  631. * @param parentMenu Parent menu name
  632. * @param menuItem Menu item to add
  633. */
  634. public void addMenuItem(final String parentMenu, final JMenuItem menuItem) {
  635. getMainFrame().getJMenuBar().addMenuItem(parentMenu, menuItem);
  636. }
  637. /** {@inheritDoc} */
  638. @Override
  639. public void requestWindowFocus(final Window window) {
  640. if (window instanceof TextFrame) {
  641. getMainFrame().setActiveFrame((TextFrame) window);
  642. }
  643. }
  644. /**
  645. * Returns the version of this swing UI.
  646. *
  647. * @return Swing version
  648. */
  649. public Version getVersion() {
  650. return pluginInfo.getMetaData().getVersion();
  651. }
  652. /**
  653. * Retrieves the window factory to use.
  654. *
  655. * @return The window factory to use.
  656. *
  657. * @deprecated Should be injected where needed.
  658. */
  659. @Deprecated
  660. public SwingWindowFactory getWindowFactory() {
  661. return swingManager.getWindowFactory();
  662. }
  663. /**
  664. * Retrieves the main frame to use.
  665. *
  666. * @return The main frame to use.
  667. *
  668. * @deprecated Should be injected where needed.
  669. */
  670. @Deprecated
  671. public MainFrame getMainFrame() {
  672. return swingManager.getMainFrame();
  673. }
  674. }