Search in sources :

Example 1 with ApplicationEvent

use of com.apple.eawt.ApplicationEvent in project Spark by igniterealtime.

the class ApplePlugin method initialize.

@SuppressWarnings("deprecation")
public void initialize() {
    _props = new AppleProperties();
    ApplePreference pref = new ApplePreference(_props);
    SparkManager.getPreferenceManager().addPreference(pref);
    _applebounce = new AppleBounce(_props);
    _appledock = new AppleDock();
    SparkManager.getNativeManager().addNativeHandler(this);
    handleIdle();
    // // register an application listener to show the about box
    _application = Application.getApplication();
    _application.setEnabledPreferencesMenu(true);
    _application.addPreferencesMenuItem();
    _application.addApplicationListener(new ApplicationAdapter() {

        public void handlePreferences(ApplicationEvent applicationEvent) {
            SparkManager.getPreferenceManager().showPreferences();
        }

        public void handleReOpenApplication(ApplicationEvent event) {
            MainWindow mainWindow = SparkManager.getMainWindow();
            if (!mainWindow.isVisible()) {
                mainWindow.setState(Frame.NORMAL);
                mainWindow.setVisible(true);
            }
            if (SparkManager.getChatManager().getChatContainer().getTotalNumberOfUnreadMessages() > 0) {
                final ChatFrame frame = SparkManager.getChatManager().getChatContainer().getChatFrame();
                frame.setState(Frame.NORMAL);
                frame.setVisible(true);
                frame.toFront();
            }
        }

        public void handleQuit(ApplicationEvent applicationEvent) {
            SparkManager.getMainWindow().shutdown();
        }
    });
}
Also used : ChatFrame(org.jivesoftware.spark.ui.ChatFrame) MainWindow(org.jivesoftware.MainWindow) ApplicationEvent(com.apple.eawt.ApplicationEvent) ApplicationAdapter(com.apple.eawt.ApplicationAdapter)

Example 2 with ApplicationEvent

use of com.apple.eawt.ApplicationEvent in project org.alloytools.alloy by AlloyTools.

the class MacUtil method registerApplicationListener.

/**
 * Register a Mac OS X "ApplicationListener"; if there was a previous listener,
 * it will be removed first.
 *
 * @param reopen - when the user clicks on the Dock icon, we'll call
 *            reopen.run() using SwingUtilities.invokeLater
 * @param about - when the user clicks on About Alloy4, we'll call about.run()
 *            using SwingUtilities.invokeLater
 * @param open - when a file needs to be opened, we'll call open.run(filename)
 *            using SwingUtilities.invokeLater
 * @param quit - when the user clicks on Quit, we'll call quit.run() using
 *            SwingUtilities.invokeAndWait
 */
public synchronized void registerApplicationListener(final Runnable reopen, final Runnable about, final Runner open, final Runnable quit) {
    if (app == null)
        app = new Application();
    else if (listener != null)
        app.removeApplicationListener(listener);
    listener = new ApplicationAdapter() {

        @Override
        public void handleReOpenApplication(ApplicationEvent arg) {
            SwingUtilities.invokeLater(reopen);
        }

        @Override
        public void handleAbout(ApplicationEvent arg) {
            arg.setHandled(true);
            SwingUtilities.invokeLater(about);
        }

        @Override
        public void handleOpenFile(ApplicationEvent arg) {
            final String filename = arg.getFilename();
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    open.run(filename);
                }
            });
        }

        @Override
        public void handleQuit(ApplicationEvent arg) {
            try {
                if (SwingUtilities.isEventDispatchThread())
                    quit.run();
                else
                    SwingUtilities.invokeAndWait(quit);
            } catch (Throwable e) {
            // Nothing we can do; we're already trying to quit!
            }
            arg.setHandled(false);
        }
    };
    app.addApplicationListener(listener);
}
Also used : ApplicationEvent(com.apple.eawt.ApplicationEvent) ApplicationAdapter(com.apple.eawt.ApplicationAdapter) Application(com.apple.eawt.Application)

Example 3 with ApplicationEvent

use of com.apple.eawt.ApplicationEvent in project org.alloytools.alloy by AlloyTools.

the class MacUtil method addMenus.

public void addMenus(SimpleGUI simpleGUI) {
    Application.getApplication().addPreferencesMenuItem();
    Application.getApplication().addAboutMenuItem();
    Application.getApplication().addApplicationListener(new ApplicationAdapter() {

        @Override
        public void handleAbout(ApplicationEvent ae) {
            simpleGUI.doAbout();
        }

        @Override
        public void handlePreferences(ApplicationEvent ae) {
            simpleGUI.doPreferences();
        }

        @Override
        public void handleQuit(ApplicationEvent arg0) {
            simpleGUI.doQuit();
        }
    });
}
Also used : ApplicationEvent(com.apple.eawt.ApplicationEvent) ApplicationAdapter(com.apple.eawt.ApplicationAdapter)

Aggregations

ApplicationAdapter (com.apple.eawt.ApplicationAdapter)3 ApplicationEvent (com.apple.eawt.ApplicationEvent)3 Application (com.apple.eawt.Application)1 MainWindow (org.jivesoftware.MainWindow)1 ChatFrame (org.jivesoftware.spark.ui.ChatFrame)1