Przeglądaj źródła

Tidy up window menu related stuff.

Change-Id: I36bbfd5f067ab32b60ba971a969121556f58a576
Reviewed-on: http://gerrit.dmdirc.com/3282
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
changes/82/3282/3
Chris Smith 10 lat temu
rodzic
commit
c7aa0faa90

+ 20
- 14
src/com/dmdirc/addons/ui_swing/framemanager/windowmenu/FrameContainerMenu.java Wyświetl plik

@@ -27,6 +27,7 @@ import com.dmdirc.addons.ui_swing.SelectionListener;
27 27
 import com.dmdirc.addons.ui_swing.SwingController;
28 28
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
29 29
 import com.dmdirc.interfaces.FrameInfoListener;
30
+import com.dmdirc.interfaces.config.AggregateConfigProvider;
30 31
 
31 32
 import java.awt.Font;
32 33
 import java.awt.event.ActionEvent;
@@ -41,33 +42,39 @@ import javax.swing.SwingUtilities;
41 42
 public class FrameContainerMenu extends JMenu implements FrameInfoListener,
42 43
         ActionListener, SelectionListener, FrameContainerMenuInterface {
43 44
 
44
-    /**
45
-     * A version number for this class. It should be changed whenever the class structure is changed
46
-     * (or anything else that would prevent serialized objects being unserialized with the new
47
-     * class).
48
-     */
45
+    /** A version number for this class. */
49 46
     private static final long serialVersionUID = 1;
50 47
     /** The swing controller that owns this item. */
51 48
     private final SwingController controller;
49
+    /** The swing frame. */
50
+    private final TextFrame window;
52 51
     /** Wrapped frame. */
53 52
     private final FrameContainer frame;
54 53
 
55 54
     /**
56 55
      * Instantiates a new FrameContainer menu item wrapping the specified frame.
57 56
      *
58
-     * @param frame      Wrapped frame
59
-     * @param controller Controller
57
+     * @param controller   Controller
58
+     * @param globalConfig The config to read settings from
59
+     * @param domain       The domain to read settings from
60
+     * @param window       The swing window being wrapped
61
+     * @param frame        Wrapped frame
60 62
      */
61
-    public FrameContainerMenu(final FrameContainer frame,
62
-            final SwingController controller) {
63
+    public FrameContainerMenu(
64
+            final SwingController controller,
65
+            final AggregateConfigProvider globalConfig,
66
+            final String domain,
67
+            final TextFrame window,
68
+            final FrameContainer frame) {
63 69
         super(frame.getName());
64
-        setIcon(frame.getIconManager().getIcon(frame.getIcon()));
65
-        new WindowMenuScroller(this, controller.getGlobalConfig(),
66
-                controller.getDomain(), 0);
67 70
 
68 71
         this.controller = controller;
72
+        this.window = window;
69 73
         this.frame = frame;
70 74
 
75
+        setIcon(frame.getIconManager().getIcon(frame.getIcon()));
76
+        new WindowMenuScroller(this, globalConfig, domain, 0);
77
+
71 78
         addActionListener(this);
72 79
         frame.addFrameInfoListener(this);
73 80
     }
@@ -110,8 +117,7 @@ public class FrameContainerMenu extends JMenu implements FrameInfoListener,
110 117
      */
111 118
     @Override
112 119
     public void actionPerformed(final ActionEvent e) {
113
-        controller.requestWindowFocus(controller.getWindowFactory()
114
-                .getSwingWindow(frame));
120
+        controller.requestWindowFocus(window);
115 121
     }
116 122
 
117 123
     @Override

+ 10
- 15
src/com/dmdirc/addons/ui_swing/framemanager/windowmenu/FrameContainerMenuItem.java Wyświetl plik

@@ -42,16 +42,14 @@ import javax.swing.SwingUtilities;
42 42
 public class FrameContainerMenuItem extends JMenuItem implements FrameInfoListener,
43 43
         ActionListener, SelectionListener, FrameContainerMenuInterface {
44 44
 
45
-    /**
46
-     * A version number for this class. It should be changed whenever the class structure is changed
47
-     * (or anything else that would prevent serialized objects being unserialized with the new
48
-     * class).
49
-     */
45
+    /** A version number for this class. */
50 46
     private static final long serialVersionUID = 1;
51 47
     /** The swing controller that owns this item. */
52 48
     private final SwingController controller;
53 49
     /** Wrapped frame. */
54 50
     private final FrameContainer frame;
51
+    /** Swing window. */
52
+    private final TextFrame window;
55 53
     /** Parent window menu frame manager. */
56 54
     private final WindowMenuFrameManager manager;
57 55
 
@@ -60,16 +58,19 @@ public class FrameContainerMenuItem extends JMenuItem implements FrameInfoListen
60 58
      *
61 59
      * @param controller The Swing Controller that owns this item
62 60
      * @param frame      Wrapped frame
61
+     * @param window     The window this menu item corresponds to.
63 62
      * @param manager    Parent window menu frame manager.
64 63
      */
65
-    public FrameContainerMenuItem(final SwingController controller,
64
+    public FrameContainerMenuItem(
65
+            final SwingController controller,
66 66
             final FrameContainer frame,
67
+            final TextFrame window,
67 68
             final WindowMenuFrameManager manager) {
68
-        super(frame.getName(),
69
-                frame.getIconManager().getIcon(frame.getIcon()));
69
+        super(frame.getName(), frame.getIconManager().getIcon(frame.getIcon()));
70 70
 
71 71
         this.controller = controller;
72 72
         this.frame = frame;
73
+        this.window = window;
73 74
         this.manager = manager;
74 75
 
75 76
         addActionListener(this);
@@ -107,15 +108,9 @@ public class FrameContainerMenuItem extends JMenuItem implements FrameInfoListen
107 108
         // Do nothing
108 109
     }
109 110
 
110
-    /**
111
-     * {@inheritDoc}
112
-     *
113
-     * @param e Action event
114
-     */
115 111
     @Override
116 112
     public void actionPerformed(final ActionEvent e) {
117
-        controller.requestWindowFocus(controller.getWindowFactory()
118
-                .getSwingWindow(frame));
113
+        controller.requestWindowFocus(window);
119 114
     }
120 115
 
121 116
     @Override

+ 38
- 15
src/com/dmdirc/addons/ui_swing/framemanager/windowmenu/WindowMenuFrameManager.java Wyświetl plik

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.framemanager.windowmenu;
24 24
 
25
+import com.dmdirc.ClientModule.GlobalConfig;
25 26
 import com.dmdirc.FrameContainer;
26 27
 import com.dmdirc.FrameContainerComparator;
27 28
 import com.dmdirc.addons.ui_swing.MainFrame;
@@ -31,6 +32,9 @@ import com.dmdirc.addons.ui_swing.SwingWindowFactory;
31 32
 import com.dmdirc.addons.ui_swing.SwingWindowListener;
32 33
 import com.dmdirc.addons.ui_swing.UIUtilities;
33 34
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
35
+import com.dmdirc.interfaces.config.AggregateConfigProvider;
36
+import com.dmdirc.plugins.PluginDomain;
37
+import com.dmdirc.ui.IconManager;
34 38
 
35 39
 import java.awt.Component;
36 40
 import java.awt.event.ActionEvent;
@@ -81,20 +85,32 @@ public class WindowMenuFrameManager extends JMenu implements
81 85
     private final Map<FrameContainer, FrameContainerMenuItem> items;
82 86
     private final Map<FrameContainer, FrameContainerMenuItem> menuItems;
83 87
 
88
+    private final MainFrame mainFrame;
89
+    private final AggregateConfigProvider globalConfig;
90
+    private final String domain;
91
+
84 92
     /**
85 93
      * Creates a new instance of WindowMenuFrameManager.
86 94
      *
87 95
      * @param controller    Swing controller
96
+     * @param iconManager   Icon manager to use for window icons.
97
+     * @param globalConfig  Config to read settings from.
98
+     * @param domain        Domain to read settings from.
88 99
      * @param windowFactory The window factory to use to create and listen for windows.
89 100
      * @param mainFrame     The frame that owns this manager
90 101
      */
91 102
     @Inject
92 103
     public WindowMenuFrameManager(
93 104
             final SwingController controller,
105
+            @GlobalConfig final IconManager iconManager,
106
+            @GlobalConfig final AggregateConfigProvider globalConfig,
107
+            @PluginDomain(SwingController.class) final String domain,
94 108
             final SwingWindowFactory windowFactory,
95 109
             final MainFrame mainFrame) {
96
-        super();
97 110
         this.controller = controller;
111
+        this.globalConfig = globalConfig;
112
+        this.domain = domain;
113
+        this.mainFrame = mainFrame;
98 114
 
99 115
         menus = Collections.synchronizedMap(
100 116
                 new HashMap<FrameContainer, FrameContainerMenu>());
@@ -107,8 +123,7 @@ public class WindowMenuFrameManager extends JMenu implements
107 123
         setMnemonic('w');
108 124
         windowFactory.addWindowListener(this);
109 125
 
110
-        closeMenuItem = new JMenuItem(controller
111
-                .getIconManager().getIcon("close"));
126
+        closeMenuItem = new JMenuItem(iconManager.getIcon("close"));
112 127
         closeMenuItem.setMnemonic('c');
113 128
         closeMenuItem.setText("Close");
114 129
         closeMenuItem.setActionCommand("Close");
@@ -122,8 +137,7 @@ public class WindowMenuFrameManager extends JMenu implements
122 137
 
123 138
         mainFrame.addSelectionListener(this);
124 139
 
125
-        new WindowMenuScroller(this, controller.getGlobalConfig(),
126
-                controller.getDomain(), itemCount);
140
+        new WindowMenuScroller(this, globalConfig, domain, itemCount);
127 141
         checkMenuItems();
128 142
     }
129 143
 
@@ -144,8 +158,10 @@ public class WindowMenuFrameManager extends JMenu implements
144 158
 
145 159
                         @Override
146 160
                         public FrameContainerMenuItem call() {
147
-                            return new FrameContainerMenuItem(controller,
161
+                            return new FrameContainerMenuItem(
162
+                                    controller,
148 163
                                     window.getContainer(),
164
+                                    window,
149 165
                                     WindowMenuFrameManager.this);
150 166
                         }
151 167
                     });
@@ -164,8 +180,10 @@ public class WindowMenuFrameManager extends JMenu implements
164 180
 
165 181
                         @Override
166 182
                         public FrameContainerMenuItem call() {
167
-                            return new FrameContainerMenuItem(controller,
183
+                            return new FrameContainerMenuItem(
184
+                                    controller,
168 185
                                     window.getContainer(),
186
+                                    window,
169 187
                                     WindowMenuFrameManager.this);
170 188
                         }
171 189
                     });
@@ -176,8 +194,12 @@ public class WindowMenuFrameManager extends JMenu implements
176 194
 
177 195
                             @Override
178 196
                             public FrameContainerMenu call() {
179
-                                return new FrameContainerMenu(parent.
180
-                                        getContainer(), controller);
197
+                                return new FrameContainerMenu(
198
+                                        controller,
199
+                                        globalConfig,
200
+                                        domain,
201
+                                        parent,
202
+                                        parent.getContainer());
181 203
                             }
182 204
                         });
183 205
                 replaceItemWithMenu(getParentMenu(parent.getContainer()),
@@ -234,8 +256,10 @@ public class WindowMenuFrameManager extends JMenu implements
234 256
                             replaceMenuWithItem(getParentMenu(parent.
235 257
                                     getContainer()),
236 258
                                     menus.get(parent.getContainer()),
237
-                                    new FrameContainerMenuItem(controller,
259
+                                    new FrameContainerMenuItem(
260
+                                            controller,
238 261
                                             parent.getContainer(),
262
+                                            parent,
239 263
                                             WindowMenuFrameManager.this));
240 264
                         }
241 265
                     }
@@ -290,7 +314,7 @@ public class WindowMenuFrameManager extends JMenu implements
290 314
     @Override
291 315
     public void actionPerformed(final ActionEvent e) {
292 316
         if (enabledMenuItems.get() && e.getActionCommand().equals("Close")) {
293
-            controller.getMainFrame().getActiveFrame().getContainer().close();
317
+            mainFrame.getActiveFrame().getContainer().close();
294 318
         }
295 319
     }
296 320
 
@@ -362,10 +386,9 @@ public class WindowMenuFrameManager extends JMenu implements
362 386
             final FrameContainer child = ((FrameContainerMenuInterface) component).getFrame();
363 387
             if (sortBefore(newChild, child)) {
364 388
                 return i;
365
-            } else if (!sortAfter(newChild, child) && controller
366
-                    .getGlobalConfig().getOptionBool("treeview",
367
-                            "sortwindows") && newChild.getName().compareToIgnoreCase(
368
-                            child.getName()) < 0) {
389
+            } else if (!sortAfter(newChild, child)
390
+                    && globalConfig.getOptionBool("treeview", "sortwindows")
391
+                    && newChild.getName().compareToIgnoreCase(child.getName()) < 0) {
369 392
                 return i;
370 393
             }
371 394
         }

Ładowanie…
Anuluj
Zapisz