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.

SwingModule.java 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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.injection;
  23. import com.dmdirc.ClientModule;
  24. import com.dmdirc.ClientModule.GlobalConfig;
  25. import com.dmdirc.ClientModule.UserConfig;
  26. import com.dmdirc.ServerManager;
  27. import com.dmdirc.actions.ActionManager;
  28. import com.dmdirc.addons.ui_swing.MainFrame;
  29. import com.dmdirc.addons.ui_swing.QuitWorker;
  30. import com.dmdirc.addons.ui_swing.SwingController;
  31. import com.dmdirc.addons.ui_swing.SwingManager;
  32. import com.dmdirc.addons.ui_swing.SwingWindowFactory;
  33. import com.dmdirc.addons.ui_swing.UIUtilities;
  34. import com.dmdirc.addons.ui_swing.commands.ChannelSettings;
  35. import com.dmdirc.addons.ui_swing.commands.Input;
  36. import com.dmdirc.addons.ui_swing.commands.PopInCommand;
  37. import com.dmdirc.addons.ui_swing.commands.PopOutCommand;
  38. import com.dmdirc.addons.ui_swing.commands.ServerSettings;
  39. import com.dmdirc.addons.ui_swing.components.addonpanel.PluginPanel;
  40. import com.dmdirc.addons.ui_swing.components.addonpanel.ThemePanel;
  41. import com.dmdirc.addons.ui_swing.dialogs.prefs.URLConfigPanel;
  42. import com.dmdirc.addons.ui_swing.dialogs.prefs.UpdateConfigPanel;
  43. import com.dmdirc.config.prefs.PreferencesDialogModel;
  44. import com.dmdirc.interfaces.LifecycleController;
  45. import com.dmdirc.interfaces.config.AggregateConfigProvider;
  46. import com.dmdirc.interfaces.config.ConfigProvider;
  47. import com.dmdirc.plugins.PluginDomain;
  48. import com.dmdirc.plugins.PluginManager;
  49. import com.dmdirc.ui.IconManager;
  50. import com.dmdirc.ui.WindowManager;
  51. import com.dmdirc.ui.core.components.StatusBarManager;
  52. import com.dmdirc.ui.core.util.URLHandler;
  53. import com.dmdirc.util.URLBuilder;
  54. import java.util.concurrent.Callable;
  55. import javax.inject.Provider;
  56. import javax.inject.Singleton;
  57. import dagger.Module;
  58. import dagger.Provides;
  59. /**
  60. * Dagger module that provides Swing-specific dependencies.
  61. */
  62. @Module(
  63. addsTo = ClientModule.class,
  64. includes = DialogModule.class,
  65. injects = {
  66. SwingManager.class,
  67. PopInCommand.class,
  68. PopOutCommand.class,
  69. Input.class,
  70. ServerSettings.class,
  71. ChannelSettings.class
  72. })
  73. public class SwingModule {
  74. /** The controller to return to clients. */
  75. private final SwingController controller;
  76. /** The domain for plugin settings. */
  77. private final String domain;
  78. /**
  79. * Creates a new instance of {@link SwingModule}.
  80. *
  81. * @param controller The controller to return. This should be removed when SwingController is
  82. * separated from the plugin implementation.
  83. * @param domain The domain for plugin settings.
  84. */
  85. public SwingModule(final SwingController controller, final String domain) {
  86. this.controller = controller;
  87. this.domain = domain;
  88. }
  89. /**
  90. * Provides the domain that the swing settings should be stored under.
  91. *
  92. * @return The settings domain for the swing plugin.
  93. */
  94. @Provides
  95. @PluginDomain(SwingController.class)
  96. public String getSettingsDomain() {
  97. return domain;
  98. }
  99. /**
  100. * Gets the swing controller to use.
  101. *
  102. * @return The swing controller.
  103. */
  104. @Provides
  105. public SwingController getController() {
  106. return controller;
  107. }
  108. /**
  109. * Gets the main DMDirc window.
  110. *
  111. * @param swingController The controller that will own the frame.
  112. * @param windowFactory The window factory to use to create and listen for windows.
  113. * @param lifecycleController The controller to use to quit the application.
  114. * @param globalConfig The config to read settings from.
  115. * @param quitWorker The worker to use when quitting the application.
  116. * @param urlBuilder The URL builder to use to find icons.
  117. * @param windowManager The core window manager to use to find windows.
  118. *
  119. * @return The main window.
  120. */
  121. @Provides
  122. @Singleton
  123. public MainFrame getMainFrame(
  124. final SwingController swingController,
  125. final SwingWindowFactory windowFactory,
  126. final LifecycleController lifecycleController,
  127. @GlobalConfig final AggregateConfigProvider globalConfig,
  128. final Provider<QuitWorker> quitWorker,
  129. final URLBuilder urlBuilder,
  130. final WindowManager windowManager) {
  131. return UIUtilities.invokeAndWait(new Callable<MainFrame>() {
  132. /** {@inheritDoc} */
  133. @Override
  134. public MainFrame call() {
  135. return new MainFrame(
  136. swingController,
  137. windowFactory,
  138. lifecycleController,
  139. globalConfig,
  140. quitWorker,
  141. new IconManager(globalConfig, urlBuilder),
  142. windowManager);
  143. }
  144. });
  145. }
  146. /**
  147. * Provides an URL handler for use in the swing UI.
  148. *
  149. * @param swingController The controller that will own the handler.
  150. * @param globalConfig The global configuration to read settings from.
  151. * @param serverManager The server manager to use to connect to servers.
  152. * @param statusBarManager The status bar manager to add messages to.
  153. *
  154. * @return The URL handler to use.
  155. */
  156. @Provides
  157. @Singleton
  158. public URLHandler getURLHandler(
  159. final SwingController swingController,
  160. @GlobalConfig final AggregateConfigProvider globalConfig,
  161. final ServerManager serverManager,
  162. final StatusBarManager statusBarManager) {
  163. return new URLHandler(swingController, globalConfig, serverManager, statusBarManager);
  164. }
  165. @Provides
  166. public PreferencesDialogModel getPrefsDialogModel(
  167. final PluginPanel pluginPanel,
  168. final ThemePanel themePanel,
  169. final UpdateConfigPanel updatePanel,
  170. final URLConfigPanel urlPanel,
  171. @GlobalConfig final AggregateConfigProvider configManager,
  172. @UserConfig final ConfigProvider identity,
  173. final ActionManager actionManager,
  174. final PluginManager pluginManager) {
  175. return new PreferencesDialogModel(pluginPanel, themePanel, updatePanel, urlPanel,
  176. configManager, identity, actionManager, pluginManager);
  177. }
  178. }