01 /*
02 * Copyright 2008-2014 the original author or authors.
03 *
04 * Licensed under the Apache License, Version 2.0 (the "License");
05 * you may not use this file except in compliance with the License.
06 * You may obtain a copy of the License at
07 *
08 * http://www.apache.org/licenses/LICENSE-2.0
09 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.codehaus.griffon.runtime.core;
17
18 import com.apple.mrj.MRJAboutHandler;
19 import com.apple.mrj.MRJApplicationUtils;
20 import com.apple.mrj.MRJPrefsHandler;
21 import com.apple.mrj.MRJQuitHandler;
22 import griffon.core.GriffonApplication;
23
24 import javax.annotation.Nonnull;
25
26 import static griffon.util.GriffonNameUtils.capitalize;
27 import static java.util.Arrays.asList;
28
29 /**
30 * Handles Linux integration.
31 *
32 * @author Andres Almiray
33 * @since 2.0.0
34 */
35 public class DefaultMacOSXPlatformHandler extends DefaultPlatformHandler {
36 @Override
37 public void handle(@Nonnull GriffonApplication application) {
38 super.handle(application);
39
40 // use unified menu bar
41 System.setProperty("apple.laf.useScreenMenuBar", "true");
42
43 // set menu bar title
44 String title = application.getConfiguration().getAsString("application.title", "Griffon");
45 System.setProperty("com.apple.mrj.application.apple.menu.about.name", capitalize(title));
46
47
48 boolean skipAbout = application.getConfiguration().getAsBoolean("osx.noabout", false);
49 boolean skipPrefs = application.getConfiguration().getAsBoolean("osx.noprefs", false);
50 boolean skipQuit = application.getConfiguration().getAsBoolean("osx.noquit", false);
51
52 GriffonMacOSXSupport handler = new GriffonMacOSXSupport(application, skipQuit);
53 if (!skipAbout) MRJApplicationUtils.registerAboutHandler(handler);
54 if (!skipPrefs) MRJApplicationUtils.registerPrefsHandler(handler);
55 MRJApplicationUtils.registerQuitHandler(handler);
56 }
57
58 private static class GriffonMacOSXSupport implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler {
59 private final GriffonApplication application;
60 private final boolean noquit;
61
62 private GriffonMacOSXSupport(@Nonnull GriffonApplication application, boolean noquit) {
63 this.application = application;
64 this.noquit = noquit;
65 }
66
67 @Override
68 public void handleAbout() {
69 application.getEventRouter().publishEvent("OSXAbout", asList(application));
70 }
71
72 @Override
73 public void handlePrefs() throws IllegalStateException {
74 application.getEventRouter().publishEvent("OSXPrefs", asList(application));
75 }
76
77 @Override
78 public void handleQuit() {
79 if (noquit) {
80 application.getEventRouter().publishEvent("OSXQuit", asList(application));
81 } else {
82 application.shutdown();
83 }
84 }
85 }
86 }
|