From 08878ef418ed23a18756fc97c192e8dae883a72e Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 12 Jan 2015 14:09:07 +0000 Subject: [PATCH] De-channel the CSD topic UI. --- .../channelsetting/TopicDisplayPane.java | 32 +++++++++---------- .../channelsetting/TopicHistoryPane.java | 13 ++++---- .../dialogs/channelsetting/TopicLabel.java | 19 ++++++----- .../dialogs/channelsetting/TopicPane.java | 23 ++++++------- 4 files changed, 46 insertions(+), 41 deletions(-) diff --git a/ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicDisplayPane.java b/ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicDisplayPane.java index 6d9b37a05..a94a87ba6 100644 --- a/ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicDisplayPane.java +++ b/ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicDisplayPane.java @@ -22,20 +22,20 @@ package com.dmdirc.addons.ui_swing.dialogs.channelsetting; -import com.dmdirc.Channel; import com.dmdirc.DMDircMBassador; import com.dmdirc.Topic; import com.dmdirc.addons.ui_swing.UIUtilities; import com.dmdirc.addons.ui_swing.actions.ReplacePasteAction; +import com.dmdirc.addons.ui_swing.components.IconManager; import com.dmdirc.addons.ui_swing.components.inputfields.SwingInputHandler; import com.dmdirc.addons.ui_swing.components.inputfields.TextAreaInputField; import com.dmdirc.addons.ui_swing.components.text.TextLabel; import com.dmdirc.interfaces.CommandController; +import com.dmdirc.interfaces.GroupChat; import com.dmdirc.interfaces.GroupChatUser; import com.dmdirc.interfaces.config.AggregateConfigProvider; import com.dmdirc.interfaces.ui.InputWindow; import com.dmdirc.plugins.ServiceManager; -import com.dmdirc.addons.ui_swing.components.IconManager; import com.dmdirc.ui.input.TabCompleterUtils; import com.dmdirc.ui.messages.ColourManagerFactory; @@ -55,7 +55,7 @@ import net.miginfocom.swing.MigLayout; /** - * Class to display a topic to an end user as part of the channel settings dialog. + * Class to display a topic to an end user as part of the groupChat settings dialog. */ public class TopicDisplayPane extends JPanel implements DocumentListener { @@ -63,8 +63,8 @@ public class TopicDisplayPane extends JPanel implements DocumentListener { private static final long serialVersionUID = 1; /** Parent topic pane. */ private final ChannelSettingsDialog parent; - /** Associated channel. */ - private final Channel channel; + /** Associated group chat. */ + private final GroupChat groupChat; /** Channel window. */ private final InputWindow channelWindow; /** the maximum length allowed for a topic. */ @@ -84,34 +84,34 @@ public class TopicDisplayPane extends JPanel implements DocumentListener { * Creates a new topic display panel. This panel shows an editable version of the current topic * along with relating meta data and validates the length of the new input. * - * @param channel Associated channel + * @param groupChat Associated group chat * @param iconManager Icon manager * @param serviceManager Service manager - * @param parent Parent channel settings dialog + * @param parent Parent settings dialog * @param channelWindow Channel window * @param clipboard Clipboard to copy and paste * @param commandController The controller to use to retrieve command information. * @param eventBus The event bus to post errors to. */ - public TopicDisplayPane(final Channel channel, final IconManager iconManager, + public TopicDisplayPane(final GroupChat groupChat, final IconManager iconManager, final ServiceManager serviceManager, final ChannelSettingsDialog parent, final InputWindow channelWindow, final Clipboard clipboard, final CommandController commandController, final DMDircMBassador eventBus, final ColourManagerFactory colourManagerFactory, final TabCompleterUtils tabCompleterUtils) { this.clipboard = clipboard; - this.channel = channel; + this.groupChat = groupChat; this.parent = parent; - topicLengthMax = channel.getConnection().get().getParser().get().getMaxTopicLength(); + topicLengthMax = groupChat.getConnection().get().getParser().get().getMaxTopicLength(); this.channelWindow = channelWindow; this.eventBus = eventBus; - initComponents(iconManager, channel.getConfigManager(), serviceManager, commandController, - colourManagerFactory, tabCompleterUtils); + initComponents(iconManager, groupChat.getWindowModel().getConfigManager(), serviceManager, + commandController, colourManagerFactory, tabCompleterUtils); addListeners(); layoutComponents(); - setTopic(channel.getCurrentTopic()); + setTopic(groupChat.getCurrentTopic()); } private void initComponents( @@ -131,10 +131,10 @@ private void initComponents( topicText.setRows(5); topicText.setColumns(30); final SwingInputHandler handler = new SwingInputHandler(serviceManager, topicText, - commandController, channel.getCommandParser(), channelWindow.getContainer(), - tabCompleterUtils, channel.getEventBus()); + commandController, groupChat.getWindowModel().getCommandParser(), + channelWindow.getContainer(), tabCompleterUtils, groupChat.getEventBus()); handler.setTypes(true, false, true, false); - handler.setTabCompleter(channel.getTabCompleter()); + handler.setTabCompleter(groupChat.getWindowModel().getTabCompleter()); topicText.getActionMap().put("paste-from-clipboard", new ReplacePasteAction(eventBus, clipboard, "(\r\n|\n|\r)", " ")); diff --git a/ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicHistoryPane.java b/ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicHistoryPane.java index 2d40aad35..6b938ee8d 100644 --- a/ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicHistoryPane.java +++ b/ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicHistoryPane.java @@ -22,9 +22,9 @@ package com.dmdirc.addons.ui_swing.dialogs.channelsetting; -import com.dmdirc.Channel; import com.dmdirc.Topic; import com.dmdirc.addons.ui_swing.UIUtilities; +import com.dmdirc.interfaces.GroupChat; import com.dmdirc.util.collections.ListenerList; import java.awt.event.ActionEvent; @@ -61,20 +61,21 @@ public class TopicHistoryPane extends JPanel implements ListSelectionListener { /** * Instantiates a new topic history pane. * - * @param channel Parent channel + * @param groupChat Parent group chat */ - public TopicHistoryPane(final Channel channel) { + public TopicHistoryPane(final GroupChat groupChat) { topicHistory.getSelectionModel().addListSelectionListener(this); topicHistory.getSelectionModel().setSelectionMode( ListSelectionModel.SINGLE_SELECTION); - final List topics = channel.getTopics(); + final List topics = groupChat.getTopics(); Collections.reverse(topics); scrollPane.getVerticalScrollBar().setUnitIncrement(15); for (Topic topic : topics) { - topicHistory.getModel().addRow(new Object[]{new TopicLabel(channel, - topic),}); + topicHistory.getModel().addRow(new Object[]{ + new TopicLabel(groupChat, topic), + }); } topicHistory.getSelectionModel().setSelectionInterval(0, 0); topicHistory.setShowGrid(false); diff --git a/ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicLabel.java b/ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicLabel.java index a1d4bb518..d41493820 100644 --- a/ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicLabel.java +++ b/ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicLabel.java @@ -22,10 +22,10 @@ package com.dmdirc.addons.ui_swing.dialogs.channelsetting; -import com.dmdirc.Channel; import com.dmdirc.Topic; import com.dmdirc.addons.ui_swing.components.text.TextLabel; import com.dmdirc.addons.ui_swing.textpane.StyledDocumentMaker; +import com.dmdirc.interfaces.GroupChat; import com.dmdirc.interfaces.GroupChatUser; import java.awt.Color; @@ -53,8 +53,8 @@ public class TopicLabel extends JPanel { private static final int MILLIS_IN_SECOND = 1000; /** Topic this label represents. */ private final Topic topic; - /** The channel to which this label belongs. */ - private final Channel channel; + /** The group chat to which this label belongs. */ + private final GroupChat groupChat; /** Topic field. */ private JEditorPane pane; /** Empty Attrib set. */ @@ -63,19 +63,18 @@ public class TopicLabel extends JPanel { /** * Instantiates a new topic label based on the specified topic. * - * @param channel The channel to which this label belongs + * @param groupChat The group chat to which this label belongs * @param topic Specified topic * * @since 0.6.3 */ - public TopicLabel(final Channel channel, final Topic topic) { - + public TopicLabel(final GroupChat groupChat, final Topic topic) { if (topic == null) { throw new IllegalArgumentException(); } this.topic = topic; - this.channel = channel; + this.groupChat = groupChat; super.setBackground(UIManager.getColor("Table.background")); super.setForeground(UIManager.getColor("Table.foreground")); @@ -123,7 +122,7 @@ private void init() { setLayout(new MigLayout("fill, ins 0, debug", "[]0[]", "[]0[]")); if (!topic.getTopic().isEmpty()) { - channel.getBackBuffer().getStyliser().addStyledString( + groupChat.getWindowModel().getBackBuffer().getStyliser().addStyledString( new StyledDocumentMaker((StyledDocument) pane.getDocument(), as), topic.getTopic()); add(pane, "wmax 450, grow, push, wrap, gapleft 5, gapleft 5"); @@ -159,6 +158,8 @@ public Topic getTopic() { @Override public void setBackground(final Color bg) { super.setBackground(bg); + // This method can be called from the super class constructor, so topic may not have been + // instansiated. if (topic != null && ((getBackground() != null && !getBackground().equals(bg)) || (bg != null && !bg.equals(getBackground())))) { @@ -169,6 +170,8 @@ public void setBackground(final Color bg) { @Override public void setForeground(final Color fg) { super.setForeground(fg); + // This method can be called from the super class constructor, so topic may not have been + // instansiated. if (topic != null && ((getForeground() != null && !getForeground().equals(fg)) || (fg != null && !fg.equals(getForeground())))) { diff --git a/ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicPane.java b/ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicPane.java index a94f9798d..8afc4bf53 100644 --- a/ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicPane.java +++ b/ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicPane.java @@ -22,13 +22,14 @@ package com.dmdirc.addons.ui_swing.dialogs.channelsetting; -import com.dmdirc.Channel; import com.dmdirc.DMDircMBassador; +import com.dmdirc.Topic; import com.dmdirc.addons.ui_swing.UIUtilities; +import com.dmdirc.addons.ui_swing.components.IconManager; import com.dmdirc.interfaces.CommandController; +import com.dmdirc.interfaces.GroupChat; import com.dmdirc.interfaces.ui.InputWindow; import com.dmdirc.plugins.ServiceManager; -import com.dmdirc.addons.ui_swing.components.IconManager; import com.dmdirc.ui.input.TabCompleterUtils; import com.dmdirc.ui.messages.ColourManagerFactory; @@ -46,8 +47,8 @@ public class TopicPane extends JPanel implements ActionListener { /** A version number for this class. */ private static final long serialVersionUID = 2; - /** Parent channel. */ - private final Channel channel; + /** Parent group chat. */ + private final GroupChat groupChat; /** Channel window. */ private final InputWindow channelWindow; /** Parent dialog. */ @@ -62,7 +63,7 @@ public class TopicPane extends JPanel implements ActionListener { /** * Creates a new instance of TopicModesPane. * - * @param channel Parent channel + * @param groupChat Parent group chat * @param iconManager Icon manager * @param commandController The controller to use to retrieve command information. * @param serviceManager Service manager @@ -71,7 +72,7 @@ public class TopicPane extends JPanel implements ActionListener { * @param clipboard Clipboard to copy and paste with * @param eventBus The event bus to post errors to */ - public TopicPane(final Channel channel, final IconManager iconManager, + public TopicPane(final GroupChat groupChat, final IconManager iconManager, final CommandController commandController, final ServiceManager serviceManager, final ChannelSettingsDialog parent, final InputWindow channelWindow, final Clipboard clipboard, @@ -79,7 +80,7 @@ public TopicPane(final Channel channel, final IconManager iconManager, final ColourManagerFactory colourManagerFactory, final TabCompleterUtils tabCompleterUtils) { setOpaque(UIUtilities.getTabbedPaneOpaque()); - this.channel = channel; + this.groupChat = groupChat; this.parent = parent; this.channelWindow = channelWindow; this.clipboard = clipboard; @@ -103,10 +104,10 @@ private void initTopicsPanel( final DMDircMBassador eventBus, final ColourManagerFactory colourManagerFactory, final TabCompleterUtils tabCompleterUtils) { - topicDisplayPane = new TopicDisplayPane(channel, iconManager, serviceManager, parent, + topicDisplayPane = new TopicDisplayPane(groupChat, iconManager, serviceManager, parent, channelWindow, clipboard, commandController, eventBus, colourManagerFactory, tabCompleterUtils); - topicHistoryPane = new TopicHistoryPane(channel); + topicHistoryPane = new TopicHistoryPane(groupChat); } /** Lays out the components. */ @@ -120,8 +121,8 @@ private void layoutComponents() { /** Processes the topic and changes it if necessary. */ protected void setChangedTopic() { final String topic = topicDisplayPane.getTopic(); - if (!channel.getChannelInfo().getTopic().equals(topic)) { - channel.setTopic(topic); + if (!groupChat.getCurrentTopic().map(Topic::getTopic).orElse("").equals(topic)) { + groupChat.setTopic(topic); } }