|
@@ -22,6 +22,7 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.addons.ui_swing;
|
24
|
24
|
|
|
25
|
+import com.dmdirc.ServerManager;
|
25
|
26
|
import com.dmdirc.actions.ActionManager;
|
26
|
27
|
import com.dmdirc.actions.CoreActionType;
|
27
|
28
|
import com.dmdirc.addons.ui_swing.components.menubar.MenuBar;
|
|
@@ -64,36 +65,30 @@ public class Apple implements InvocationHandler, ActionListener {
|
64
|
65
|
/** The "Application" object used to do stuff on OS X. */
|
65
|
66
|
private Object application;
|
66
|
67
|
|
67
|
|
- /** Are we listening? */
|
|
68
|
+ /** Whether we're listening or not. */
|
68
|
69
|
private boolean isListener = false;
|
69
|
70
|
|
70
|
71
|
/** The MenuBar for the application. */
|
71
|
72
|
private MenuBar menuBar = null;
|
72
|
73
|
|
73
|
|
- /** Has the CLIENT_OPENED action been called? */
|
|
74
|
+ /** Whether the CLIENT_OPENED action has been called or not. */
|
74
|
75
|
private boolean clientOpened = false;
|
75
|
76
|
|
76
|
|
- /** Our swing controller. */
|
77
|
|
- private final SwingController controller;
|
|
77
|
+ /** The server manager to use to connect to URLs. */
|
|
78
|
+ private final ServerManager serverManager;
|
78
|
79
|
|
79
|
80
|
/**
|
80
|
|
- * Create the Apple class.
|
81
|
|
- * <p>
|
82
|
|
- * This attempts to:
|
83
|
|
- * </p>
|
|
81
|
+ * Creates a new instance of {@link Apple}.
|
84
|
82
|
*
|
85
|
|
- * <ul>
|
86
|
|
- * <li>load the JNI library</li>
|
87
|
|
- * <li>register the callback</li>
|
88
|
|
- * <li>register a CLIENT_OPENED listener</li>
|
89
|
|
- * </ul>
|
|
83
|
+ * <p>This will attempt to load the native library and register the URL open callback.
|
90
|
84
|
*
|
91
|
85
|
* @param configManager Config manager
|
92
|
|
- * @param controller Parent swing controller
|
|
86
|
+ * @param serverManager The server manager to use to connect to URLs.
|
93
|
87
|
*/
|
94
|
|
- public Apple(final AggregateConfigProvider configManager, final SwingController controller) {
|
|
88
|
+ public Apple(final AggregateConfigProvider configManager, final ServerManager serverManager) {
|
95
|
89
|
this.configManager = configManager;
|
96
|
|
- this.controller = controller;
|
|
90
|
+ this.serverManager = serverManager;
|
|
91
|
+
|
97
|
92
|
if (isApple()) {
|
98
|
93
|
try {
|
99
|
94
|
System.loadLibrary("DMDirc-Apple"); // NOPMD
|
|
@@ -117,7 +112,7 @@ public class Apple implements InvocationHandler, ActionListener {
|
117
|
112
|
* Call a method on the given object.
|
118
|
113
|
*
|
119
|
114
|
* @param obj Object to call method on.
|
120
|
|
- * @oaram className Name of class that object really is.
|
|
115
|
+ * @param className Name of class that object really is.
|
121
|
116
|
* @param methodName Method to call
|
122
|
117
|
* @param classes Array of classes to pass when calling getMethod
|
123
|
118
|
* @param objects Array of objects to pass when invoking.
|
|
@@ -128,8 +123,7 @@ public class Apple implements InvocationHandler, ActionListener {
|
128
|
123
|
final Class<?> clazz = className == null ? obj.getClass() : Class.forName(className);
|
129
|
124
|
final Method method = clazz.getMethod(methodName, classes == null ? new Class<?>[0] : classes);
|
130
|
125
|
return method.invoke(obj, objects == null ? new Object[0] : objects);
|
131
|
|
- } catch (IllegalArgumentException | InvocationTargetException |
|
132
|
|
- ClassNotFoundException | NoSuchMethodException | IllegalAccessException ex) {
|
|
126
|
+ } catch (ReflectiveOperationException ex) {
|
133
|
127
|
Logger.userError(ErrorLevel.LOW, "Unable to find OS X classes");
|
134
|
128
|
}
|
135
|
129
|
|
|
@@ -329,10 +323,11 @@ public class Apple implements InvocationHandler, ActionListener {
|
329
|
323
|
/**
|
330
|
324
|
* {@inheritDoc}
|
331
|
325
|
*
|
332
|
|
- * @throws Throwable Throws stuff on errors
|
|
326
|
+ * @throws ReflectiveOperationException if attempting to invoke the method fails.
|
333
|
327
|
*/
|
334
|
328
|
@Override
|
335
|
|
- public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
|
|
329
|
+ public Object invoke(final Object proxy, final Method method, final Object[] args)
|
|
330
|
+ throws ReflectiveOperationException {
|
336
|
331
|
if (!isApple()) {
|
337
|
332
|
return null;
|
338
|
333
|
}
|
|
@@ -357,7 +352,7 @@ public class Apple implements InvocationHandler, ActionListener {
|
357
|
352
|
return thisMethod.invoke(this, args);
|
358
|
353
|
} catch (final NoSuchMethodException e) {
|
359
|
354
|
if (method.getName().equals("equals") && args.length == 1) {
|
360
|
|
- return Boolean.valueOf(proxy == args[0]);
|
|
355
|
+ return proxy == args[0];
|
361
|
356
|
}
|
362
|
357
|
}
|
363
|
358
|
|
|
@@ -434,7 +429,7 @@ public class Apple implements InvocationHandler, ActionListener {
|
434
|
429
|
synchronized (addresses) {
|
435
|
430
|
clientOpened = true;
|
436
|
431
|
for (final URI addr : addresses) {
|
437
|
|
- controller.getServerManager().connectToAddress(addr);
|
|
432
|
+ serverManager.connectToAddress(addr);
|
438
|
433
|
}
|
439
|
434
|
addresses.clear();
|
440
|
435
|
}
|
|
@@ -466,8 +461,7 @@ public class Apple implements InvocationHandler, ActionListener {
|
466
|
461
|
*/
|
467
|
462
|
public void handleOpenURL(final String url) {
|
468
|
463
|
try {
|
469
|
|
- final URI addr = NewServer.getURI(url);
|
470
|
|
- handleURI(addr);
|
|
464
|
+ handleURI(NewServer.getURI(url));
|
471
|
465
|
} catch (final URISyntaxException use) { }
|
472
|
466
|
}
|
473
|
467
|
|
|
@@ -485,8 +479,7 @@ public class Apple implements InvocationHandler, ActionListener {
|
485
|
479
|
|
486
|
480
|
final Object obj = reflectMethod(event, null, "getURI", null, null);
|
487
|
481
|
if (obj instanceof URI) {
|
488
|
|
- final URI uri = (URI)obj;
|
489
|
|
- handleURI(uri);
|
|
482
|
+ handleURI((URI) obj);
|
490
|
483
|
}
|
491
|
484
|
}
|
492
|
485
|
|
|
@@ -508,7 +501,8 @@ public class Apple implements InvocationHandler, ActionListener {
|
508
|
501
|
if (Thread.currentThread().getContextClassLoader() == null) {
|
509
|
502
|
Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
|
510
|
503
|
}
|
511
|
|
- controller.getServerManager().connectToAddress(uri);
|
|
504
|
+
|
|
505
|
+ serverManager.connectToAddress(uri);
|
512
|
506
|
} else {
|
513
|
507
|
addresses.add(uri);
|
514
|
508
|
}
|