×

Welcome to TagMyCode

Please login or create account to add a snippet.
1
0
 
1
Language: Java
Posted by: Hani Ibrahim
Added: Dec 30, 2016 8:18 AM
Views: 12
Dock icon, info dialog & preferences dialog for Mac OS X. Need AppleJava Extension library
  1. import com.apple.eawt.AboutHandler;
  2. import com.apple.eawt.AppEvent.AboutEvent;
  3. import com.apple.eawt.AppEvent.PreferencesEvent;
  4. import com.apple.eawt.AppEvent.QuitEvent;
  5. import com.apple.eawt.Application;
  6. import com.apple.eawt.PreferencesHandler;
  7. import com.apple.eawt.QuitHandler;
  8. import com.apple.eawt.QuitResponse;
  9. import javax.swing.ImageIcon;
  10.  
  11. /**
  12.  *
  13.  * @author Hani Ibrahim
  14.  */
  15. class MacImpl implements ClassSelector, AboutHandler, PreferencesHandler, QuitHandler {
  16.  
  17.     Application application;
  18.  
  19.     public MacImpl() {
  20.         handleOS();
  21.     }
  22.  
  23.     @Override
  24.     public void handleOS() {
  25.  
  26.         try {
  27.             application = Application.getApplication();
  28.             application.setAboutHandler(this);
  29.             // PreferenceHandler not used yet
  30.             // application.setPreferencesHandler(this);
  31.         } catch (Throwable e) {
  32.             System.err.println("setupMacOSXApplicationListener failed: "
  33.                     + e.getMessage());
  34.         }
  35.  
  36.         // Set dock icon
  37.         application.setDockIconImage(new ImageIcon(getClass().getResource("XXX.png")).getImage());
  38.     }
  39.  
  40.     // Info Dialog
  41.     @Override
  42.     public void handleAbout(AboutEvent arg0) {
  43.         InfoDialog info = new InfoDialog(MAINCLASS.getFrames()[0], true);
  44.         info.setLocationRelativeTo(null /*MAINCLASS.getFrames()[0]*/);
  45.         info.setVisible(true);
  46.         // System.out.println("handleAbout()");
  47.     }
  48.  
  49.     // Options dialog
  50.     @Override
  51.     public void handlePreferences(PreferencesEvent arg0) {
  52.         // new OptionsDialog();
  53.         //System.out.println("handlePreferences()");
  54.     }
  55.  
  56.     @Override
  57.     public void handleQuitRequestWith(QuitEvent arg0, QuitResponse arg1) {
  58.         System.exit(0);
  59.     }
  60. }
  61.  
  62. interface ClassSelector {
  63.  
  64.     public void handleOS();
  65. }