Browse Source

Remove some deprecated methods usages

Change-Id: I0a9ffdb11dfcf13e88c2bce63ca8d68b4d9feed9
Reviewed-on: http://gerrit.dmdirc.com/3290
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
changes/90/3290/2
Greg Holmes 10 years ago
parent
commit
49c86f48a6

+ 30
- 65
src/com/dmdirc/addons/ui_swing/components/TopicBar.java View File

@@ -37,11 +37,10 @@ import com.dmdirc.addons.ui_swing.components.text.WrapEditorKit;
37 37
 import com.dmdirc.interfaces.TopicChangeListener;
38 38
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
39 39
 import com.dmdirc.interfaces.config.ConfigChangeListener;
40
-import com.dmdirc.parser.common.ChannelJoinRequest;
40
+import com.dmdirc.interfaces.ui.Window;
41 41
 import com.dmdirc.plugins.PluginDomain;
42 42
 import com.dmdirc.plugins.PluginManager;
43 43
 import com.dmdirc.ui.IconManager;
44
-import com.dmdirc.ui.core.util.URLHandler;
45 44
 import com.dmdirc.ui.messages.ColourManager;
46 45
 import com.dmdirc.ui.messages.Styliser;
47 46
 import com.dmdirc.util.annotations.factory.Factory;
@@ -62,8 +61,6 @@ import javax.swing.KeyStroke;
62 61
 import javax.swing.SwingUtilities;
63 62
 import javax.swing.event.DocumentEvent;
64 63
 import javax.swing.event.DocumentListener;
65
-import javax.swing.event.HyperlinkEvent;
66
-import javax.swing.event.HyperlinkListener;
67 64
 import javax.swing.text.DefaultStyledDocument;
68 65
 import javax.swing.text.SimpleAttributeSet;
69 66
 import javax.swing.text.StyleConstants;
@@ -75,9 +72,8 @@ import net.miginfocom.swing.MigLayout;
75 72
  * Component to show and edit topics for a channel.
76 73
  */
77 74
 @Factory(inject = true, singleton = true)
78
-public class TopicBar extends JComponent implements ActionListener,
79
-        ConfigChangeListener, HyperlinkListener, MouseListener,
80
-        DocumentListener, TopicChangeListener {
75
+public class TopicBar extends JComponent implements ActionListener, ConfigChangeListener,
76
+        MouseListener, DocumentListener, TopicChangeListener {
81 77
 
82 78
     /** Serial version UID. */
83 79
     private static final long serialVersionUID = 1;
@@ -91,10 +87,8 @@ public class TopicBar extends JComponent implements ActionListener,
91 87
     private final SwingWindowFactory windowFactory;
92 88
     /** Manager to use to resolve colours. */
93 89
     private final ColourManager colourManager;
94
-    /** The URL handler to use to launch URLs. */
95
-    private final URLHandler urlHandler;
96
-    /** The controller to use to manage window focus. */
97
-    private final SwingController swingController;
90
+    /** The window this topic bar is for. */
91
+    private final Window window;
98 92
     /** Associated channel. */
99 93
     private final Channel channel;
100 94
     /** the maximum length allowed for a topic. */
@@ -128,6 +122,7 @@ public class TopicBar extends JComponent implements ActionListener,
128 122
      * @param urlHandler      The URL handler to use to open URLs.
129 123
      * @param swingController The controller to use to manage window focus.
130 124
      * @param channel         The channel that this topic bar is for.
125
+     * @param window          The window this topic bar is for.
131 126
      * @param iconManager     The icon manager to use for this bar's icons.
132 127
      */
133 128
     public TopicBar(
@@ -137,23 +132,19 @@ public class TopicBar extends JComponent implements ActionListener,
137 132
             final ColourManager colourManager,
138 133
             final PluginManager pluginManager,
139 134
             final SwingWindowFactory windowFactory,
140
-            final URLHandler urlHandler,
141
-            final SwingController swingController,
142 135
             @Unbound final Channel channel,
136
+            @Unbound final Window window,
143 137
             @Unbound final IconManager iconManager) {
144
-        super();
145
-
146 138
         this.channel = channel;
147 139
         this.domain = domain;
148 140
         this.windowFactory = windowFactory;
149
-        this.urlHandler = urlHandler;
150 141
         this.colourManager = colourManager;
151
-        this.swingController = swingController;
142
+        this.window = window;
152 143
         topicText = new TextPaneInputField(parentWindow, globalConfig, colourManager, iconManager);
153 144
         topicLengthMax = channel.getMaxTopicLength();
154 145
         updateOptions();
155 146
         errorIcon = new JLabel(iconManager.getIcon("input-error"));
156
-        topicText.setEditorKit(new WrapEditorKit(showFull));
147
+        topicText.setEditorKit(new WrapEditorKit(showFull, channel.getEventBus(), window));
157 148
         ((DefaultStyledDocument) topicText.getDocument()).setDocumentFilter(
158 149
                 new NewlinesDocumentFilter());
159 150
 
@@ -189,34 +180,26 @@ public class TopicBar extends JComponent implements ActionListener,
189 180
         topicText.addActionListener(this);
190 181
         topicEdit.addActionListener(this);
191 182
         topicCancel.addActionListener(this);
192
-        topicText.getInputMap().put(KeyStroke.getKeyStroke("ENTER"),
193
-                "enterButton");
194
-        topicText.getActionMap().put("enterButton", new AbstractAction(
195
-                "enterButton") {
196
-                    /**
197
-                     * A version number for this class. It should be changed whenever the class
198
-                     * structure is changed (or anything else that would prevent serialized objects
199
-                     * being unserialized with the new class).
200
-                     */
201
-                    private static final long serialVersionUID = 1;
202
-
203
-                    @Override
204
-                    public void actionPerformed(final ActionEvent e) {
205
-                        commitTopicEdit();
206
-                    }
207
-                });
208
-        topicText.getInputMap().put(KeyStroke.getKeyStroke("ESCAPE"),
209
-                "escapeButton");
210
-        topicText.getActionMap().put("escapeButton", new AbstractAction(
211
-                "escapeButton") {
212
-                    private static final long serialVersionUID = 1;
213
-
214
-                    @Override
215
-                    public void actionPerformed(final ActionEvent e) {
216
-                        cancelTopicEdit();
217
-                    }
218
-                });
219
-        topicText.addHyperlinkListener(this);
183
+        topicText.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "enterButton");
184
+        topicText.getActionMap().put("enterButton", new AbstractAction("enterButton") {
185
+            /** A version number for this class. */
186
+            private static final long serialVersionUID = 1;
187
+
188
+            @Override
189
+            public void actionPerformed(final ActionEvent e) {
190
+                commitTopicEdit();
191
+            }
192
+        });
193
+        topicText.getInputMap().put(KeyStroke.getKeyStroke("ESCAPE"), "escapeButton");
194
+        topicText.getActionMap().put("escapeButton", new AbstractAction("escapeButton") {
195
+            /** A version number for this class. */
196
+            private static final long serialVersionUID = 1;
197
+
198
+            @Override
199
+            public void actionPerformed(final ActionEvent e) {
200
+                cancelTopicEdit();
201
+            }
202
+        });
220 203
         topicText.addMouseListener(this);
221 204
         topicText.getDocument().addDocumentListener(this);
222 205
 
@@ -351,24 +334,6 @@ public class TopicBar extends JComponent implements ActionListener,
351 334
         topicChanged(channel, null);
352 335
     }
353 336
 
354
-    @Override
355
-    public void hyperlinkUpdate(final HyperlinkEvent e) {
356
-        if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
357
-            final String url = e.getDescription();
358
-            if (url == null) {
359
-                return;
360
-            }
361
-            if (url.charAt(0) == '#') {
362
-                channel.getConnection().join(new ChannelJoinRequest(url));
363
-            } else if (url.contains("://")) {
364
-                urlHandler.launchApp(e.getDescription());
365
-            } else {
366
-                swingController.requestWindowFocus(
367
-                        windowFactory.getSwingWindow(channel.getConnection().getQuery(url)));
368
-            }
369
-        }
370
-    }
371
-
372 337
     /**
373 338
      * Load and set colours.
374 339
      */
@@ -496,7 +461,7 @@ public class TopicBar extends JComponent implements ActionListener,
496 461
         setVisible(showBar);
497 462
         cancelTopicEdit();
498 463
         if ("showfulltopic".equals(key)) {
499
-            topicText.setEditorKit(new WrapEditorKit(showFull));
464
+            topicText.setEditorKit(new WrapEditorKit(showFull, channel.getEventBus(), window));
500 465
             ((DefaultStyledDocument) topicText.getDocument()).setDocumentFilter(
501 466
                     new NewlinesDocumentFilter());
502 467
             topicChanged(channel, null);

+ 20
- 17
src/com/dmdirc/addons/ui_swing/components/frames/ChannelFrame.java View File

@@ -32,11 +32,14 @@ import com.dmdirc.addons.ui_swing.components.SplitPane;
32 32
 import com.dmdirc.addons.ui_swing.components.TopicBar;
33 33
 import com.dmdirc.addons.ui_swing.components.TopicBarFactory;
34 34
 import com.dmdirc.addons.ui_swing.components.inputfields.SwingInputField;
35
+import com.dmdirc.addons.ui_swing.dialogs.channelsetting.ChannelSettingsDialog;
36
+import com.dmdirc.addons.ui_swing.injection.KeyedDialogProvider;
35 37
 import com.dmdirc.commandparser.PopupType;
36 38
 import com.dmdirc.events.ClientClosingEvent;
37 39
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
38 40
 import com.dmdirc.interfaces.config.ConfigProvider;
39 41
 import com.dmdirc.interfaces.config.IdentityFactory;
42
+import com.dmdirc.plugins.PluginDomain;
40 43
 import com.dmdirc.util.annotations.factory.Factory;
41 44
 import com.dmdirc.util.annotations.factory.Unbound;
42 45
 
@@ -60,11 +63,7 @@ import net.miginfocom.swing.MigLayout;
60 63
 @Factory(inject = true, singleton = true, providers = true)
61 64
 public final class ChannelFrame extends InputTextFrame implements ActionListener {
62 65
 
63
-    /**
64
-     * A version number for this class. It should be changed whenever the class structure is changed
65
-     * (or anything else that would prevent serialized objects being unserialized with the new
66
-     * class).
67
-     */
66
+    /** A version number for this class. */
68 67
     private static final long serialVersionUID = 10;
69 68
     /** Identity. */
70 69
     private final ConfigProvider identity;
@@ -76,12 +75,14 @@ public final class ChannelFrame extends InputTextFrame implements ActionListener
76 75
     private NickList nicklist;
77 76
     /** Topic bar. */
78 77
     private TopicBar topicBar;
79
-    /** UI controller. */
80
-    private final SwingController controller;
81 78
     /** Event bus to despatch events on. */
82 79
     private final EventBus eventBus;
83 80
     /** Config to read settings from. */
84 81
     private final AggregateConfigProvider globalConfig;
82
+    /** The domain to read settings from. */
83
+    private final String domain;
84
+    /** Channel settings dialog provider. */
85
+    private final KeyedDialogProvider<Channel, ChannelSettingsDialog> dialogProvider;
85 86
 
86 87
     /**
87 88
      * Creates a new instance of ChannelFrame. Sets up callbacks and handlers, and default options
@@ -92,23 +93,28 @@ public final class ChannelFrame extends InputTextFrame implements ActionListener
92 93
      * @param identityFactory    The factory to use to create a channel identity.
93 94
      * @param topicBarFactory    The factory to use to create topic bars.
94 95
      * @param owner              The Channel object that owns this frame
96
+     * @param domain             The domain to read settings from
97
+     * @param dialogProvider     The dialog provider to get the channel settings dialog from.
95 98
      */
96 99
     public ChannelFrame(
100
+            @SuppressWarnings("qualifiers") @PluginDomain(SwingController.class) final String domain,
97 101
             final TextFrameDependencies deps,
98 102
             final Provider<SwingInputField> inputFieldProvider,
99 103
             final IdentityFactory identityFactory,
104
+            final KeyedDialogProvider<Channel, ChannelSettingsDialog> dialogProvider,
100 105
             final TopicBarFactory topicBarFactory,
101 106
             @Unbound final Channel owner) {
102 107
         super(deps, inputFieldProvider, owner);
103 108
 
104
-        this.controller = deps.controller;
105 109
         this.eventBus = deps.eventBus;
106 110
         this.globalConfig = deps.globalConfig;
111
+        this.domain = domain;
112
+        this.dialogProvider = dialogProvider;
107 113
 
108 114
         initComponents(topicBarFactory);
109 115
 
110 116
         globalConfig.addChangeListener("ui", "channelSplitPanePosition", this);
111
-        globalConfig.addChangeListener(controller.getDomain(), "shownicklist", this);
117
+        globalConfig.addChangeListener(domain, "shownicklist", this);
112 118
         eventBus.register(this);
113 119
 
114 120
         identity = identityFactory.createChannelConfig(owner.getConnection().getNetwork(),
@@ -139,7 +145,7 @@ public final class ChannelFrame extends InputTextFrame implements ActionListener
139 145
      * @param topicBarFactory The factory to use to produce topic bars.
140 146
      */
141 147
     private void initComponents(final TopicBarFactory topicBarFactory) {
142
-        topicBar = topicBarFactory.getTopicBar((Channel) getContainer(),
148
+        topicBar = topicBarFactory.getTopicBar((Channel) getContainer(), this,
143 149
                 getContainer().getIconManager());
144 150
 
145 151
         nicklist = new NickList(this, getContainer().getConfigManager());
@@ -156,8 +162,7 @@ public final class ChannelFrame extends InputTextFrame implements ActionListener
156 162
         add(inputPanel, "growx");
157 163
 
158 164
         splitPane.setLeftComponent(getTextPane());
159
-        if (getContainer().getConfigManager().getOptionBool(
160
-                controller.getDomain(), "shownicklist")) {
165
+        if (getContainer().getConfigManager().getOptionBool(domain, "shownicklist")) {
161 166
             splitPane.setRightComponent(nicklist);
162 167
         } else {
163 168
             splitPane.setRightComponent(null);
@@ -174,7 +179,7 @@ public final class ChannelFrame extends InputTextFrame implements ActionListener
174 179
     @Override
175 180
     public void actionPerformed(final ActionEvent actionEvent) {
176 181
         if (actionEvent.getSource() == settingsMI) {
177
-            controller.showChannelSettingsDialog((Channel) getContainer());
182
+            dialogProvider.displayOrRequestFocus((Channel) getContainer());
178 183
         }
179 184
     }
180 185
 
@@ -206,8 +211,7 @@ public final class ChannelFrame extends InputTextFrame implements ActionListener
206 211
             });
207 212
         }
208 213
         if ("shownicklist".equals(key)) {
209
-            if (getContainer().getConfigManager()
210
-                    .getOptionBool(controller.getDomain(), "shownicklist")) {
214
+            if (getContainer().getConfigManager().getOptionBool(domain, "shownicklist")) {
211 215
                 splitPane.setRightComponent(nicklist);
212 216
             } else {
213 217
                 splitPane.setRightComponent(null);
@@ -227,8 +231,7 @@ public final class ChannelFrame extends InputTextFrame implements ActionListener
227 231
             public void run() {
228 232
                 if (getContainer().getConfigManager().getOptionInt("ui",
229 233
                         "channelSplitPanePosition") != nicklist.getWidth()) {
230
-                    identity.setOption("ui", "channelSplitPanePosition",
231
-                            nicklist.getWidth());
234
+                    identity.setOption("ui", "channelSplitPanePosition", nicklist.getWidth());
232 235
                 }
233 236
             }
234 237
         });

+ 22
- 24
src/com/dmdirc/addons/ui_swing/components/text/WrapEditorKit.java View File

@@ -7,8 +7,14 @@
7 7
 
8 8
 package com.dmdirc.addons.ui_swing.components.text;
9 9
 
10
+import com.dmdirc.events.LinkChannelClickedEvent;
11
+import com.dmdirc.events.LinkNicknameClickedEvent;
12
+import com.dmdirc.events.LinkUrlClickedEvent;
13
+import com.dmdirc.interfaces.ui.Window;
10 14
 import com.dmdirc.ui.messages.IRCTextAttribute;
11 15
 
16
+import com.google.common.eventbus.EventBus;
17
+
12 18
 import java.awt.Cursor;
13 19
 import java.awt.event.MouseEvent;
14 20
 import java.awt.event.MouseListener;
@@ -16,7 +22,6 @@ import java.awt.event.MouseMotionListener;
16 22
 
17 23
 import javax.swing.JEditorPane;
18 24
 import javax.swing.SwingUtilities;
19
-import javax.swing.event.HyperlinkEvent;
20 25
 import javax.swing.text.Element;
21 26
 import javax.swing.text.StyledDocument;
22 27
 import javax.swing.text.StyledEditorKit;
@@ -28,14 +33,9 @@ import javax.swing.text.ViewFactory;
28 33
  *
29 34
  * Extended for Hyperlink events
30 35
  */
31
-public class WrapEditorKit extends StyledEditorKit implements MouseListener,
32
-        MouseMotionListener {
36
+public class WrapEditorKit extends StyledEditorKit implements MouseListener, MouseMotionListener {
33 37
 
34
-    /**
35
-     * A version number for this class. It should be changed whenever the class structure is changed
36
-     * (or anything else that would prevent serialized objects being unserialized with the new
37
-     * class).
38
-     */
38
+    /** A version number for this class. */
39 39
     private static final long serialVersionUID = 1;
40 40
     /** Wrap column factory. */
41 41
     private final ViewFactory defaultFactory = new WrapColumnFactory();
@@ -45,15 +45,21 @@ public class WrapEditorKit extends StyledEditorKit implements MouseListener,
45 45
     private final boolean wrap;
46 46
     /** Associated Component. */
47 47
     private JEditorPane editorPane;
48
+    /** Event bus to fire link click events on. */
49
+    private final EventBus eventBus;
50
+    /** The window this editor kit is used in. */
51
+    private final Window window;
48 52
 
49 53
     /**
50 54
      * Initialises a new wrapping editor kit.
51 55
      *
52 56
      * @param wrapping true iif the text needs to wrap
57
+     * @param eventBus Event bus to raise hyperlink events on
58
+     * @param window   Window as source for hyperlink events
53 59
      */
54
-    public WrapEditorKit(final boolean wrapping) {
55
-        super();
56
-
60
+    public WrapEditorKit(final boolean wrapping, final EventBus eventBus, final Window window) {
61
+        this.window = window;
62
+        this.eventBus = eventBus;
57 63
         wrap = wrapping;
58 64
     }
59 65
 
@@ -118,23 +124,15 @@ public class WrapEditorKit extends StyledEditorKit implements MouseListener,
118 124
             Object target = characterElementAt(e).getAttributes().getAttribute(
119 125
                     IRCTextAttribute.HYPERLINK);
120 126
             if (target != null) {
121
-                editorPane.fireHyperlinkUpdate(new HyperlinkEvent(editorPane,
122
-                        HyperlinkEvent.EventType.ACTIVATED, null,
123
-                        (String) target));
127
+                eventBus.post(new LinkUrlClickedEvent(window, (String) target));
124 128
             }
125
-            target = characterElementAt(e).getAttributes().getAttribute(
126
-                    IRCTextAttribute.CHANNEL);
129
+            target = characterElementAt(e).getAttributes().getAttribute(IRCTextAttribute.CHANNEL);
127 130
             if (target != null) {
128
-                editorPane.fireHyperlinkUpdate(new HyperlinkEvent(editorPane,
129
-                        HyperlinkEvent.EventType.ACTIVATED, null,
130
-                        (String) target));
131
+                eventBus.post(new LinkChannelClickedEvent(window, (String) target));
131 132
             }
132
-            target = characterElementAt(e).getAttributes().getAttribute(
133
-                    IRCTextAttribute.NICKNAME);
133
+            target = characterElementAt(e).getAttributes().getAttribute(IRCTextAttribute.NICKNAME);
134 134
             if (target != null) {
135
-                editorPane.fireHyperlinkUpdate(new HyperlinkEvent(editorPane,
136
-                        HyperlinkEvent.EventType.ACTIVATED, null,
137
-                        (String) target));
135
+                eventBus.post(new LinkNicknameClickedEvent(window, (String) target));
138 136
             }
139 137
         }
140 138
     }

Loading…
Cancel
Save