1 package edu.umd.cs.findbugs.gui; 2 3 import com.apple.eawt.ApplicationAdapter; 4 import com.apple.eawt.ApplicationEvent; 5 6 13 public class OSXAdapter extends ApplicationAdapter { 14 15 private static OSXAdapter theAdapter; 18 private static com.apple.eawt.Application theApplication; 19 20 private FindBugsFrame mainApp; 22 23 private OSXAdapter (FindBugsFrame inApp) { 24 mainApp = inApp; 25 } 26 27 31 @Override 32 public void handleAbout(ApplicationEvent ae) { 33 if (mainApp != null) { 34 ae.setHandled(true); 35 javax.swing.SwingUtilities.invokeLater(new Runnable () { 41 public void run() { 42 mainApp.about(); 43 } 44 }); 45 } else { 46 throw new IllegalStateException ("handleAbout: " + 47 "MyApp instance detached from listener"); 48 } 49 } 50 51 @Override 52 public void handlePreferences(ApplicationEvent ae) { 53 if (mainApp != null) { 54 ae.setHandled(true); 56 } else { 57 throw new IllegalStateException ("handlePreferences: MyApp instance " + 58 "detached from listener"); 59 } 60 } 61 62 @Override 63 public void handleQuit(ApplicationEvent ae) { 64 if (mainApp != null) { 65 66 76 77 ae.setHandled(false); 78 mainApp.exitFindBugs(); 79 } else { 80 throw new IllegalStateException ("handleQuit: MyApp instance detached " + 81 "from listener"); 82 } 83 } 84 85 86 public static void registerMacOSXApplication(FindBugsFrame inApp) { 90 if (theApplication == null) { 91 theApplication = new com.apple.eawt.Application(); 92 } 93 94 if (theAdapter == null) { 95 theAdapter = new OSXAdapter(inApp); 96 } 97 theApplication.addApplicationListener(theAdapter); 98 } 99 100 public static void enablePrefs(boolean enabled) { 103 if (theApplication == null) { 104 theApplication = new com.apple.eawt.Application(); 105 } 106 theApplication.setEnabledPreferencesMenu(enabled); 107 } 108 } | Popular Tags |