Kaynağa Gözat

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 yıl önce
ebeveyn
işleme
1739163552

+ 16
- 4
src/com/dmdirc/addons/ui_swing/MainFrame.java Dosyayı Görüntüle

375
         initFrameManagers();
375
         initFrameManagers();
376
         mainSplitPane = initSplitPane();
376
         mainSplitPane = initSplitPane();
377
 
377
 
378
-        final MenuBar menu = new MenuBar(controller, windowFactory, this);
379
-        controller.getApple().setMenuBar(menu);
380
-        setJMenuBar(menu);
381
-
382
         setPreferredSize(new Dimension(800, 600));
378
         setPreferredSize(new Dimension(800, 600));
383
 
379
 
384
         getContentPane().setLayout(new MigLayout(
380
         getContentPane().setLayout(new MigLayout(
390
         pack();
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
      * Lays out the this component.
406
      * Lays out the this component.
395
      */
407
      */

+ 6
- 1
src/com/dmdirc/addons/ui_swing/SwingManager.java Dosyayı Görüntüle

22
 
22
 
23
 package com.dmdirc.addons.ui_swing;
23
 package com.dmdirc.addons.ui_swing;
24
 
24
 
25
+import com.dmdirc.addons.ui_swing.components.menubar.MenuBar;
25
 import com.dmdirc.ui.WindowManager;
26
 import com.dmdirc.ui.WindowManager;
26
 
27
 
27
 import java.awt.Toolkit;
28
 import java.awt.Toolkit;
54
      * @param windowFactory The window factory in use.
55
      * @param windowFactory The window factory in use.
55
      * @param windowManager The window manager to listen on for events.
56
      * @param windowManager The window manager to listen on for events.
56
      * @param mainFrame The main frame of the Swing UI.
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
     @Inject
60
     @Inject
59
     public SwingManager(
61
     public SwingManager(
60
             final DMDircEventQueue eventQueue,
62
             final DMDircEventQueue eventQueue,
61
             final SwingWindowFactory windowFactory,
63
             final SwingWindowFactory windowFactory,
62
             final WindowManager windowManager,
64
             final WindowManager windowManager,
63
-            final MainFrame mainFrame) {
65
+            final MainFrame mainFrame,
66
+            final MenuBar menuBar) {
64
         this.eventQueue = eventQueue;
67
         this.eventQueue = eventQueue;
65
         this.windowFactory = windowFactory;
68
         this.windowFactory = windowFactory;
66
         this.windowManager = windowManager;
69
         this.windowManager = windowManager;
70
+
67
         this.mainFrame = mainFrame;
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 Dosyayı Görüntüle

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

+ 2
- 7
src/com/dmdirc/addons/ui_swing/components/frames/AppleJFrame.java Dosyayı Görüntüle

24
 
24
 
25
 import com.dmdirc.addons.ui_swing.MainFrame;
25
 import com.dmdirc.addons.ui_swing.MainFrame;
26
 import com.dmdirc.addons.ui_swing.SwingController;
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
 import javax.swing.JFrame;
28
 import javax.swing.JFrame;
31
 
29
 
42
      * Create a new Apple JFrame
40
      * Create a new Apple JFrame
43
      *
41
      *
44
      * @param parentWindow Main Window
42
      * @param parentWindow Main Window
45
-     * @param windowFactory The window factory to use to create and listen for windows.
46
      * @param controller Parent swing controller
43
      * @param controller Parent swing controller
47
      */
44
      */
48
     public AppleJFrame(
45
     public AppleJFrame(
49
             final MainFrame parentWindow,
46
             final MainFrame parentWindow,
50
-            final SwingWindowFactory windowFactory,
51
             final SwingController controller) {
47
             final SwingController controller) {
52
         super();
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 Dosyayı Görüntüle

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

+ 4
- 0
src/com/dmdirc/addons/ui_swing/components/menubar/HelpMenu.java Dosyayı Görüntüle

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

+ 22
- 15
src/com/dmdirc/addons/ui_swing/components/menubar/MenuBar.java Dosyayı Görüntüle

22
 
22
 
23
 package com.dmdirc.addons.ui_swing.components.menubar;
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
 import com.dmdirc.addons.ui_swing.components.MDIBar;
25
 import com.dmdirc.addons.ui_swing.components.MDIBar;
29
 import com.dmdirc.addons.ui_swing.framemanager.windowmenu.WindowMenuFrameManager;
26
 import com.dmdirc.addons.ui_swing.framemanager.windowmenu.WindowMenuFrameManager;
30
 
27
 
31
 import java.awt.Component;
28
 import java.awt.Component;
32
 
29
 
30
+import javax.inject.Inject;
31
+import javax.inject.Singleton;
33
 import javax.swing.Box;
32
 import javax.swing.Box;
34
 import javax.swing.JMenu;
33
 import javax.swing.JMenu;
35
 import javax.swing.JMenuBar;
34
 import javax.swing.JMenuBar;
41
 /**
40
 /**
42
  * DMDirc menu bar.
41
  * DMDirc menu bar.
43
  */
42
  */
43
+@Singleton
44
 public class MenuBar extends JMenuBar {
44
 public class MenuBar extends JMenuBar {
45
 
45
 
46
     /**
46
     /**
55
     /**
55
     /**
56
      * Instantiates a new menu bar.
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
     public MenuBar(
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
         super();
73
         super();
67
 
74
 
68
         setLayout(new MigLayout("ins 0, fillx"));
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
         final int tempCount = getComponentCount();
82
         final int tempCount = getComponentCount();
76
         add(Box.createHorizontalGlue(), "growx, pushx");
83
         add(Box.createHorizontalGlue(), "growx, pushx");
77
-        add(new MDIBar(controller, windowFactory, mainFrame));
84
+        add(mdiBar);
78
         add(Box.createHorizontalStrut(PlatformDefaults.getPanelInsets(1)
85
         add(Box.createHorizontalStrut(PlatformDefaults.getPanelInsets(1)
79
                 .getUnit()));
86
                 .getUnit()));
80
         menuItemCount = getComponentCount() - tempCount;
87
         menuItemCount = getComponentCount() - tempCount;

+ 9
- 5
src/com/dmdirc/addons/ui_swing/components/menubar/ServerMenu.java Dosyayı Görüntüle

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

+ 4
- 0
src/com/dmdirc/addons/ui_swing/components/menubar/SettingsMenu.java Dosyayı Görüntüle

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

+ 3
- 3
src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionsManagerDialog.java Dosyayı Görüntüle

108
     @SuppressWarnings("unchecked")
108
     @SuppressWarnings("unchecked")
109
     public ActionsManagerDialog(final Window parentWindow,
109
     public ActionsManagerDialog(final Window parentWindow,
110
             final SwingController controller) {
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
         initComponents();
115
         initComponents();
116
         validator = new ValidatorChain<>(
116
         validator = new ValidatorChain<>(

+ 5
- 1
src/com/dmdirc/addons/ui_swing/framemanager/windowmenu/WindowMenuFrameManager.java Dosyayı Görüntüle

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

Loading…
İptal
Kaydet