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.

NickColourPlugin.java 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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.nickcolours;
  23. import com.dmdirc.addons.ui_swing.SwingController;
  24. import com.dmdirc.addons.ui_swing.UIUtilities;
  25. import com.dmdirc.config.prefs.PluginPreferencesCategory;
  26. import com.dmdirc.config.prefs.PreferencesCategory;
  27. import com.dmdirc.config.prefs.PreferencesDialogModel;
  28. import com.dmdirc.config.prefs.PreferencesSetting;
  29. import com.dmdirc.config.prefs.PreferencesType;
  30. import com.dmdirc.plugins.PluginInfo;
  31. import com.dmdirc.plugins.implementations.BasePlugin;
  32. import com.dmdirc.ui.IconManager;
  33. import com.dmdirc.ui.messages.ColourManager;
  34. import java.awt.Window;
  35. import java.util.concurrent.Callable;
  36. import dagger.ObjectGraph;
  37. /**
  38. * Adds support for nick colours throughout the client.
  39. */
  40. public class NickColourPlugin extends BasePlugin {
  41. /** Plugin info. */
  42. private final PluginInfo pluginInfo;
  43. /** Main window that will own any dialogs. */
  44. private final Window mainWindow;
  45. /** Icon manager. */
  46. private final IconManager iconManager;
  47. /** Colour manager. */
  48. private final ColourManager colourManager;
  49. /** Nick colour manager. */
  50. private NickColourManager nickColourManager;
  51. public NickColourPlugin(final PluginInfo pluginInfo, final SwingController controller,
  52. final IconManager iconManager,
  53. final ColourManager colourManager) {
  54. this.pluginInfo = pluginInfo;
  55. this.mainWindow = controller.getMainFrame();
  56. this.iconManager = iconManager;
  57. this.colourManager = colourManager;
  58. }
  59. @Override
  60. public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
  61. super.load(pluginInfo, graph);
  62. setObjectGraph(graph.plus(new NickColourModule(pluginInfo.getDomain())));
  63. nickColourManager = getObjectGraph().get(NickColourManager.class);
  64. }
  65. @Override
  66. public void onLoad() {
  67. super.onLoad();
  68. nickColourManager.onLoad();
  69. }
  70. @Override
  71. public void onUnload() {
  72. super.onUnload();
  73. nickColourManager.onUnload();
  74. }
  75. @Override
  76. public void showConfig(final PreferencesDialogModel manager) {
  77. final PreferencesCategory general = new PluginPreferencesCategory(
  78. pluginInfo, "Nick Colours",
  79. "General configuration for NickColour plugin.");
  80. final PreferencesCategory colours = new PluginPreferencesCategory(
  81. pluginInfo, "Colours",
  82. "Set colours for specific nicknames.", UIUtilities.invokeAndWait(
  83. new Callable<NickColourPanel>() {
  84. @Override
  85. public NickColourPanel call() {
  86. return new NickColourPanel(mainWindow, iconManager, colourManager,
  87. manager.getIdentity(), manager.getConfigManager(),
  88. pluginInfo.getDomain());
  89. }
  90. }));
  91. general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  92. "ui", "shownickcoloursintext", "Show colours in text area",
  93. "Colour nicknames in main text area?",
  94. manager.getConfigManager(), manager.getIdentity()));
  95. general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  96. "ui", "shownickcoloursinnicklist", "Show colours in"
  97. + " nick list", "Colour nicknames in channel nick lists?",
  98. manager.getConfigManager(), manager.getIdentity()));
  99. general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN, pluginInfo.getDomain(),
  100. "settext", "Set colours in textarea",
  101. "Should the plugin set the textarea colour of nicks?",
  102. manager.getConfigManager(), manager.getIdentity()));
  103. general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN, pluginInfo.getDomain(),
  104. "setnicklist", "Set colours in nick list",
  105. "Should the plugin set the nick list colour of nicks?",
  106. manager.getConfigManager(), manager.getIdentity()));
  107. general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  108. pluginInfo.getDomain(), "userandomcolour", "Use random colour",
  109. "Use a pseudo-random colour for each person?",
  110. manager.getConfigManager(), manager.getIdentity()));
  111. general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  112. pluginInfo.getDomain(), "useowncolour", "Use colour for own nick",
  113. "Always use the same colour for our own nickname?",
  114. manager.getConfigManager(), manager.getIdentity()));
  115. general.addSetting(new PreferencesSetting(PreferencesType.COLOUR, pluginInfo.getDomain(),
  116. "owncolour", "Colour to use for own nick",
  117. "Colour used for our own nickname, if above setting is "
  118. + "enabled.", manager.getConfigManager(), manager.getIdentity()));
  119. general.addSubCategory(colours);
  120. manager.getCategory("Plugins").addSubCategory(general);
  121. }
  122. }