Package org.jdesktop.swingx.util
Class Utilities
- java.lang.Object
-
- org.jdesktop.swingx.util.Utilities
-
public class Utilities extends java.lang.Object
Contribution from NetBeans: Issue #319-swingx.PENDING: need to reconcile with OS, JVM... added as-is because needed the shortcut handling to fix #
-
-
Field Summary
Fields Modifier and Type Field Description private static int
ALT_WILDCARD_MASK
private static int
CTRL_WILDCARD_MASK
private static java.lang.ref.Reference<java.lang.Object>
namesAndValues
reference to map that maps allowed key names to their values (String, Integer) and reference to map for mapping of values to their namesprivate static int
operatingSystem
static int
OS_AIX
Operating system is IBM AIX.static int
OS_FREEBSD
Operating system is FreeBSDstatic int
OS_HP
Operating system is HP-UX.static int
OS_IRIX
Operating system is SGI IRIX.static int
OS_LINUX
Operating system is Linux.static int
OS_MAC
Operating system is Mac.static int
OS_OS2
Operating system is OS/2.static int
OS_OTHER
Operating system is unknown.static int
OS_SOLARIS
Operating system is Solaris.static int
OS_SUNOS
Operating system is Sun OS.static int
OS_TRU64
Operating system is Compaq TRU64 Unixstatic int
OS_UNIX_MASK
A mask for Unix platforms.static int
OS_VMS
Operating system is Compaq OpenVMSstatic int
OS_WIN_OTHER
Operating system is one of the Windows variants but we don't know which one it isstatic int
OS_WIN2000
Operating system is Windows 2000.static int
OS_WIN95
Operating system is Windows 95.static int
OS_WIN98
Operating system is Windows 98.static int
OS_WINDOWS_MASK
A mask for Windows platforms.static int
OS_WINNT
Operating system is Windows NT.private static int
TYPICAL_MACOSX_MENU_HEIGHT
A height of the Mac OS X's menustatic int
TYPICAL_WINDOWS_TASKBAR_HEIGHT
A height of the windows's taskbar
-
Constructor Summary
Constructors Modifier Constructor Description private
Utilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static boolean
addModifiers(java.lang.StringBuffer buf, int modif)
Adds characters for modifiers to the buffer.private static java.awt.GraphicsConfiguration
getCurrentGraphicsConfiguration()
Finds out the monitor where the user currently has the input focus.private static int
getMenuShortCutKeyMask()
need to guard against headlessExceptions when testing.static int
getOperatingSystem()
Get the operating system on which NetBeans is running.static java.awt.Rectangle
getUsableScreenBounds()
Returns the usable area of the screen where applications can place its windows.static java.awt.Rectangle
getUsableScreenBounds(java.awt.GraphicsConfiguration gconf)
Returns the usable area of the screen where applications can place its windows.private static java.util.HashMap[]
initNameAndValues()
Initialization of the names and valuesstatic boolean
isLargeFrameIcons()
Test whether the operating system supports icons on frames (windows).static boolean
isUnix()
Test whether NetBeans is running on some variant of Unix.static boolean
isWindows()
Test whether NetBeans is running on some variant of Windows.static java.lang.String
keyToString(javax.swing.KeyStroke stroke)
Converts a Swing key stroke descriptor to a familiar Emacs-like name.private static int
readModifiers(java.lang.String s)
Reads for modifiers and creates integer with required mask.static javax.swing.KeyStroke
stringToKey(java.lang.String s)
Construct a new key description from a given universal string description.static javax.swing.KeyStroke[]
stringToKeys(java.lang.String s)
Convert a space-separated list of Emacs-like key binding names to a list of Swing key strokes.static java.lang.Object[]
toObjectArray(java.lang.Object array)
Convert an array of primitive types to an array of objects.static java.lang.Object
toPrimitiveArray(java.lang.Object[] array)
Convert an array of objects to an array of primitive types.private static java.lang.String
trimString(java.lang.String s)
private static boolean
usableKeyOnMac(int key, int mask)
static java.lang.String[]
wrapStringToArray(java.lang.String original, int width, java.text.BreakIterator breakIterator, boolean removeNewLines)
Wrap multi-line strings (and get the individual lines).
-
-
-
Field Detail
-
CTRL_WILDCARD_MASK
private static final int CTRL_WILDCARD_MASK
- See Also:
- Constant Field Values
-
ALT_WILDCARD_MASK
private static final int ALT_WILDCARD_MASK
- See Also:
- Constant Field Values
-
OS_WINNT
public static final int OS_WINNT
Operating system is Windows NT.- See Also:
- Constant Field Values
-
OS_WIN95
public static final int OS_WIN95
Operating system is Windows 95.- See Also:
- Constant Field Values
-
OS_WIN98
public static final int OS_WIN98
Operating system is Windows 98.- See Also:
- Constant Field Values
-
OS_SOLARIS
public static final int OS_SOLARIS
Operating system is Solaris.- See Also:
- Constant Field Values
-
OS_LINUX
public static final int OS_LINUX
Operating system is Linux.- See Also:
- Constant Field Values
-
OS_HP
public static final int OS_HP
Operating system is HP-UX.- See Also:
- Constant Field Values
-
OS_AIX
public static final int OS_AIX
Operating system is IBM AIX.- See Also:
- Constant Field Values
-
OS_IRIX
public static final int OS_IRIX
Operating system is SGI IRIX.- See Also:
- Constant Field Values
-
OS_SUNOS
public static final int OS_SUNOS
Operating system is Sun OS.- See Also:
- Constant Field Values
-
OS_TRU64
public static final int OS_TRU64
Operating system is Compaq TRU64 Unix- See Also:
- Constant Field Values
-
OS_OS2
public static final int OS_OS2
Operating system is OS/2.- See Also:
- Constant Field Values
-
OS_MAC
public static final int OS_MAC
Operating system is Mac.- See Also:
- Constant Field Values
-
OS_WIN2000
public static final int OS_WIN2000
Operating system is Windows 2000.- See Also:
- Constant Field Values
-
OS_VMS
public static final int OS_VMS
Operating system is Compaq OpenVMS- See Also:
- Constant Field Values
-
OS_WIN_OTHER
public static final int OS_WIN_OTHER
Operating system is one of the Windows variants but we don't know which one it is- See Also:
- Constant Field Values
-
OS_OTHER
public static final int OS_OTHER
Operating system is unknown.- See Also:
- Constant Field Values
-
OS_FREEBSD
public static final int OS_FREEBSD
Operating system is FreeBSD- Since:
- 4.50
- See Also:
- Constant Field Values
-
OS_WINDOWS_MASK
public static final int OS_WINDOWS_MASK
A mask for Windows platforms.- See Also:
- Constant Field Values
-
OS_UNIX_MASK
public static final int OS_UNIX_MASK
A mask for Unix platforms.- See Also:
- Constant Field Values
-
TYPICAL_WINDOWS_TASKBAR_HEIGHT
public static final int TYPICAL_WINDOWS_TASKBAR_HEIGHT
A height of the windows's taskbar- See Also:
- Constant Field Values
-
TYPICAL_MACOSX_MENU_HEIGHT
private static final int TYPICAL_MACOSX_MENU_HEIGHT
A height of the Mac OS X's menu- See Also:
- Constant Field Values
-
operatingSystem
private static int operatingSystem
-
namesAndValues
private static java.lang.ref.Reference<java.lang.Object> namesAndValues
reference to map that maps allowed key names to their values (String, Integer) and reference to map for mapping of values to their names
-
-
Method Detail
-
getOperatingSystem
public static int getOperatingSystem()
Get the operating system on which NetBeans is running.- Returns:
- one of the
OS_*
constants (such asOS_WINNT
)
-
isWindows
public static boolean isWindows()
Test whether NetBeans is running on some variant of Windows.- Returns:
true
if Windows,false
if some other manner of operating system
-
isUnix
public static boolean isUnix()
Test whether NetBeans is running on some variant of Unix. Linux is included as well as the commercial vendors, and Mac OS X.- Returns:
true
some sort of Unix,false
if some other manner of operating system
-
isLargeFrameIcons
public static boolean isLargeFrameIcons()
Test whether the operating system supports icons on frames (windows).- Returns:
true
if it does not
-
getCurrentGraphicsConfiguration
private static java.awt.GraphicsConfiguration getCurrentGraphicsConfiguration()
Finds out the monitor where the user currently has the input focus. This method is usually used to help the client code to figure out on which monitor it should place newly created windows/frames/dialogs.- Returns:
- the GraphicsConfiguration of the monitor which currently has the input focus
-
getUsableScreenBounds
public static java.awt.Rectangle getUsableScreenBounds()
Returns the usable area of the screen where applications can place its windows. The method subtracts from the screen the area of taskbars, system menus and the like. The screen this method applies to is the one which is considered current, ussually the one where the current input focus is.- Returns:
- the rectangle of the screen where one can place windows
- Since:
- 2.5
-
getUsableScreenBounds
public static java.awt.Rectangle getUsableScreenBounds(java.awt.GraphicsConfiguration gconf)
Returns the usable area of the screen where applications can place its windows. The method subtracts from the screen the area of taskbars, system menus and the like.- Parameters:
gconf
- the GraphicsConfiguration of the monitor- Returns:
- the rectangle of the screen where one can place windows
- Since:
- 2.5
-
initNameAndValues
private static java.util.HashMap[] initNameAndValues()
Initialization of the names and values- Returns:
- array of two hashmaps first maps allowed key names to their values (String, Integer) and second hashtable for mapping of values to their names (Integer, String)
-
keyToString
public static java.lang.String keyToString(javax.swing.KeyStroke stroke)
Converts a Swing key stroke descriptor to a familiar Emacs-like name.- Parameters:
stroke
- key description- Returns:
- name of the key (e.g.
CS-F1
for control-shift-function key one) - See Also:
stringToKey(java.lang.String)
-
stringToKey
public static javax.swing.KeyStroke stringToKey(java.lang.String s)
Construct a new key description from a given universal string description. Provides mapping between Emacs-like textual key descriptions and theKeyStroke
object used in Swing.This format has following form:
[C][A][S][M]-identifier
Where:
-
C
stands for the Control key -
A
stands for the Alt key -
S
stands for the Shift key -
M
stands for the Meta key
-
D
stands for the default menu accelerator - the Control key on most platforms, the Command (meta) key on Macintosh -
O
stands for the alternate accelerator - the Alt key on most platforms, the Ctrl key on Macintosh (Macintosh uses Alt as a secondary shift key for composing international characters - if you bind Alt-8 to an action, a mac user with a French keyboard will not be able to type the[
character, which is a significant handicap
D-Q
will always map to Control-Q.Every modifier before the hyphen must be pressed. identifier can be any text constant from
KeyEvent
but without the leadingVK_
characters. SoKeyEvent.VK_ENTER
is described asENTER
.- Parameters:
s
- the string with the description of the key- Returns:
- key description object, or
null
if the string does not represent any valid key
-
-
getMenuShortCutKeyMask
private static int getMenuShortCutKeyMask()
need to guard against headlessExceptions when testing.- Returns:
- the acceletor mask for shortcuts.
-
usableKeyOnMac
private static boolean usableKeyOnMac(int key, int mask)
-
stringToKeys
public static javax.swing.KeyStroke[] stringToKeys(java.lang.String s)
Convert a space-separated list of Emacs-like key binding names to a list of Swing key strokes.- Parameters:
s
- the string with keys- Returns:
- array of key strokes, or
null
if the string description is not valid - See Also:
stringToKey(java.lang.String)
-
addModifiers
private static boolean addModifiers(java.lang.StringBuffer buf, int modif)
Adds characters for modifiers to the buffer.- Parameters:
buf
- buffer to add tomodif
- modifiers to add (KeyEvent.XXX_MASK)- Returns:
- true if something has been added
-
readModifiers
private static int readModifiers(java.lang.String s) throws java.util.NoSuchElementException
Reads for modifiers and creates integer with required mask.- Parameters:
s
- string with modifiers- Returns:
- integer with mask
- Throws:
java.util.NoSuchElementException
- if some letter is not modifier
-
toPrimitiveArray
public static java.lang.Object toPrimitiveArray(java.lang.Object[] array)
Convert an array of objects to an array of primitive types. E.g. anInteger[]
would be changed to anint[]
.- Parameters:
array
- the wrapper array- Returns:
- a primitive array
- Throws:
java.lang.IllegalArgumentException
- if the array element type is not a primitive wrapper
-
toObjectArray
public static java.lang.Object[] toObjectArray(java.lang.Object array)
Convert an array of primitive types to an array of objects. E.g. anint[]
would be turned into anInteger[]
.- Parameters:
array
- the primitive array- Returns:
- a wrapper array
- Throws:
java.lang.IllegalArgumentException
- if the array element type is not primitive
-
wrapStringToArray
public static java.lang.String[] wrapStringToArray(java.lang.String original, int width, java.text.BreakIterator breakIterator, boolean removeNewLines)
Wrap multi-line strings (and get the individual lines).- Parameters:
original
- the original string to wrapwidth
- the maximum width of linesbreakIterator
- breaks original to chars, words, sentences, depending on what instance you provide.removeNewLines
- iftrue
, any newlines in the original string are ignored- Returns:
- the lines after wrapping
-
trimString
private static java.lang.String trimString(java.lang.String s)
-
-