Explorar el Código

Add an event for frame opened.

For some reason this was only exposed through the WindowManager
listeners.
pull/699/head
Chris Smith hace 8 años
padre
commit
61dd0758bd

+ 28
- 0
src/main/java/com/dmdirc/events/FrameOpenedEvent.java Ver fichero

1
+package com.dmdirc.events;
2
+
3
+import com.dmdirc.interfaces.WindowModel;
4
+
5
+import java.util.Optional;
6
+
7
+/**
8
+ * Fired when a new window is opened.
9
+ */
10
+public class FrameOpenedEvent extends FrameEvent {
11
+
12
+    private final Optional<WindowModel> parent;
13
+
14
+    public FrameOpenedEvent(final WindowModel source, final WindowModel parent) {
15
+        super(source);
16
+        this.parent = Optional.of(parent);
17
+    }
18
+
19
+    public FrameOpenedEvent(final WindowModel source) {
20
+        super(source);
21
+        this.parent = Optional.empty();
22
+    }
23
+
24
+    public Optional<WindowModel> getParent() {
25
+        return parent;
26
+    }
27
+
28
+}

+ 7
- 1
src/main/java/com/dmdirc/ui/WindowManager.java Ver fichero

26
 import com.dmdirc.DMDircMBassador;
26
 import com.dmdirc.DMDircMBassador;
27
 import com.dmdirc.Precondition;
27
 import com.dmdirc.Precondition;
28
 import com.dmdirc.events.FrameClosingEvent;
28
 import com.dmdirc.events.FrameClosingEvent;
29
+import com.dmdirc.events.FrameOpenedEvent;
29
 import com.dmdirc.interfaces.WindowModel;
30
 import com.dmdirc.interfaces.WindowModel;
30
 import com.dmdirc.interfaces.ui.FrameListener;
31
 import com.dmdirc.interfaces.ui.FrameListener;
31
 import com.dmdirc.util.collections.ListenerList;
32
 import com.dmdirc.util.collections.ListenerList;
67
     private final ListenerList listeners = new ListenerList();
68
     private final ListenerList listeners = new ListenerList();
68
     /** Counter to use for ID assignments. */
69
     /** Counter to use for ID assignments. */
69
     private final AtomicLong nextId = new AtomicLong(0L);
70
     private final AtomicLong nextId = new AtomicLong(0L);
71
+    /** Event bus to dispatch window events on. */
72
+    private final DMDircMBassador eventBus;
70
 
73
 
71
     /**
74
     /**
72
      * Creates a new instance of {@link WindowManager}.
75
      * Creates a new instance of {@link WindowManager}.
73
      */
76
      */
74
     @Inject
77
     @Inject
75
     public WindowManager(final DMDircMBassador eventBus) {
78
     public WindowManager(final DMDircMBassador eventBus) {
79
+        this.eventBus = eventBus;
76
         eventBus.subscribe(this);
80
         eventBus.subscribe(this);
77
     }
81
     }
78
 
82
 
238
      *
242
      *
239
      * @return True if the target is in the hierarchy, false otherwise
243
      * @return True if the target is in the hierarchy, false otherwise
240
      */
244
      */
241
-    protected boolean isInHierarchy(final WindowModel target) {
245
+    private boolean isInHierarchy(final WindowModel target) {
242
         return rootWindows.contains(target) || parents.containsKey(target);
246
         return rootWindows.contains(target) || parents.containsKey(target);
243
     }
247
     }
244
 
248
 
366
      * @param focus  Should this window become focused
370
      * @param focus  Should this window become focused
367
      */
371
      */
368
     private void fireAddWindow(final WindowModel window, final boolean focus) {
372
     private void fireAddWindow(final WindowModel window, final boolean focus) {
373
+        eventBus.publishAsync(new FrameOpenedEvent(window));
369
         for (FrameListener listener : listeners.get(FrameListener.class)) {
374
         for (FrameListener listener : listeners.get(FrameListener.class)) {
370
             listener.addWindow(window, focus);
375
             listener.addWindow(window, focus);
371
         }
376
         }
381
      */
386
      */
382
     private void fireAddWindow(final WindowModel parent,
387
     private void fireAddWindow(final WindowModel parent,
383
             final WindowModel child, final boolean focus) {
388
             final WindowModel child, final boolean focus) {
389
+        eventBus.publishAsync(new FrameOpenedEvent(child, parent));
384
         for (FrameListener listener : listeners.get(FrameListener.class)) {
390
         for (FrameListener listener : listeners.get(FrameListener.class)) {
385
             listener.addWindow(parent, child, focus);
391
             listener.addWindow(parent, child, focus);
386
         }
392
         }

Loading…
Cancelar
Guardar