Package com.apple.eawt

Examples of com.apple.eawt.Application


  private static class MacOSXConfiguration {
    /**
     * Binds <code>controller</code> to Mac OS X application menu.
     */
    public static void bindToApplicationMenu(final EditorController controller) {
      Application macosxApplication = Application.getApplication();
      // Add a listener to Mac OS X application that will call controller methods
      macosxApplication.addApplicationListener(new ApplicationAdapter() {     
        @Override
        public void handleQuit(ApplicationEvent ev) {
          controller.exit();
        }
       
        @Override
        public void handleAbout(ApplicationEvent ev) {
          controller.about();
          ev.setHandled(true);
        }

        @Override
        public void handlePreferences(ApplicationEvent ev) {
          controller.editPreferences();
          ev.setHandled(true);
        }
       
        @Override
        public void handleOpenFile(ApplicationEvent ev) {
          controller.open(ev.getFilename());
        }
       
        @Override
        public void handleReOpenApplication(ApplicationEvent ev) {
          SwingUtilities.getWindowAncestor((JComponent)controller.getView()).toFront();
        }
      });
      macosxApplication.setEnabledAboutMenu(true);
      macosxApplication.setEnabledPreferencesMenu(true);
     
      // Set application icon if program wasn't launch from bundle
      if (!"true".equalsIgnoreCase(System.getProperty("furniturelibraryeditor.bundle", "false"))) {
        try {
          Image icon = ImageIO.read(MacOSXConfiguration.class.getResource("swing/resources/aboutIcon.png"));
          macosxApplication.setDockIconImage(icon);
        } catch (NoSuchMethodError ex) {
          // Ignore icon change if setDockIconImage isn't available
        } catch (IOException ex) {
        }
      }
View Full Code Here


class MacOSXConfiguration {
  /**
   * Binds <code>homeApplication</code> to Mac OS X application menu.
   */
  public static void bindToApplicationMenu(final SweetHome3D homeApplication) {
    Application macosxApplication = Application.getApplication();
    // Create a default controller for an empty home and disable unrelated actions
    final HomeController defaultController =
        homeApplication.createHomeFrameController(homeApplication.createHome()).getHomeController();
    final HomePane defaultHomeView = (HomePane)defaultController.getView();
    for (HomePane.ActionType action : HomePane.ActionType.values()) {
      switch (action) {
        case ABOUT :
        case NEW_HOME :
        case OPEN :
        case DELETE_RECENT_HOMES :
        case HELP :
          break;
        default :
          defaultHomeView.setEnabled(action, false);
      }
    }

    final JMenuBar defaultMenuBar = defaultHomeView.getJMenuBar();
    JFrame frame;
    try {
      if (UIManager.getLookAndFeel().getClass().getName().equals(UIManager.getSystemLookAndFeelClassName())) {
        macosxApplication.setDefaultMenuBar(defaultMenuBar);
        addWindowMenu(null, defaultMenuBar, homeApplication, true);
      }
      frame = null;
    } catch (NoSuchMethodError ex) {
      // Create default frame if setDefaultMenuBar isn't available
      frame = new JFrame();
      final JFrame defaultFrame = frame;
      EventQueue.invokeLater(new Runnable() {
        public void run() {
          // Create a default undecorated frame out of sight
          // and attach the application menu bar of empty view to it
          defaultFrame.setLocation(-10, 0);
          defaultFrame.setUndecorated(true);
          defaultFrame.setVisible(true);
          defaultFrame.setJMenuBar(defaultMenuBar);
          defaultFrame.setContentPane(defaultHomeView);
          addWindowMenu(defaultFrame, defaultMenuBar, homeApplication, true);
        }
      });
    }

    final JFrame defaultFrame = frame;
    // Add a listener to Mac OS X application that will call
    // controller methods of the active frame
    macosxApplication.addApplicationListener(new ApplicationAdapter() {     
      @Override
      public void handleQuit(ApplicationEvent ev) {
        handleAction(new Runnable() {
            public void run() {
              defaultController.exit();
            }
          });
        if (homeApplication.getHomes().isEmpty()) {
          System.exit(0);
        }
      }
     
      @Override
      public void handleAbout(ApplicationEvent ev) {
        handleAction(new Runnable() {
            public void run() {
              defaultController.about();
            }
          });
        ev.setHandled(true);
      }

      @Override
      public void handlePreferences(ApplicationEvent ev) {
        handleAction(new Runnable() {
            public void run() {
              defaultController.editPreferences();
            }
          });
      }
     
      private void handleAction(Runnable runnable) {
        Frame activeFrame = null;
        for (Frame frame : Frame.getFrames()) {
          if (frame.isActive()) {
            activeFrame = frame;
            break;
          }
        }
        if (defaultFrame != null) {
          // Move default frame to center to display dialogs at center
          defaultFrame.setLocationRelativeTo(null);
        }
       
        runnable.run();
       
        // Activate previous frame again
        if (activeFrame != null) {
          activeFrame.toFront();
        }
        if (defaultFrame != null) {
          // Move default frame out of user view
          defaultFrame.setLocation(-10, 0);
        }
      }

      @Override
      public void handleOpenFile(ApplicationEvent ev) {
        // handleOpenFile is called when user opens a document
        // associated with a Java Web Start application
        // Just call main with -open file arguments as JNLP specifies
        homeApplication.run(new String [] {"-open", ev.getFilename()});
      }
     
      @Override
      public void handleReOpenApplication(ApplicationEvent ev) {
        // handleReOpenApplication is called when user launches
        // the application when it's already open
        homeApplication.run(new String [0]);
      }
    });
    macosxApplication.setEnabledAboutMenu(true);
    macosxApplication.setEnabledPreferencesMenu(true);
   
    homeApplication.addHomesListener(new CollectionListener<Home>() {
      public void collectionChanged(CollectionEvent<Home> ev) {
        if (ev.getType() == CollectionEvent.Type.ADD) {
          // Add Mac OS X Window menu on new homes
          JFrame homeFrame = homeApplication.getHomeFrame(ev.getItem());
          MacOSXConfiguration.addWindowMenu(
              homeFrame, homeFrame.getJMenuBar(), homeApplication, false);
        }
      };
    });
   
    // Set application icon if program wasn't launch from bundle
    if (!"true".equalsIgnoreCase(System.getProperty("sweethome3d.bundle", "false"))) {
      try {
        String iconPath = homeApplication.getUserPreferences().getLocalizedString(HomePane.class, "about.icon");
        Image icon = ImageIO.read(HomePane.class.getResource(iconPath));
        macosxApplication.setDockIconImage(icon);
      } catch (NoSuchMethodError ex) {
        // Ignore icon change if setDockIconImage isn't available
      } catch (IOException ex) {
      }
    }
View Full Code Here

    {
      delegate = new Delegate();
      NSApplication app = NSApplication.sharedApplication();
     
      Macros.registerHandler(new AppleScriptHandler());
      Application app2 = new Application();
      app2.addApplicationListener(delegate);
      app2.setEnabledPreferencesMenu(true);
      app2.setEnabledAboutMenu(true);
     
      app.setDelegate(delegate);
      //app.setServicesProvider(delegate);
    }
  } //}}}
View Full Code Here

                KeyEvent.VK_SLASH, KeyEvent.SHIFT_MASK |
                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    }

    public void actionPerformed(ActionEvent e) {
      Application app = Application.getApplication();
      app.openHelpViewer();
     
        //HelpBook.launchHelpViewer();
    }   
View Full Code Here

  protected void platformSpecificSetup(){
   
        finishAction = new QuitAction(this);
        aboutAction = new MacAboutAction(this);
       
        Application app = Application.getApplication();
    app.setAboutHandler(new AboutHandler() {
      @Override
      public void handleAbout(AboutEvent arg0) {
        aboutAction.actionPerformed(null);
      }
    });
        app.setQuitHandler(new QuitHandler() {
      public void handleQuitRequestWith(QuitEvent arg0, QuitResponse arg1) {
        finishAction.actionPerformed(null);
      }
    });
        app.setOpenFileHandler(new OpenFilesHandler() {
      @Override
      public void openFiles(OpenFilesEvent arg0) {
        List<File> ff = arg0.getFiles();
        File first = ff.get(0);
        String nm = first.getName().toLowerCase();
View Full Code Here

* @author Maxence Bernard
*/
class EAWTHandler implements ApplicationListener {

    public EAWTHandler() {
        Application app = new Application();
        // Enable the 'About' menu item
        app.setEnabledAboutMenu(true);
        // Enable the 'Preferences' menu item
        app.setEnabledPreferencesMenu(true);
        // Register this ApplicationListener
        app.addApplicationListener(this);
    }
View Full Code Here

        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                client.init();

                if (isMac()) {
                    Application macApplication = Application.getApplication();
                    macApplication.setDockIconImage(new ImageIcon(Client.class.getClassLoader().getResource("sysimages/ico.png")).getImage());
                    macApplication.addApplicationListener(new MacApplicationAdapter(client));
                }

                DebugConfig debugConfig = client.getConfig().getDebug();
                if (debugConfig != null && debugConfig.isAutostartEnabled()) {
                    client.createGame();
View Full Code Here

/* 276 */       throw e;
/*     */     }
/*     */   }
/*     */
/*     */   static synchronized void registerAboutHandler(MRJAboutHandler handler) {
/* 281 */     Application fApplication = new Application();
/* 282 */     ApplicationAdapter fAdapter = new MRJAboutApplicationAdapter(handler);
/*     */
/* 284 */     fApplication.addApplicationListener(fAdapter);
/*     */   }
View Full Code Here

/*     */
/* 284 */     fApplication.addApplicationListener(fAdapter);
/*     */   }
/*     */
/*     */   static synchronized void registerOpenApplicationHandler(MRJOpenApplicationHandler handler) {
/* 288 */     Application fApplication = new Application();
/* 289 */     ApplicationAdapter fAdapter = new MRJOpenApplicationApplicationAdapter(handler);
/*     */
/* 291 */     fApplication.addApplicationListener(fAdapter);
/*     */   }
View Full Code Here

/*     */
/* 291 */     fApplication.addApplicationListener(fAdapter);
/*     */   }
/*     */
/*     */   static synchronized void registerOpenDocumentHandler(MRJOpenDocumentHandler handler) {
/* 295 */     Application fApplication = new Application();
/* 296 */     ApplicationAdapter fAdapter = new MRJOpenDocumentApplicationAdapter(handler);
/*     */
/* 298 */     fApplication.addApplicationListener(fAdapter);
/*     */   }
View Full Code Here

TOP

Related Classes of com.apple.eawt.Application

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.