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 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 dagger.ObjectGraph;
  36. /**
  37. * Adds support for nick colours throughout the client.
  38. */
  39. public class NickColourPlugin extends BasePlugin {
  40. /** Plugin info. */
  41. private final PluginInfo pluginInfo;
  42. /** Main window that will own any dialogs. */
  43. private final Window mainWindow;
  44. /** Icon manager. */
  45. private final IconManager iconManager;
  46. /** Colour manager. */
  47. private final ColourManager colourManager;
  48. /** Nick colour manager. */
  49. private NickColourManager nickColourManager;
  50. public NickColourPlugin(final PluginInfo pluginInfo, final SwingController controller,
  51. final IconManager iconManager,
  52. final ColourManager colourManager) {
  53. this.pluginInfo = pluginInfo;
  54. this.mainWindow = controller.getMainFrame();
  55. this.iconManager = iconManager;
  56. this.colourManager = colourManager;
  57. }
  58. @Override
  59. public void load(final PluginInfo pluginInfo, final ObjectGraph graph) {
  60. super.load(pluginInfo, graph);
  61. setObjectGraph(graph.plus(new NickColourModule(pluginInfo.getDomain())));
  62. nickColourManager = getObjectGraph().get(NickColourManager.class);
  63. }
  64. @Override
  65. public void onLoad() {
  66. super.onLoad();
  67. nickColourManager.onLoad();
  68. }
  69. @Override
  70. public void onUnload() {
  71. super.onUnload();
  72. nickColourManager.onUnload();
  73. }
  74. @Override
  75. public void showConfig(final PreferencesDialogModel manager) {
  76. final PreferencesCategory general = new PluginPreferencesCategory(
  77. pluginInfo, "Nick Colours",
  78. "General configuration for NickColour plugin.");
  79. final PreferencesCategory colours = new PluginPreferencesCategory(
  80. pluginInfo, "Colours",
  81. "Set colours for specific nicknames.", UIUtilities.invokeAndWait(
  82. () -> new NickColourPanel(mainWindow, iconManager, colourManager,
  83. manager.getIdentity(), manager.getConfigManager(),
  84. pluginInfo.getDomain())));
  85. general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  86. pluginInfo.getDomain(), "userandomcolour", "Use random colour",
  87. "Use a pseudo-random colour for each person?",
  88. manager.getConfigManager(), manager.getIdentity()));
  89. general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  90. pluginInfo.getDomain(), "useowncolour", "Use colour for own nick",
  91. "Always use the same colour for our own nickname?",
  92. manager.getConfigManager(), manager.getIdentity()));
  93. general.addSetting(new PreferencesSetting(PreferencesType.COLOUR, pluginInfo.getDomain(),
  94. "owncolour", "Colour to use for own nick",
  95. "Colour used for our own nickname, if above setting is "
  96. + "enabled.", manager.getConfigManager(), manager.getIdentity()));
  97. general.addSubCategory(colours);
  98. manager.getCategory("Plugins").addSubCategory(general);
  99. }
  100. }