Search in sources :

Example 1 with QuitEvent

use of com.apple.eawt.AppEvent.QuitEvent in project cytoscape-impl by cytoscape.

the class MacCyActivator method start.

@Override
public void start(BundleContext context) throws Exception {
    final CyServiceRegistrar serviceRegistrar = getService(context, CyServiceRegistrar.class);
    final CyShutdown shutdown = getService(context, CyShutdown.class);
    final TaskFactory aboutTaskFactory = new HelpAboutTaskFactory(serviceRegistrar);
    final DialogTaskManager taskManager = getService(context, DialogTaskManager.class);
    final CyShutdownEvent[] lastShutdownEvent = new CyShutdownEvent[1];
    CyShutdownListener listener = (CyShutdownEvent e) -> {
        lastShutdownEvent[0] = e;
    };
    registerService(context, listener, CyShutdownListener.class, new Properties());
    Application application = Application.getApplication();
    application.setQuitHandler((QuitEvent event, QuitResponse response) -> {
        shutdown.exit(0);
        if (lastShutdownEvent[0] != null && !lastShutdownEvent[0].actuallyShutdown()) {
            response.cancelQuit();
        }
    });
    application.setAboutHandler((AboutEvent event) -> {
        taskManager.execute(aboutTaskFactory.createTaskIterator());
    });
}
Also used : AboutEvent(com.apple.eawt.AppEvent.AboutEvent) DialogTaskManager(org.cytoscape.work.swing.DialogTaskManager) Properties(java.util.Properties) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) CyShutdownListener(org.cytoscape.application.events.CyShutdownListener) HelpAboutTaskFactory(org.cytoscape.internal.view.help.HelpAboutTaskFactory) HelpAboutTaskFactory(org.cytoscape.internal.view.help.HelpAboutTaskFactory) TaskFactory(org.cytoscape.work.TaskFactory) Application(com.apple.eawt.Application) CyShutdownEvent(org.cytoscape.application.events.CyShutdownEvent) QuitResponse(com.apple.eawt.QuitResponse) CyShutdown(org.cytoscape.application.CyShutdown) QuitEvent(com.apple.eawt.AppEvent.QuitEvent)

Example 2 with QuitEvent

use of com.apple.eawt.AppEvent.QuitEvent in project energy3d by concord-consortium.

the class Mac method init.

public static void init() {
    final Application application = Application.getApplication();
    application.setDockIconImage(Toolkit.getDefaultToolkit().getImage(MainFrame.class.getResource("icons/icon.png")));
    application.setOpenFileHandler(new OpenFilesHandler() {

        @Override
        public void openFiles(final OpenFilesEvent e) {
            MainApplication.isMacOpeningFile = true;
            SceneManager.getTaskManager().update(new Callable<Object>() {

                @Override
                public Object call() throws Exception {
                    // somehow newFile() must be called to set up the scene before we can correctly load the content when an NG3 file is double-clicked without an open instance
                    if (Scene.getURL() == null) {
                        Scene.newFile();
                    }
                    try {
                        Scene.open(new File(e.getFiles().get(0).toString()).toURI().toURL());
                    } catch (final Throwable err) {
                        BugReporter.report(err, e.getFiles().get(0).toString());
                    }
                    return null;
                }
            });
        }
    });
    application.setAboutHandler(new AboutHandler() {

        @Override
        public void handleAbout(final AboutEvent e) {
            MainFrame.getInstance().showAbout();
        }
    });
    application.setPreferencesHandler(new PreferencesHandler() {

        @Override
        public void handlePreferences(final PreferencesEvent e) {
            MainFrame.getInstance().showPreferences();
        }
    });
    application.setQuitHandler(new QuitHandler() {

        @Override
        public void handleQuitRequestWith(final QuitEvent e, final QuitResponse r) {
            MainFrame.getInstance().exit();
            r.cancelQuit();
        }
    });
}
Also used : AboutEvent(com.apple.eawt.AppEvent.AboutEvent) PreferencesHandler(com.apple.eawt.PreferencesHandler) OpenFilesHandler(com.apple.eawt.OpenFilesHandler) Callable(java.util.concurrent.Callable) AboutHandler(com.apple.eawt.AboutHandler) QuitHandler(com.apple.eawt.QuitHandler) OpenFilesEvent(com.apple.eawt.AppEvent.OpenFilesEvent) PreferencesEvent(com.apple.eawt.AppEvent.PreferencesEvent) MainApplication(org.concord.energy3d.MainApplication) Application(com.apple.eawt.Application) File(java.io.File) QuitResponse(com.apple.eawt.QuitResponse) QuitEvent(com.apple.eawt.AppEvent.QuitEvent)

Aggregations

AboutEvent (com.apple.eawt.AppEvent.AboutEvent)2 QuitEvent (com.apple.eawt.AppEvent.QuitEvent)2 Application (com.apple.eawt.Application)2 QuitResponse (com.apple.eawt.QuitResponse)2 AboutHandler (com.apple.eawt.AboutHandler)1 OpenFilesEvent (com.apple.eawt.AppEvent.OpenFilesEvent)1 PreferencesEvent (com.apple.eawt.AppEvent.PreferencesEvent)1 OpenFilesHandler (com.apple.eawt.OpenFilesHandler)1 PreferencesHandler (com.apple.eawt.PreferencesHandler)1 QuitHandler (com.apple.eawt.QuitHandler)1 File (java.io.File)1 Properties (java.util.Properties)1 Callable (java.util.concurrent.Callable)1 MainApplication (org.concord.energy3d.MainApplication)1 CyShutdown (org.cytoscape.application.CyShutdown)1 CyShutdownEvent (org.cytoscape.application.events.CyShutdownEvent)1 CyShutdownListener (org.cytoscape.application.events.CyShutdownListener)1 HelpAboutTaskFactory (org.cytoscape.internal.view.help.HelpAboutTaskFactory)1 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)1 TaskFactory (org.cytoscape.work.TaskFactory)1