001/******************************************************************************* 002 003 File: AboutJMenuItem.java 004 Author: Steve Roy <steve@sillybit.com> 005 006 Part of MRJ Adapter, a unified API for easy integration of Mac OS specific 007 functionality within your cross-platform Java application. 008 009 This library is open source and can be modified and/or distributed under 010 the terms of the Artistic License. 011 <http://mrjadapter.dev.java.net/license.html> 012 013 Change History: 014 01/31/03 Created this file - Steve 015 016*******************************************************************************/ 017 018package jahuwaldt.swing; 019 020import javax.swing.JMenuItem; 021import java.awt.event.ActionListener; 022import static java.util.Objects.nonNull; 023 024/** 025 * This is the Swing implementation of the About menu item. 026 * <p> 027 * On all versions of Mac OS, this menu item is always automatically included 028 * in the menu bar of the application. On other platforms, it never is. You 029 * can find out at runtime if the menu item is automatically included with the 030 * <code>isAutomaticallyPresent()</code> method and then add it yourself if 031 * it isn't. This will make your code cross-platform while letting the 032 * application do the right thing for the current platform. 033 * <p> 034 * In the case where the About menu item is automatically included, this menu 035 * item is really just a placeholder for the actual native menu item, passing 036 * off operations to and from the native menu item where possible. Of course, 037 * when this is the case, not all methods of this class will be functional. 038 * However, there is no harm in calling dysfunctional methods, other than 039 * your user interface not matching your requests. 040 * <p> 041 * The methods that work on all platforms are the following. 042 * <ul> 043 * <li>addActionListener</li> 044 * <li>removeActionListener</li> 045 * <li>setAction (only making the action the listener will actually work on 046 * all platforms)</li> 047 * </ul> 048 * 049 * MRJ Adapter 1.2, Modified by Joseph A. Huwaldt 050 * @version December 12, 2023 051 */ 052public class AboutJMenuItem extends JMenuItem { 053 054 /** 055 * Construct an About menu item. This method is package private so only the 056 * <code>Application</code> class can create an About menu item. 057 * 058 * @param application the application instance using this item 059 */ 060 @SuppressWarnings("OverridableMethodCallInConstructor") 061 AboutJMenuItem(MDIApplication application) { 062 super("About"); 063 String appName = application.getName(); 064 if (nonNull(appName)) 065 setText("About " + appName); 066 } 067 068 /** 069 * Get whether this menu item is automatically present in the menu bar of the current 070 * underlying platform. 071 * 072 * @return whether this menu item is automatically present 073 */ 074 public static boolean isAutomaticallyPresent() { 075 return MacOSUtilities.isMacOS(); 076 } 077}