Browse Source

De-channel the CSD topic UI.

pull/314/head
Chris Smith 9 years ago
parent
commit
08878ef418

+ 16
- 16
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicDisplayPane.java View File

@@ -22,20 +22,20 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.dialogs.channelsetting;
24 24
 
25
-import com.dmdirc.Channel;
26 25
 import com.dmdirc.DMDircMBassador;
27 26
 import com.dmdirc.Topic;
28 27
 import com.dmdirc.addons.ui_swing.UIUtilities;
29 28
 import com.dmdirc.addons.ui_swing.actions.ReplacePasteAction;
29
+import com.dmdirc.addons.ui_swing.components.IconManager;
30 30
 import com.dmdirc.addons.ui_swing.components.inputfields.SwingInputHandler;
31 31
 import com.dmdirc.addons.ui_swing.components.inputfields.TextAreaInputField;
32 32
 import com.dmdirc.addons.ui_swing.components.text.TextLabel;
33 33
 import com.dmdirc.interfaces.CommandController;
34
+import com.dmdirc.interfaces.GroupChat;
34 35
 import com.dmdirc.interfaces.GroupChatUser;
35 36
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
36 37
 import com.dmdirc.interfaces.ui.InputWindow;
37 38
 import com.dmdirc.plugins.ServiceManager;
38
-import com.dmdirc.addons.ui_swing.components.IconManager;
39 39
 import com.dmdirc.ui.input.TabCompleterUtils;
40 40
 import com.dmdirc.ui.messages.ColourManagerFactory;
41 41
 
@@ -55,7 +55,7 @@ import javax.swing.event.DocumentListener;
55 55
 import net.miginfocom.swing.MigLayout;
56 56
 
57 57
 /**
58
- * Class to display a topic to an end user as part of the channel settings dialog.
58
+ * Class to display a topic to an end user as part of the groupChat settings dialog.
59 59
  */
60 60
 public class TopicDisplayPane extends JPanel implements DocumentListener {
61 61
 
@@ -63,8 +63,8 @@ public class TopicDisplayPane extends JPanel implements DocumentListener {
63 63
     private static final long serialVersionUID = 1;
64 64
     /** Parent topic pane. */
65 65
     private final ChannelSettingsDialog parent;
66
-    /** Associated channel. */
67
-    private final Channel channel;
66
+    /** Associated group chat. */
67
+    private final GroupChat groupChat;
68 68
     /** Channel window. */
69 69
     private final InputWindow channelWindow;
70 70
     /** the maximum length allowed for a topic. */
@@ -84,34 +84,34 @@ public class TopicDisplayPane extends JPanel implements DocumentListener {
84 84
      * Creates a new topic display panel. This panel shows an editable version of the current topic
85 85
      * along with relating meta data and validates the length of the new input.
86 86
      *
87
-     * @param channel           Associated channel
87
+     * @param groupChat         Associated group chat
88 88
      * @param iconManager       Icon manager
89 89
      * @param serviceManager    Service manager
90
-     * @param parent            Parent channel settings dialog
90
+     * @param parent            Parent settings dialog
91 91
      * @param channelWindow     Channel window
92 92
      * @param clipboard         Clipboard to copy and paste
93 93
      * @param commandController The controller to use to retrieve command information.
94 94
      * @param eventBus          The event bus to post errors to.
95 95
      */
96
-    public TopicDisplayPane(final Channel channel, final IconManager iconManager,
96
+    public TopicDisplayPane(final GroupChat groupChat, final IconManager iconManager,
97 97
             final ServiceManager serviceManager, final ChannelSettingsDialog parent,
98 98
             final InputWindow channelWindow, final Clipboard clipboard,
99 99
             final CommandController commandController, final DMDircMBassador eventBus,
100 100
             final ColourManagerFactory colourManagerFactory,
101 101
             final TabCompleterUtils tabCompleterUtils) {
102 102
         this.clipboard = clipboard;
103
-        this.channel = channel;
103
+        this.groupChat = groupChat;
104 104
         this.parent = parent;
105
-        topicLengthMax = channel.getConnection().get().getParser().get().getMaxTopicLength();
105
+        topicLengthMax = groupChat.getConnection().get().getParser().get().getMaxTopicLength();
106 106
         this.channelWindow = channelWindow;
107 107
         this.eventBus = eventBus;
108 108
 
109
-        initComponents(iconManager, channel.getConfigManager(), serviceManager, commandController,
110
-                colourManagerFactory, tabCompleterUtils);
109
+        initComponents(iconManager, groupChat.getWindowModel().getConfigManager(), serviceManager,
110
+                commandController, colourManagerFactory, tabCompleterUtils);
111 111
         addListeners();
112 112
         layoutComponents();
113 113
 
114
-        setTopic(channel.getCurrentTopic());
114
+        setTopic(groupChat.getCurrentTopic());
115 115
     }
116 116
 
117 117
     private void initComponents(
@@ -131,10 +131,10 @@ public class TopicDisplayPane extends JPanel implements DocumentListener {
131 131
         topicText.setRows(5);
132 132
         topicText.setColumns(30);
133 133
         final SwingInputHandler handler = new SwingInputHandler(serviceManager, topicText,
134
-                commandController, channel.getCommandParser(), channelWindow.getContainer(),
135
-                tabCompleterUtils, channel.getEventBus());
134
+                commandController, groupChat.getWindowModel().getCommandParser(),
135
+                channelWindow.getContainer(), tabCompleterUtils, groupChat.getEventBus());
136 136
         handler.setTypes(true, false, true, false);
137
-        handler.setTabCompleter(channel.getTabCompleter());
137
+        handler.setTabCompleter(groupChat.getWindowModel().getTabCompleter());
138 138
 
139 139
         topicText.getActionMap().put("paste-from-clipboard",
140 140
                 new ReplacePasteAction(eventBus, clipboard, "(\r\n|\n|\r)", " "));

+ 7
- 6
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicHistoryPane.java View File

@@ -22,9 +22,9 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.dialogs.channelsetting;
24 24
 
25
-import com.dmdirc.Channel;
26 25
 import com.dmdirc.Topic;
27 26
 import com.dmdirc.addons.ui_swing.UIUtilities;
27
+import com.dmdirc.interfaces.GroupChat;
28 28
 import com.dmdirc.util.collections.ListenerList;
29 29
 
30 30
 import java.awt.event.ActionEvent;
@@ -61,20 +61,21 @@ public class TopicHistoryPane extends JPanel implements ListSelectionListener {
61 61
     /**
62 62
      * Instantiates a new topic history pane.
63 63
      *
64
-     * @param channel Parent channel
64
+     * @param groupChat Parent group chat
65 65
      */
66
-    public TopicHistoryPane(final Channel channel) {
66
+    public TopicHistoryPane(final GroupChat groupChat) {
67 67
 
68 68
         topicHistory.getSelectionModel().addListSelectionListener(this);
69 69
         topicHistory.getSelectionModel().setSelectionMode(
70 70
                 ListSelectionModel.SINGLE_SELECTION);
71
-        final List<Topic> topics = channel.getTopics();
71
+        final List<Topic> topics = groupChat.getTopics();
72 72
         Collections.reverse(topics);
73 73
         scrollPane.getVerticalScrollBar().setUnitIncrement(15);
74 74
 
75 75
         for (Topic topic : topics) {
76
-            topicHistory.getModel().addRow(new Object[]{new TopicLabel(channel,
77
-                topic),});
76
+            topicHistory.getModel().addRow(new Object[]{
77
+                    new TopicLabel(groupChat, topic),
78
+            });
78 79
         }
79 80
         topicHistory.getSelectionModel().setSelectionInterval(0, 0);
80 81
         topicHistory.setShowGrid(false);

+ 11
- 8
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicLabel.java View File

@@ -22,10 +22,10 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.dialogs.channelsetting;
24 24
 
25
-import com.dmdirc.Channel;
26 25
 import com.dmdirc.Topic;
27 26
 import com.dmdirc.addons.ui_swing.components.text.TextLabel;
28 27
 import com.dmdirc.addons.ui_swing.textpane.StyledDocumentMaker;
28
+import com.dmdirc.interfaces.GroupChat;
29 29
 import com.dmdirc.interfaces.GroupChatUser;
30 30
 
31 31
 import java.awt.Color;
@@ -53,8 +53,8 @@ public class TopicLabel extends JPanel {
53 53
     private static final int MILLIS_IN_SECOND = 1000;
54 54
     /** Topic this label represents. */
55 55
     private final Topic topic;
56
-    /** The channel to which this label belongs. */
57
-    private final Channel channel;
56
+    /** The group chat to which this label belongs. */
57
+    private final GroupChat groupChat;
58 58
     /** Topic field. */
59 59
     private JEditorPane pane;
60 60
     /** Empty Attrib set. */
@@ -63,19 +63,18 @@ public class TopicLabel extends JPanel {
63 63
     /**
64 64
      * Instantiates a new topic label based on the specified topic.
65 65
      *
66
-     * @param channel The channel to which this label belongs
66
+     * @param groupChat The group chat to which this label belongs
67 67
      * @param topic   Specified topic
68 68
      *
69 69
      * @since 0.6.3
70 70
      */
71
-    public TopicLabel(final Channel channel, final Topic topic) {
72
-
71
+    public TopicLabel(final GroupChat groupChat, final Topic topic) {
73 72
         if (topic == null) {
74 73
             throw new IllegalArgumentException();
75 74
         }
76 75
 
77 76
         this.topic = topic;
78
-        this.channel = channel;
77
+        this.groupChat = groupChat;
79 78
 
80 79
         super.setBackground(UIManager.getColor("Table.background"));
81 80
         super.setForeground(UIManager.getColor("Table.foreground"));
@@ -123,7 +122,7 @@ public class TopicLabel extends JPanel {
123 122
         setLayout(new MigLayout("fill, ins 0, debug", "[]0[]", "[]0[]"));
124 123
 
125 124
         if (!topic.getTopic().isEmpty()) {
126
-            channel.getBackBuffer().getStyliser().addStyledString(
125
+            groupChat.getWindowModel().getBackBuffer().getStyliser().addStyledString(
127 126
                     new StyledDocumentMaker((StyledDocument) pane.getDocument(), as),
128 127
                     topic.getTopic());
129 128
             add(pane, "wmax 450, grow, push, wrap, gapleft 5, gapleft 5");
@@ -159,6 +158,8 @@ public class TopicLabel extends JPanel {
159 158
     @Override
160 159
     public void setBackground(final Color bg) {
161 160
         super.setBackground(bg);
161
+        // This method can be called from the super class constructor, so topic may not have been
162
+        // instansiated.
162 163
         if (topic != null
163 164
                 && ((getBackground() != null && !getBackground().equals(bg))
164 165
                 || (bg != null && !bg.equals(getBackground())))) {
@@ -169,6 +170,8 @@ public class TopicLabel extends JPanel {
169 170
     @Override
170 171
     public void setForeground(final Color fg) {
171 172
         super.setForeground(fg);
173
+        // This method can be called from the super class constructor, so topic may not have been
174
+        // instansiated.
172 175
         if (topic != null
173 176
                 && ((getForeground() != null && !getForeground().equals(fg))
174 177
                 || (fg != null && !fg.equals(getForeground())))) {

+ 12
- 11
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicPane.java View File

@@ -22,13 +22,14 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.dialogs.channelsetting;
24 24
 
25
-import com.dmdirc.Channel;
26 25
 import com.dmdirc.DMDircMBassador;
26
+import com.dmdirc.Topic;
27 27
 import com.dmdirc.addons.ui_swing.UIUtilities;
28
+import com.dmdirc.addons.ui_swing.components.IconManager;
28 29
 import com.dmdirc.interfaces.CommandController;
30
+import com.dmdirc.interfaces.GroupChat;
29 31
 import com.dmdirc.interfaces.ui.InputWindow;
30 32
 import com.dmdirc.plugins.ServiceManager;
31
-import com.dmdirc.addons.ui_swing.components.IconManager;
32 33
 import com.dmdirc.ui.input.TabCompleterUtils;
33 34
 import com.dmdirc.ui.messages.ColourManagerFactory;
34 35
 
@@ -46,8 +47,8 @@ public class TopicPane extends JPanel implements ActionListener {
46 47
 
47 48
     /** A version number for this class. */
48 49
     private static final long serialVersionUID = 2;
49
-    /** Parent channel. */
50
-    private final Channel channel;
50
+    /** Parent group chat. */
51
+    private final GroupChat groupChat;
51 52
     /** Channel window. */
52 53
     private final InputWindow channelWindow;
53 54
     /** Parent dialog. */
@@ -62,7 +63,7 @@ public class TopicPane extends JPanel implements ActionListener {
62 63
     /**
63 64
      * Creates a new instance of TopicModesPane.
64 65
      *
65
-     * @param channel           Parent channel
66
+     * @param groupChat         Parent group chat
66 67
      * @param iconManager       Icon manager
67 68
      * @param commandController The controller to use to retrieve command information.
68 69
      * @param serviceManager    Service manager
@@ -71,7 +72,7 @@ public class TopicPane extends JPanel implements ActionListener {
71 72
      * @param clipboard         Clipboard to copy and paste with
72 73
      * @param eventBus          The event bus to post errors to
73 74
      */
74
-    public TopicPane(final Channel channel, final IconManager iconManager,
75
+    public TopicPane(final GroupChat groupChat, final IconManager iconManager,
75 76
             final CommandController commandController,
76 77
             final ServiceManager serviceManager, final ChannelSettingsDialog parent,
77 78
             final InputWindow channelWindow, final Clipboard clipboard,
@@ -79,7 +80,7 @@ public class TopicPane extends JPanel implements ActionListener {
79 80
             final ColourManagerFactory colourManagerFactory,
80 81
             final TabCompleterUtils tabCompleterUtils) {
81 82
         setOpaque(UIUtilities.getTabbedPaneOpaque());
82
-        this.channel = channel;
83
+        this.groupChat = groupChat;
83 84
         this.parent = parent;
84 85
         this.channelWindow = channelWindow;
85 86
         this.clipboard = clipboard;
@@ -103,10 +104,10 @@ public class TopicPane extends JPanel implements ActionListener {
103 104
             final DMDircMBassador eventBus,
104 105
             final ColourManagerFactory colourManagerFactory,
105 106
             final TabCompleterUtils tabCompleterUtils) {
106
-        topicDisplayPane = new TopicDisplayPane(channel, iconManager, serviceManager, parent,
107
+        topicDisplayPane = new TopicDisplayPane(groupChat, iconManager, serviceManager, parent,
107 108
                 channelWindow, clipboard, commandController, eventBus, colourManagerFactory,
108 109
                 tabCompleterUtils);
109
-        topicHistoryPane = new TopicHistoryPane(channel);
110
+        topicHistoryPane = new TopicHistoryPane(groupChat);
110 111
     }
111 112
 
112 113
     /** Lays out the components. */
@@ -120,8 +121,8 @@ public class TopicPane extends JPanel implements ActionListener {
120 121
     /** Processes the topic and changes it if necessary. */
121 122
     protected void setChangedTopic() {
122 123
         final String topic = topicDisplayPane.getTopic();
123
-        if (!channel.getChannelInfo().getTopic().equals(topic)) {
124
-            channel.setTopic(topic);
124
+        if (!groupChat.getCurrentTopic().map(Topic::getTopic).orElse("").equals(topic)) {
125
+            groupChat.setTopic(topic);
125 126
         }
126 127
     }
127 128
 

Loading…
Cancel
Save