API addition proposal -- Add Action enum and methods to javafx.application.Application
David Kopp
codebangusllc at gmail.com
Sat Oct 12 14:35:00 UTC 2024
Hello everyone,
I develop cross platform JavaFX applications. On MacOS one of the annoying things about JavaFX is that it does not provide a way to add About <<app_name>> and Settings… to the application menu bar like the java.awt.Desktop class does in Swing.
My proposal is to add similar functionality to JavaFX. I propose adding the following to javafx.platform.Application:
/**
* Represents an action type. Each platform supports a different set of actions.
*
* @since JavaFX 24
*/
public static enum Action {
/**
* Represents an AboutHandler.
*/
APP_ABOUT,
/**
* Represents a PreferencesHandler.
*/
APP_PREFERENCES
}
/**
* Tests whether an action is supported on the current platform.
*
* @param action the specified Application.Action
* @return {@code true} if the specified action is supported on the current platform;
* {@code false} otherwise
*
* @since JavaFX 24
*/
public boolean isSupported(Application.Action action) {
return PlatformImpl.isActionSupported(action);
}
/**
* Installs a handler to show a custom About window for your application.
* <p>
* Setting the AboutHandler to null reverts it to the default behavior.
*
* @param handler the handler
*
* @throws UnsupportedOperationException - if the current platform does not support the
* Application.Action.APP_ABOUT action
*
* @since JavaFX 24
*/
public void setAboutHandler(AboutHandler handler) {
PlatformImpl.setAboutHandler(handler);
}
/**
* Installs a handler to show a custom Preferences window for your application.
* <p>
* Setting the PreferencesHandler to null reverts it to the default behavior.
*
* @param handler the handler
*
* @throws UnsupportedOperationException - if the current platform does not support the
* Application.Action.APP_PREFERENCES action
*
* @since JavaFX 24
*/
public void setPreferencesHandler(PreferencesHandler handler) {
PlatformImpl.setPreferencesHandler(handler);
}
AboutHandle and PreferencesHander are functional interfaces added to the javafx.application package. They have methods handleAbout() and handlePreferences() respectively.
I have implemented the above on my fork of jfx by modifying the PlatformImpl, com.sun.glass.ui.Application, and com.sun.glass.ui.MacApplication classes.
What does the mailing list think?
Have a blessed day,
David Kopp
More information about the openjfx-dev
mailing list