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.

ChannelFactory.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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;
  18. import com.dmdirc.commandparser.CommandType;
  19. import com.dmdirc.commandparser.parsers.ChannelCommandParser;
  20. import com.dmdirc.events.ChannelOpenedEvent;
  21. import com.dmdirc.interfaces.CommandController;
  22. import com.dmdirc.interfaces.Connection;
  23. import com.dmdirc.events.eventbus.EventBus;
  24. import com.dmdirc.config.provider.ConfigProviderMigrator;
  25. import com.dmdirc.parser.interfaces.ChannelInfo;
  26. import com.dmdirc.ui.WindowManager;
  27. import com.dmdirc.ui.input.TabCompleterFactory;
  28. import com.dmdirc.ui.messages.BackBufferFactory;
  29. import javax.inject.Inject;
  30. import javax.inject.Singleton;
  31. /**
  32. * Factory for {@link Channel}s.
  33. */
  34. @Singleton
  35. public class ChannelFactory {
  36. private final TabCompleterFactory tabCompleterFactory;
  37. private final CommandController commandController;
  38. private final EventBus eventBus;
  39. private final BackBufferFactory backBufferFactory;
  40. private final GroupChatUserManager groupChatUserManager;
  41. private final WindowManager windowManager;
  42. @Inject
  43. public ChannelFactory(final TabCompleterFactory tabCompleterFactory,
  44. final CommandController commandController,
  45. final EventBus eventBus, final BackBufferFactory backBufferFactory,
  46. final GroupChatUserManager groupChatUserManager, final WindowManager windowManager) {
  47. this.tabCompleterFactory = tabCompleterFactory;
  48. this.commandController = commandController;
  49. this.eventBus = eventBus;
  50. this.backBufferFactory = backBufferFactory;
  51. this.groupChatUserManager = groupChatUserManager;
  52. this.windowManager = windowManager;
  53. }
  54. public Channel getChannel(final Connection connection,
  55. final ChannelInfo channelInfo,
  56. final ConfigProviderMigrator configMigrator) {
  57. final Channel channel = new Channel(connection, channelInfo, configMigrator,
  58. backBufferFactory, groupChatUserManager);
  59. channel.setInputModel(new DefaultInputModel(
  60. channel::sendLine,
  61. new ChannelCommandParser(
  62. connection.getWindowModel(),
  63. commandController,
  64. eventBus,
  65. channel),
  66. tabCompleterFactory.getTabCompleter(
  67. connection.getWindowModel().getInputModel().get().getTabCompleter(),
  68. configMigrator.getConfigProvider(),
  69. CommandType.TYPE_CHANNEL,
  70. CommandType.TYPE_CHAT),
  71. channel::getMaxLineLength));
  72. windowManager.addWindow(connection.getWindowModel(), channel);
  73. connection.getWindowModel().getEventBus().publish(new ChannelOpenedEvent(channel));
  74. channel.selfJoin();
  75. return channel;
  76. }
  77. }