瀏覽代碼

Inject the menu bar and menus.

Change-Id: Id49ecdf582679829f8cbc44f4e9ff0589edf90d3
Reviewed-on: http://gerrit.dmdirc.com/2920
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.8
Chris Smith 10 年之前
父節點
當前提交
1739163552

+ 16
- 4
src/com/dmdirc/addons/ui_swing/MainFrame.java 查看文件

@@ -375,10 +375,6 @@ public class MainFrame extends JFrame implements WindowListener,
375 375
         initFrameManagers();
376 376
         mainSplitPane = initSplitPane();
377 377
 
378
-        final MenuBar menu = new MenuBar(controller, windowFactory, this);
379
-        controller.getApple().setMenuBar(menu);
380
-        setJMenuBar(menu);
381
-
382 378
         setPreferredSize(new Dimension(800, 600));
383 379
 
384 380
         getContentPane().setLayout(new MigLayout(
@@ -390,6 +386,22 @@ public class MainFrame extends JFrame implements WindowListener,
390 386
         pack();
391 387
     }
392 388
 
389
+    /**
390
+     * Sets the menu bar that this frame will use.
391
+     *
392
+     * @param menuBar The menu bar to use.
393
+     */
394
+    public void setMenuBar(final MenuBar menuBar) {
395
+        UIUtilities.invokeAndWait(new Runnable() {
396
+            /** {@inheritDoc} */
397
+            @Override
398
+            public void run() {
399
+                controller.getApple().setMenuBar(menuBar);
400
+                setJMenuBar(menuBar);
401
+            }
402
+        });
403
+    }
404
+
393 405
     /**
394 406
      * Lays out the this component.
395 407
      */

+ 6
- 1
src/com/dmdirc/addons/ui_swing/SwingManager.java 查看文件

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing;
24 24
 
25
+import com.dmdirc.addons.ui_swing.components.menubar.MenuBar;
25 26
 import com.dmdirc.ui.WindowManager;
26 27
 
27 28
 import java.awt.Toolkit;
@@ -54,17 +55,21 @@ public class SwingManager {
54 55
      * @param windowFactory The window factory in use.
55 56
      * @param windowManager The window manager to listen on for events.
56 57
      * @param mainFrame The main frame of the Swing UI.
58
+     * @param menuBar The menu bar to use for the main frame.
57 59
      */
58 60
     @Inject
59 61
     public SwingManager(
60 62
             final DMDircEventQueue eventQueue,
61 63
             final SwingWindowFactory windowFactory,
62 64
             final WindowManager windowManager,
63
-            final MainFrame mainFrame) {
65
+            final MainFrame mainFrame,
66
+            final MenuBar menuBar) {
64 67
         this.eventQueue = eventQueue;
65 68
         this.windowFactory = windowFactory;
66 69
         this.windowManager = windowManager;
70
+
67 71
         this.mainFrame = mainFrame;
72
+        this.mainFrame.setMenuBar(menuBar);
68 73
     }
69 74
 
70 75
     /**

+ 4
- 0
src/com/dmdirc/addons/ui_swing/components/MDIBar.java 查看文件

@@ -34,6 +34,8 @@ import com.dmdirc.interfaces.config.ConfigChangeListener;
34 34
 import java.awt.event.ActionEvent;
35 35
 import java.awt.event.ActionListener;
36 36
 
37
+import javax.inject.Inject;
38
+import javax.inject.Singleton;
37 39
 import javax.swing.JPanel;
38 40
 import javax.swing.SwingUtilities;
39 41
 
@@ -42,6 +44,7 @@ import net.miginfocom.swing.MigLayout;
42 44
 /**
43 45
  * Provides an MDI style bar for closing frames.
44 46
  */
47
+@Singleton
45 48
 public class MDIBar extends JPanel implements SwingWindowListener,
46 49
         SelectionListener, ActionListener, ConfigChangeListener {
47 50
 
@@ -71,6 +74,7 @@ public class MDIBar extends JPanel implements SwingWindowListener,
71 74
      * @param windowFactory The window factory to use to create and listen for windows.
72 75
      * @param mainFrame Main frame instance
73 76
      */
77
+    @Inject
74 78
     public MDIBar(
75 79
             final SwingController controller,
76 80
             final SwingWindowFactory windowFactory,

+ 2
- 7
src/com/dmdirc/addons/ui_swing/components/frames/AppleJFrame.java 查看文件

@@ -24,8 +24,6 @@ package com.dmdirc.addons.ui_swing.components.frames;
24 24
 
25 25
 import com.dmdirc.addons.ui_swing.MainFrame;
26 26
 import com.dmdirc.addons.ui_swing.SwingController;
27
-import com.dmdirc.addons.ui_swing.SwingWindowFactory;
28
-import com.dmdirc.addons.ui_swing.components.menubar.MenuBar;
29 27
 
30 28
 import javax.swing.JFrame;
31 29
 
@@ -42,16 +40,13 @@ public class AppleJFrame extends JFrame {
42 40
      * Create a new Apple JFrame
43 41
      *
44 42
      * @param parentWindow Main Window
45
-     * @param windowFactory The window factory to use to create and listen for windows.
46 43
      * @param controller Parent swing controller
47 44
      */
48 45
     public AppleJFrame(
49 46
             final MainFrame parentWindow,
50
-            final SwingWindowFactory windowFactory,
51 47
             final SwingController controller) {
52 48
         super();
53
-        final MenuBar menu = new MenuBar(controller, windowFactory, parentWindow);
54
-        controller.getApple().setMenuBar(menu);
55
-        setJMenuBar(menu);
49
+        controller.getApple().setMenuBar(parentWindow.getJMenuBar());
50
+        setJMenuBar(parentWindow.getJMenuBar());
56 51
     }
57 52
 }

+ 7
- 3
src/com/dmdirc/addons/ui_swing/components/menubar/ChannelMenu.java 查看文件

@@ -35,6 +35,8 @@ import java.awt.Dialog.ModalityType;
35 35
 import java.awt.event.ActionEvent;
36 36
 import java.awt.event.ActionListener;
37 37
 
38
+import javax.inject.Inject;
39
+import javax.inject.Singleton;
38 40
 import javax.swing.JMenu;
39 41
 import javax.swing.JMenuItem;
40 42
 import javax.swing.event.MenuEvent;
@@ -43,6 +45,7 @@ import javax.swing.event.MenuListener;
43 45
 /**
44 46
  * A menu to provide channel related commands in the menu bar.
45 47
  */
48
+@Singleton
46 49
 public class ChannelMenu extends JMenu implements ActionListener,
47 50
         MenuListener {
48 51
 
@@ -65,7 +68,9 @@ public class ChannelMenu extends JMenu implements ActionListener,
65 68
      * @param controller Parent swing controller.
66 69
      * @param mainFrame Parent mainframe
67 70
      */
68
-    public ChannelMenu(final SwingController controller,
71
+    @Inject
72
+    public ChannelMenu(
73
+            final SwingController controller,
69 74
             final MainFrame mainFrame) {
70 75
         super("Channel");
71 76
         this.controller = controller;
@@ -112,8 +117,7 @@ public class ChannelMenu extends JMenu implements ActionListener,
112 117
                         .display();
113 118
                 break;
114 119
             case "ChannelSettings":
115
-                final FrameContainer activeWindow = controller.getMainFrame()
116
-                        .getActiveFrame().getContainer();
120
+                final FrameContainer activeWindow = mainFrame.getActiveFrame().getContainer();
117 121
                 if (activeWindow instanceof Channel) {
118 122
                     controller.showChannelSettingsDialog(((Channel) activeWindow));
119 123
                 }   break;

+ 4
- 0
src/com/dmdirc/addons/ui_swing/components/menubar/HelpMenu.java 查看文件

@@ -30,12 +30,15 @@ import com.dmdirc.addons.ui_swing.dialogs.about.AboutDialog;
30 30
 import java.awt.event.ActionEvent;
31 31
 import java.awt.event.ActionListener;
32 32
 
33
+import javax.inject.Inject;
34
+import javax.inject.Singleton;
33 35
 import javax.swing.JMenu;
34 36
 import javax.swing.JMenuItem;
35 37
 
36 38
 /**
37 39
  * A menu providing help commands to the menu bar.
38 40
  */
41
+@Singleton
39 42
 public class HelpMenu extends JMenu implements ActionListener {
40 43
 
41 44
     /** Serial version UID. */
@@ -48,6 +51,7 @@ public class HelpMenu extends JMenu implements ActionListener {
48 51
      *
49 52
      * @param controller Swing controller
50 53
      */
54
+    @Inject
51 55
     public HelpMenu(final SwingController controller) {
52 56
         super("Help");
53 57
         this.controller = controller;

+ 22
- 15
src/com/dmdirc/addons/ui_swing/components/menubar/MenuBar.java 查看文件

@@ -22,14 +22,13 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.components.menubar;
24 24
 
25
-import com.dmdirc.addons.ui_swing.MainFrame;
26
-import com.dmdirc.addons.ui_swing.SwingController;
27
-import com.dmdirc.addons.ui_swing.SwingWindowFactory;
28 25
 import com.dmdirc.addons.ui_swing.components.MDIBar;
29 26
 import com.dmdirc.addons.ui_swing.framemanager.windowmenu.WindowMenuFrameManager;
30 27
 
31 28
 import java.awt.Component;
32 29
 
30
+import javax.inject.Inject;
31
+import javax.inject.Singleton;
33 32
 import javax.swing.Box;
34 33
 import javax.swing.JMenu;
35 34
 import javax.swing.JMenuBar;
@@ -41,6 +40,7 @@ import net.miginfocom.swing.MigLayout;
41 40
 /**
42 41
  * DMDirc menu bar.
43 42
  */
43
+@Singleton
44 44
 public class MenuBar extends JMenuBar {
45 45
 
46 46
     /**
@@ -55,26 +55,33 @@ public class MenuBar extends JMenuBar {
55 55
     /**
56 56
      * Instantiates a new menu bar.
57 57
      *
58
-     * @param controller Swing controller
59
-     * @param windowFactory The window factory to use to create and listen for windows.
60
-     * @param mainFrame Main frame
58
+     * @param serverMenu The server menu to use.
59
+     * @param channelMenu The channel menu to use.
60
+     * @param settingsMenu The settings menu to use.
61
+     * @param windowMenu The window menu to use.
62
+     * @param helpMenu The help menu to use.
63
+     * @param mdiBar The MDI bar to use.
61 64
      */
65
+    @Inject
62 66
     public MenuBar(
63
-            final SwingController controller,
64
-            final SwingWindowFactory windowFactory,
65
-            final MainFrame mainFrame) {
67
+            final ServerMenu serverMenu,
68
+            final ChannelMenu channelMenu,
69
+            final SettingsMenu settingsMenu,
70
+            final WindowMenuFrameManager windowMenu,
71
+            final HelpMenu helpMenu,
72
+            final MDIBar mdiBar) {
66 73
         super();
67 74
 
68 75
         setLayout(new MigLayout("ins 0, fillx"));
69 76
 
70
-        add(new ServerMenu(controller, mainFrame));
71
-        add(new ChannelMenu(controller, mainFrame));
72
-        add(new SettingsMenu(controller));
73
-        add(new WindowMenuFrameManager(controller, windowFactory, mainFrame));
74
-        add(new HelpMenu(controller));
77
+        add(serverMenu);
78
+        add(channelMenu);
79
+        add(settingsMenu);
80
+        add(windowMenu);
81
+        add(helpMenu);
75 82
         final int tempCount = getComponentCount();
76 83
         add(Box.createHorizontalGlue(), "growx, pushx");
77
-        add(new MDIBar(controller, windowFactory, mainFrame));
84
+        add(mdiBar);
78 85
         add(Box.createHorizontalStrut(PlatformDefaults.getPanelInsets(1)
79 86
                 .getUnit()));
80 87
         menuItemCount = getComponentCount() - tempCount;

+ 9
- 5
src/com/dmdirc/addons/ui_swing/components/menubar/ServerMenu.java 查看文件

@@ -33,6 +33,8 @@ import com.dmdirc.addons.ui_swing.dialogs.NewServerDialog;
33 33
 import java.awt.event.ActionEvent;
34 34
 import java.awt.event.ActionListener;
35 35
 
36
+import javax.inject.Inject;
37
+import javax.inject.Singleton;
36 38
 import javax.swing.JMenu;
37 39
 import javax.swing.JMenuItem;
38 40
 import javax.swing.event.MenuEvent;
@@ -41,6 +43,7 @@ import javax.swing.event.MenuListener;
41 43
 /**
42 44
  * A menu providing server related commands to the menu bar.
43 45
  */
46
+@Singleton
44 47
 public class ServerMenu extends JMenu implements ActionListener,
45 48
         MenuListener {
46 49
 
@@ -63,7 +66,9 @@ public class ServerMenu extends JMenu implements ActionListener,
63 66
      * @param controller Parent swing controller
64 67
      * @param mainFrame Parent main frame
65 68
      */
66
-    public ServerMenu(final SwingController controller,
69
+    @Inject
70
+    public ServerMenu(
71
+            final SwingController controller,
67 72
             final MainFrame mainFrame) {
68 73
         super("Server");
69 74
         this.controller = controller;
@@ -120,12 +125,11 @@ public class ServerMenu extends JMenu implements ActionListener,
120 125
                 mainFrame.quit();
121 126
                 break;
122 127
             case "ServerSettings":
123
-                controller.showServerSettingsDialog(controller.getMainFrame()
124
-                        .getActiveFrame().getContainer().getServer());
128
+                controller.showServerSettingsDialog(
129
+                        mainFrame.getActiveFrame().getContainer().getServer());
125 130
                 break;
126 131
             case "Disconnect":
127
-                controller.getMainFrame().getActiveFrame().getContainer()
128
-                        .getServer().disconnect();
132
+                mainFrame.getActiveFrame().getContainer().getServer().disconnect();
129 133
                 break;
130 134
         }
131 135
     }

+ 4
- 0
src/com/dmdirc/addons/ui_swing/components/menubar/SettingsMenu.java 查看文件

@@ -32,12 +32,15 @@ import com.dmdirc.addons.ui_swing.dialogs.profiles.ProfileManagerDialog;
32 32
 import java.awt.event.ActionEvent;
33 33
 import java.awt.event.ActionListener;
34 34
 
35
+import javax.inject.Inject;
36
+import javax.inject.Singleton;
35 37
 import javax.swing.JMenu;
36 38
 import javax.swing.JMenuItem;
37 39
 
38 40
 /**
39 41
  * A menu to add settings related commands to the menu bar.
40 42
  */
43
+@Singleton
41 44
 public class SettingsMenu extends JMenu implements ActionListener {
42 45
 
43 46
     /** Serial version UID. */
@@ -45,6 +48,7 @@ public class SettingsMenu extends JMenu implements ActionListener {
45 48
     /** Swing controller. */
46 49
     private final SwingController controller;
47 50
 
51
+    @Inject
48 52
     public SettingsMenu(final SwingController controller) {
49 53
         super("Settings");
50 54
         this.controller = controller;

+ 3
- 3
src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionsManagerDialog.java 查看文件

@@ -108,9 +108,9 @@ public final class ActionsManagerDialog extends StandardDialog implements
108 108
     @SuppressWarnings("unchecked")
109 109
     public ActionsManagerDialog(final Window parentWindow,
110 110
             final SwingController controller) {
111
-        super(controller, Apple.isAppleUI() ?
112
-                new AppleJFrame((MainFrame) parentWindow,
113
-                controller.getWindowFactory(), controller) : null, ModalityType.MODELESS);
111
+        super(controller, Apple.isAppleUI()
112
+                ? new AppleJFrame((MainFrame) parentWindow, controller)
113
+                : null, ModalityType.MODELESS);
114 114
 
115 115
         initComponents();
116 116
         validator = new ValidatorChain<>(

+ 5
- 1
src/com/dmdirc/addons/ui_swing/framemanager/windowmenu/WindowMenuFrameManager.java 查看文件

@@ -43,6 +43,8 @@ import java.util.Map;
43 43
 import java.util.concurrent.Callable;
44 44
 import java.util.concurrent.atomic.AtomicBoolean;
45 45
 
46
+import javax.inject.Inject;
47
+import javax.inject.Singleton;
46 48
 import javax.swing.AbstractButton;
47 49
 import javax.swing.JMenu;
48 50
 import javax.swing.JMenuItem;
@@ -52,7 +54,8 @@ import javax.swing.JSeparator;
52 54
 /**
53 55
  * Manages the window menu window list.
54 56
  */
55
-public final class WindowMenuFrameManager extends JMenu implements
57
+@Singleton
58
+public class WindowMenuFrameManager extends JMenu implements
56 59
         SwingWindowListener, ActionListener, SelectionListener {
57 60
 
58 61
     /**
@@ -86,6 +89,7 @@ public final class WindowMenuFrameManager extends JMenu implements
86 89
      * @param windowFactory The window factory to use to create and listen for windows.
87 90
      * @param mainFrame The frame that owns this manager
88 91
      */
92
+    @Inject
89 93
     public WindowMenuFrameManager(
90 94
             final SwingController controller,
91 95
             final SwingWindowFactory windowFactory,

Loading…
取消
儲存