001/******************************************************************************* 002 003 File: PreferencesJMenuItem.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; 021 022/** 023 * This is the Swing implementation of the Preferences menu item. 024 * <p> 025 * On Mac OS X, this menu item is always automatically included in the menu 026 * bar of the application. On other platforms, it never is. You can find out 027 * at runtime if the menu item is automatically included with the 028 * <code>isAutomaticallyPresent()</code> method and then add it yourself if 029 * it isn't. This will make your code cross-platform while letting the 030 * application do the right thing for the current platform. 031 * <p> 032 * In the case where the Preferences menu item is automatically included, 033 * this menu item is really just a placeholder for the actual native menu 034 * item, passing off operations to and from the native menu item where 035 * possible. Of course, when this is the case, not all methods of this class 036 * will be functional. However, there is no harm in calling dysfunctional 037 * methods, other than your user interface not matching your requests. 038 * <p> 039 * The methods that work on all platforms are the following. 040 * <ul> 041 * <li>addActionListener</li> 042 * <li>removeActionListener</li> 043 * <li>setAction (only making the action the listener will actually work on 044 * all platforms)</li> 045 * <li>setEnabled()</li> 046 * <li>isEnabled()</li> 047 * </ul> 048 * 049 * Based pm MRJ Adapter 1.2, Modified by: Joseph A. Huwaldt 050 * @version December 24, 2023 051 */ 052public class PreferencesJMenuItem extends JMenuItem { 053 054 /** 055 * Construct a Preferences menu item. This method is package private so only the 056 * <code>Application</code> class can create a Preferences menu item. 057 */ 058 PreferencesJMenuItem() { 059 super("Preferences"); 060 } 061 062 /** 063 * Construct a Preferences menu item. This method is package private so only the 064 * <code>Application</code> class can create a Preferences menu item. 065 * 066 * @param prefsLabel the label for the preferences menu item. 067 */ 068 PreferencesJMenuItem(String prefsLabel) { 069 super(prefsLabel); 070 } 071 072 /** 073 * Get whether this menu item is automatically present in the menu bar of the current 074 * underlying platform. 075 * 076 * @return whether this menu item is automatically present 077 */ 078 public static boolean isAutomaticallyPresent() { 079 return MacOSUtilities.isMacOS(); 080 } 081}