Search in sources :

Example 1 with Application

use of com.apple.eawt.Application in project zaproxy by zaproxy.

the class OsXGui method setup.

/**
     * Setups the GUI of ZAP for OSX.
     * <p>
     * Sets OS X related GUI properties and functionalities.
     */
public static void setup() {
    // Set the various and sundry OS X-specific system properties
    System.setProperty("apple.laf.useScreenMenuBar", "true");
    // Broken and unfixed; thanks, Apple
    System.setProperty("dock:name", "ZAP");
    // more thx
    System.setProperty("com.apple.mrj.application.apple.menu.about.name", "ZAP");
    // Override various handlers, so that About, Preferences, and Quit behave in an OS X typical fashion.
    LOGGER.info("Initializing OS X specific settings, despite Apple's best efforts");
    // Attempt to load the apple classes
    Application app = Application.getApplication();
    // Set the dock image icon
    Image img = Toolkit.getDefaultToolkit().getImage(GuiBootstrap.class.getResource("/resource/zap1024x1024.png"));
    app.setDockIconImage(img);
    // Set handlers for About and Preferences
    app.setAboutHandler(new OSXAboutHandler());
    app.setPreferencesHandler(new OSXPreferencesHandler());
    // Let's not forget to clean up our database mess when we Quit
    OSXQuitHandler quitHandler = new OSXQuitHandler();
    // quitHandler.removeZAPViewItem(view); // TODO
    app.setQuitHandler(quitHandler);
}
Also used : OSXAboutHandler(org.zaproxy.zap.view.osxhandlers.OSXAboutHandler) Image(java.awt.Image) Application(com.apple.eawt.Application) OSXPreferencesHandler(org.zaproxy.zap.view.osxhandlers.OSXPreferencesHandler) OSXQuitHandler(org.zaproxy.zap.view.osxhandlers.OSXQuitHandler)

Example 2 with Application

use of com.apple.eawt.Application in project VocabHunter by VocabHunter.

the class OsxEventSource method setListener.

@Override
public void setListener(final ExternalEventListener listener) {
    Application application = Application.getApplication();
    application.setOpenFileHandler(new OsxOpenFilesHandler(listener));
}
Also used : Application(com.apple.eawt.Application)

Example 3 with Application

use of com.apple.eawt.Application in project cayenne by apache.

the class OSXApplicationWrapper method setHandler.

private void setHandler(Method setMethod, Class<?> handlerClass, Runnable action) {
    InvocationHandler handler = (proxy, method, args) -> {
        action.run();
        return null;
    };
    Object proxy = createProxy(handlerClass, handler);
    try {
        setMethod.invoke(application, proxy);
    } catch (IllegalAccessException | InvocationTargetException ex) {
        logger.warn("Unable to call " + setMethod.getName(), ex);
    }
}
Also used : Consumer(java.util.function.Consumer) Proxy(java.lang.reflect.Proxy) Logger(org.slf4j.Logger) Application(com.apple.eawt.Application) LoggerFactory(org.slf4j.LoggerFactory) InvocationHandler(java.lang.reflect.InvocationHandler) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationHandler(java.lang.reflect.InvocationHandler) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with Application

use of com.apple.eawt.Application in project cayenne by apache.

the class OSXApplicationWrapper method setQuitHandler.

public void setQuitHandler(Consumer<OSXQuitResponseWrapper> action) {
    InvocationHandler handler = (proxy, method, args) -> {
        // args: 0 - event, 1 - quitResponse
        action.accept(new OSXQuitResponseWrapper(args[1]));
        return null;
    };
    Object proxy = createProxy(quitHandlerClass, handler);
    try {
        setQuitHandler.invoke(application, proxy);
    } catch (IllegalAccessException | InvocationTargetException ex) {
        logger.warn("Unable to call " + setQuitHandler.getName(), ex);
    }
}
Also used : Consumer(java.util.function.Consumer) Proxy(java.lang.reflect.Proxy) Logger(org.slf4j.Logger) Application(com.apple.eawt.Application) LoggerFactory(org.slf4j.LoggerFactory) InvocationHandler(java.lang.reflect.InvocationHandler) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationHandler(java.lang.reflect.InvocationHandler) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with Application

use of com.apple.eawt.Application in project gocd by gocd.

the class AgentMacWindow method initializeApplicationAdapter.

private MacBootstrapperApplicationAdapter initializeApplicationAdapter() {
    Application application = Application.getApplication();
    application.setEnabledPreferencesMenu(true);
    application.setEnabledAboutMenu(true);
    setVisible(false);
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    setResizable(false);
    setSize(getPreferredSize());
    MacBootstrapperApplicationAdapter applicationAdapter = new MacBootstrapperApplicationAdapter(this);
    application.addApplicationListener(applicationAdapter);
    return applicationAdapter;
}
Also used : Application(com.apple.eawt.Application)

Aggregations

Application (com.apple.eawt.Application)5 InvocationHandler (java.lang.reflect.InvocationHandler)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 Proxy (java.lang.reflect.Proxy)2 Consumer (java.util.function.Consumer)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Image (java.awt.Image)1 OSXAboutHandler (org.zaproxy.zap.view.osxhandlers.OSXAboutHandler)1 OSXPreferencesHandler (org.zaproxy.zap.view.osxhandlers.OSXPreferencesHandler)1 OSXQuitHandler (org.zaproxy.zap.view.osxhandlers.OSXQuitHandler)1