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.

TopicPane.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright (c) 2006-2015 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.dialogs.channelsetting;
  23. import com.dmdirc.Topic;
  24. import com.dmdirc.addons.ui_swing.UIUtilities;
  25. import com.dmdirc.addons.ui_swing.components.IconManager;
  26. import com.dmdirc.interfaces.CommandController;
  27. import com.dmdirc.interfaces.GroupChat;
  28. import com.dmdirc.interfaces.ui.InputWindow;
  29. import com.dmdirc.plugins.ServiceManager;
  30. import com.dmdirc.ui.input.TabCompleterUtils;
  31. import com.dmdirc.ui.messages.ColourManagerFactory;
  32. import java.awt.datatransfer.Clipboard;
  33. import java.awt.event.ActionEvent;
  34. import java.awt.event.ActionListener;
  35. import java.util.Optional;
  36. import javax.swing.JPanel;
  37. import net.miginfocom.swing.MigLayout;
  38. /** Topic panel. */
  39. public class TopicPane extends JPanel implements ActionListener {
  40. /** A version number for this class. */
  41. private static final long serialVersionUID = 2;
  42. /** Parent group chat. */
  43. private final GroupChat groupChat;
  44. /** Channel window. */
  45. private final InputWindow channelWindow;
  46. /** Parent dialog. */
  47. private final ChannelSettingsDialog parent;
  48. /** Clipboard to copy and paste with. */
  49. private final Clipboard clipboard;
  50. /** Topic history panel. */
  51. private TopicHistoryPane topicHistoryPane;
  52. /** Topic display pane. */
  53. private TopicDisplayPane topicDisplayPane;
  54. /**
  55. * Creates a new instance of TopicModesPane.
  56. *
  57. * @param groupChat Parent group chat
  58. * @param iconManager Icon manager
  59. * @param commandController The controller to use to retrieve command information.
  60. * @param serviceManager Service manager
  61. * @param parent Parent dialog
  62. * @param channelWindow Channel window
  63. * @param clipboard Clipboard to copy and paste with
  64. */
  65. public TopicPane(final GroupChat groupChat, final IconManager iconManager,
  66. final CommandController commandController,
  67. final ServiceManager serviceManager, final ChannelSettingsDialog parent,
  68. final InputWindow channelWindow, final Clipboard clipboard,
  69. final ColourManagerFactory colourManagerFactory,
  70. final TabCompleterUtils tabCompleterUtils) {
  71. setOpaque(UIUtilities.getTabbedPaneOpaque());
  72. this.groupChat = groupChat;
  73. this.parent = parent;
  74. this.channelWindow = channelWindow;
  75. this.clipboard = clipboard;
  76. setVisible(false);
  77. removeAll();
  78. initTopicsPanel(iconManager, serviceManager, commandController, colourManagerFactory,
  79. tabCompleterUtils);
  80. layoutComponents();
  81. topicHistoryPane.addActionListener(this);
  82. setVisible(true);
  83. }
  84. private void initTopicsPanel(
  85. final IconManager iconManager,
  86. final ServiceManager serviceManager,
  87. final CommandController commandController,
  88. final ColourManagerFactory colourManagerFactory,
  89. final TabCompleterUtils tabCompleterUtils) {
  90. topicDisplayPane = new TopicDisplayPane(groupChat, iconManager, serviceManager, parent,
  91. channelWindow, clipboard, commandController, colourManagerFactory,
  92. tabCompleterUtils);
  93. topicHistoryPane = new TopicHistoryPane(groupChat);
  94. }
  95. /** Lays out the components. */
  96. private void layoutComponents() {
  97. setLayout(new MigLayout("wrap 1, fill, wmax 450"));
  98. add(topicDisplayPane, "grow, push");
  99. add(topicHistoryPane, "grow, pushy");
  100. }
  101. /** Processes the topic and changes it if necessary. */
  102. protected void setChangedTopic() {
  103. final String topic = topicDisplayPane.getTopic();
  104. if (!groupChat.getCurrentTopic().map(Topic::getTopic).orElse("").equals(topic)) {
  105. groupChat.setTopic(topic);
  106. }
  107. }
  108. /**
  109. * {@inheritDoc}.
  110. *
  111. * @param e Action event
  112. */
  113. @Override
  114. public void actionPerformed(final ActionEvent e) {
  115. if (e != null && e.getSource() == topicHistoryPane) {
  116. topicDisplayPane.setTopic(Optional.ofNullable(topicHistoryPane.getSelectedTopic()));
  117. }
  118. }
  119. }