Преглед на файлове

Overhaul and tidy Manu bar code.

Fixes issue CLIENT-96

Change-Id: Ibc98def05f395e6ffee6f5cb3159cf1c9a599664
Reviewed-on: http://gerrit.dmdirc.com/1589
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.5
Greg Holmes преди 13 години
родител
ревизия
db95f29d75

+ 61
- 39
src/com/dmdirc/addons/ui_swing/Apple.java Целия файл

@@ -26,12 +26,13 @@ import com.dmdirc.ServerManager;
26 26
 import com.dmdirc.actions.ActionManager;
27 27
 import com.dmdirc.actions.CoreActionType;
28 28
 import com.dmdirc.actions.interfaces.ActionType;
29
-import com.dmdirc.addons.ui_swing.components.MenuBar;
29
+import com.dmdirc.addons.ui_swing.components.menubar.MenuBar;
30 30
 import com.dmdirc.commandparser.commands.global.NewServer;
31 31
 import com.dmdirc.config.IdentityManager;
32 32
 import com.dmdirc.interfaces.ActionListener;
33 33
 import com.dmdirc.logger.ErrorLevel;
34 34
 import com.dmdirc.logger.Logger;
35
+import java.awt.Toolkit;
35 36
 
36 37
 import java.awt.event.ActionEvent;
37 38
 import java.lang.reflect.Field;
@@ -42,6 +43,7 @@ import java.lang.reflect.Proxy;
42 43
 import java.net.URI;
43 44
 import java.net.URISyntaxException;
44 45
 import java.util.ArrayList;
46
+import java.util.List;
45 47
 
46 48
 import javax.swing.JMenu;
47 49
 import javax.swing.JMenuItem;
@@ -108,7 +110,7 @@ public final class Apple implements InvocationHandler, ActionListener {
108 110
     /** Has the CLIENT_OPENED action been called? */
109 111
     private volatile boolean clientOpened = false;
110 112
     /** Store any addresses that are opened before CLIENT_OPENED. */
111
-    private final ArrayList<URI> addresses = new ArrayList<URI>();
113
+    private final List<URI> addresses = new ArrayList<URI>();
112 114
 
113 115
     /**
114 116
      * Get the "Apple" instance.
@@ -146,7 +148,7 @@ public final class Apple implements InvocationHandler, ActionListener {
146 148
     }
147 149
 
148 150
     /**
149
-     * Get the "Application" object
151
+     * Get the "Application" object.
150 152
      *
151 153
      * @return Object that on OSX will be an "Application"
152 154
      */
@@ -157,19 +159,25 @@ public final class Apple implements InvocationHandler, ActionListener {
157 159
                 final Method method = app.getMethod("getApplication",
158 160
                         new Class[0]);
159 161
                 application = method.invoke(null, new Object[0]);
160
-            } catch (ClassNotFoundException ex) { // Probably not on OS X, do nothing.
161
-            } catch (NoSuchMethodException ex) { // Probably not on OS X, do nothing.
162
-            } catch (SecurityException ex) { // Probably not on OS X, do nothing.
163
-            } catch (IllegalAccessException ex) { // Probably not on OS X, do nothing.
164
-            } catch (IllegalArgumentException ex) { // Probably not on OS X, do nothing.
165
-            } catch (InvocationTargetException ex) { // Probably not on OS X, do nothing.
162
+            } catch (ClassNotFoundException ex) {
163
+                // Probably not on OS X, do nothing.
164
+            } catch (NoSuchMethodException ex) {
165
+                // Probably not on OS X, do nothing.
166
+            } catch (SecurityException ex) {
167
+                // Probably not on OS X, do nothing.
168
+            } catch (IllegalAccessException ex) {
169
+                // Probably not on OS X, do nothing.
170
+            } catch (IllegalArgumentException ex) {
171
+                // Probably not on OS X, do nothing.
172
+            } catch (InvocationTargetException ex) {
173
+                // Probably not on OS X, do nothing.
166 174
             }
167 175
         }
168 176
         return application;
169 177
     }
170 178
 
171 179
     /**
172
-     * Get the "NSApplication" object
180
+     * Get the "NSApplication" object.
173 181
      *
174 182
      * @return Object that on OSX will be an "NSApplication"
175 183
      */
@@ -181,10 +189,14 @@ public final class Apple implements InvocationHandler, ActionListener {
181 189
                 final Method method = app.getMethod("sharedApplication",
182 190
                         new Class[0]);
183 191
                 nsApplication = method.invoke(null, new Object[0]);
184
-            } catch (ClassNotFoundException ex) { // Probably not on OS X, do nothing.
185
-            } catch (NoSuchMethodException ex) { // Probably not on OS X, do nothing.
186
-            } catch (IllegalAccessException ex) { // Probably not on OS X, do nothing.
187
-            } catch (InvocationTargetException ex) { // Probably not on OS X, do nothing.
192
+            } catch (ClassNotFoundException ex) {
193
+                // Probably not on OS X, do nothing.
194
+            } catch (NoSuchMethodException ex) {
195
+                // Probably not on OS X, do nothing.
196
+            } catch (IllegalAccessException ex) {
197
+                // Probably not on OS X, do nothing.
198
+            } catch (InvocationTargetException ex) {
199
+                // Probably not on OS X, do nothing.
188 200
             }
189 201
         }
190 202
         return nsApplication;
@@ -227,7 +239,8 @@ public final class Apple implements InvocationHandler, ActionListener {
227 239
         System.setProperty("com.apple.mrj.application.apple.menu.about.name",
228 240
                 "DMDirc");
229 241
         System.setProperty("apple.laf.useScreenMenuBar", "true");
230
-        System.setProperty("com.apple.mrj.application.growbox.intrudes", "false");
242
+        System.setProperty("com.apple.mrj.application.growbox.intrudes",
243
+                "false");
231 244
         System.setProperty("com.apple.mrj.application.live-resize", "true");
232 245
     }
233 246
 
@@ -249,15 +262,19 @@ public final class Apple implements InvocationHandler, ActionListener {
249 262
             final Method method = getNSApplication().getClass().getMethod(
250 263
                     "requestUserAttention", new Class[]{Integer.TYPE});
251 264
             method.invoke(getNSApplication(), new Object[]{type.get(null)});
252
-        } catch (NoSuchFieldException ex) { // Probably not on OS X, do nothing.
253
-        } catch (NoSuchMethodException ex) { // Probably not on OS X, do nothing.
254
-        } catch (IllegalAccessException ex) { // Probably not on OS X, do nothing.
255
-        } catch (InvocationTargetException ex) { // Probably not on OS X, do nothing.
265
+        } catch (NoSuchFieldException ex) {
266
+            // Probably not on OS X, do nothing.
267
+        } catch (NoSuchMethodException ex) {
268
+            // Probably not on OS X, do nothing.
269
+        } catch (IllegalAccessException ex) {
270
+            // Probably not on OS X, do nothing.
271
+        } catch (InvocationTargetException ex) {
272
+            // Probably not on OS X, do nothing.
256 273
         }
257 274
     }
258 275
 
259 276
     /**
260
-     * Set this up as a listener for the Apple Events
277
+     * Set this up as a listener for the Apple Events.
261 278
      *
262 279
      * @return True if the listener was added, else false.
263 280
      */
@@ -287,10 +304,14 @@ public final class Apple implements InvocationHandler, ActionListener {
287 304
                     new Class[]{Boolean.TYPE});
288 305
             method.invoke(getApplication(), new Object[]{Boolean.TRUE});
289 306
             return true;
290
-        } catch (ClassNotFoundException ex) { // Probably not on OS X, do nothing.
291
-        } catch (NoSuchMethodException ex) { // Probably not on OS X, do nothing.
292
-        } catch (IllegalAccessException ex) { // Probably not on OS X, do nothing.
293
-        } catch (InvocationTargetException ex) { // Probably not on OS X, do nothing.
307
+        } catch (ClassNotFoundException ex) {
308
+            // Probably not on OS X, do nothing.
309
+        } catch (NoSuchMethodException ex) {
310
+            // Probably not on OS X, do nothing.
311
+        } catch (IllegalAccessException ex) {
312
+            // Probably not on OS X, do nothing.
313
+        } catch (InvocationTargetException ex) {
314
+            // Probably not on OS X, do nothing.
294 315
         }
295 316
         return false;
296 317
     }
@@ -320,8 +341,8 @@ public final class Apple implements InvocationHandler, ActionListener {
320 341
                             getParameterTypes()).invoke(args[0], a);
321 342
                 }
322 343
             });
323
-            Method thisMethod = this.getClass().getMethod(method.getName(),
324
-                    new Class[]{ApplicationEvent.class});
344
+            final Method thisMethod = this.getClass().getMethod(
345
+                    method.getName(), new Class[]{ApplicationEvent.class});
325 346
             return thisMethod.invoke(this, event);
326 347
         } catch (NoSuchMethodException e) {
327 348
             if (method.getName().equals("equals") && args.length == 1) {
@@ -357,7 +378,7 @@ public final class Apple implements InvocationHandler, ActionListener {
357 378
     }
358 379
 
359 380
     /**
360
-     * Handle an event using the menuBar
381
+     * Handle an event using the menuBar.
361 382
      *
362 383
      * @param name The name of the event according to the menubar
363 384
      * @param event The ApplicationEvent we are handingle
@@ -367,15 +388,16 @@ public final class Apple implements InvocationHandler, ActionListener {
367 388
         if (!isApple() || menuBar == null) {
368 389
             return;
369 390
         }
391
+        event.setHandled(true);
370 392
         final ActionEvent actionEvent = new ActionEvent(this,
371 393
                 ActionEvent.ACTION_PERFORMED, name);
372 394
 
373
-        menuBar.actionPerformed(actionEvent);
374
-        event.setHandled(true);
395
+        Toolkit.getDefaultToolkit().getSystemEventQueue()
396
+                .postEvent(actionEvent);
375 397
     }
376 398
 
377 399
     /**
378
-     * This is called when Quit is selected from the Application menu
400
+     * This is called when Quit is selected from the Application menu.
379 401
      *
380 402
      * @param event an ApplicationEvent object
381 403
      */
@@ -384,7 +406,7 @@ public final class Apple implements InvocationHandler, ActionListener {
384 406
     }
385 407
 
386 408
     /**
387
-     * This is called when About is selected from the Application menu
409
+     * This is called when About is selected from the Application menu.
388 410
      *
389 411
      * @param event an ApplicationEvent object
390 412
      */
@@ -393,7 +415,7 @@ public final class Apple implements InvocationHandler, ActionListener {
393 415
     }
394 416
 
395 417
     /**
396
-     * This is called when Preferences is selected from the Application menu
418
+     * This is called when Preferences is selected from the Application menu.
397 419
      *
398 420
      * @param event an ApplicationEvent object
399 421
      */
@@ -402,7 +424,7 @@ public final class Apple implements InvocationHandler, ActionListener {
402 424
     }
403 425
 
404 426
     /**
405
-     * This is called when the Application is opened
427
+     * This is called when the Application is opened.
406 428
      *
407 429
      * @param event an ApplicationEvent object
408 430
      */
@@ -410,7 +432,7 @@ public final class Apple implements InvocationHandler, ActionListener {
410 432
     }
411 433
 
412 434
     /**
413
-     * This is called when the application is asked to open a file
435
+     * This is called when the application is asked to open a file.
414 436
      *
415 437
      * @param event an ApplicationEvent object
416 438
      */
@@ -418,7 +440,7 @@ public final class Apple implements InvocationHandler, ActionListener {
418 440
     }
419 441
 
420 442
     /**
421
-     * This is called when asked to print
443
+     * This is called when asked to print.
422 444
      *
423 445
      * @param event an ApplicationEvent object
424 446
      */
@@ -426,7 +448,7 @@ public final class Apple implements InvocationHandler, ActionListener {
426 448
     }
427 449
 
428 450
     /**
429
-     * This is called when the application is reopened
451
+     * This is called when the application is reopened.
430 452
      *
431 453
      * @param event an ApplicationEvent object
432 454
      */
@@ -450,9 +472,9 @@ public final class Apple implements InvocationHandler, ActionListener {
450 472
 
451 473
     /**
452 474
      * Callback from JNI library.
453
-     * If called before the client has finished opening, the URL will be added to
454
-     * a list that will be connected to once the CLIENT_OPENED action is called.
455
-     * Otherwise we connect right away.
475
+     * If called before the client has finished opening, the URL will be added
476
+     * to a list that will be connected to once the CLIENT_OPENED action is
477
+     * called. Otherwise we connect right away.
456 478
      *
457 479
      * @param url The irc url to connect to.
458 480
      */

+ 1
- 1
src/com/dmdirc/addons/ui_swing/MainFrame.java Целия файл

@@ -27,7 +27,7 @@ import com.dmdirc.ServerManager;
27 27
 import com.dmdirc.actions.ActionManager;
28 28
 import com.dmdirc.actions.CoreActionType;
29 29
 import com.dmdirc.addons.ui_swing.components.LoggingSwingWorker;
30
-import com.dmdirc.addons.ui_swing.components.MenuBar;
30
+import com.dmdirc.addons.ui_swing.components.menubar.MenuBar;
31 31
 import com.dmdirc.addons.ui_swing.components.SplitPane;
32 32
 import com.dmdirc.addons.ui_swing.components.desktopPane.DMDircDesktopPane;
33 33
 import com.dmdirc.addons.ui_swing.components.statusbar.SwingStatusBar;

+ 0
- 367
src/com/dmdirc/addons/ui_swing/components/MenuBar.java Целия файл

@@ -1,367 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
-package com.dmdirc.addons.ui_swing.components;
24
-
25
-import com.dmdirc.Channel;
26
-import com.dmdirc.FrameContainer;
27
-import com.dmdirc.ServerManager;
28
-import com.dmdirc.ServerState;
29
-import com.dmdirc.addons.ui_swing.Apple;
30
-import com.dmdirc.addons.ui_swing.MainFrame;
31
-import com.dmdirc.addons.ui_swing.SwingController;
32
-import com.dmdirc.addons.ui_swing.dialogs.FeedbackDialog;
33
-import com.dmdirc.addons.ui_swing.dialogs.NewServerDialog;
34
-import com.dmdirc.addons.ui_swing.dialogs.StandardInputDialog;
35
-import com.dmdirc.addons.ui_swing.dialogs.about.AboutDialog;
36
-import com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog;
37
-import com.dmdirc.addons.ui_swing.dialogs.aliases.AliasManagerDialog;
38
-import com.dmdirc.addons.ui_swing.dialogs.prefs.SwingPreferencesDialog;
39
-import com.dmdirc.addons.ui_swing.dialogs.profiles.ProfileManagerDialog;
40
-import com.dmdirc.addons.ui_swing.dialogs.serverlist.ServerListDialog;
41
-import com.dmdirc.addons.ui_swing.framemanager.windowmenu.WindowMenuFrameManager;
42
-import com.dmdirc.parser.common.ChannelJoinRequest;
43
-import com.dmdirc.plugins.PluginInfo;
44
-import com.dmdirc.plugins.PluginManager;
45
-import com.dmdirc.ui.WindowManager;
46
-
47
-import java.awt.Dialog.ModalityType;
48
-import java.awt.event.ActionEvent;
49
-import java.awt.event.ActionListener;
50
-
51
-import javax.swing.Box;
52
-import javax.swing.JMenu;
53
-import javax.swing.JMenuBar;
54
-import javax.swing.JMenuItem;
55
-import javax.swing.event.MenuEvent;
56
-import javax.swing.event.MenuListener;
57
-
58
-import net.miginfocom.layout.PlatformDefaults;
59
-import net.miginfocom.swing.MigLayout;
60
-
61
-/**
62
- * DMDirc menu bar.
63
- */
64
-public class MenuBar extends JMenuBar implements ActionListener, MenuListener {
65
-
66
-    /**
67
-     * A version number for this class. It should be changed whenever the class
68
-     * structure is changed (or anything else that would prevent serialized
69
-     * objects being unserialized with the new class).
70
-     */
71
-    private static final long serialVersionUID = 1;
72
-    /** Menu items which can be enabled/disabled. */
73
-    private JMenuItem csd, ssd, disconnect, serverlist, join;
74
-    /** Server menu. */
75
-    private JMenu serverMenu;
76
-    /** Swing controller. */
77
-    private final SwingController controller;
78
-    /** Main frame. */
79
-    private final MainFrame mainFrame;
80
-    /** Normal menu count. */
81
-    private int menuItemCount = 0;
82
-
83
-    /**
84
-     * Instantiates a new menu bar.
85
-     *
86
-     * @param controller Swing controller
87
-     * @param mainFrame Main frame
88
-     */
89
-    public MenuBar(final SwingController controller, 
90
-            final MainFrame mainFrame) {
91
-        super();
92
-        this.controller = controller;
93
-        this.mainFrame = mainFrame;
94
-
95
-        setLayout(new MigLayout("ins 0, fillx"));
96
-
97
-        initServerMenu();
98
-        initChannelMenu();
99
-        initSettingsMenu();
100
-        add(new WindowMenuFrameManager(controller));
101
-        initHelpMenu();
102
-        menuItemCount = getComponentCount();
103
-        super.add(Box.createHorizontalGlue(), "growx, pushx");
104
-        super.add(new MDIBar(controller, mainFrame));
105
-        super.add(Box.createHorizontalStrut(PlatformDefaults.getPanelInsets(1)
106
-                .getUnit()));
107
-        menuItemCount = getComponentCount() - menuItemCount;
108
-
109
-        getActionMap().setParent(null);
110
-        getActionMap().clear();
111
-        menuSelected(null);
112
-    }
113
-
114
-    /** {@inheritDoc} */
115
-    @Override
116
-    public JMenu add(final JMenu c) {
117
-        return (JMenu) super.add(c, getComponentCount() - menuItemCount);
118
-    }
119
-
120
-    /**
121
-     * Initialises the server menu.
122
-     */
123
-    private void initServerMenu() {
124
-        serverMenu = new JMenu("Server");
125
-        serverMenu.setMnemonic('s');
126
-        serverMenu.addMenuListener(this);
127
-        add(serverMenu);
128
-
129
-        serverlist = new JMenuItem();
130
-        serverlist.setText("Server list dialog");
131
-        serverlist.setMnemonic('l');
132
-        serverlist.setActionCommand("ServerList");
133
-        serverlist.addActionListener(this);
134
-
135
-        JMenuItem menuItem = new JMenuItem();
136
-        menuItem.setText("New Server...");
137
-        menuItem.setMnemonic('n');
138
-        menuItem.setActionCommand("NewServer");
139
-        menuItem.addActionListener(this);
140
-        serverMenu.add(menuItem);
141
-
142
-        disconnect = new JMenuItem();
143
-        disconnect.setText("Disconnect");
144
-        disconnect.setMnemonic('d');
145
-        disconnect.setActionCommand("Disconnect");
146
-        disconnect.addActionListener(this);
147
-        serverMenu.add(disconnect);
148
-
149
-        ssd = new JMenuItem();
150
-        ssd.setMnemonic('s');
151
-        ssd.setText("Server settings");
152
-        ssd.setActionCommand("ServerSettings");
153
-        ssd.addActionListener(this);
154
-        serverMenu.add(ssd);
155
-
156
-        if (!Apple.isAppleUI()) {
157
-            menuItem = new JMenuItem();
158
-            menuItem.setText("Exit");
159
-            menuItem.setMnemonic('x');
160
-            menuItem.setActionCommand("Exit");
161
-            menuItem.addActionListener(this);
162
-            serverMenu.add(menuItem);
163
-        }
164
-    }
165
-
166
-    /**
167
-     * Initialises the channel menu.
168
-     */
169
-    private void initChannelMenu() {
170
-        final JMenu menu = new JMenu("Channel");
171
-        menu.setMnemonic('c');
172
-        menu.addMenuListener(this);
173
-        add(menu);
174
-
175
-        join = new JMenuItem();
176
-        join.setText("Join Channel...");
177
-        join.setMnemonic('j');
178
-        join.setActionCommand("JoinChannel");
179
-        join.addActionListener(this);
180
-        menu.add(join);
181
-
182
-        csd = new JMenuItem();
183
-        csd.setMnemonic('c');
184
-        csd.setText("Channel Settings");
185
-        csd.setActionCommand("ChannelSettings");
186
-        csd.addActionListener(this);
187
-        menu.add(csd);
188
-    }
189
-
190
-    /**
191
-     * Initialises the settings menu.
192
-     */
193
-    private void initSettingsMenu() {
194
-        JMenuItem menuItem;
195
-        final JMenu menu = new JMenu("Settings");
196
-        menu.setMnemonic('e');
197
-        menu.addMenuListener(this);
198
-        add(menu);
199
-
200
-        if (!Apple.isAppleUI()) {
201
-            menuItem = new JMenuItem();
202
-            menuItem.setText("Preferences");
203
-            menuItem.setMnemonic('p');
204
-            menuItem.setActionCommand("Preferences");
205
-            menuItem.addActionListener(this);
206
-            menu.add(menuItem);
207
-        }
208
-
209
-        menuItem = new JMenuItem();
210
-        menuItem.setMnemonic('m');
211
-        menuItem.setText("Profile Manager");
212
-        menuItem.setActionCommand("Profile");
213
-        menuItem.addActionListener(this);
214
-        menu.add(menuItem);
215
-
216
-        menuItem = new JMenuItem();
217
-        menuItem.setMnemonic('a');
218
-        menuItem.setText("Actions Manager");
219
-        menuItem.setActionCommand("Actions");
220
-        menuItem.addActionListener(this);
221
-        menu.add(menuItem);
222
-
223
-        menuItem = new JMenuItem();
224
-        menuItem.setMnemonic('l');
225
-        menuItem.setText("Alias Manager");
226
-        menuItem.setActionCommand("Aliases");
227
-        menuItem.addActionListener(this);
228
-        menu.add(menuItem);
229
-    }
230
-
231
-    /**
232
-     * Initialises the help menu.
233
-     */
234
-    private void initHelpMenu() {
235
-        JMenuItem menuItem;
236
-        final JMenu menu = new JMenu("Help");
237
-        menu.setMnemonic('h');
238
-        add(menu);
239
-
240
-        menuItem = new JMenuItem();
241
-        menuItem.setMnemonic('j');
242
-        menuItem.setText("Join Dev channel");
243
-        menuItem.setActionCommand("JoinDevChat");
244
-        menuItem.addActionListener(this);
245
-        menu.add(menuItem);
246
-
247
-        menuItem = new JMenuItem();
248
-        menuItem.setMnemonic('f');
249
-        menuItem.setText("Send Feedback");
250
-        menuItem.setActionCommand("feedback");
251
-        menuItem.addActionListener(this);
252
-        menu.add(menuItem);
253
-
254
-        if (!Apple.isAppleUI()) {
255
-            menuItem = new JMenuItem();
256
-            menuItem.setMnemonic('a');
257
-            menuItem.setText("About");
258
-            menuItem.setActionCommand("About");
259
-            menuItem.addActionListener(this);
260
-            menu.add(menuItem);
261
-        }
262
-    }
263
-
264
-    /**
265
-     * {@inheritDoc}
266
-     *
267
-     * @param e Action event
268
-     */
269
-    @Override
270
-    public void actionPerformed(final ActionEvent e) {
271
-        if ("ServerList".equals(e.getActionCommand())) {
272
-            ServerListDialog.showServerListDialog(mainFrame, controller.getURLHandler());
273
-        } else if ("NewServer".equals(e.getActionCommand())) {
274
-            NewServerDialog.showNewServerDialog(mainFrame);
275
-        } else if ("Preferences".equals(e.getActionCommand())) {
276
-            SwingPreferencesDialog.showSwingPreferencesDialog(controller);
277
-        } else if (e.getActionCommand().equals("About")) {
278
-            AboutDialog.showAboutDialog(mainFrame, controller.getURLHandler());
279
-        } else if (e.getActionCommand().equals("Profile")) {
280
-            ProfileManagerDialog.showProfileManagerDialog(mainFrame);
281
-        } else if (e.getActionCommand().equals("Exit")) {
282
-            mainFrame.quit();
283
-        } else if (e.getActionCommand().equals("Actions")) {
284
-            ActionsManagerDialog.showActionsManagerDialog(mainFrame,
285
-                    controller);
286
-        } else if (e.getActionCommand().equals("Aliases")) {
287
-            AliasManagerDialog.showAliasManagerDialog(mainFrame);
288
-        } else if (e.getActionCommand().equals("JoinDevChat")) {
289
-            ServerManager.getServerManager().joinDevChat();
290
-        } else if (e.getActionCommand().equals("feedback")) {
291
-            FeedbackDialog.showFeedbackDialog(mainFrame);
292
-        } else if (e.getActionCommand().equals("ChannelSettings")) {
293
-            final FrameContainer<?> activeWindow = WindowManager
294
-                    .getActiveWindow();
295
-            if (activeWindow instanceof Channel) {
296
-                controller.showChannelSettingsDialog(((Channel) activeWindow));
297
-            }
298
-        } else if (e.getActionCommand().equals("ServerSettings")) {
299
-            controller.showServerSettingsDialog(WindowManager
300
-                    .getActiveServer());
301
-        } else if (e.getActionCommand().equals("Disconnect")) {
302
-            WindowManager.getActiveServer().disconnect();
303
-        } else if (e.getActionCommand().equals("JoinChannel")) {
304
-            new StandardInputDialog(mainFrame, ModalityType.MODELESS,
305
-                    "Join channel", "Enter the name of the channel to join.") {
306
-
307
-                /** Serial version UID. */
308
-                private static final long serialVersionUID = 1;
309
-
310
-                /** {@inheritDoc} */
311
-                @Override
312
-                public boolean save() {
313
-                    WindowManager.getActiveServer().join(new ChannelJoinRequest(
314
-                            getText()));
315
-                    return true;
316
-                }
317
-
318
-                /** {@inheritDoc} */
319
-                @Override
320
-                public void cancelled() {
321
-                    //Ignore
322
-                }
323
-            }.display();
324
-        }
325
-    }
326
-
327
-    /** {@inheritDoc} */
328
-    @Override
329
-    public void menuSelected(final MenuEvent e) {
330
-        final FrameContainer<?> activeWindow = WindowManager.getActiveWindow();
331
-
332
-        ssd.setEnabled(activeWindow != null && activeWindow.getServer() != null
333
-                && activeWindow.getServer().getState() == ServerState.CONNECTED);
334
-        csd.setEnabled(activeWindow instanceof Channel
335
-                && activeWindow.getServer() != null
336
-                && activeWindow.getServer().getState() == ServerState.CONNECTED);
337
-        disconnect.setEnabled(activeWindow != null
338
-                && activeWindow.getServer() != null
339
-                && activeWindow.getServer().getState() == ServerState.CONNECTED);
340
-        join.setEnabled(activeWindow != null && activeWindow.getServer() != null
341
-                && activeWindow.getServer().getState() == ServerState.CONNECTED);
342
-
343
-        final PluginInfo plugin = PluginManager.getPluginManager()
344
-                .getPluginInfoByName("serverlists");
345
-        if (plugin != null) {
346
-            if (!plugin.isLoaded()) {
347
-                plugin.loadPlugin();
348
-            }
349
-
350
-            if (serverMenu.getMenuComponent(0) != serverlist) {
351
-                serverMenu.add(serverlist, 0);
352
-            }
353
-        }
354
-    }
355
-
356
-    /** {@inheritDoc} */
357
-    @Override
358
-    public void menuDeselected(final MenuEvent e) {
359
-        //Ignore
360
-    }
361
-
362
-    /** {@inheritDoc} */
363
-    @Override
364
-    public void menuCanceled(final MenuEvent e) {
365
-        //Ignore
366
-    }
367
-}

+ 1
- 1
src/com/dmdirc/addons/ui_swing/components/frames/AppleJFrame.java Целия файл

@@ -25,7 +25,7 @@ package com.dmdirc.addons.ui_swing.components.frames;
25 25
 import com.dmdirc.addons.ui_swing.Apple;
26 26
 import com.dmdirc.addons.ui_swing.MainFrame;
27 27
 import com.dmdirc.addons.ui_swing.SwingController;
28
-import com.dmdirc.addons.ui_swing.components.MenuBar;
28
+import com.dmdirc.addons.ui_swing.components.menubar.MenuBar;
29 29
 
30 30
 import javax.swing.JFrame;
31 31
 

+ 137
- 0
src/com/dmdirc/addons/ui_swing/components/menubar/ChannelMenu.java Целия файл

@@ -0,0 +1,137 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.ui_swing.components.menubar;
24
+
25
+import com.dmdirc.Channel;
26
+import com.dmdirc.FrameContainer;
27
+import com.dmdirc.ServerState;
28
+import com.dmdirc.addons.ui_swing.MainFrame;
29
+import com.dmdirc.addons.ui_swing.SwingController;
30
+import com.dmdirc.addons.ui_swing.dialogs.ChannelJoinDialog;
31
+import com.dmdirc.ui.WindowManager;
32
+
33
+import java.awt.Dialog.ModalityType;
34
+import java.awt.event.ActionEvent;
35
+import java.awt.event.ActionListener;
36
+
37
+import javax.swing.JMenu;
38
+import javax.swing.JMenuItem;
39
+import javax.swing.event.MenuEvent;
40
+import javax.swing.event.MenuListener;
41
+
42
+/**
43
+ * A menu to provide channel related commands in the menu bar.
44
+ */
45
+public class ChannelMenu extends JMenu implements ActionListener,
46
+        MenuListener {
47
+
48
+    /**
49
+     * A version number for this class. It should be changed whenever the class
50
+     * structure is changed (or anything else that would prevent serialized
51
+     * objects being unserialized with the new class).
52
+     */
53
+    private static final long serialVersionUID = 1;
54
+    /** Swing controller. */
55
+    private final SwingController controller;
56
+    /** Main frame. */
57
+    private final MainFrame mainFrame;
58
+    /** Menu items to be disabled/enabled. */
59
+    private JMenuItem csd, join;
60
+
61
+    /**
62
+     * Creates a new channel menu.
63
+     *
64
+     * @param controller Parent swing controller.
65
+     * @param mainFrame Parent mainframe
66
+     */
67
+    public ChannelMenu(final SwingController controller,
68
+            final MainFrame mainFrame) {
69
+        super("Channel");
70
+        this.controller = controller;
71
+        this.mainFrame = mainFrame;
72
+        setMnemonic('c');
73
+        addMenuListener(this);
74
+        initChannelMenu();
75
+        menuSelected(null);
76
+    }
77
+
78
+    /**
79
+     * Initialises the channel menu.
80
+     */
81
+    private void initChannelMenu() {
82
+        join = new JMenuItem();
83
+        join.setText("Join Channel...");
84
+        join.setMnemonic('j');
85
+        join.setActionCommand("JoinChannel");
86
+        join.addActionListener(this);
87
+        add(join);
88
+
89
+        csd = new JMenuItem();
90
+        csd.setMnemonic('c');
91
+        csd.setText("Channel Settings");
92
+        csd.setActionCommand("ChannelSettings");
93
+        csd.addActionListener(this);
94
+        add(csd);
95
+    }
96
+
97
+    /** {@inheritDoc} */
98
+    @Override
99
+    public void actionPerformed(final ActionEvent e) {
100
+        if (e.getActionCommand().equals("JoinChannel")) {
101
+            new ChannelJoinDialog(mainFrame, ModalityType.MODELESS,
102
+                    "Join channel", "Enter the name of the channel to join.")
103
+                    .display();
104
+        } else if (e.getActionCommand().equals("ChannelSettings")) {
105
+            final FrameContainer<?> activeWindow = WindowManager
106
+                    .getActiveWindow();
107
+            if (activeWindow instanceof Channel) {
108
+                controller.showChannelSettingsDialog(((Channel) activeWindow));
109
+            }
110
+        }
111
+    }
112
+
113
+    /** {@inheritDoc} */
114
+    @Override
115
+    public final void menuSelected(final MenuEvent e) {
116
+        final FrameContainer<?> activeWindow = WindowManager.getActiveWindow();
117
+
118
+        join.setEnabled(activeWindow != null && activeWindow.getServer()
119
+                != null && activeWindow.getServer().getState()
120
+                == ServerState.CONNECTED);
121
+        csd.setEnabled(activeWindow instanceof Channel && activeWindow
122
+                .getServer() != null && activeWindow.getServer().getState()
123
+                == ServerState.CONNECTED);
124
+    }
125
+
126
+    /** {@inheritDoc} */
127
+    @Override
128
+    public final void menuDeselected(final MenuEvent e) {
129
+        //Ignore
130
+    }
131
+
132
+    /** {@inheritDoc} */
133
+    @Override
134
+    public final void menuCanceled(final MenuEvent e) {
135
+        //Ignore
136
+    }
137
+}

+ 109
- 0
src/com/dmdirc/addons/ui_swing/components/menubar/HelpMenu.java Целия файл

@@ -0,0 +1,109 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+package com.dmdirc.addons.ui_swing.components.menubar;
23
+
24
+import com.dmdirc.ServerManager;
25
+import com.dmdirc.addons.ui_swing.Apple;
26
+import com.dmdirc.addons.ui_swing.MainFrame;
27
+import com.dmdirc.addons.ui_swing.SwingController;
28
+import com.dmdirc.addons.ui_swing.dialogs.FeedbackDialog;
29
+import com.dmdirc.addons.ui_swing.dialogs.about.AboutDialog;
30
+
31
+import java.awt.event.ActionEvent;
32
+import java.awt.event.ActionListener;
33
+
34
+import javax.swing.JMenu;
35
+import javax.swing.JMenuItem;
36
+
37
+/**
38
+ * A menu providing help commands to the menu bar.
39
+ */
40
+public class HelpMenu extends JMenu implements ActionListener {
41
+
42
+    /**
43
+     * A version number for this class. It should be changed whenever the class
44
+     * structure is changed (or anything else that would prevent serialized
45
+     * objects being unserialized with the new class).
46
+     */
47
+    private static final long serialVersionUID = 1;
48
+    /** Swing controller. */
49
+    private final SwingController controller;
50
+    /** Main frame. */
51
+    private final MainFrame mainFrame;
52
+
53
+    /**
54
+     * Instantiates a new help menu.
55
+     *
56
+     * @param controller Swing controller
57
+     * @param mainFrame Main frame
58
+     */
59
+    public HelpMenu(final SwingController controller,
60
+            final MainFrame mainFrame) {
61
+        super("Help");
62
+        this.controller = controller;
63
+        this.mainFrame = mainFrame;
64
+        setMnemonic('h');
65
+        initHelpMenu();
66
+    }
67
+
68
+    /**
69
+     * Initialises the help menu.
70
+     */
71
+    private void initHelpMenu() {
72
+        JMenuItem menuItem;
73
+
74
+        menuItem = new JMenuItem();
75
+        menuItem.setMnemonic('j');
76
+        menuItem.setText("Join Dev channel");
77
+        menuItem.setActionCommand("JoinDevChat");
78
+        menuItem.addActionListener(this);
79
+        add(menuItem);
80
+
81
+        menuItem = new JMenuItem();
82
+        menuItem.setMnemonic('f');
83
+        menuItem.setText("Send Feedback");
84
+        menuItem.setActionCommand("feedback");
85
+        menuItem.addActionListener(this);
86
+        add(menuItem);
87
+
88
+        if (!Apple.isAppleUI()) {
89
+            menuItem = new JMenuItem();
90
+            menuItem.setMnemonic('a');
91
+            menuItem.setText("About");
92
+            menuItem.setActionCommand("About");
93
+            menuItem.addActionListener(this);
94
+            add(menuItem);
95
+        }
96
+    }
97
+
98
+    /** {@inheritDoc} */
99
+    @Override
100
+    public void actionPerformed(final ActionEvent e) {
101
+        if (e.getActionCommand().equals("About")) {
102
+            AboutDialog.showAboutDialog(mainFrame, controller.getURLHandler());
103
+        } else if (e.getActionCommand().equals("JoinDevChat")) {
104
+            ServerManager.getServerManager().joinDevChat();
105
+        } else if (e.getActionCommand().equals("feedback")) {
106
+            FeedbackDialog.showFeedbackDialog(mainFrame);
107
+        }
108
+    }
109
+}

+ 86
- 0
src/com/dmdirc/addons/ui_swing/components/menubar/MenuBar.java Целия файл

@@ -0,0 +1,86 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.ui_swing.components.menubar;
24
+
25
+import com.dmdirc.addons.ui_swing.MainFrame;
26
+import com.dmdirc.addons.ui_swing.SwingController;
27
+import com.dmdirc.addons.ui_swing.components.MDIBar;
28
+import com.dmdirc.addons.ui_swing.framemanager.windowmenu.WindowMenuFrameManager;
29
+
30
+import java.awt.Component;
31
+
32
+import javax.swing.Box;
33
+import javax.swing.JMenuBar;
34
+
35
+import net.miginfocom.layout.PlatformDefaults;
36
+import net.miginfocom.swing.MigLayout;
37
+
38
+/**
39
+ * DMDirc menu bar.
40
+ */
41
+public class MenuBar extends JMenuBar {
42
+
43
+    /**
44
+     * A version number for this class. It should be changed whenever the class
45
+     * structure is changed (or anything else that would prevent serialized
46
+     * objects being unserialized with the new class).
47
+     */
48
+    private static final long serialVersionUID = 1;
49
+    /** Normal menu count. */
50
+    private final int menuItemCount;
51
+
52
+    /**
53
+     * Instantiates a new menu bar.
54
+     *
55
+     * @param controller Swing controller
56
+     * @param mainFrame Main frame
57
+     */
58
+    public MenuBar(final SwingController controller,
59
+            final MainFrame mainFrame) {
60
+        super();
61
+
62
+        setLayout(new MigLayout("ins 0, fillx"));
63
+
64
+        add(new ServerMenu(controller, mainFrame));
65
+        add(new ChannelMenu(controller, mainFrame));
66
+        add(new SettingsMenu(controller, mainFrame));
67
+        add(new WindowMenuFrameManager(controller));
68
+        add(new HelpMenu(controller, mainFrame));
69
+        final int tempCount = getComponentCount();
70
+        add(Box.createHorizontalGlue(), "growx, pushx");
71
+        add(new MDIBar(controller, mainFrame));
72
+        add(Box.createHorizontalStrut(PlatformDefaults.getPanelInsets(1)
73
+                .getUnit()));
74
+        menuItemCount = getComponentCount() - tempCount;
75
+
76
+        getActionMap().setParent(null);
77
+        getActionMap().clear();
78
+    }
79
+
80
+    /** {@inheritDoc} */
81
+    @Override
82
+    protected void addImpl(final Component comp, final Object constraints,
83
+            final int index) {
84
+        super.addImpl(comp, constraints, getComponentCount() - menuItemCount);
85
+    }
86
+}

+ 175
- 0
src/com/dmdirc/addons/ui_swing/components/menubar/ServerMenu.java Целия файл

@@ -0,0 +1,175 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.ui_swing.components.menubar;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.ServerState;
27
+import com.dmdirc.addons.ui_swing.Apple;
28
+import com.dmdirc.addons.ui_swing.MainFrame;
29
+import com.dmdirc.addons.ui_swing.SwingController;
30
+import com.dmdirc.addons.ui_swing.dialogs.NewServerDialog;
31
+import com.dmdirc.addons.ui_swing.dialogs.serverlist.ServerListDialog;
32
+import com.dmdirc.plugins.PluginInfo;
33
+import com.dmdirc.plugins.PluginManager;
34
+import com.dmdirc.ui.WindowManager;
35
+
36
+import java.awt.event.ActionEvent;
37
+import java.awt.event.ActionListener;
38
+
39
+import javax.swing.JMenu;
40
+import javax.swing.JMenuItem;
41
+import javax.swing.event.MenuEvent;
42
+import javax.swing.event.MenuListener;
43
+
44
+/**
45
+ * A menu providing server related commands to the menu bar.
46
+ */
47
+public class ServerMenu extends JMenu implements ActionListener,
48
+        MenuListener {
49
+
50
+    /**
51
+     * A version number for this class. It should be changed whenever the class
52
+     * structure is changed (or anything else that would prevent serialized
53
+     * objects being unserialized with the new class).
54
+     */
55
+    private static final long serialVersionUID = 1;
56
+    /** Swing controller. */
57
+    private final SwingController controller;
58
+    /** Main frame. */
59
+    private final MainFrame mainFrame;
60
+    /** Menu items which can be enabled/disabled. */
61
+    private JMenuItem ssd, disconnect, serverlist;
62
+
63
+    /**
64
+     * Creates a new Server menu.
65
+     *
66
+     * @param controller Parent swing controller
67
+     * @param mainFrame Parent main frame
68
+     */
69
+    public ServerMenu(final SwingController controller,
70
+            final MainFrame mainFrame) {
71
+        super("Server");
72
+        this.controller = controller;
73
+        this.mainFrame = mainFrame;
74
+        setMnemonic('s');
75
+        addMenuListener(this);
76
+        initServerMenu();
77
+        menuSelected(null);
78
+    }
79
+
80
+    /**
81
+     * Initialises the server menu.
82
+     */
83
+    private void initServerMenu() {
84
+        serverlist = new JMenuItem();
85
+        serverlist.setText("Server lists");
86
+        serverlist.setMnemonic('l');
87
+        serverlist.setActionCommand("ServerList");
88
+        serverlist.addActionListener(this);
89
+
90
+        JMenuItem menuItem = new JMenuItem();
91
+        menuItem.setText("New Server...");
92
+        menuItem.setMnemonic('n');
93
+        menuItem.setActionCommand("NewServer");
94
+        menuItem.addActionListener(this);
95
+        add(menuItem);
96
+
97
+        disconnect = new JMenuItem();
98
+        disconnect.setText("Disconnect");
99
+        disconnect.setMnemonic('d');
100
+        disconnect.setActionCommand("Disconnect");
101
+        disconnect.addActionListener(this);
102
+        add(disconnect);
103
+
104
+        ssd = new JMenuItem();
105
+        ssd.setMnemonic('s');
106
+        ssd.setText("Server settings");
107
+        ssd.setActionCommand("ServerSettings");
108
+        ssd.addActionListener(this);
109
+        add(ssd);
110
+
111
+        if (!Apple.isAppleUI()) {
112
+            menuItem = new JMenuItem();
113
+            menuItem.setText("Exit");
114
+            menuItem.setMnemonic('x');
115
+            menuItem.setActionCommand("Exit");
116
+            menuItem.addActionListener(this);
117
+            add(menuItem);
118
+        }
119
+    }
120
+
121
+    /** {@inheritDoc} */
122
+    @Override
123
+    public void actionPerformed(final ActionEvent e) {
124
+        if ("NewServer".equals(e.getActionCommand())) {
125
+            NewServerDialog.showNewServerDialog(mainFrame);
126
+        } else if (e.getActionCommand().equals("ServerList")) {
127
+            ServerListDialog.showServerListDialog(mainFrame,
128
+                    controller.getURLHandler());
129
+        } else if (e.getActionCommand().equals("Exit")) {
130
+            mainFrame.quit();
131
+        } else if (e.getActionCommand().equals("ServerSettings")) {
132
+            controller.showServerSettingsDialog(WindowManager
133
+                    .getActiveServer());
134
+        } else if (e.getActionCommand().equals("Disconnect")) {
135
+            WindowManager.getActiveServer().disconnect();
136
+        }
137
+    }
138
+
139
+    /** {@inheritDoc} */
140
+    @Override
141
+    public final void menuSelected(final MenuEvent e) {
142
+        final FrameContainer<?> activeWindow = WindowManager.getActiveWindow();
143
+
144
+        ssd.setEnabled(activeWindow != null && activeWindow
145
+                .getServer() != null && activeWindow.getServer().getState()
146
+                == ServerState.CONNECTED);
147
+        disconnect.setEnabled(activeWindow != null && activeWindow
148
+                .getServer() != null && activeWindow.getServer().getState()
149
+                == ServerState.CONNECTED);
150
+
151
+        final PluginInfo plugin = PluginManager.getPluginManager()
152
+                .getPluginInfoByName("serverlists");
153
+        if (plugin != null) {
154
+            if (!plugin.isLoaded()) {
155
+                plugin.loadPlugin();
156
+            }
157
+
158
+            if (getMenuComponent(0) != serverlist) {
159
+                add(serverlist, 0);
160
+            }
161
+        }
162
+    }
163
+
164
+    /** {@inheritDoc} */
165
+    @Override
166
+    public final void menuDeselected(final MenuEvent e) {
167
+        //Ignore
168
+    }
169
+
170
+    /** {@inheritDoc} */
171
+    @Override
172
+    public final void menuCanceled(final MenuEvent e) {
173
+        //Ignore
174
+    }
175
+}

+ 115
- 0
src/com/dmdirc/addons/ui_swing/components/menubar/SettingsMenu.java Целия файл

@@ -0,0 +1,115 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.ui_swing.components.menubar;
24
+
25
+import com.dmdirc.addons.ui_swing.Apple;
26
+import com.dmdirc.addons.ui_swing.MainFrame;
27
+import com.dmdirc.addons.ui_swing.SwingController;
28
+import com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog;
29
+import com.dmdirc.addons.ui_swing.dialogs.aliases.AliasManagerDialog;
30
+import com.dmdirc.addons.ui_swing.dialogs.prefs.SwingPreferencesDialog;
31
+import com.dmdirc.addons.ui_swing.dialogs.profiles.ProfileManagerDialog;
32
+
33
+import java.awt.event.ActionEvent;
34
+import java.awt.event.ActionListener;
35
+
36
+import javax.swing.JMenu;
37
+import javax.swing.JMenuItem;
38
+
39
+/**
40
+ * A menu to add settings related commands to the menu bar.
41
+ */
42
+public class SettingsMenu extends JMenu implements ActionListener {
43
+
44
+    /**
45
+     * A version number for this class. It should be changed whenever the class
46
+     * structure is changed (or anything else that would prevent serialized
47
+     * objects being unserialized with the new class).
48
+     */
49
+    private static final long serialVersionUID = 1;
50
+    /** Swing controller. */
51
+    private final SwingController controller;
52
+    /** Main frame. */
53
+    private final MainFrame mainFrame;
54
+
55
+    public SettingsMenu(final SwingController controller,
56
+            final MainFrame mainFrame) {
57
+        super("Settings");
58
+        this.controller = controller;
59
+        this.mainFrame = mainFrame;
60
+        setMnemonic('e');
61
+        initSettingsMenu();
62
+    }
63
+
64
+    /**
65
+     * Initialises the settings menu.
66
+     */
67
+    private void initSettingsMenu() {
68
+        JMenuItem menuItem;
69
+
70
+        if (!Apple.isAppleUI()) {
71
+            menuItem = new JMenuItem();
72
+            menuItem.setText("Preferences");
73
+            menuItem.setMnemonic('p');
74
+            menuItem.setActionCommand("Preferences");
75
+            menuItem.addActionListener(this);
76
+            add(menuItem);
77
+        }
78
+
79
+        menuItem = new JMenuItem();
80
+        menuItem.setMnemonic('m');
81
+        menuItem.setText("Profile Manager");
82
+        menuItem.setActionCommand("Profile");
83
+        menuItem.addActionListener(this);
84
+        add(menuItem);
85
+
86
+        menuItem = new JMenuItem();
87
+        menuItem.setMnemonic('a');
88
+        menuItem.setText("Actions Manager");
89
+        menuItem.setActionCommand("Actions");
90
+        menuItem.addActionListener(this);
91
+        add(menuItem);
92
+
93
+        menuItem = new JMenuItem();
94
+        menuItem.setMnemonic('l');
95
+        menuItem.setText("Alias Manager");
96
+        menuItem.setActionCommand("Aliases");
97
+        menuItem.addActionListener(this);
98
+        add(menuItem);
99
+    }
100
+
101
+    /** {@inheritDoc} */
102
+    @Override
103
+    public void actionPerformed(final ActionEvent e) {
104
+        if ("Preferences".equals(e.getActionCommand())) {
105
+            SwingPreferencesDialog.showSwingPreferencesDialog(controller);
106
+        } else if (e.getActionCommand().equals("Profile")) {
107
+            ProfileManagerDialog.showProfileManagerDialog(mainFrame);
108
+        }  else if (e.getActionCommand().equals("Actions")) {
109
+            ActionsManagerDialog.showActionsManagerDialog(mainFrame,
110
+                    controller);
111
+        } else if (e.getActionCommand().equals("Aliases")) {
112
+            AliasManagerDialog.showAliasManagerDialog(mainFrame);
113
+        }
114
+    }
115
+}

+ 65
- 0
src/com/dmdirc/addons/ui_swing/dialogs/ChannelJoinDialog.java Целия файл

@@ -0,0 +1,65 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.ui_swing.dialogs;
24
+
25
+import com.dmdirc.parser.common.ChannelJoinRequest;
26
+import com.dmdirc.ui.WindowManager;
27
+
28
+import java.awt.Dialog.ModalityType;
29
+import java.awt.Window;
30
+
31
+/**
32
+ * A dialog to prompt the user for a channel and then join that channel.
33
+ */
34
+public class ChannelJoinDialog extends StandardInputDialog {
35
+
36
+    /** Serial version UID. */
37
+    private static final long serialVersionUID = 1;
38
+
39
+    /**
40
+     * Creates a new dialog which prompts a user and then joins the channel
41
+     * they specify.
42
+     *
43
+     * @param owner Parent window
44
+     * @param modality Window modality
45
+     * @param title Window title
46
+     * @param message Window message
47
+     */
48
+    public ChannelJoinDialog(final Window owner, final ModalityType modality,
49
+            final String title, final String message) {
50
+        super(owner, modality, title, message);
51
+    }
52
+
53
+    /** {@inheritDoc} */
54
+    @Override
55
+    public boolean save() {
56
+        WindowManager.getActiveServer().join(new ChannelJoinRequest(getText()));
57
+        return true;
58
+    }
59
+
60
+    /** {@inheritDoc} */
61
+    @Override
62
+    public void cancelled() {
63
+        //Ignore
64
+    }
65
+}

Loading…
Отказ
Запис