1 19 20 package edu.umd.cs.findbugs.gui2; 21 22 import com.apple.eawt.ApplicationAdapter; 23 import com.apple.eawt.ApplicationEvent; 24 25 32 public class OSXAdapter extends ApplicationAdapter { 33 34 private static OSXAdapter theAdapter; 37 private static com.apple.eawt.Application theApplication; 38 39 private MainFrame mainApp; 41 42 private OSXAdapter (MainFrame inApp) { 43 mainApp = inApp; 44 } 45 46 50 @Override 51 public void handleAbout(ApplicationEvent ae) { 52 if (mainApp != null) { 53 ae.setHandled(true); 54 javax.swing.SwingUtilities.invokeLater(new Runnable () { 60 public void run() { 61 mainApp.about(); 62 } 63 }); 64 } else { 65 throw new IllegalStateException ("handleAbout: " + 66 "MyApp instance detached from listener"); 67 } 68 } 69 70 @Override 71 public void handlePreferences(ApplicationEvent ae) { 72 if (mainApp != null) { 73 ae.setHandled(true); 75 } else { 76 throw new IllegalStateException ("handlePreferences: MyApp instance " + 77 "detached from listener"); 78 } 79 } 80 81 @Override 82 public void handleQuit(ApplicationEvent ae) { 83 if (mainApp != null) { 84 85 95 96 ae.setHandled(false); 97 mainApp.callOnClose(); 98 } else { 99 throw new IllegalStateException ("handleQuit: MyApp instance detached " + 100 "from listener"); 101 } 102 } 103 104 105 public static void registerMacOSXApplication(MainFrame inApp) { 109 if (theApplication == null) { 110 theApplication = new com.apple.eawt.Application(); 111 } 112 113 if (theAdapter == null) { 114 theAdapter = new OSXAdapter(inApp); 115 } 116 theApplication.addApplicationListener(theAdapter); 117 } 118 119 public static void enablePrefs(boolean enabled) { 122 if (theApplication == null) { 123 theApplication = new com.apple.eawt.Application(); 124 } 125 theApplication.setEnabledPreferencesMenu(enabled); 126 } 127 } | Popular Tags |