All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.roydesign.app.PreferencesJMenuItem Maven / Gradle / Ivy

Go to download

MRJ Adapter is a wrapper around built in Java Virtual Machine APIs provided by Apple.

The newest version!
/*******************************************************************************

	File:		PreferencesJMenuItem.java
	Author:		Steve Roy 
				
	Part of MRJ Adapter, a unified API for easy integration of Mac OS specific
	functionality within your cross-platform Java application.
	
	This library is open source and can be modified and/or distributed under
	the terms of the Artistic License.
	
	
	Change History:
	01/31/03	Created this file - Steve

*******************************************************************************/

package net.roydesign.app;

import net.roydesign.mac.MRJAdapter;

import javax.swing.JMenuItem;
import java.awt.event.ActionListener;

/**
 * This is the Swing implementation of the Preferences menu item.
 * 

* On Mac OS X, this menu item is always automatically included in the menu * bar of the application. On other platforms, it never is. You can find out * at runtime if the menu item is automatically included with the * {@code isAutomaticallyPresent()} method and then add it yourself if * it isn't. This will make your code cross-platform while letting the * application do the right thing for the current platform. *

* In the case where the Preferences menu item is automatically included, * this menu item is really just a placeholder for the actual native menu * item, passing off operations to and from the native menu item where * possible. Of course, when this is the case, not all methods of this class * will be functional. However, there is no harm in calling dysfunctional * methods, other than your user interface not matching your requests. *

* The methods that work on all platforms are the following. *

    *
  • addActionListener
  • *
  • removeActionListener
  • *
  • setAction (only making the action the listener will actually work on * all platforms)
  • *
  • setEnabled()
  • *
  • isEnabled()
  • *
* * @version MRJ Adapter 1.2 */ public class PreferencesJMenuItem extends JMenuItem { /** * Construct a Preferences menu item. This method is package private so only * the {@code Application} class can create a Preferences menu item. */ PreferencesJMenuItem() { super("Preferences"); } /** * Add an action listener to the menu item. * @param l the action listener to be added */ @Override public void addActionListener(ActionListener l) { MRJAdapter.addPreferencesListener(l, this); super.addActionListener(l); } /** * Remove an action listener from the menu item. * @param l the action listener to be removed */ @Override public void removeActionListener(ActionListener l) { MRJAdapter.removePreferencesListener(l); super.removeActionListener(l); } /** * Set whether the menu item can interact with the user or not. This * method is overriden to pass off the action to the native menu item. * @param enabled whether the menu item can interact with the user */ @Override public void setEnabled(boolean enabled) { MRJAdapter.setPreferencesEnabled(enabled); super.setEnabled(enabled); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy