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.

SwingLinkHandler.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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;
  18. import com.dmdirc.addons.ui_swing.events.SwingActiveWindowChangeRequestEvent;
  19. import com.dmdirc.addons.ui_swing.events.SwingEventBus;
  20. import com.dmdirc.events.LinkChannelClickedEvent;
  21. import com.dmdirc.events.LinkNicknameClickedEvent;
  22. import com.dmdirc.events.LinkUrlClickedEvent;
  23. import com.dmdirc.interfaces.Connection;
  24. import com.dmdirc.interfaces.WindowModel;
  25. import com.dmdirc.parser.common.ChannelJoinRequest;
  26. import com.dmdirc.ui.core.util.URLHandler;
  27. import java.util.Optional;
  28. import javax.inject.Inject;
  29. import javax.inject.Singleton;
  30. import net.engio.mbassy.listener.Handler;
  31. /**
  32. * Handles response to users clicking on links within the Swing UI.
  33. */
  34. @Singleton
  35. public class SwingLinkHandler {
  36. private final URLHandler urlHandler;
  37. private final SwingEventBus eventBus;
  38. private final SwingWindowFactory windowFactory;
  39. @Inject
  40. public SwingLinkHandler(
  41. final SwingEventBus eventBus,
  42. final URLHandler urlHandler,
  43. final SwingWindowFactory windowFactory) {
  44. this.urlHandler = urlHandler;
  45. this.eventBus = eventBus;
  46. this.windowFactory = windowFactory;
  47. }
  48. @Handler
  49. public void handleChannelClick(final LinkChannelClickedEvent event) {
  50. final WindowModel container = event.getWindow();
  51. container.getConnection()
  52. .map(Connection::getGroupChatManager)
  53. .ifPresent(c -> c.join(new ChannelJoinRequest(event.getTarget())));
  54. }
  55. @Handler
  56. public void handleLinkClick(final LinkUrlClickedEvent event) {
  57. urlHandler.launchApp(event.getTarget());
  58. }
  59. @Handler
  60. public void handleNicknameClick(final LinkNicknameClickedEvent event) {
  61. final WindowModel container = event.getWindow();
  62. container.getConnection().ifPresent(c ->
  63. eventBus.publishAsync(new SwingActiveWindowChangeRequestEvent(Optional.ofNullable(
  64. windowFactory.getSwingWindow(
  65. c.getQuery(event.getTarget()).getWindowModel())))));
  66. }
  67. }