Browse Source

Switch to events for selection.

pull/69/head
Greg Holmes 9 years ago
parent
commit
b503f89771

+ 21
- 12
lagdisplay/src/com/dmdirc/addons/lagdisplay/LagDisplayManager.java View File

26
 import com.dmdirc.DMDircMBassador;
26
 import com.dmdirc.DMDircMBassador;
27
 import com.dmdirc.FrameContainer;
27
 import com.dmdirc.FrameContainer;
28
 import com.dmdirc.ServerState;
28
 import com.dmdirc.ServerState;
29
-import com.dmdirc.addons.ui_swing.SelectionListener;
29
+import com.dmdirc.addons.ui_swing.EdtHandlerInvocation;
30
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
30
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
31
+import com.dmdirc.addons.ui_swing.events.SwingWindowSelectedEvent;
32
+import com.dmdirc.addons.ui_swing.injection.SwingEventBus;
31
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
33
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
32
 import com.dmdirc.events.ServerDisconnectedEvent;
34
 import com.dmdirc.events.ServerDisconnectedEvent;
33
 import com.dmdirc.events.ServerGotpingEvent;
35
 import com.dmdirc.events.ServerGotpingEvent;
52
 import javax.inject.Singleton;
54
 import javax.inject.Singleton;
53
 
55
 
54
 import net.engio.mbassy.listener.Handler;
56
 import net.engio.mbassy.listener.Handler;
57
+import net.engio.mbassy.listener.Invoke;
55
 
58
 
56
 /**
59
 /**
57
  * Manages the lifecycle of the lag display plugin.
60
  * Manages the lifecycle of the lag display plugin.
58
  */
61
  */
59
 @Singleton
62
 @Singleton
60
-public class LagDisplayManager implements ConfigChangeListener, SelectionListener {
63
+public class LagDisplayManager implements ConfigChangeListener {
61
 
64
 
62
     /** Event bus to receive events on. */
65
     /** Event bus to receive events on. */
63
     private final DMDircMBassador eventBus;
66
     private final DMDircMBassador eventBus;
67
+    /** Swing event bus to receive events from. */
68
+    private final DMDircMBassador swingEventBus;
64
     /** Active frame manager. */
69
     /** Active frame manager. */
65
     private final ActiveFrameManager activeFrameManager;
70
     private final ActiveFrameManager activeFrameManager;
66
     private final Provider<LagDisplayPanel> panelProvider;
71
     private final Provider<LagDisplayPanel> panelProvider;
83
 
88
 
84
     @Inject
89
     @Inject
85
     public LagDisplayManager(final DMDircMBassador eventBus,
90
     public LagDisplayManager(final DMDircMBassador eventBus,
91
+            @SwingEventBus final DMDircMBassador swingEventBus,
86
             final ActiveFrameManager activeFrameManager,
92
             final ActiveFrameManager activeFrameManager,
87
             final Provider<LagDisplayPanel> panelProvider,
93
             final Provider<LagDisplayPanel> panelProvider,
88
             @PluginDomain(LagDisplayPlugin.class) final String domain,
94
             @PluginDomain(LagDisplayPlugin.class) final String domain,
89
             @GlobalConfig final AggregateConfigProvider globalConfig) {
95
             @GlobalConfig final AggregateConfigProvider globalConfig) {
90
         this.eventBus = eventBus;
96
         this.eventBus = eventBus;
97
+        this.swingEventBus = swingEventBus;
91
         this.activeFrameManager = activeFrameManager;
98
         this.activeFrameManager = activeFrameManager;
92
         this.panelProvider = panelProvider;
99
         this.panelProvider = panelProvider;
93
         this.domain = domain;
100
         this.domain = domain;
97
     public void load() {
104
     public void load() {
98
         panel = panelProvider.get();
105
         panel = panelProvider.get();
99
         eventBus.publishAsync(new StatusBarComponentAddedEvent(panel));
106
         eventBus.publishAsync(new StatusBarComponentAddedEvent(panel));
100
-        activeFrameManager.addSelectionListener(this);
101
         globalConfig.addChangeListener(domain, this);
107
         globalConfig.addChangeListener(domain, this);
102
         readConfig();
108
         readConfig();
109
+        swingEventBus.subscribe(this);
103
         eventBus.subscribe(this);
110
         eventBus.subscribe(this);
104
     }
111
     }
105
 
112
 
106
     public void unload() {
113
     public void unload() {
107
         eventBus.publishAsync(new StatusBarComponentRemovedEvent(panel));
114
         eventBus.publishAsync(new StatusBarComponentRemovedEvent(panel));
108
-        activeFrameManager.removeSelectionListener(this);
109
         globalConfig.removeListener(this);
115
         globalConfig.removeListener(this);
116
+        swingEventBus.unsubscribe(this);
110
         eventBus.unsubscribe(this);
117
         eventBus.unsubscribe(this);
111
         panel = null;
118
         panel = null;
112
     }
119
     }
152
         return showLabels;
159
         return showLabels;
153
     }
160
     }
154
 
161
 
155
-    @Override
156
-    public void selectionChanged(final TextFrame window) {
157
-        final FrameContainer source = window.getContainer();
158
-        if (source == null || source.getConnection() == null) {
159
-            panel.getComponent().setText("Unknown");
160
-        } else if (source.getConnection().getState() != ServerState.CONNECTED) {
161
-            panel.getComponent().setText("Not connected");
162
+    @Handler(invocation = EdtHandlerInvocation.class, delivery = Invoke.Asynchronously)
163
+    public void selectionChanged(final SwingWindowSelectedEvent event) {
164
+        if (event.getWindow().isPresent()) {
165
+            final Connection connection = event.getWindow().get().getContainer().getConnection();
166
+            if (connection != null && connection.getState() != ServerState.CONNECTED) {
167
+                panel.getComponent().setText("Not connected");
168
+            } else {
169
+                panel.getComponent().setText(getTime(connection));
170
+            }
162
         } else {
171
         } else {
163
-            panel.getComponent().setText(getTime(source.getConnection()));
172
+            panel.getComponent().setText("Unknown");
164
         }
173
         }
165
         panel.refreshDialog();
174
         panel.refreshDialog();
166
     }
175
     }

+ 14
- 17
ui_swing/src/com/dmdirc/addons/ui_swing/MainFrame.java View File

31
 import com.dmdirc.addons.ui_swing.dialogs.StandardQuestionDialog;
31
 import com.dmdirc.addons.ui_swing.dialogs.StandardQuestionDialog;
32
 import com.dmdirc.addons.ui_swing.events.SwingWindowAddedEvent;
32
 import com.dmdirc.addons.ui_swing.events.SwingWindowAddedEvent;
33
 import com.dmdirc.addons.ui_swing.events.SwingWindowDeletedEvent;
33
 import com.dmdirc.addons.ui_swing.events.SwingWindowDeletedEvent;
34
+import com.dmdirc.addons.ui_swing.events.SwingWindowSelectedEvent;
34
 import com.dmdirc.addons.ui_swing.framemanager.FrameManager;
35
 import com.dmdirc.addons.ui_swing.framemanager.FrameManager;
35
 import com.dmdirc.addons.ui_swing.framemanager.FramemanagerPosition;
36
 import com.dmdirc.addons.ui_swing.framemanager.FramemanagerPosition;
36
 import com.dmdirc.addons.ui_swing.framemanager.ctrltab.CtrlTabWindowManager;
37
 import com.dmdirc.addons.ui_swing.framemanager.ctrltab.CtrlTabWindowManager;
44
 import com.dmdirc.interfaces.LifecycleController;
45
 import com.dmdirc.interfaces.LifecycleController;
45
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
46
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
46
 import com.dmdirc.interfaces.config.ConfigChangeListener;
47
 import com.dmdirc.interfaces.config.ConfigChangeListener;
48
+import com.dmdirc.interfaces.ui.Window;
47
 import com.dmdirc.ui.CoreUIUtils;
49
 import com.dmdirc.ui.CoreUIUtils;
48
 import com.dmdirc.ui.IconManager;
50
 import com.dmdirc.ui.IconManager;
49
 import com.dmdirc.util.collections.ListenerList;
51
 import com.dmdirc.util.collections.ListenerList;
50
 import com.dmdirc.util.collections.QueuedLinkedHashSet;
52
 import com.dmdirc.util.collections.QueuedLinkedHashSet;
51
 
53
 
54
+import com.google.common.base.Optional;
55
+
52
 import java.awt.Dimension;
56
 import java.awt.Dimension;
53
 import java.awt.event.WindowEvent;
57
 import java.awt.event.WindowEvent;
54
 import java.awt.event.WindowFocusListener;
58
 import java.awt.event.WindowFocusListener;
98
     private final Provider<FrameManager> frameManagerProvider;
102
     private final Provider<FrameManager> frameManagerProvider;
99
     /** The bus to despatch events on. */
103
     /** The bus to despatch events on. */
100
     private final DMDircMBassador eventBus;
104
     private final DMDircMBassador eventBus;
105
+    /** Swing event bus to post events to. */
106
+    private final DMDircMBassador swingEventBus;
101
     /** The main application icon. */
107
     /** The main application icon. */
102
     private ImageIcon imageIcon;
108
     private ImageIcon imageIcon;
103
     /** The frame manager that's being used. */
109
     /** The frame manager that's being used. */
133
      * @param iconManager          The icon manager to use to get icons.
139
      * @param iconManager          The icon manager to use to get icons.
134
      * @param frameManagerProvider Provider to use to retrieve frame managers.
140
      * @param frameManagerProvider Provider to use to retrieve frame managers.
135
      * @param eventBus             The event bus to post events to.
141
      * @param eventBus             The event bus to post events to.
142
+     * @param swingEventBus        The event bus to post swing events to.
136
      */
143
      */
137
     public MainFrame(
144
     public MainFrame(
138
             final Apple apple,
145
             final Apple apple,
141
             final Provider<QuitWorker> quitWorker,
148
             final Provider<QuitWorker> quitWorker,
142
             final IconManager iconManager,
149
             final IconManager iconManager,
143
             final Provider<FrameManager> frameManagerProvider,
150
             final Provider<FrameManager> frameManagerProvider,
144
-            final DMDircMBassador eventBus) {
151
+            final DMDircMBassador eventBus,
152
+            final DMDircMBassador swingEventBus) {
145
         checkOnEDT();
153
         checkOnEDT();
146
         this.apple = apple;
154
         this.apple = apple;
147
         this.lifecycleController = lifecycleController;
155
         this.lifecycleController = lifecycleController;
150
         this.iconManager = iconManager;
158
         this.iconManager = iconManager;
151
         this.frameManagerProvider = frameManagerProvider;
159
         this.frameManagerProvider = frameManagerProvider;
152
         this.eventBus = eventBus;
160
         this.eventBus = eventBus;
161
+        this.swingEventBus = swingEventBus;
153
         version = globalConfig.getOption("version", "version");
162
         version = globalConfig.getOption("version", "version");
154
         focusOrder = new QueuedLinkedHashSet<>();
163
         focusOrder = new QueuedLinkedHashSet<>();
155
     }
164
     }
299
             public void run() {
308
             public void run() {
300
                 frameManagerPanel.removeAll();
309
                 frameManagerPanel.removeAll();
301
                 if (mainFrameManager != null) {
310
                 if (mainFrameManager != null) {
302
-                    removeSelectionListener(mainFrameManager);
311
+                    swingEventBus.unsubscribe(mainFrameManager);
303
                 }
312
                 }
304
                 mainFrameManager = frameManagerProvider.get();
313
                 mainFrameManager = frameManagerProvider.get();
305
                 mainFrameManager.setParent(frameManagerPanel);
314
                 mainFrameManager.setParent(frameManagerPanel);
306
-                addSelectionListener(mainFrameManager);
315
+                swingEventBus.subscribe(mainFrameManager);
307
             }
316
             }
308
         });
317
         });
309
     }
318
     }
561
                     activeFrame.activateFrame();
570
                     activeFrame.activateFrame();
562
                 }
571
                 }
563
 
572
 
564
-                for (final SelectionListener listener : listeners.get(
565
-                        SelectionListener.class)) {
566
-                    listener.selectionChanged(activeFrame);
567
-                }
573
+                swingEventBus.publish(
574
+                        new SwingWindowSelectedEvent(Optional.fromNullable((Window) activeFrame)));
568
             }
575
             }
569
         });
576
         });
570
     }
577
     }
571
 
578
 
572
-    @Override
573
-    public void addSelectionListener(final SelectionListener listener) {
574
-        listeners.add(SelectionListener.class, listener);
575
-    }
576
-
577
-    @Override
578
-    public void removeSelectionListener(final SelectionListener listener) {
579
-        listeners.remove(SelectionListener.class, listener);
580
-    }
581
-
582
     @Handler
579
     @Handler
583
     public void doWindowAdded(final SwingWindowAddedEvent event) {
580
     public void doWindowAdded(final SwingWindowAddedEvent event) {
584
         final TextFrame window = event.getChildWindow();
581
         final TextFrame window = event.getChildWindow();

+ 0
- 48
ui_swing/src/com/dmdirc/addons/ui_swing/SwingWindowListener.java View File

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.addons.ui_swing.components.frames.TextFrame;
26
-
27
-/**
28
- * An interface for objects interested in Swing UI window events.
29
- */
30
-public interface SwingWindowListener {
31
-
32
-    /**
33
-     * Called when a new window is added.
34
-     *
35
-     * @param parent The parent of the added window (may be null)
36
-     * @param window The window that was added
37
-     */
38
-    void windowAdded(final TextFrame parent, final TextFrame window);
39
-
40
-    /**
41
-     * Called when a new window was deleted.
42
-     *
43
-     * @param parent The parent of the added window (may be null)
44
-     * @param window The window that was deleted
45
-     */
46
-    void windowDeleted(final TextFrame parent, final TextFrame window);
47
-
48
-}

+ 5
- 7
ui_swing/src/com/dmdirc/addons/ui_swing/components/MDIBar.java View File

24
 
24
 
25
 import com.dmdirc.ClientModule.GlobalConfig;
25
 import com.dmdirc.ClientModule.GlobalConfig;
26
 import com.dmdirc.DMDircMBassador;
26
 import com.dmdirc.DMDircMBassador;
27
-import com.dmdirc.addons.ui_swing.SelectionListener;
27
+import com.dmdirc.addons.ui_swing.EdtHandlerInvocation;
28
 import com.dmdirc.addons.ui_swing.SwingController;
28
 import com.dmdirc.addons.ui_swing.SwingController;
29
-import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
30
 import com.dmdirc.addons.ui_swing.events.SwingWindowAddedEvent;
29
 import com.dmdirc.addons.ui_swing.events.SwingWindowAddedEvent;
31
 import com.dmdirc.addons.ui_swing.events.SwingWindowDeletedEvent;
30
 import com.dmdirc.addons.ui_swing.events.SwingWindowDeletedEvent;
31
+import com.dmdirc.addons.ui_swing.events.SwingWindowSelectedEvent;
32
 import com.dmdirc.addons.ui_swing.injection.SwingEventBus;
32
 import com.dmdirc.addons.ui_swing.injection.SwingEventBus;
33
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
33
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
34
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
34
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
52
  * Provides an MDI style bar for closing frames.
52
  * Provides an MDI style bar for closing frames.
53
  */
53
  */
54
 @Singleton
54
 @Singleton
55
-public class MDIBar extends JPanel implements SelectionListener, ActionListener,
56
-        ConfigChangeListener {
55
+public class MDIBar extends JPanel implements ActionListener, ConfigChangeListener {
57
 
56
 
58
     /** A version number for this class. */
57
     /** A version number for this class. */
59
     private static final long serialVersionUID = -8028057596226636245L;
58
     private static final long serialVersionUID = -8028057596226636245L;
99
 
98
 
100
         eventBus.subscribe(this);
99
         eventBus.subscribe(this);
101
 
100
 
102
-        activeFrameManager.addSelectionListener(this);
103
         closeButton.addActionListener(this);
101
         closeButton.addActionListener(this);
104
         config.addChangeListener(configDomain, "mdiBarVisibility", this);
102
         config.addChangeListener(configDomain, "mdiBarVisibility", this);
105
 
103
 
150
         check();
148
         check();
151
     }
149
     }
152
 
150
 
153
-    @Override
154
-    public void selectionChanged(final TextFrame window) {
151
+    @Handler(invocation = EdtHandlerInvocation.class)
152
+    public void selectionChanged(final SwingWindowSelectedEvent event) {
155
         check();
153
         check();
156
     }
154
     }
157
 
155
 

+ 17
- 17
ui_swing/src/com/dmdirc/addons/ui_swing/components/statusbar/InviteLabel.java View File

25
 import com.dmdirc.ClientModule.GlobalConfig;
25
 import com.dmdirc.ClientModule.GlobalConfig;
26
 import com.dmdirc.DMDircMBassador;
26
 import com.dmdirc.DMDircMBassador;
27
 import com.dmdirc.Invite;
27
 import com.dmdirc.Invite;
28
+import com.dmdirc.addons.ui_swing.EdtHandlerInvocation;
28
 import com.dmdirc.addons.ui_swing.MainFrame;
29
 import com.dmdirc.addons.ui_swing.MainFrame;
29
-import com.dmdirc.addons.ui_swing.SelectionListener;
30
 import com.dmdirc.addons.ui_swing.UIUtilities;
30
 import com.dmdirc.addons.ui_swing.UIUtilities;
31
-import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
31
+import com.dmdirc.addons.ui_swing.events.SwingWindowSelectedEvent;
32
+import com.dmdirc.addons.ui_swing.injection.SwingEventBus;
32
 import com.dmdirc.events.ServerConnectErrorEvent;
33
 import com.dmdirc.events.ServerConnectErrorEvent;
33
 import com.dmdirc.events.ServerConnectedEvent;
34
 import com.dmdirc.events.ServerConnectedEvent;
34
 import com.dmdirc.events.ServerDisconnectedEvent;
35
 import com.dmdirc.events.ServerDisconnectedEvent;
51
 import javax.swing.JSeparator;
52
 import javax.swing.JSeparator;
52
 
53
 
53
 import net.engio.mbassy.listener.Handler;
54
 import net.engio.mbassy.listener.Handler;
55
+import net.engio.mbassy.listener.Invoke;
54
 
56
 
55
 /**
57
 /**
56
  * A status bar component to show invites to the user and enable them to accept or dismiss them.
58
  * A status bar component to show invites to the user and enable them to accept or dismiss them.
57
  */
59
  */
58
-public class InviteLabel extends StatusbarPopupPanel<JLabel> implements InviteListener, ActionListener, SelectionListener {
60
+public class InviteLabel extends StatusbarPopupPanel<JLabel>
61
+        implements InviteListener, ActionListener {
59
 
62
 
60
     /** A version number for this class. */
63
     /** A version number for this class. */
61
     private static final long serialVersionUID = 1;
64
     private static final long serialVersionUID = 1;
70
     /** Active connection. */
73
     /** Active connection. */
71
     private Connection activeConnection;
74
     private Connection activeConnection;
72
 
75
 
73
-    /**
74
-     * Instantiates a new invite label.
75
-     *
76
-     * @param eventBus      The event bus to subscribe to events on
77
-     * @param iconManager   The manager to retrieve the invite icon from.
78
-     * @param connectionManager The manager to use to iterate servers.
79
-     * @param mainFrame     Main frame
80
-     */
81
     @Inject
76
     @Inject
82
     public InviteLabel(
77
     public InviteLabel(
83
             final DMDircMBassador eventBus,
78
             final DMDircMBassador eventBus,
84
             @GlobalConfig final IconManager iconManager,
79
             @GlobalConfig final IconManager iconManager,
85
             final ConnectionManager connectionManager,
80
             final ConnectionManager connectionManager,
86
-            final MainFrame mainFrame) {
81
+            final MainFrame mainFrame,
82
+            @SwingEventBus final DMDircMBassador swingEventBus) {
87
         super(new JLabel());
83
         super(new JLabel());
88
 
84
 
89
         this.parentWindow = mainFrame;
85
         this.parentWindow = mainFrame;
103
             connection.addInviteListener(this);
99
             connection.addInviteListener(this);
104
         }
100
         }
105
 
101
 
106
-        mainFrame.addSelectionListener(this);
102
+        swingEventBus.subscribe(this);
107
         eventBus.subscribe(this);
103
         eventBus.subscribe(this);
108
 
104
 
109
         update();
105
         update();
179
 
175
 
180
     @Override
176
     @Override
181
     public void mouseReleased(final MouseEvent e) {
177
     public void mouseReleased(final MouseEvent e) {
182
-        super.mouseClicked(e);
178
+        mouseClicked(e);
183
         popuplateMenu();
179
         popuplateMenu();
184
         if (menu.getComponentCount() > 0) {
180
         if (menu.getComponentCount() > 0) {
185
             menu.show(this, e.getX(), e.getY());
181
             menu.show(this, e.getX(), e.getY());
198
         }
194
         }
199
     }
195
     }
200
 
196
 
201
-    @Override
202
-    public void selectionChanged(final TextFrame window) {
203
-        activeConnection = window == null ? null : window.getContainer().getConnection();
197
+    @Handler(invocation = EdtHandlerInvocation.class, delivery = Invoke.Asynchronously)
198
+    public void selectionChanged(final SwingWindowSelectedEvent event) {
199
+        if (event.getWindow().isPresent()) {
200
+            activeConnection = event.getWindow().get().getContainer().getConnection();
201
+        } else {
202
+            activeConnection = null;
203
+        }
204
         update();
204
         update();
205
     }
205
     }
206
 
206
 

ui_swing/src/com/dmdirc/addons/ui_swing/SelectionListener.java → ui_swing/src/com/dmdirc/addons/ui_swing/events/SwingWindowSelectedEvent.java View File

20
  * SOFTWARE.
20
  * SOFTWARE.
21
  */
21
  */
22
 
22
 
23
-package com.dmdirc.addons.ui_swing;
23
+package com.dmdirc.addons.ui_swing.events;
24
 
24
 
25
-import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
25
+import com.dmdirc.interfaces.ui.Window;
26
 
26
 
27
-import java.util.EventListener;
27
+import com.google.common.base.Optional;
28
 
28
 
29
 /**
29
 /**
30
- * Defines the methods that should be implemented by classes which wish to receive information about
31
- * Swing frame selection changes.
30
+ * Fired when the window selection changes.
32
  */
31
  */
33
-public interface SelectionListener extends EventListener {
32
+public class SwingWindowSelectedEvent extends SwingEvent {
34
 
33
 
35
-    /**
36
-     * Called when a new window is selected.
37
-     *
38
-     * @param window The window that's now selected
39
-     */
40
-    void selectionChanged(final TextFrame window);
34
+    private final Optional<Window> selectedWindow;
41
 
35
 
36
+    public SwingWindowSelectedEvent(final Optional<Window> selectedWindow) {
37
+        this.selectedWindow = selectedWindow;
38
+    }
39
+
40
+    public Optional<Window> getWindow() {
41
+        return selectedWindow;
42
+    }
42
 }
43
 }

+ 1
- 3
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/FrameManager.java View File

22
 
22
 
23
 package com.dmdirc.addons.ui_swing.framemanager;
23
 package com.dmdirc.addons.ui_swing.framemanager;
24
 
24
 
25
-import com.dmdirc.addons.ui_swing.SelectionListener;
26
-
27
 import javax.swing.JComponent;
25
 import javax.swing.JComponent;
28
 
26
 
29
 /**
27
 /**
30
  * A frame manager is a widget that allows the user to navigate between the various frames that will
28
  * A frame manager is a widget that allows the user to navigate between the various frames that will
31
  * be open at any one time.
29
  * be open at any one time.
32
  */
30
  */
33
-public interface FrameManager extends SelectionListener {
31
+public interface FrameManager {
34
 
32
 
35
     /**
33
     /**
36
      * Sets the parent component of this frame manager. The frame manager should render itself
34
      * Sets the parent component of this frame manager. The frame manager should render itself

+ 20
- 22
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/buttonbar/ButtonBar.java View File

33
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
33
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
34
 import com.dmdirc.addons.ui_swing.events.SwingWindowAddedEvent;
34
 import com.dmdirc.addons.ui_swing.events.SwingWindowAddedEvent;
35
 import com.dmdirc.addons.ui_swing.events.SwingWindowDeletedEvent;
35
 import com.dmdirc.addons.ui_swing.events.SwingWindowDeletedEvent;
36
+import com.dmdirc.addons.ui_swing.events.SwingWindowSelectedEvent;
36
 import com.dmdirc.addons.ui_swing.framemanager.FrameManager;
37
 import com.dmdirc.addons.ui_swing.framemanager.FrameManager;
37
 import com.dmdirc.addons.ui_swing.framemanager.FramemanagerPosition;
38
 import com.dmdirc.addons.ui_swing.framemanager.FramemanagerPosition;
39
+import com.dmdirc.addons.ui_swing.injection.SwingEventBus;
38
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
40
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
39
 import com.dmdirc.events.FrameIconChangedEvent;
41
 import com.dmdirc.events.FrameIconChangedEvent;
40
 import com.dmdirc.events.FrameNameChangedEvent;
42
 import com.dmdirc.events.FrameNameChangedEvent;
134
             @GlobalConfig final AggregateConfigProvider globalConfig,
136
             @GlobalConfig final AggregateConfigProvider globalConfig,
135
             final WindowManager windowManager,
137
             final WindowManager windowManager,
136
             final ActiveFrameManager activeFrameManager,
138
             final ActiveFrameManager activeFrameManager,
137
-            final DMDircMBassador eventBus) {
139
+            final DMDircMBassador eventBus,
140
+            @SwingEventBus final DMDircMBassador swingEventBus) {
138
         this.windowFactory = windowFactory;
141
         this.windowFactory = windowFactory;
139
         this.globalConfig = globalConfig;
142
         this.globalConfig = globalConfig;
140
         this.windowManager = windowManager;
143
         this.windowManager = windowManager;
141
         this.activeFrameManager = activeFrameManager;
144
         this.activeFrameManager = activeFrameManager;
142
 
145
 
143
         eventBus.subscribe(this);
146
         eventBus.subscribe(this);
147
+        swingEventBus.subscribe(this);
144
 
148
 
145
         scrollPane = new JScrollPane();
149
         scrollPane = new JScrollPane();
146
         scrollPane.setBorder(null);
150
         scrollPane.setBorder(null);
209
 
213
 
210
                 final TextFrame activeFrame = activeFrameManager.getActiveFrame();
214
                 final TextFrame activeFrame = activeFrameManager.getActiveFrame();
211
                 if (activeFrame != null) {
215
                 if (activeFrame != null) {
212
-                    selectionChanged(activeFrame);
216
+                    selectionChanged(new SwingWindowSelectedEvent(
217
+                            Optional.fromNullable((Window) activeFrame)));
213
                 }
218
                 }
214
                 parent.setVisible(true);
219
                 parent.setVisible(true);
215
             }
220
             }
391
                 event.getWindow().getNotification().or(Colour.BLACK)));
396
                 event.getWindow().getNotification().or(Colour.BLACK)));
392
     }
397
     }
393
 
398
 
394
-    @Override
395
-    public void selectionChanged(final TextFrame window) {
396
-        UIUtilities.invokeLater(new Runnable() {
397
-
398
-            @Override
399
-            public void run() {
400
-                activeWindow = window;
401
-                final FrameToggleButton selectedButton = getButton(selected);
402
-                if (selected != null && selectedButton != null) {
403
-                    selectedButton.setSelected(false);
404
-                }
399
+    @Handler(invocation = EdtHandlerInvocation.class, delivery = Invoke.Asynchronously)
400
+    public void selectionChanged(final SwingWindowSelectedEvent event) {
401
+        activeWindow = event.getWindow().orNull();
402
+        final FrameToggleButton selectedButton = getButton(selected);
403
+        if (selected != null && selectedButton != null) {
404
+            selectedButton.setSelected(false);
405
+        }
405
 
406
 
406
-                selected = window.getContainer();
407
-                final FrameToggleButton button = getButton(window.getContainer());
408
-                if (button != null) {
409
-                    scrollPane.getViewport().scrollRectToVisible(
410
-                            button.getBounds());
411
-                    button.setSelected(true);
412
-                }
413
-            }
414
-        });
407
+        selected = activeWindow == null ? null : activeWindow.getContainer();
408
+        final FrameToggleButton button = getButton(event.getWindow().get().getContainer());
409
+        if (button != null) {
410
+            scrollPane.getViewport().scrollRectToVisible(button.getBounds());
411
+            button.setSelected(true);
412
+        }
415
     }
413
     }
416
 
414
 
417
     @Handler(invocation = EdtHandlerInvocation.class, delivery = Invoke.Asynchronously)
415
     @Handler(invocation = EdtHandlerInvocation.class, delivery = Invoke.Asynchronously)

+ 17
- 25
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/ctrltab/CtrlTabWindowManager.java View File

24
 
24
 
25
 import com.dmdirc.ClientModule.GlobalConfig;
25
 import com.dmdirc.ClientModule.GlobalConfig;
26
 import com.dmdirc.DMDircMBassador;
26
 import com.dmdirc.DMDircMBassador;
27
+import com.dmdirc.addons.ui_swing.EdtHandlerInvocation;
27
 import com.dmdirc.addons.ui_swing.MainFrame;
28
 import com.dmdirc.addons.ui_swing.MainFrame;
28
-import com.dmdirc.addons.ui_swing.SelectionListener;
29
 import com.dmdirc.addons.ui_swing.SwingWindowFactory;
29
 import com.dmdirc.addons.ui_swing.SwingWindowFactory;
30
 import com.dmdirc.addons.ui_swing.UIUtilities;
30
 import com.dmdirc.addons.ui_swing.UIUtilities;
31
 import com.dmdirc.addons.ui_swing.actions.NextFrameAction;
31
 import com.dmdirc.addons.ui_swing.actions.NextFrameAction;
34
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
34
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
35
 import com.dmdirc.addons.ui_swing.events.SwingWindowAddedEvent;
35
 import com.dmdirc.addons.ui_swing.events.SwingWindowAddedEvent;
36
 import com.dmdirc.addons.ui_swing.events.SwingWindowDeletedEvent;
36
 import com.dmdirc.addons.ui_swing.events.SwingWindowDeletedEvent;
37
+import com.dmdirc.addons.ui_swing.events.SwingWindowSelectedEvent;
37
 import com.dmdirc.addons.ui_swing.framemanager.tree.TreeViewModel;
38
 import com.dmdirc.addons.ui_swing.framemanager.tree.TreeViewModel;
38
 import com.dmdirc.addons.ui_swing.framemanager.tree.TreeViewNode;
39
 import com.dmdirc.addons.ui_swing.framemanager.tree.TreeViewNode;
40
+import com.dmdirc.addons.ui_swing.injection.SwingEventBus;
39
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
41
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
40
 import com.dmdirc.events.UserErrorEvent;
42
 import com.dmdirc.events.UserErrorEvent;
41
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
43
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
58
 import javax.swing.tree.TreeSelectionModel;
60
 import javax.swing.tree.TreeSelectionModel;
59
 
61
 
60
 import net.engio.mbassy.listener.Handler;
62
 import net.engio.mbassy.listener.Handler;
63
+import net.engio.mbassy.listener.Invoke;
61
 
64
 
62
 /**
65
 /**
63
  * A Window manager to handle ctrl[+shift]+tab switching between windows.
66
  * A Window manager to handle ctrl[+shift]+tab switching between windows.
64
  */
67
  */
65
 @Singleton
68
 @Singleton
66
-public class CtrlTabWindowManager implements SelectionListener {
69
+public class CtrlTabWindowManager {
67
 
70
 
68
     /** Node storage, used for adding and deleting nodes correctly. */
71
     /** Node storage, used for adding and deleting nodes correctly. */
69
     private final Map<Window, TreeViewNode> nodes;
72
     private final Map<Window, TreeViewNode> nodes;
76
     /** The event bus to post errors to. */
79
     /** The event bus to post errors to. */
77
     private final DMDircMBassador eventBus;
80
     private final DMDircMBassador eventBus;
78
 
81
 
79
-    /**
80
-     * Creates a new ctrl tab window manager.
81
-     *
82
-     * @param globalConfig       The configuration to read settings from.
83
-     * @param windowFactory      The window factory to use to create and listen for windows.
84
-     * @param mainFrame          The main frame that owns this window manager
85
-     * @param activeFrameManager Active frame manager.
86
-     * @param eventBus           The eventBus to post errors to
87
-     */
88
     @Inject
82
     @Inject
89
     public CtrlTabWindowManager(
83
     public CtrlTabWindowManager(
90
             @GlobalConfig final AggregateConfigProvider globalConfig,
84
             @GlobalConfig final AggregateConfigProvider globalConfig,
91
             final SwingWindowFactory windowFactory,
85
             final SwingWindowFactory windowFactory,
92
             final ActiveFrameManager activeFrameManager,
86
             final ActiveFrameManager activeFrameManager,
93
             final MainFrame mainFrame,
87
             final MainFrame mainFrame,
94
-            final DMDircMBassador eventBus) {
88
+            final DMDircMBassador eventBus,
89
+            @SwingEventBus final DMDircMBassador swingEventBus) {
95
         this.eventBus = eventBus;
90
         this.eventBus = eventBus;
96
         nodes = new HashMap<>();
91
         nodes = new HashMap<>();
97
         model = new TreeViewModel(globalConfig, new TreeViewNode(null, null));
92
         model = new TreeViewModel(globalConfig, new TreeViewNode(null, null));
106
             }
101
             }
107
         };
102
         };
108
 
103
 
109
-        activeFrameManager.addSelectionListener(this);
104
+        swingEventBus.subscribe(this);
110
 
105
 
111
         if (mainFrame.getRootPane().getActionMap() != null) {
106
         if (mainFrame.getRootPane().getActionMap() != null) {
112
             mainFrame.getRootPane().getActionMap()
107
             mainFrame.getRootPane().getActionMap()
183
         treeScroller.changeFocus(false);
178
         treeScroller.changeFocus(false);
184
     }
179
     }
185
 
180
 
186
-    @Override
187
-    public void selectionChanged(final TextFrame window) {
188
-        UIUtilities.invokeLater(new Runnable() {
189
-
190
-            @Override
191
-            public void run() {
192
-                final TreeNode[] path = model.getPathToRoot(nodes.get(
193
-                        window));
194
-                if (path != null && path.length > 0) {
195
-                    selectionModel.setSelectionPath(new TreePath(path));
196
-                }
181
+    @Handler(invocation = EdtHandlerInvocation.class, delivery = Invoke.Asynchronously)
182
+    public void selectionChanged(final SwingWindowSelectedEvent event) {
183
+        if (event.getWindow().isPresent()) {
184
+            final TreeNode[] path = model.getPathToRoot(nodes.get(event.getWindow().get()));
185
+            if (path != null && path.length > 0) {
186
+                selectionModel.setSelectionPath(new TreePath(path));
197
             }
187
             }
198
-        });
188
+        } else {
189
+            selectionModel.setSelectionPath(null);
190
+        }
199
     }
191
     }
200
 
192
 
201
 }
193
 }

+ 6
- 6
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/tree/NodeLabel.java View File

23
 package com.dmdirc.addons.ui_swing.framemanager.tree;
23
 package com.dmdirc.addons.ui_swing.framemanager.tree;
24
 
24
 
25
 import com.dmdirc.FrameContainer;
25
 import com.dmdirc.FrameContainer;
26
-import com.dmdirc.addons.ui_swing.SelectionListener;
27
 import com.dmdirc.addons.ui_swing.UIUtilities;
26
 import com.dmdirc.addons.ui_swing.UIUtilities;
28
 import com.dmdirc.addons.ui_swing.components.ImageButton;
27
 import com.dmdirc.addons.ui_swing.components.ImageButton;
29
-import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
28
+import com.dmdirc.addons.ui_swing.events.SwingWindowSelectedEvent;
30
 import com.dmdirc.events.FrameIconChangedEvent;
29
 import com.dmdirc.events.FrameIconChangedEvent;
31
 import com.dmdirc.events.FrameNameChangedEvent;
30
 import com.dmdirc.events.FrameNameChangedEvent;
32
 import com.dmdirc.events.NotificationSetEvent;
31
 import com.dmdirc.events.NotificationSetEvent;
48
 /**
47
 /**
49
  * Node label.
48
  * Node label.
50
  */
49
  */
51
-public class NodeLabel extends JPanel implements SelectionListener {
50
+public class NodeLabel extends JPanel {
52
 
51
 
53
     /** A version number for this class. */
52
     /** A version number for this class. */
54
     private static final long serialVersionUID = 1;
53
     private static final long serialVersionUID = 1;
100
         selected = false;
99
         selected = false;
101
     }
100
     }
102
 
101
 
103
-    @Override
104
-    public void selectionChanged(final TextFrame window) {
105
-        selected = this.window.equals(window.getContainer());
102
+    @Handler
103
+    public void selectionChanged(final SwingWindowSelectedEvent event) {
104
+        selected = event.getWindow().isPresent()
105
+                && window.equals(event.getWindow().get().getContainer());
106
     }
106
     }
107
 
107
 
108
     public void notificationSet(final NotificationSetEvent event) {
108
     public void notificationSet(final NotificationSetEvent event) {

+ 12
- 15
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/tree/TreeFrameManager.java View File

33
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
33
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
34
 import com.dmdirc.addons.ui_swing.events.SwingWindowAddedEvent;
34
 import com.dmdirc.addons.ui_swing.events.SwingWindowAddedEvent;
35
 import com.dmdirc.addons.ui_swing.events.SwingWindowDeletedEvent;
35
 import com.dmdirc.addons.ui_swing.events.SwingWindowDeletedEvent;
36
+import com.dmdirc.addons.ui_swing.events.SwingWindowSelectedEvent;
36
 import com.dmdirc.addons.ui_swing.framemanager.FrameManager;
37
 import com.dmdirc.addons.ui_swing.framemanager.FrameManager;
37
 import com.dmdirc.addons.ui_swing.injection.SwingEventBus;
38
 import com.dmdirc.addons.ui_swing.injection.SwingEventBus;
38
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
39
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
42
 import com.dmdirc.events.UserErrorEvent;
43
 import com.dmdirc.events.UserErrorEvent;
43
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
44
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
44
 import com.dmdirc.interfaces.config.ConfigChangeListener;
45
 import com.dmdirc.interfaces.config.ConfigChangeListener;
46
+import com.dmdirc.interfaces.ui.Window;
45
 import com.dmdirc.logger.ErrorLevel;
47
 import com.dmdirc.logger.ErrorLevel;
46
 import com.dmdirc.plugins.PluginDomain;
48
 import com.dmdirc.plugins.PluginDomain;
47
-import com.dmdirc.util.colours.Colour;
48
 import com.dmdirc.ui.WindowManager;
49
 import com.dmdirc.ui.WindowManager;
49
 import com.dmdirc.ui.messages.ColourManager;
50
 import com.dmdirc.ui.messages.ColourManager;
51
+import com.dmdirc.util.colours.Colour;
52
+
53
+import com.google.common.base.Optional;
50
 
54
 
51
 import java.awt.Rectangle;
55
 import java.awt.Rectangle;
52
 import java.awt.event.MouseEvent;
56
 import java.awt.event.MouseEvent;
53
 import java.io.Serializable;
57
 import java.io.Serializable;
54
-import java.util.ArrayList;
55
 import java.util.Collection;
58
 import java.util.Collection;
56
 import java.util.HashMap;
59
 import java.util.HashMap;
57
 import java.util.Map;
60
 import java.util.Map;
240
             public void run() {
243
             public void run() {
241
                 final NodeLabel label = new NodeLabel(window);
244
                 final NodeLabel label = new NodeLabel(window);
242
                 eventBus.subscribe(label);
245
                 eventBus.subscribe(label);
246
+                swingEventBus.subscribe(label);
243
                 final TreeViewNode node = new TreeViewNode(label, window);
247
                 final TreeViewNode node = new TreeViewNode(label, window);
244
                 synchronized (nodes) {
248
                 synchronized (nodes) {
245
                     nodes.put(window, node);
249
                     nodes.put(window, node);
339
                 }
343
                 }
340
 
344
 
341
                 if (activeFrameManager.getActiveFrame() != null) {
345
                 if (activeFrameManager.getActiveFrame() != null) {
342
-                    selectionChanged(activeFrameManager.getActiveFrame());
346
+                    selectionChanged(new SwingWindowSelectedEvent(Optional.fromNullable((Window)
347
+                            activeFrameManager.getActiveFrame())));
343
                 }
348
                 }
344
             }
349
             }
345
         });
350
         });
346
     }
351
     }
347
 
352
 
348
-    @Override
349
-    public void selectionChanged(final TextFrame window) {
350
-        synchronized (nodes) {
351
-            final Iterable<TreeViewNode> collection = new ArrayList<>(nodes.values());
352
-            for (TreeViewNode treeNode : collection) {
353
-                final NodeLabel label = treeNode.getLabel();
354
-                label.selectionChanged(window);
355
-            }
356
-        }
357
-
358
-        if (window != null) {
353
+    @Handler(invocation = EdtHandlerInvocation.class, delivery = Invoke.Asynchronously)
354
+    public void selectionChanged(final SwingWindowSelectedEvent event) {
355
+        if (event.getWindow().isPresent()) {
359
             UIUtilities.invokeLater(new Runnable() {
356
             UIUtilities.invokeLater(new Runnable() {
360
 
357
 
361
                 @Override
358
                 @Override
362
                 public void run() {
359
                 public void run() {
363
                     final TreeNode[] treePath = ((DefaultTreeModel) tree.getModel())
360
                     final TreeNode[] treePath = ((DefaultTreeModel) tree.getModel())
364
-                            .getPathToRoot(nodes.get(window.getContainer()));
361
+                            .getPathToRoot(nodes.get(event.getWindow().get().getContainer()));
365
                     if (treePath != null && treePath.length > 0) {
362
                     if (treePath != null && treePath.length > 0) {
366
                         final TreePath path = new TreePath(treePath);
363
                         final TreePath path = new TreePath(treePath);
367
                         tree.setTreePath(path);
364
                         tree.setTreePath(path);

+ 20
- 9
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/windowmenu/WindowSelectionFontChanger.java View File

22
 
22
 
23
 package com.dmdirc.addons.ui_swing.framemanager.windowmenu;
23
 package com.dmdirc.addons.ui_swing.framemanager.windowmenu;
24
 
24
 
25
-import com.dmdirc.addons.ui_swing.SelectionListener;
26
-import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
25
+import com.dmdirc.DMDircMBassador;
26
+import com.dmdirc.addons.ui_swing.EdtHandlerInvocation;
27
+import com.dmdirc.addons.ui_swing.events.SwingWindowSelectedEvent;
27
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
28
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
28
 import com.dmdirc.interfaces.ui.Window;
29
 import com.dmdirc.interfaces.ui.Window;
29
 
30
 
31
+import com.google.common.base.Optional;
32
+
30
 import java.awt.Font;
33
 import java.awt.Font;
31
 
34
 
32
 import javax.swing.JComponent;
35
 import javax.swing.JComponent;
33
 import javax.swing.UIManager;
36
 import javax.swing.UIManager;
34
 
37
 
38
+import net.engio.mbassy.listener.Handler;
39
+import net.engio.mbassy.listener.Invoke;
40
+import net.engio.mbassy.listener.Listener;
41
+import net.engio.mbassy.listener.References;
42
+
35
 /**
43
 /**
36
  * Changes the font for a JComponent on a selection change.
44
  * Changes the font for a JComponent on a selection change.
37
  */
45
  */
38
-public class WindowSelectionFontChanger implements SelectionListener {
46
+@Listener(references = References.Strong)
47
+public class WindowSelectionFontChanger {
39
 
48
 
40
     private final JComponent component;
49
     private final JComponent component;
41
     private final Window window;
50
     private final Window window;
45
         this.window = window;
54
         this.window = window;
46
     }
55
     }
47
 
56
 
48
-    public void init(final ActiveFrameManager activeFrameMaanger) {
49
-        activeFrameMaanger.addSelectionListener(this);
50
-        selectionChanged(activeFrameMaanger.getActiveFrame());
57
+    public void init(final ActiveFrameManager activeFrameMaanger,
58
+            final DMDircMBassador eventBus) {
59
+        eventBus.subscribe(this);
60
+        selectionChanged(new SwingWindowSelectedEvent(
61
+                Optional.fromNullable((Window) activeFrameMaanger.getActiveFrame())));
51
     }
62
     }
52
 
63
 
53
-    @Override
54
-    public void selectionChanged(final TextFrame window) {
64
+    @Handler(invocation = EdtHandlerInvocation.class, delivery = Invoke.Asynchronously)
65
+    public void selectionChanged(final SwingWindowSelectedEvent event) {
55
         // TODO: Check children and set italic
66
         // TODO: Check children and set italic
56
-        if (this.window.equals(window)) {
67
+        if (event.getWindow().isPresent() && window.equals(event.getWindow().get())) {
57
             component.setFont(UIManager.getFont("MenuItem.font").deriveFont(Font.BOLD));
68
             component.setFont(UIManager.getFont("MenuItem.font").deriveFont(Font.BOLD));
58
         } else {
69
         } else {
59
             component.setFont(UIManager.getFont("MenuItem.font").deriveFont(Font.PLAIN));
70
             component.setFont(UIManager.getFont("MenuItem.font").deriveFont(Font.PLAIN));

+ 7
- 2
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/windowmenu/WindowSelectionFontChangerFactory.java View File

22
 
22
 
23
 package com.dmdirc.addons.ui_swing.framemanager.windowmenu;
23
 package com.dmdirc.addons.ui_swing.framemanager.windowmenu;
24
 
24
 
25
+import com.dmdirc.DMDircMBassador;
26
+import com.dmdirc.addons.ui_swing.injection.SwingEventBus;
25
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
27
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
26
 import com.dmdirc.interfaces.ui.Window;
28
 import com.dmdirc.interfaces.ui.Window;
27
 
29
 
34
 public class WindowSelectionFontChangerFactory {
36
 public class WindowSelectionFontChangerFactory {
35
 
37
 
36
     private final ActiveFrameManager activeFrameManager;
38
     private final ActiveFrameManager activeFrameManager;
39
+    private final DMDircMBassador swingEventBus;
37
 
40
 
38
     @Inject
41
     @Inject
39
-    public WindowSelectionFontChangerFactory(final ActiveFrameManager activeFrameManager) {
42
+    public WindowSelectionFontChangerFactory(final ActiveFrameManager activeFrameManager,
43
+            @SwingEventBus final DMDircMBassador swingEventBus) {
40
         this.activeFrameManager = activeFrameManager;
44
         this.activeFrameManager = activeFrameManager;
45
+        this.swingEventBus = swingEventBus;
41
     }
46
     }
42
 
47
 
43
     public WindowSelectionFontChanger getWindowSelectionFontChanger(final JComponent component,
48
     public WindowSelectionFontChanger getWindowSelectionFontChanger(final JComponent component,
44
             final Window window) {
49
             final Window window) {
45
         final WindowSelectionFontChanger windowSelectionFontChanger
50
         final WindowSelectionFontChanger windowSelectionFontChanger
46
                 = new WindowSelectionFontChanger(component, window);
51
                 = new WindowSelectionFontChanger(component, window);
47
-        windowSelectionFontChanger.init(activeFrameManager);
52
+        windowSelectionFontChanger.init(activeFrameManager, swingEventBus);
48
         return windowSelectionFontChanger;
53
         return windowSelectionFontChanger;
49
     }
54
     }
50
 }
55
 }

+ 4
- 2
ui_swing/src/com/dmdirc/addons/ui_swing/injection/SwingModule.java View File

140
             final Provider<QuitWorker> quitWorker,
140
             final Provider<QuitWorker> quitWorker,
141
             final URLBuilder urlBuilder,
141
             final URLBuilder urlBuilder,
142
             final Provider<FrameManager> frameManagerProvider,
142
             final Provider<FrameManager> frameManagerProvider,
143
-            final DMDircMBassador eventBus) {
143
+            final DMDircMBassador eventBus,
144
+            @SwingEventBus final DMDircMBassador swingEventBus) {
144
         return UIUtilities.invokeAndWait(new Callable<MainFrame>() {
145
         return UIUtilities.invokeAndWait(new Callable<MainFrame>() {
145
 
146
 
146
             @Override
147
             @Override
152
                         quitWorker,
153
                         quitWorker,
153
                         new IconManager(globalConfig, urlBuilder),
154
                         new IconManager(globalConfig, urlBuilder),
154
                         frameManagerProvider,
155
                         frameManagerProvider,
155
-                        eventBus);
156
+                        eventBus,
157
+                        swingEventBus);
156
             }
158
             }
157
         });
159
         });
158
     }
160
     }

+ 0
- 21
ui_swing/src/com/dmdirc/addons/ui_swing/interfaces/ActiveFrameManager.java View File

22
 
22
 
23
 package com.dmdirc.addons.ui_swing.interfaces;
23
 package com.dmdirc.addons.ui_swing.interfaces;
24
 
24
 
25
-import com.dmdirc.addons.ui_swing.SelectionListener;
26
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
25
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
27
 
26
 
28
 /**
27
 /**
44
      */
43
      */
45
     void setActiveFrame(TextFrame activeFrame);
44
     void setActiveFrame(TextFrame activeFrame);
46
 
45
 
47
-    /**
48
-     * Registers a new selection listener with this frame. The listener will be notified whenever
49
-     * the currently selected frame is changed.
50
-     *
51
-     * @param listener The listener to be added
52
-     *
53
-     * @see #setActiveFrame(com.dmdirc.addons.ui_swing.components.frames.TextFrame)
54
-     * @see #getActiveFrame()
55
-     */
56
-    void addSelectionListener(SelectionListener listener);
57
-
58
-    /**
59
-     * Removes a previously registered selection listener.
60
-     *
61
-     * @param listener The listener to be removed
62
-     *
63
-     * @see #addSelectionListener(com.dmdirc.addons.ui_swing.SelectionListener)
64
-     */
65
-    void removeSelectionListener(SelectionListener listener);
66
-
67
 }
46
 }

+ 18
- 9
windowstatus/src/com/dmdirc/addons/windowstatus/WindowStatusManager.java View File

26
 import com.dmdirc.DMDircMBassador;
26
 import com.dmdirc.DMDircMBassador;
27
 import com.dmdirc.FrameContainer;
27
 import com.dmdirc.FrameContainer;
28
 import com.dmdirc.Query;
28
 import com.dmdirc.Query;
29
-import com.dmdirc.addons.ui_swing.SelectionListener;
29
+import com.dmdirc.addons.ui_swing.EdtHandlerInvocation;
30
 import com.dmdirc.addons.ui_swing.UIUtilities;
30
 import com.dmdirc.addons.ui_swing.UIUtilities;
31
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
31
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
32
+import com.dmdirc.addons.ui_swing.events.SwingWindowSelectedEvent;
33
+import com.dmdirc.addons.ui_swing.injection.SwingEventBus;
32
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
34
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
33
 import com.dmdirc.events.StatusBarComponentAddedEvent;
35
 import com.dmdirc.events.StatusBarComponentAddedEvent;
34
 import com.dmdirc.events.StatusBarComponentRemovedEvent;
36
 import com.dmdirc.events.StatusBarComponentRemovedEvent;
44
 
46
 
45
 import javax.inject.Inject;
47
 import javax.inject.Inject;
46
 
48
 
49
+import net.engio.mbassy.listener.Handler;
50
+import net.engio.mbassy.listener.Invoke;
51
+
47
 /**
52
 /**
48
  * Displays information related to the current window in the status bar.
53
  * Displays information related to the current window in the status bar.
49
  */
54
  */
50
-public class WindowStatusManager implements ConfigChangeListener, SelectionListener {
55
+public class WindowStatusManager implements ConfigChangeListener {
51
 
56
 
52
     /** Active frame manager. */
57
     /** Active frame manager. */
53
     private final ActiveFrameManager activeFrameManager;
58
     private final ActiveFrameManager activeFrameManager;
57
     private final String domain;
62
     private final String domain;
58
     /** The event bus to post events to. */
63
     /** The event bus to post events to. */
59
     private final DMDircMBassador eventBus;
64
     private final DMDircMBassador eventBus;
65
+    /** The swing event bus to register for events on. */
66
+    private final DMDircMBassador swingEventBus;
60
     /** The panel we use in the status bar. */
67
     /** The panel we use in the status bar. */
61
     private WindowStatusPanel panel;
68
     private WindowStatusPanel panel;
62
     /** Should we show the real name in queries? */
69
     /** Should we show the real name in queries? */
70
     public WindowStatusManager(final ActiveFrameManager activeFrameManager,
77
     public WindowStatusManager(final ActiveFrameManager activeFrameManager,
71
             final IdentityController identityController,
78
             final IdentityController identityController,
72
             @PluginDomain(WindowStatusPlugin.class) final String domain,
79
             @PluginDomain(WindowStatusPlugin.class) final String domain,
73
-            final DMDircMBassador eventBus) {
80
+            final DMDircMBassador eventBus,
81
+            @SwingEventBus final DMDircMBassador swingEventBus) {
74
         this.domain = domain;
82
         this.domain = domain;
75
         this.activeFrameManager = activeFrameManager;
83
         this.activeFrameManager = activeFrameManager;
76
         this.identityController = identityController;
84
         this.identityController = identityController;
77
         this.eventBus = eventBus;
85
         this.eventBus = eventBus;
86
+        this.swingEventBus = swingEventBus;
78
     }
87
     }
79
 
88
 
80
     /**
89
     /**
89
             }
98
             }
90
         });
99
         });
91
         eventBus.publishAsync(new StatusBarComponentAddedEvent(panel));
100
         eventBus.publishAsync(new StatusBarComponentAddedEvent(panel));
92
-        activeFrameManager.addSelectionListener(this);
101
+        swingEventBus.subscribe(this);
93
         identityController.getGlobalConfiguration().addChangeListener(domain, this);
102
         identityController.getGlobalConfiguration().addChangeListener(domain, this);
94
         updateCache();
103
         updateCache();
95
     }
104
     }
98
      * Unloads the plugin.
107
      * Unloads the plugin.
99
      */
108
      */
100
     public void onUnload() {
109
     public void onUnload() {
101
-        activeFrameManager.removeSelectionListener(this);
110
+        swingEventBus.unsubscribe(this);
102
         eventBus.publishAsync(new StatusBarComponentRemovedEvent(panel));
111
         eventBus.publishAsync(new StatusBarComponentRemovedEvent(panel));
103
         panel = null;
112
         panel = null;
104
     }
113
     }
105
 
114
 
106
-    @Override
107
-    public void selectionChanged(final TextFrame window) {
108
-        if (window != null) {
109
-            updateStatus(window.getContainer());
115
+    @Handler(invocation = EdtHandlerInvocation.class, delivery = Invoke.Asynchronously)
116
+    public void selectionChanged(final SwingWindowSelectedEvent event) {
117
+        if (event.getWindow().isPresent()) {
118
+            updateStatus(event.getWindow().get().getContainer());
110
         }
119
         }
111
     }
120
     }
112
 
121
 

Loading…
Cancel
Save