Просмотр исходного кода

Use frame info events in Button bar.

Change-Id: Ief1c6c123935ccf9faadba374caec8829c4f5efd
Reviewed-on: http://gerrit.dmdirc.com/3763
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
changes/63/3763/2
Greg Holmes 9 лет назад
Родитель
Сommit
c20831aa1e
1 измененных файлов: 19 добавлений и 76 удалений
  1. 19
    76
      src/com/dmdirc/addons/ui_swing/framemanager/buttonbar/ButtonBar.java

+ 19
- 76
src/com/dmdirc/addons/ui_swing/framemanager/buttonbar/ButtonBar.java Просмотреть файл

@@ -34,7 +34,8 @@ import com.dmdirc.addons.ui_swing.events.SwingWindowDeletedEvent;
34 34
 import com.dmdirc.addons.ui_swing.framemanager.FrameManager;
35 35
 import com.dmdirc.addons.ui_swing.framemanager.FramemanagerPosition;
36 36
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
37
-import com.dmdirc.interfaces.FrameInfoListener;
37
+import com.dmdirc.events.FrameIconChangedEvent;
38
+import com.dmdirc.events.FrameNameChangedEvent;
38 39
 import com.dmdirc.interfaces.NotificationListener;
39 40
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
40 41
 import com.dmdirc.interfaces.config.ConfigChangeListener;
@@ -43,6 +44,7 @@ import com.dmdirc.ui.Colour;
43 44
 import com.dmdirc.ui.WindowManager;
44 45
 
45 46
 import com.google.common.base.Optional;
47
+import com.google.common.eventbus.EventBus;
46 48
 import com.google.common.eventbus.Subscribe;
47 49
 
48 50
 import java.awt.Dimension;
@@ -77,7 +79,7 @@ import net.miginfocom.swing.MigLayout;
77 79
  */
78 80
 public final class ButtonBar implements FrameManager, ActionListener,
79 81
         ComponentListener, Serializable, NotificationListener,
80
-        FrameInfoListener, MouseListener, ConfigChangeListener {
82
+        MouseListener, ConfigChangeListener {
81 83
 
82 84
     /** Serial version UID. */
83 85
     private static final long serialVersionUID = 3;
@@ -127,12 +129,15 @@ public final class ButtonBar implements FrameManager, ActionListener,
127 129
             final SwingWindowFactory windowFactory,
128 130
             @GlobalConfig final AggregateConfigProvider globalConfig,
129 131
             final WindowManager windowManager,
130
-            final ActiveFrameManager activeFrameManager) {
132
+            final ActiveFrameManager activeFrameManager,
133
+            final EventBus eventBus) {
131 134
         this.windowFactory = windowFactory;
132 135
         this.globalConfig = globalConfig;
133 136
         this.windowManager = windowManager;
134 137
         this.activeFrameManager = activeFrameManager;
135 138
 
139
+        eventBus.register(this);
140
+
136 141
         scrollPane = new JScrollPane();
137 142
         scrollPane.setBorder(null);
138 143
         scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
@@ -185,7 +190,7 @@ public final class ButtonBar implements FrameManager, ActionListener,
185 190
     @Override
186 191
     public void setParent(final JComponent parent) {
187 192
         SwingUtilities.invokeLater(new Runnable() {
188
-            /** {inheritDoc} */
193
+
189 194
             @Override
190 195
             public void run() {
191 196
                 ButtonBar.this.parent = parent;
@@ -215,7 +220,6 @@ public final class ButtonBar implements FrameManager, ActionListener,
215 220
      *
216 221
      * @param windowCollection Collection of windows {@link FrameContainer}
217 222
      *
218
-     * @author Simon Mott
219 223
      * @since 0.6.4
220 224
      */
221 225
     private void initButtons(
@@ -260,7 +264,6 @@ public final class ButtonBar implements FrameManager, ActionListener,
260 264
      *
261 265
      * @param windowCollection Collection of windows {@link FrameContainer}
262 266
      *
263
-     * @author Simon Mott
264 267
      * @since 0.6.4
265 268
      */
266 269
     private void displayButtons(
@@ -339,7 +342,6 @@ public final class ButtonBar implements FrameManager, ActionListener,
339 342
                 addButton(window);
340 343
                 relayout();
341 344
                 window.getContainer().addNotificationListener(ButtonBar.this);
342
-                window.getContainer().addFrameInfoListener(ButtonBar.this);
343 345
             }
344 346
         });
345 347
     }
@@ -351,9 +353,7 @@ public final class ButtonBar implements FrameManager, ActionListener,
351 353
 
352 354
             @Override
353 355
             public void run() {
354
-                window.getContainer().removeNotificationListener(
355
-                        ButtonBar.this);
356
-                window.getContainer().removeFrameInfoListener(ButtonBar.this);
356
+                window.getContainer().removeNotificationListener(ButtonBar.this);
357 357
                 if (buttons.containsKey(window)) {
358 358
                     buttonPanel.setVisible(false);
359 359
                     buttonPanel.remove(buttons.get(window));
@@ -364,11 +364,6 @@ public final class ButtonBar implements FrameManager, ActionListener,
364 364
         });
365 365
     }
366 366
 
367
-    /**
368
-     * Called when the user clicks on one of the buttons.
369
-     *
370
-     * @param e The action event associated with this action
371
-     */
372 367
     @Override
373 368
     public void actionPerformed(final ActionEvent e) {
374 369
         final FrameToggleButton button = (FrameToggleButton) e.getSource();
@@ -380,43 +375,22 @@ public final class ButtonBar implements FrameManager, ActionListener,
380 375
         activeFrameManager.setActiveFrame(frame);
381 376
     }
382 377
 
383
-    /**
384
-     * Called when the parent component is resized.
385
-     *
386
-     * @param e A ComponentEvent corresponding to this event.
387
-     */
388 378
     @Override
389 379
     public void componentResized(final ComponentEvent e) {
390
-        buttonWidth = position.isHorizontal() ? 150
391
-                : (parent.getWidth() / NUM_CELLS);
380
+        buttonWidth = position.isHorizontal() ? 150 : (parent.getWidth() / NUM_CELLS);
392 381
         relayout();
393 382
     }
394 383
 
395
-    /**
396
-     * Called when the parent component is moved.
397
-     *
398
-     * @param e A ComponentEvent corresponding to this event.
399
-     */
400 384
     @Override
401 385
     public void componentMoved(final ComponentEvent e) {
402 386
         // Do nothing
403 387
     }
404 388
 
405
-    /**
406
-     * Called when the parent component is made visible.
407
-     *
408
-     * @param e A ComponentEvent corresponding to this event.
409
-     */
410 389
     @Override
411 390
     public void componentShown(final ComponentEvent e) {
412 391
         // Do nothing
413 392
     }
414 393
 
415
-    /**
416
-     * Called when the parent component is made invisible.
417
-     *
418
-     * @param e A ComponentEvent corresponding to this event.
419
-     */
420 394
     @Override
421 395
     public void componentHidden(final ComponentEvent e) {
422 396
         // Do nothing
@@ -473,40 +447,34 @@ public final class ButtonBar implements FrameManager, ActionListener,
473 447
         });
474 448
     }
475 449
 
476
-    @Override
477
-    public void iconChanged(final FrameContainer window, final String icon) {
450
+    @Subscribe
451
+    public void iconChanged(final FrameIconChangedEvent event) {
478 452
         UIUtilities.invokeLater(new Runnable() {
479 453
 
480 454
             @Override
481 455
             public void run() {
482
-                final FrameToggleButton button = getButton(window);
456
+                final FrameToggleButton button = getButton(event.getContainer());
483 457
                 if (button != null) {
484
-                    button.setIcon(window.getIconManager().getIcon(icon));
458
+                    button.setIcon(event.getContainer().getIconManager().getIcon(event.getIcon()));
485 459
                 }
486 460
             }
487 461
         });
488 462
     }
489 463
 
490
-    @Override
491
-    public void nameChanged(final FrameContainer window, final String name) {
464
+    @Subscribe
465
+    public void nameChanged(final FrameNameChangedEvent event) {
492 466
         UIUtilities.invokeLater(new Runnable() {
493 467
 
494 468
             @Override
495 469
             public void run() {
496
-                final FrameToggleButton button = getButton(window);
470
+                final FrameToggleButton button = getButton(event.getContainer());
497 471
                 if (button != null) {
498
-                    button.setText(name);
472
+                    button.setText(event.getName());
499 473
                 }
500 474
             }
501 475
         });
502 476
     }
503 477
 
504
-    @Override
505
-    public void titleChanged(final FrameContainer window,
506
-            final String title) {
507
-        // Do nothing
508
-    }
509
-
510 478
     /**
511 479
      * Creates and displays a Popup menu for the button that was clicked.
512 480
      *
@@ -529,51 +497,26 @@ public final class ButtonBar implements FrameManager, ActionListener,
529 497
         }
530 498
     }
531 499
 
532
-    /**
533
-     * {@inheritDoc}
534
-     *
535
-     * @param e MouseEvent for this event
536
-     */
537 500
     @Override
538 501
     public void mouseClicked(final MouseEvent e) {
539 502
         processMouseEvents(e);
540 503
     }
541 504
 
542
-    /**
543
-     * {@inheritDoc}
544
-     *
545
-     * @param e MouseEvent for this event
546
-     */
547 505
     @Override
548 506
     public void mousePressed(final MouseEvent e) {
549 507
         processMouseEvents(e);
550 508
     }
551 509
 
552
-    /**
553
-     * {@inheritDoc}
554
-     *
555
-     * @param e MouseEvent for this event
556
-     */
557 510
     @Override
558 511
     public void mouseReleased(final MouseEvent e) {
559 512
         processMouseEvents(e);
560 513
     }
561 514
 
562
-    /**
563
-     * {@inheritDoc}
564
-     *
565
-     * @param e MouseEvent for this event
566
-     */
567 515
     @Override
568 516
     public void mouseEntered(final MouseEvent e) {
569 517
         //Do nothing
570 518
     }
571 519
 
572
-    /**
573
-     * {@inheritDoc}
574
-     *
575
-     * @param e MouseEvent for this event
576
-     */
577 520
     @Override
578 521
     public void mouseExited(final MouseEvent e) {
579 522
         //Do nothing

Загрузка…
Отмена
Сохранить