Suggest a feature
×

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
Modified: Aug 31, 2018 9:09 AM
Views: 36
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.  * macOS Implementations for dock icon, apple-style menu, info and
  13.  * preference dialog
  14.  *
  15.  * @author Hani Ibrahim
  16.  */
  17. class MacImpl implements ClassSelector, AboutHandler, PreferencesHandler, QuitHandler {
  18.  
  19.     Application application;
  20.  
  21.     public MacImpl() {
  22.         handleOS();
  23.     }
  24.  
  25.     @Override
  26.     public void handleOS() {
  27.  
  28.         try {
  29.             application = Application.getApplication();
  30.             application.setAboutHandler(this);
  31.             // PreferenceHandler not used yet
  32.             // application.setPreferencesHandler(this);
  33.         } catch (Throwable e) {
  34.             System.err.println("setupMacOSXApplicationListener failed: "
  35.                     + e.getMessage());
  36.         }
  37.  
  38.         // Set dock icon
  39.         application.setDockIconImage(new ImageIcon(getClass().getResource("XXX.png")).getImage());
  40.     }
  41.  
  42.     // Info Dialog
  43.     @Override
  44.     public void handleAbout(AboutEvent arg0) {
  45.         InfoDialog info = new InfoDialog(MAINCLASS.getFrames()[0], true);
  46.         info.setLocationRelativeTo(null /*MAINCLASS.getFrames()[0]*/);
  47.         info.setVisible(true);
  48.         // System.out.println("handleAbout()");
  49.     }
  50.  
  51.     // Options dialog
  52.     @Override
  53.     public void handlePreferences(PreferencesEvent arg0) {
  54.         // new OptionsDialog();
  55.         //System.out.println("handlePreferences()");
  56.     }
  57.  
  58.     @Override
  59.     public void handleQuitRequestWith(QuitEvent arg0, QuitResponse arg1) {
  60.         System.exit(0);
  61.     }
  62. }
  63.  
  64. interface ClassSelector {
  65.  
  66.     public void handleOS();
  67. }