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.

ChannelFrameFactory.java 4.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.components.frames;
  18. import com.dmdirc.addons.ui_swing.SwingController;
  19. import com.dmdirc.addons.ui_swing.SwingWindowFactory;
  20. import com.dmdirc.addons.ui_swing.components.TopicBarFactory;
  21. import com.dmdirc.addons.ui_swing.components.inputfields.SwingInputField;
  22. import com.dmdirc.addons.ui_swing.dialogs.channelsetting.ChannelSettingsDialog;
  23. import com.dmdirc.addons.ui_swing.injection.KeyedDialogProvider;
  24. import com.dmdirc.events.eventbus.EventBus;
  25. import com.dmdirc.interfaces.GroupChat;
  26. import com.dmdirc.interfaces.WindowModel;
  27. import com.dmdirc.interfaces.config.IdentityFactory;
  28. import com.dmdirc.plugins.PluginDomain;
  29. import com.dmdirc.ui.core.components.WindowComponent;
  30. import java.util.Arrays;
  31. import java.util.HashSet;
  32. import java.util.Set;
  33. import javax.inject.Inject;
  34. import javax.inject.Provider;
  35. import javax.inject.Singleton;
  36. import static com.dmdirc.addons.ui_swing.components.frames.TextFrame.TextFrameDependencies;
  37. /**
  38. * Factory for {@link ChannelFrame}s.
  39. */
  40. @Singleton
  41. public class ChannelFrameFactory implements SwingWindowFactory.WindowProvider {
  42. private final String domain;
  43. private final Provider<TextFrameDependencies> dependencies;
  44. private final Provider<SwingInputField> inputFieldProvider;
  45. private final IdentityFactory identityFactory;
  46. private final InputTextFramePasteActionFactory inputTextFramePasteActionFactory;
  47. private final Provider<KeyedDialogProvider<GroupChat, ChannelSettingsDialog>> dialogProvider;
  48. private final TopicBarFactory topicBarFactory;
  49. private final EventBus eventBus;
  50. @Inject
  51. public ChannelFrameFactory(
  52. final EventBus eventBus,
  53. @PluginDomain(SwingController.class) final String domain,
  54. final Provider<TextFrameDependencies> dependencies,
  55. final Provider<SwingInputField> inputFieldProvider,
  56. final InputTextFramePasteActionFactory inputTextFramePasteActionFactory,
  57. final IdentityFactory identityFactory,
  58. final Provider<KeyedDialogProvider<GroupChat, ChannelSettingsDialog>> dialogProvider,
  59. final TopicBarFactory topicBarFactory) {
  60. this.eventBus = eventBus;
  61. this.domain = domain;
  62. this.dependencies = dependencies;
  63. this.inputFieldProvider = inputFieldProvider;
  64. this.identityFactory = identityFactory;
  65. this.dialogProvider = dialogProvider;
  66. this.topicBarFactory = topicBarFactory;
  67. this.inputTextFramePasteActionFactory = inputTextFramePasteActionFactory;
  68. }
  69. @Override
  70. public TextFrame getWindow(final WindowModel container) {
  71. final ChannelFrame frame = new ChannelFrame(domain, dependencies.get(), inputFieldProvider,
  72. identityFactory, dialogProvider.get(), inputTextFramePasteActionFactory,
  73. topicBarFactory, (GroupChat) container);
  74. // TODO: Can't assume containers are GroupChats...
  75. eventBus.subscribe(frame);
  76. return frame;
  77. }
  78. @Override
  79. public Set<String> getComponents() {
  80. return new HashSet<>(Arrays.asList(
  81. WindowComponent.TEXTAREA.getIdentifier(),
  82. WindowComponent.INPUTFIELD.getIdentifier(),
  83. WindowComponent.TOPICBAR.getIdentifier(),
  84. WindowComponent.USERLIST.getIdentifier()));
  85. }
  86. }