|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.openide.util.Utilities
Otherwise uncategorized useful static methods.
Nested Class Summary | |
static class |
Utilities.UnorderableException
Deprecated. Used only by the deprecated partialSort |
Field Summary | |
static int |
OS_AIX
Operating system is IBM AIX. |
static int |
OS_DEC
Deprecated. please use OS_TRU64 instead |
static int |
OS_FREEBSD
Operating system is FreeBSD |
static 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 Unix |
static int |
OS_UNIX_MASK
A mask for Unix platforms. |
static int |
OS_VMS
Operating system is Compaq OpenVMS |
static int |
OS_WIN_OTHER
Operating system is one of the Windows variants but we don't know which one it is |
static 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. |
static int |
TYPICAL_WINDOWS_TASKBAR_HEIGHT
A height of the windows's taskbar |
Method Summary | |
static Lookup |
actionsGlobalContext()
Global context for actions. |
static JPopupMenu |
actionsToPopup(Action[] actions,
Component component)
Builds a popup menu for provided component. |
static JPopupMenu |
actionsToPopup(Action[] actions,
Lookup context)
Builds a popup menu from actions for provided context specified by Lookup . |
static ReferenceQueue |
activeReferenceQueue()
Useful queue for all parts of system that use java.lang.ref.Reference s
together with some ReferenceQueue and need to do some clean up
when the reference is enqued. |
static int |
arrayHashCode(Object[] arr)
Compute hash code of array. |
static void |
attachInitJob(Component comp4Init,
AsyncGUIJob initJob)
Attaches asynchronous init job to given component. |
static boolean |
compareObjects(Object o1,
Object o2)
Safe equality check. |
static boolean |
compareObjectsImpl(Object o1,
Object o2,
int checkArraysDepth)
Safe equality check with array recursion. |
static Cursor |
createCustomCursor(Component component,
Image icon,
String name)
|
static Cursor |
createProgressCursor(Component component)
Returns a cursor with an arrow and an hourglass (or stop watch) badge, to be used when a component is busy but the UI is still responding to the user. |
static String |
escapeParameters(String[] params)
Complementary method to parseParameters |
static Rectangle |
findCenterBounds(Dimension componentSize)
Helps client code place components on the center of the screen. |
static BeanInfo |
getBeanInfo(Class clazz)
Central method for obtaining BeanInfo for potential JavaBean classes. |
static BeanInfo |
getBeanInfo(Class clazz,
Class stopClass)
Central method for obtaining BeanInfo for potential JavaBean classes, with a stop class. |
static String |
getClassName(Class clazz)
Assemble a human-presentable class name for a specified class. |
static Component |
getFocusTraversableComponent(Component c)
Find a focus-traverable component. |
static Class |
getObjectType(Class c)
Get the object type for given primitive type. |
static int |
getOperatingSystem()
Get the operating system on which the IDE is running. |
static Class |
getPrimitiveType(Class c)
Get the primitive type for given object type. |
static Dimension |
getScreenSize()
Deprecated. this method is almost useless in multiple monitor configuration |
static String |
getShortClassName(Class clazz)
Assemble a human-presentable class name for a specified class (omitting the package). |
static Rectangle |
getUsableScreenBounds()
Returns the usable area of the screen where applications can place its windows. |
static Rectangle |
getUsableScreenBounds(GraphicsConfiguration gconf)
Returns the usable area of the screen where applications can place its windows. |
static boolean |
isJavaIdentifier(String id)
Test whether a given string is a valid Java identifier. |
static boolean |
isLargeFrameIcons()
Test whether the operating system supports icons on frames (windows). |
static boolean |
isUnix()
Test whether the IDE is running on some variant of Unix. |
static boolean |
isWindows()
Test whether the IDE is running on some variant of Windows. |
static String |
keyToString(KeyStroke stroke)
Converts a Swing key stroke descriptor to a familiar Emacs-like name. |
static Image |
loadImage(String resourceID)
Loads an image from the specified resource ID. |
static Image |
loadImage(String resource,
boolean localized)
Loads an image based on resource path. |
static Image |
mergeImages(Image image1,
Image image2,
int x,
int y)
This method merges two images into the new one. |
static String[] |
parseParameters(String s)
Parses parameters from a given string in shell-like manner. |
static List |
partialSort(List l,
Comparator c,
boolean stable)
Deprecated. Deprecated in favor of the potentially much faster (and possibly more correct) topologicalSort(java.util.Collection, java.util.Map) . |
static String |
pureClassName(String fullName)
Turn full name of an inner class into its pure form. |
static String |
replaceString(String original,
String replaceFrom,
String replaceTo)
Search-and-replace fixed string matches within a string. |
static int |
showJFileChooser(JFileChooser chooser,
Component parent,
String approveButtonText)
Deprecated. Not needed in JDK 1.4. |
static KeyStroke |
stringToKey(String s)
Construct a new key description from a given universal string description. |
static KeyStroke[] |
stringToKeys(String s)
Convert a space-separated list of user-friendly key binding names to a list of Swing key strokes. |
static File |
toFile(URL u)
Deprecated. Use URI.URI(String) and File.File(URI) instead under JDK 1.4.
(There was no proper equivalent under JDK 1.3.) |
static Object[] |
toObjectArray(Object array)
Convert an array of primitive types to an array of objects. |
static List |
topologicalSort(Collection c,
Map edges)
Topologically sort some objects. |
static Object |
toPrimitiveArray(Object[] array)
Convert an array of objects to an array of primitive types. |
static URL |
toURL(File f)
Deprecated. Use File.toURI() and URI.toURL() instead under JDK 1.4.
(File.toURL() is buggy in JDK 1.3 and the bugs are not fixed in JDK 1.4.) |
static String |
translate(String className)
Provides support for parts of the system that deal with classnames (use Class.forName , NbObjectInputStream , etc.). |
static String |
wrapString(String original,
int width,
boolean wrapWords,
boolean removeNewLines)
Deprecated. Use (String, int, BreakIterator, boolean) as it is friendlier to I18N. |
static String |
wrapString(String original,
int width,
BreakIterator breakIterator,
boolean removeNewLines)
Wrap multi-line strings. |
static String[] |
wrapStringToArray(String original,
int width,
boolean wrapWords,
boolean removeNewLines)
Deprecated. use wrapStringToArray(String, int, BreakIterator, boolean) since it is better for I18N |
static String[] |
wrapStringToArray(String original,
int width,
BreakIterator breakIterator,
boolean removeNewLines)
Wrap multi-line strings (and get the individual lines). |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int OS_WINNT
public static final int OS_WIN95
public static final int OS_WIN98
public static final int OS_SOLARIS
public static final int OS_LINUX
public static final int OS_HP
public static final int OS_AIX
public static final int OS_IRIX
public static final int OS_SUNOS
public static final int OS_TRU64
public static final int OS_DEC
public static final int OS_OS2
public static final int OS_MAC
public static final int OS_WIN2000
public static final int OS_VMS
public static final int OS_WIN_OTHER
public static final int OS_OTHER
public static final int OS_FREEBSD
public static final int OS_WINDOWS_MASK
public static final int OS_UNIX_MASK
public static final int TYPICAL_WINDOWS_TASKBAR_HEIGHT
Method Detail |
public static ReferenceQueue activeReferenceQueue()
java.lang.ref.Reference
s
together with some ReferenceQueue
and need to do some clean up
when the reference is enqued. Usually, in order to be notified about that, one
needs to either create a dedicated thread that blocks on the queue and is
Object.notify
-ed, which is the right approach but consumes
valuable system resources (threads) or one can peridically check the content
of the queue by RequestProcessor.Task.schedule
which is
completelly wrong, because it wakes up the system every (say) 15 seconds.
In order to provide useful support for this problem, this queue has been
provided.
If you have a reference that needs clean up, make it implement Runnable
inteface and register it with the activeReferenceQueue
:
class MyReference extends WeakReference implements Runnable { private Object dataToCleanUp; public MyReference (Object ref, Object data) { super (ref, Utilities.activeReferenceQueue ()); // here you specify the queue dataToCleanUp = data; } public void run () { // clean up your data } }When the
ref
object is garbage collected, your run method
will be invoked by calling
((Runnable)reference).run ()
and you can perform what ever cleanup is necessary. Be sure not to block
in such cleanup for a long time as this prevents other waiting references
to cleanup themselves.
Please do not call any methods of the ReferenceQueue yourself. They will throw exceptions.
public static final int getOperatingSystem()
OS_*
constants (such as OS_WINNT
)public static final boolean isWindows()
true
if Windows, false
if some other manner of operating systempublic static final boolean isUnix()
true
some sort of Unix, false
if some other manner of operating systempublic static final boolean isJavaIdentifier(String id)
id
- string which should be checked
true
if a valid identifierpublic static BeanInfo getBeanInfo(Class clazz) throws IntrospectionException
BeanInfo
for potential JavaBean classes.
clazz
- class of the bean to provide the BeanInfo
for
IntrospectionException
- for the usual reasonsIntrospector.getBeanInfo(Class)
public static BeanInfo getBeanInfo(Class clazz, Class stopClass) throws IntrospectionException
BeanInfo
for potential JavaBean classes, with a stop class.
clazz
- class of the bean to provide the BeanInfo
forstopClass
- the stop class
IntrospectionException
- for the usual reasonsIntrospector.getBeanInfo(Class, Class)
public static String[] wrapStringToArray(String original, int width, boolean wrapWords, boolean removeNewLines)
wrapStringToArray(String, int, BreakIterator, boolean)
since it is better for I18N
original
- the original string to wrapwidth
- the maximum width of lineswrapWords
- if true
, the lines are wrapped on word boundaries (if possible);
if false
, character boundaries are usedremoveNewLines
- if true
, any newlines in the original string are ignored
public static String[] wrapStringToArray(String original, int width, BreakIterator breakIterator, boolean removeNewLines)
original
- the original string to wrapwidth
- the maximum width of linesbreakIterator
- breaks original to chars, words, sentences, depending on what instance you provide.removeNewLines
- if true
, any newlines in the original string are ignored
public static String wrapString(String original, int width, BreakIterator breakIterator, boolean removeNewLines)
original
- the original string to wrapwidth
- the maximum width of linesbreakIterator
- algorithm for breaking linesremoveNewLines
- if true
, any newlines in the original string are ignored
public static String wrapString(String original, int width, boolean wrapWords, boolean removeNewLines)
(String, int, BreakIterator, boolean)
as it is friendlier to I18N.
original
- the original string to wrapwidth
- the maximum width of lineswrapWords
- if true
, the lines are wrapped on word boundaries (if possible);
if false
, character boundaries are usedremoveNewLines
- if true
, any newlines in the original string are ignored
public static String replaceString(String original, String replaceFrom, String replaceTo)
original
- the original stringreplaceFrom
- the substring to be findreplaceTo
- the substring to replace it with
public static final String pureClassName(String fullName)
fullName
- e.g. some.pkg.SomeClass$Inner
Inner
public static final boolean isLargeFrameIcons()
true
if it does notpublic static int arrayHashCode(Object[] arr)
arr
- array of objects, can contain null
s
Object.hashCode()
public static boolean compareObjects(Object o1, Object o2)
null
Object.equals(java.lang.Object)
null
-safe, so if one of the parameters is true and the second not,
it returns false
.
o1
- the first object to compareo2
- the second object to compare
true
if the objects are equalpublic static boolean compareObjectsImpl(Object o1, Object o2, int checkArraysDepth)
o1
- the first object to compareo2
- the second object to comparecheckArraysDepth
- the depth to which arrays should be compared for equality (negative for infinite depth, zero for no comparison of elements, one for shallow, etc.)
true
if the objects are equalcompareObjects(Object, Object)
public static String getClassName(Class clazz)
java.lang.String[]
.
clazz
- the class to name
public static String getShortClassName(Class clazz)
String[]
.
clazz
- the class to name
public static Object toPrimitiveArray(Object[] array)
Integer[]
would be changed to an int[]
.
array
- the wrapper array
IllegalArgumentException
- if the array element type is not a primitive wrapperpublic static Object[] toObjectArray(Object array)
int[]
would be turned into an Integer[]
.
array
- the primitive array
IllegalArgumentException
- if the array element type is not primitivepublic static Class getObjectType(Class c)
c
- primitive type (e.g. int
)
Integer
)public static Class getPrimitiveType(Class c)
c
- object type (e.g. Integer
)
int
)public static Component getFocusTraversableComponent(Component c)
c
- the component to look in
null
Component.isFocusTraversable()
public static String[] parseParameters(String s)
org.openide.execution.NbProcessDescriptor
(Execution API)
you should be able to:
c:\Program Files\jdk\bin\javac
.
-Dname=value
.
"c:\program files\jdk\bin\java" -Dmessage="Hello /\\/\\ there!" -Xmx128m
This example would create the following executable name and arguments:
c:\program files\jdk\bin\java
-Dmessage=Hello /\/\ there!
-Xmx128m
s
- a string to parse
public static String escapeParameters(String[] params)
parseParameters(java.lang.String)
public static String keyToString(KeyStroke stroke)
stroke
- key description
CS-F1
for control-shift-function key one)stringToKey(java.lang.String)
public static KeyStroke stringToKey(String s)
KeyStroke
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 MacintoshO
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 handicapD-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 leading VK_
characters. So KeyEvent.VK_ENTER
is described as
ENTER
.
s
- the string with the description of the key
null
if the string does not represent any valid keypublic static KeyStroke[] stringToKeys(String s)
s
- the string with keys
null
if the string description is not validstringToKey(java.lang.String)
public static Rectangle getUsableScreenBounds()
public static Rectangle getUsableScreenBounds(GraphicsConfiguration gconf)
gconf
- the GraphicsConfiguration of the monitor
public static Rectangle findCenterBounds(Dimension componentSize)
componentSize
- the size of the component
public static final Dimension getScreenSize()
getUsableScreenBounds()
,
findCenterBounds(Dimension)
public static final int showJFileChooser(JFileChooser chooser, Component parent, String approveButtonText)
parent
- approveButtonText
- public static List partialSort(List l, Comparator c, boolean stable) throws Utilities.UnorderableException
topologicalSort(java.util.Collection, java.util.Map)
.
l
- the list to sort (will not be modified)c
- a comparator to impose the partial order; "equal" means that the elements
are not ordered with respect to one another, i.e. may be only a partial orderstable
- whether to attempt a stable sort, meaning that the position of elements
will be disturbed as little as possible; might be slightly slower
Utilities.UnorderableException
- if the specified partial order is inconsistent on this listpublic static List topologicalSort(Collection c, Map edges) throws TopologicalSortException
There may not be any nulls among the objects, nor duplicates (as per hash/equals), nor duplicates among the edge lists. The edge map need not contain an entry for every object, only if it has some outgoing edges (empty but not null map values are permitted). The edge map may contain neither keys nor value entries for objects not in the collection to be sorted.
The incoming parameters will not be modified; they must not be changed during the call and possible calls to TopologicalSortException methods. The returned list will support modifications.
There is a weak stability guarantee: if there are no edges which contradict the incoming order, the resulting list will be in the same order as the incoming elements. However if some elements need to be rearranged, it is not guaranteed that others will not also be rearranged, even if they did not strictly speaking need to be.
c
- a collection of objects to be topologically sortededges
- constraints among those objects, of type Map<Object,Collection>
;
if an object is a key in this map, the resulting order will
have that object before any objects listed in the value
TopologicalSortException
- if the sort cannot succeed due to cycles in the graph, the
exception contains additional information to describe and possibly recover from the errorpublic static String translate(String className)
Class.forName
, NbObjectInputStream
, etc.).
Often class names (especially package names) changes during lifecycle
of a module. When some piece of the system stores the name of a class
in certain point of a time and wants to find the correct Class
later it needs to count with the possibility of rename.
For such purposes this method has been created. It allows modules to register their classes that changed names and other parts of system that deal with class names to find the correct names.
To register a mapping from old class names to new ones create a file
META-INF/netbeans/translate.names
in your module and fill it
with your mapping:
# # Mapping of legacy classes to new ones # org.oldpackage.MyClass=org.newpackage.MyClass # rename of package for one class org.mypackage.OldClass=org.mypackage.NewClass # rename of class in a package # rename of class and package org.oldpackage.OldClass=org.newpackage.NewClass # rename of whole package org.someoldpackage=org.my.new.package.structureBtw. one can use spaces instead of
=
sign.
For a real world example
check the
xml module.
For purposes of org.openide.util.io.NbObjectInputStream there is a following special convention: If the className is not listed as one that is to be renamed, the returned string == className, if the className is registered to be renamed than the className != returned value, even in a case when className.equals (retValue)
className
- fully qualified name of a class to translate
public static final Image mergeImages(Image image1, Image image2, int x, int y)
null
, it makes default transparent 16x16 image.
image1
- underlying imageimage2
- second imagex
- x position of top-left cornery
- y position of top-left corner
public static final Image loadImage(String resourceID)
resourceID
- resource path of the icon (no initial slash)
public static JPopupMenu actionsToPopup(Action[] actions, Lookup context)
Lookup
.
Takes list of actions and for actions whic are instances of
ContextAwareAction
creates and uses the context aware instance.
Then gets the action presenter or simple menu item for the action to the
popup menu for each action (or separator for each 'lonely' null array member).
actions
- array of actions to build menu for. Can contain null
elements, they will be replaced by separatorscontext
- the context for which the popup is build
ContextAwareAction
public static JPopupMenu actionsToPopup(Action[] actions, Component component)
Lookup.Provider
instance).
If none of the components is Lookup.Provider
instance, then
it is created context which is fed with composite ActionMap which delegates
to all components up to hierarchy started from the specified one.
Then actionsToPopup(Action[], Lookup)
} is called with
the found Lookup
instance, which actually creates a popup menu.
actions
- array of actions to build menu for. Can contain null
elements, they will be replaced by separatorscomponent
- a component in which to search for a context
Lookup.Provider
,
actionsToPopup(Action[], Lookup)
public static Lookup actionsGlobalContext()
ContextGlobalProvider
public static final Image loadImage(String resource, boolean localized)
loadImage(String)
but may do a localized search.
For example, requesting org/netbeans/modules/foo/resources/foo.gif
might actually find org/netbeans/modules/foo/resources/foo_ja.gif
or org/netbeans/modules/foo/resources/foo_mybranding.gif.
public static final Cursor createProgressCursor(Component component)
Cursor.WAIT_CURSOR
, but has an arrow to indicate
a still-responsive UI.
Typically you will set the cursor only temporarily:
// code is running in other then event dispatch thread currentComponent.setCursor(Utilities.createProgressCursor(currentComponent)); try { // perform some work in other than event dispatch thread // (do not block UI) } finally { currentComponent.setCursor(null); }
This implementation provides one cursor for all Mac systems, one for all Unix systems (regardless of window manager), and one for all other systems including Windows.
component
- the non-null component that will use the progress cursor
public static Cursor createCustomCursor(Component component, Image icon, String name)
public static final void attachInitJob(Component comp4Init, AsyncGUIJob initJob)
AsyncGUIJob.construct()
will be called after first
paint, when paint event arrives. Later, AsyncGUIJob.finished()
will be called according to the rules of the AsyncGUIJob
interface.
Useful for components that have slower initialization phase, component
can benefit from more responsive behaviour during init.
comp4Init
- Regular component in its pre-inited state, state in which
component will be shown between first paint and init completion.initJob
- Initialization job to be called asynchronously. Job can
optionally implement Cancellable
interface for proper cancel logic. Cancel method will be called
when component stops to be showing during job's progress.
See Component.isShowing()
public static URL toURL(File f) throws MalformedURLException
File.toURI()
and URI.toURL()
instead under JDK 1.4.
(File.toURL()
is buggy in JDK 1.3 and the bugs are not fixed in JDK 1.4.)
file:
URL.
f
- a file (absolute only)
file
protocol
MalformedURLException
- for no good reasontoFile(java.net.URL)
,
Issue #29711public static File toFile(URL u)
URI.URI(String)
and File.File(URI)
instead under JDK 1.4.
(There was no proper equivalent under JDK 1.3.)
file:
URL to a matching file.
You may not use a URL generated from a file on a different platform, as file name conventions may make the result meaningless or even unparsable.
u
- a URL with the file
protocol
null
if the URL
does not seem to point to a file at alltoURL(java.io.File)
,
Issue #29711
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |