瀏覽代碼

Split focus listener into its own class.

pull/155/head
Greg Holmes 9 年之前
父節點
當前提交
845307fdc8

+ 52
- 0
ui_swing/src/com/dmdirc/addons/ui_swing/EventTriggeringFocusListener.java 查看文件

@@ -0,0 +1,52 @@
1
+/*
2
+ * Copyright (c) 2006-2014 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
+
23
+package com.dmdirc.addons.ui_swing;
24
+
25
+import com.dmdirc.DMDircMBassador;
26
+import com.dmdirc.events.ClientFocusGainedEvent;
27
+import com.dmdirc.events.ClientFocusLostEvent;
28
+
29
+import java.awt.event.WindowEvent;
30
+import java.awt.event.WindowFocusListener;
31
+
32
+/**
33
+* Focus listener that triggers focus events on an event bus.
34
+*/
35
+class EventTriggeringFocusListener implements WindowFocusListener {
36
+
37
+    private final DMDircMBassador eventBus;
38
+
39
+    public EventTriggeringFocusListener(final DMDircMBassador eventBus) {
40
+        this.eventBus = eventBus;
41
+    }
42
+
43
+    @Override
44
+    public void windowGainedFocus(final WindowEvent e) {
45
+        eventBus.publishAsync(new ClientFocusGainedEvent());
46
+    }
47
+
48
+    @Override
49
+    public void windowLostFocus(final WindowEvent e) {
50
+        eventBus.publishAsync(new ClientFocusLostEvent());
51
+    }
52
+}

+ 1
- 15
ui_swing/src/com/dmdirc/addons/ui_swing/MainFrame.java 查看文件

@@ -36,8 +36,6 @@ import com.dmdirc.addons.ui_swing.events.SwingWindowSelectedEvent;
36 36
 import com.dmdirc.addons.ui_swing.framemanager.FrameManager;
37 37
 import com.dmdirc.addons.ui_swing.framemanager.FramemanagerPosition;
38 38
 import com.dmdirc.addons.ui_swing.framemanager.ctrltab.CtrlTabWindowManager;
39
-import com.dmdirc.events.ClientFocusGainedEvent;
40
-import com.dmdirc.events.ClientFocusLostEvent;
41 39
 import com.dmdirc.events.ClientMinimisedEvent;
42 40
 import com.dmdirc.events.ClientUnminimisedEvent;
43 41
 import com.dmdirc.events.FrameTitleChangedEvent;
@@ -53,7 +51,6 @@ import com.dmdirc.util.collections.QueuedLinkedHashSet;
53 51
 import java.awt.Dialog;
54 52
 import java.awt.Dimension;
55 53
 import java.awt.event.WindowEvent;
56
-import java.awt.event.WindowFocusListener;
57 54
 import java.awt.event.WindowListener;
58 55
 import java.util.Optional;
59 56
 
@@ -177,18 +174,7 @@ public class MainFrame extends JFrame implements WindowListener, ConfigChangeLis
177 174
             globalConfig.addChangeListener("ui", "framemanagerPosition", this);
178 175
             globalConfig.addChangeListener("icon", "icon", this);
179 176
 
180
-            addWindowFocusListener(new WindowFocusListener() {
181
-
182
-                @Override
183
-                public void windowGainedFocus(final WindowEvent e) {
184
-                    eventBus.publishAsync(new ClientFocusGainedEvent());
185
-                }
186
-
187
-                @Override
188
-                public void windowLostFocus(final WindowEvent e) {
189
-                    eventBus.publishAsync(new ClientFocusLostEvent());
190
-                }
191
-            });
177
+            addWindowFocusListener(new EventTriggeringFocusListener(eventBus));
192 178
 
193 179
             setTitle(getTitlePrefix());
194 180
             initDone = true;

Loading…
取消
儲存