Class PlatformSupport
- java.lang.Object
-
- ca.cgjennings.platform.PlatformSupport
-
public class PlatformSupport extends java.lang.ObjectThis utility class provides methods that help integrate an application into the native operating system more cleanly. It is pure Java code.- Author:
- Chris Jennings
-
-
Field Summary
Fields Modifier and Type Field Description static booleanPLATFORM_IS_MACTrue if the JVM is running on an Apple macOS operating system.static booleanPLATFORM_IS_OSXDeprecated.Alias forPLATFORM_IS_MAC.static booleanPLATFORM_IS_OTHERTrue if running on a non-Windows, non-maxOS operating system.static booleanPLATFORM_IS_WINDOWSTrue if the JVM is running on a Windows operating system.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static javax.swing.JButtongetAgnosticCancel(boolean isInOKCancelOrder, javax.swing.JButton designedOK, javax.swing.JButton designedCancel)Return the button that will be (or is) the Cancel button in an agnostic dialog.static javax.swing.JButtongetAgnosticOK(boolean isInOKCancelOrder, javax.swing.JButton designedOK, javax.swing.JButton designedCancel)Return the button that will be (or is) the OK button in an agnostic dialog.static javax.swing.KeyStrokegetKeyStroke(java.lang.String stroke)Parse a string to create aKeyStrokeappropriate as an accelerator for the native OS.static voidinstallNativeLookAndFeel()Call this method before opening any Swing windows to install the native look and feel.static booleanisAgnosticOKInFirstPosition()Returnstrueif the OK button should be left (ahead) of the Cancel button on this platform.static javax.swing.JButtonmakeAgnosticDialog(AgnosticDialog dialog, boolean isInOKCancelOrder, javax.swing.JButton designedOK, javax.swing.JButton designedCancel)Initialize anAgnosticDialogby swapping the OK and Cancel buttons, if appropriate, and attaching action listeners to theAgnosticDialog.handleOKAction(java.awt.event.ActionEvent)andAgnosticDialog.handleCancelAction(java.awt.event.ActionEvent)methods.static javax.swing.JButtonmakeAgnosticDialog(AgnosticDialog dialog, javax.swing.JButton designedOK, javax.swing.JButton designedCancel)A convenience method formakeAgnosticDialog( dialog, true, designedOK, designedCancel ), which assumes that the dialog buttons are in "Windows order" (OK on the left, Cancel on the right).
-
-
-
Field Detail
-
PLATFORM_IS_MAC
public static final boolean PLATFORM_IS_MAC
True if the JVM is running on an Apple macOS operating system.
-
PLATFORM_IS_OSX
@Deprecated public static final boolean PLATFORM_IS_OSX
Deprecated.Alias forPLATFORM_IS_MAC.
-
PLATFORM_IS_WINDOWS
public static final boolean PLATFORM_IS_WINDOWS
True if the JVM is running on a Windows operating system.
-
PLATFORM_IS_OTHER
public static final boolean PLATFORM_IS_OTHER
True if running on a non-Windows, non-maxOS operating system. Typically this means a Unix-like operating system such as Linux.
-
-
Method Detail
-
makeAgnosticDialog
public static javax.swing.JButton makeAgnosticDialog(AgnosticDialog dialog, javax.swing.JButton designedOK, javax.swing.JButton designedCancel)
A convenience method formakeAgnosticDialog( dialog, true, designedOK, designedCancel ), which assumes that the dialog buttons are in "Windows order" (OK on the left, Cancel on the right).- Parameters:
dialog- the dialog or other control to be reordereddesignedOK- the button used as the OK button in the designdesignedCancel- the button used as the Cancel button in the design- Returns:
- the button that will be used as the OK button
-
makeAgnosticDialog
public static javax.swing.JButton makeAgnosticDialog(AgnosticDialog dialog, boolean isInOKCancelOrder, javax.swing.JButton designedOK, javax.swing.JButton designedCancel)
Initialize anAgnosticDialogby swapping the OK and Cancel buttons, if appropriate, and attaching action listeners to theAgnosticDialog.handleOKAction(java.awt.event.ActionEvent)andAgnosticDialog.handleCancelAction(java.awt.event.ActionEvent)methods.This method should generally be applied during the window's construction, before it is first made visible.
By default, this method will automatically swap the text, icon, mnemonic, displayed mnemonic index, and default button status of the two buttons if they need to be swapped. No other properties are changed. For complete control over the actions taken when a swap occurs, implement
QueriedAgnosticDialoginstead. This is a subinterface ofAgnosticDialog.Notes:
- You must ensure that this method is only called once for a given
AgnosticDialogduring its lifetime, or the button order will be inconsistent and the action events will be called multiple times. - Although referred to in the general sense as the "OK" button, the text of this button should name the specific action it will perform.
- Parameters:
dialog- the dialog or other control to be reorderedisInOKCancelOrder-trueis the dialog is designed withdesignedOKon the leftdesignedOK- the button that was designed to be the "OK" (accept, commit) buttondesignedCancel- the button that was designed to be the "Cancel" button- Returns:
- the button that will be used as the OK button
- Throws:
java.lang.IllegalArgumentException- if either button isnullor if they refer to the same object
- You must ensure that this method is only called once for a given
-
getAgnosticOK
public static javax.swing.JButton getAgnosticOK(boolean isInOKCancelOrder, javax.swing.JButton designedOK, javax.swing.JButton designedCancel)Return the button that will be (or is) the OK button in an agnostic dialog. This can be called before or aftermakeAgnosticDialog(ca.cgjennings.platform.AgnosticDialog, javax.swing.JButton, javax.swing.JButton).- Parameters:
isInOKCancelOrder-trueis the dialog is designed withdesignedOKon the leftdesignedOK- the button that was designed as the "OK" (accept, commit) buttondesignedCancel- the button that was designed as the "Cancel" button- Returns:
- the button that will represent the OK button in an agnostic dialog
-
getAgnosticCancel
public static javax.swing.JButton getAgnosticCancel(boolean isInOKCancelOrder, javax.swing.JButton designedOK, javax.swing.JButton designedCancel)Return the button that will be (or is) the Cancel button in an agnostic dialog. This can be called before or aftermakeAgnosticDialog(ca.cgjennings.platform.AgnosticDialog, javax.swing.JButton, javax.swing.JButton).- Parameters:
isInOKCancelOrder-trueis the dialog is designed withdesignedOKon the leftdesignedOK- the button that was designed as the "OK" (accept, commit) buttondesignedCancel- the button that was designed as the "Cancel" button- Returns:
- the button that will represent the OK button in an agnostic dialog
-
isAgnosticOKInFirstPosition
public static boolean isAgnosticOKInFirstPosition()
Returnstrueif the OK button should be left (ahead) of the Cancel button on this platform.- Returns:
trueif OK comes before Cancel;falseif it comes after
-
installNativeLookAndFeel
public static void installNativeLookAndFeel()
Call this method before opening any Swing windows to install the native look and feel. If they are available in the classpath, various OS-specific optimizations and patches may also be installed.
-
getKeyStroke
public static javax.swing.KeyStroke getKeyStroke(java.lang.String stroke)
Parse a string to create aKeyStrokeappropriate as an accelerator for the native OS. The string must have the following syntax:<modifiers>* (<typedID> | <pressedReleasedID>) modifiers := menu | shift | control | ctrl | meta | alt | altGraph typedID := typed <typedKey> typedKey := string of length 1 giving Unicode character. pressedReleasedID := (pressed | released) key key := KeyEvent key code name, without the "VK_" prefix.If typed, pressed or released is not specified, pressed is assumed.The special pseudo-modifier "menu" will be converted into the correct menu accelerator key for the native platform. For example, "menu X" will be treated as "ctrl X" on the Windows platform, but as "meta X" (which is Command key + X) on Max OS X platform. Note that there is no way to determine from the returned
KeyStrokeinstance whether the "menu" modifier was used or not.- Parameters:
stroke- a string formatted as above- Returns:
- a
KeyStrokeobject representing the specified key event
-
-