public static void enablePrefs(boolean enabled) { if (app == null) { app = new com.apple.eawt.Application(); } app.setEnabledPreferencesMenu(enabled); }
public static void registerMacOSXApplication(TregexGUI inApp) { if (app == null) { app = new com.apple.eawt.Application(); } if (adapter == null) { adapter = new OSXAdapter(inApp); } app.addApplicationListener(adapter); }
public void handleQuit(ApplicationEvent event) { LOG.info("Got the boot..."); super.handleQuit(event); System.exit(0); } }
private MacBootstrapperApplicationAdapter initializeApplicationAdapter() { Application application = Application.getApplication(); application.setEnabledPreferencesMenu(true); application.setEnabledAboutMenu(true); setVisible(false); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); setResizable(false); setSize(getPreferredSize()); MacBootstrapperApplicationAdapter applicationAdapter = new MacBootstrapperApplicationAdapter(this); application.addApplicationListener(applicationAdapter); return applicationAdapter; }
import com.apple.eawt.Application; import javax.swing.*; class SetIcon extends JFrame { SetIcon() { setIconImage(new ImageIcon("doc.png").getImage()); Application.getApplication().setDockIconImage( new ImageIcon("app.png").getImage()); } public static void main(String args[]) { SetIcon s = new SetIcon(); s.setVisible(true); } }
public GoMacLauncher() throws HeadlessException { application.addApplicationListener(new MyApplicationAdapter()); application.setEnabledAboutMenu(true); application.setEnabledPreferencesMenu(false); setVisible(false); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); setResizable(false); setSize(getPreferredSize()); }
@Override public void handleAbout(ApplicationEvent ae) { if (mainApp != null) { ae.setHandled(true); mainApp.about(); } else { throw new IllegalStateException("handleAbout: TregexGUI instance detached from listener"); } }
/** * Requests the foreground in a macOS friendly way. */ public static void requestFocus() { if (OSType.getOSType() == OSType.MacOS) { Application app = Application.getApplication(); app.requestForeground(true); log.debug("Requested focus on macOS"); } } }
private void updateDockIconBadge(String badgeValue) { try { Application.getApplication().setDockIconBadge(badgeValue); } catch (RuntimeException e) { LOGGER.debug("Error: {} - This is probably because we run on a non-Mac platform and these components are not implemented", e.getMessage()); } catch (Exception e) { LOGGER.error("", e); } } }
import com.apple.eawt.Application; ... Application application = Application.getApplication(); Image image = Toolkit.getDefaultToolkit().getImage("icon.png"); application.setDockIconImage(image);
public void handleOpenFile(ApplicationEvent e) { Luyten.openFileInInstance(new File(e.getFilename())); }
/** * Enables the osx native fullscreen if running on a mac. * * @param gui The gui to enable the fullscreen on. */ public static void tryEnableFullscreen(JFrame gui) { if (OSType.getOSType() == OSType.MacOS) { FullScreenUtilities.setWindowCanFullScreen(gui, true); log.debug("Enabled fullscreen on macOS"); } }
@Override public void run() { try { URL envelopeImage = getClass().getResource(Configuration.INSTANCE.get("application.icon.path")); if (envelopeImage != null) { Application.getApplication().setDockIconImage(Toolkit.getDefaultToolkit().getImage(envelopeImage)); } } catch (RuntimeException e) { LOGGER.debug("Error: {} - This is probably because we run on a non-Mac platform and these components are not implemented", e.getMessage()); } catch (Exception e) { LOGGER.error("", e); } System.setProperty("apple.laf.useScreenMenuBar", "true"); System.setProperty("com.apple.mrj.application.apple.menu.about.name", Configuration.INSTANCE.get("application.name")); UIManager.put("swing.boldMetal", Boolean.FALSE); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { LOGGER.error("", e); } new MainFrame(); } });
@Override public void handlePreferences(ApplicationEvent ae) { if (mainApp != null) { mainApp.doPreferences(); ae.setHandled(true); } else { throw new IllegalStateException("handlePreferences: TregexGUI instance detached from listener"); } }
public static void main(String[] args) { // Set a flag that says we are running in OS X System.setProperty("us.deathmarine.luyten.Luyten.running_in_osx", "true"); // Add an adapter as the handler to a new instance of the application // class @SuppressWarnings("deprecation") Application app = new Application(); app.addApplicationListener(new ApplicationAdapter() { public void handleOpenFile(ApplicationEvent e) { Luyten.openFileInInstance(new File(e.getFilename())); } public void handleQuit(ApplicationEvent e) { Luyten.quitInstance(); } }); // Call the superclass's main function Luyten.main(args); } }
public void handleQuit(ApplicationEvent event) { LOG.info("Got the boot..."); super.handleQuit(event); System.exit(0); }
@Override public void handleQuit(ApplicationEvent ae) { if (mainApp != null) { /* / You MUST setHandled(false) if you want to delay or cancel the quit. / This is important for cross-platform development -- have a universal quit / routine that chooses whether or not to quit, so the functionality is identical / on all platforms. This example simply cancels the AppleEvent-based quit and / defers to that universal method. */ ae.setHandled(false); TregexGUI.doQuit(); } else { throw new IllegalStateException("handleQuit: TregexGUI instance detached from listener"); } }
public void handlePreferences(ApplicationEvent e) { if (prefPane == null) { prefPane = new MacPreferencesPane(agentMacWindow); } LOG.info("Got Preferences event"); prefPane.ask(); if (e != null) { e.setHandled(true); } }
public void handleAbout(ApplicationEvent e) { if (aboutBox == null) { aboutBox = new MacAboutBox(); } LOG.info("Got About event"); aboutBox.setVisible(true); e.setHandled(true); }
public void handleAbout(ApplicationEvent e) { if (aboutBox == null) { aboutBox = new MacAboutBox(); } LOG.info("Got About describeChange"); aboutBox.setResizable(false); aboutBox.setVisible(true); e.setHandled(true); }