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

net.roydesign.app.QuitMenuItem 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:		QuitMenuItem.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 java.awt.MenuItem;
import java.awt.MenuShortcut;
import java.awt.event.ActionListener;

/**
 * This is the AWT implementation of the Quit 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 Quit 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)
  • *
* * @version MRJ Adapter 1.2 */ public class QuitMenuItem extends MenuItem { /** * Construct a Quit menu item. This method is package private so only * the {@code Application} class can create a Quit menu item. * @param application the application instance using this item */ QuitMenuItem(Application application) { super("Quit", new MenuShortcut('Q')); String appName = application.getName(); if (appName != null) setLabel("Quit " + appName); } /** * Add an action listener to the menu item. * @param l the action listener to be added */ @Override public synchronized void addActionListener(ActionListener l) { MRJAdapter.addQuitApplicationListener(l, this); super.addActionListener(l); } /** * Remove an action listener from the menu item. * @param l the action listener to be removed */ @Override public synchronized void removeActionListener(ActionListener l) { MRJAdapter.removeQuitApplicationListener(l); super.removeActionListener(l); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy