Package org.jdesktop.swingx
Class SwingXUtilities
- java.lang.Object
-
- org.jdesktop.swingx.SwingXUtilities
-
public final class SwingXUtilities extends java.lang.ObjectA collection of utility methods for Swing(X) classes.-
PENDING JW: think about location of this class and/or its methods, Options:
- move this class to the swingx utils package which already has a bunch of xxUtils
- move methods between xxUtils classes as appropriate (one window/comp related util)
- keep here in swingx (consistent with swingutilities in core)
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringSTYLESHEET
-
Constructor Summary
Constructors Modifier Constructor Description privateSwingXUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidadjustFocus(javax.swing.JComponent component)static intconvertModifiersToDropAction(int modifiers, int sourcActions)static <T> TgetAncestor(java.lang.Class<T> clazz, java.awt.Component c)An improved version ofSwingUtilities.getAncestorOfClass(Class, Component).private static java.awt.Component[]getChildren(java.awt.Component c)(package private) static javax.swing.RepaintManagergetTranslucentRepaintManager(javax.swing.RepaintManager delegate)Obtains aTranslucentRepaintManagerfrom the specified manager.static <T> TinvokeAndWait(java.util.concurrent.Callable<T> callable)A version ofSwingUtilities.invokeAndWait(Runnable)that supports return values.static <T> java.util.concurrent.FutureTask<T>invokeLater(java.util.concurrent.Callable<T> callable)A version ofSwingUtilities.invokeLater(Runnable)that supports return values.static booleanisDescendingFrom(java.awt.Component focusOwner, java.awt.Component parent)Returns whether the component is part of the parent's container hierarchy.static booleanisUIInstallable(java.lang.Object property)Checks and returns whether the given property should be replaced by the UI's default value.static intloc2IndexFileList(javax.swing.JList list, java.awt.Point point)(package private) static <C extends javax.swing.JComponent & BackgroundPaintable>
voidpaintBackground(C comp, java.awt.Graphics2D g)private static booleanpointIsInActualBounds(javax.swing.JList list, int index, java.awt.Point point)static voidsetComponentTreeBackground(java.awt.Component c, java.awt.Color color)Sets the background for an entire component hierarchy to the specified color.static voidsetComponentTreeEnabled(java.awt.Component c, boolean enabled)Enables or disables of the components in the tree starting withc.static voidsetComponentTreeFont(java.awt.Component c, java.awt.Font font)Sets the font for an entire component hierarchy to the specified font.static voidsetComponentTreeForeground(java.awt.Component c, java.awt.Color color)Sets the foreground for an entire component hierarchy to the specified color.static voidsetComponentTreeLocale(java.awt.Component c, java.util.Locale locale)Sets the locale for an entire component hierarchy to the specified locale.static voidsetHtmlFont(javax.swing.text.html.HTMLDocument doc, java.awt.Font font)Sets the font used for HTML displays to the specified font.static voidsetLeadAnchorWithoutSelection(javax.swing.ListSelectionModel selectionModel, int lead, int anchor)Updates lead and anchor selection index without changing the selection.static booleanshouldIgnore(java.awt.event.MouseEvent mouseEvent, javax.swing.JComponent component)static voidupdateAllComponentTreeUIs()Updates the componentTreeUI of all top-level windows of the current application.static voidupdateAllComponentTreeUIs(java.awt.Window window)Updates the componentTreeUI of the given window and all its owned windows, recursively.static voidupdateMnemonicBinding(javax.swing.JComponent c, java.lang.String pressed)A helper for creating and updating key bindings for components with mnemonics.static voidupdateMnemonicBinding(javax.swing.JComponent c, java.lang.String pressed, java.lang.String released)A helper for creating and updating key bindings for components with mnemonics.
-
-
-
Method Detail
-
updateMnemonicBinding
public static void updateMnemonicBinding(javax.swing.JComponent c, java.lang.String pressed)A helper for creating and updating key bindings for components with mnemonics. Thepressedaction will be invoked when the mnemonic is activated.TODO establish an interface for the mnemonic properties, such as
MnemonicEnabledand change signature topublic static <T extends JComponent & MnemonicEnabled> void updateMnemonicBinding(T c, String pressed)- Parameters:
c- the component bindings to updatepressed- the name of the action in the action map to invoke when the mnemonic is pressed- Throws:
java.lang.NullPointerException- if the component isnull
-
updateMnemonicBinding
public static void updateMnemonicBinding(javax.swing.JComponent c, java.lang.String pressed, java.lang.String released)A helper for creating and updating key bindings for components with mnemonics. Thepressedaction will be invoked when the mnemonic is activated and thereleasedaction will be invoked when the mnemonic is deactivated.TODO establish an interface for the mnemonic properties, such as
MnemonicEnabledand change signature topublic static <T extends JComponent & MnemonicEnabled> void updateMnemonicBinding(T c, String pressed, String released)- Parameters:
c- the component bindings to updatepressed- the name of the action in the action map to invoke when the mnemonic is pressedreleased- the name of the action in the action map to invoke when the mnemonic is released (if the action is a toggle style, then this parameter should benull)- Throws:
java.lang.NullPointerException- if the component isnull
-
paintBackground
static <C extends javax.swing.JComponent & BackgroundPaintable> void paintBackground(C comp, java.awt.Graphics2D g)
-
getChildren
private static java.awt.Component[] getChildren(java.awt.Component c)
-
setComponentTreeEnabled
public static void setComponentTreeEnabled(java.awt.Component c, boolean enabled)Enables or disables of the components in the tree starting withc.- Parameters:
c- the starting componentenabled-trueif the component is to enabled;falseotherwise
-
setComponentTreeLocale
public static void setComponentTreeLocale(java.awt.Component c, java.util.Locale locale)Sets the locale for an entire component hierarchy to the specified locale.- Parameters:
c- the starting componentlocale- the locale to set
-
setComponentTreeBackground
public static void setComponentTreeBackground(java.awt.Component c, java.awt.Color color)Sets the background for an entire component hierarchy to the specified color.- Parameters:
c- the starting componentcolor- the color to set
-
setComponentTreeForeground
public static void setComponentTreeForeground(java.awt.Component c, java.awt.Color color)Sets the foreground for an entire component hierarchy to the specified color.- Parameters:
c- the starting componentcolor- the color to set
-
setComponentTreeFont
public static void setComponentTreeFont(java.awt.Component c, java.awt.Font font)Sets the font for an entire component hierarchy to the specified font.- Parameters:
c- the starting componentfont- the font to set
-
setHtmlFont
public static void setHtmlFont(javax.swing.text.html.HTMLDocument doc, java.awt.Font font)Sets the font used for HTML displays to the specified font. Components that display HTML do not necessarily honor font properties, since the HTML document can override these values. CallingsetHtmlFontafter the data is set will force the HTML display to use the font specified to this method.- Parameters:
doc- the HTML document to updatefont- the font to use- Throws:
java.lang.NullPointerException- if any parameter isnull
-
updateAllComponentTreeUIs
public static void updateAllComponentTreeUIs()
Updates the componentTreeUI of all top-level windows of the current application.
-
updateAllComponentTreeUIs
public static void updateAllComponentTreeUIs(java.awt.Window window)
Updates the componentTreeUI of the given window and all its owned windows, recursively.- Parameters:
window- the window to update
-
invokeLater
public static <T> java.util.concurrent.FutureTask<T> invokeLater(java.util.concurrent.Callable<T> callable)
A version ofSwingUtilities.invokeLater(Runnable)that supports return values.- Type Parameters:
T- the return type of the callable- Parameters:
callable- the callable to execute- Returns:
- a future task for accessing the return value
- See Also:
Callable
-
invokeAndWait
public static <T> T invokeAndWait(java.util.concurrent.Callable<T> callable) throws java.lang.InterruptedException, java.lang.reflect.InvocationTargetExceptionA version ofSwingUtilities.invokeAndWait(Runnable)that supports return values.- Type Parameters:
T- the return type of the callable- Parameters:
callable- the callable to execute- Returns:
- the value returned by the callable
- Throws:
java.lang.InterruptedException- if we're interrupted while waiting for the event dispatching thread to finish executingcallable.call()java.lang.reflect.InvocationTargetException- if an exception is thrown while runningcallable- See Also:
Callable
-
getAncestor
public static <T> T getAncestor(java.lang.Class<T> clazz, java.awt.Component c)An improved version ofSwingUtilities.getAncestorOfClass(Class, Component). This method traversesJPopupMenuinvoker and uses generics to return an appropriately typed object.- Type Parameters:
T- the type of ancestor to find- Parameters:
clazz- the class instance of the ancestor to findc- the component to start the search from- Returns:
- an ancestor of the correct type or
nullif no such ancestor exists. This method also returnsnullif any parameter isnull.
-
isDescendingFrom
public static boolean isDescendingFrom(java.awt.Component focusOwner, java.awt.Component parent)Returns whether the component is part of the parent's container hierarchy. If a parent in the chain is of type JPopupMenu, the parent chain of its invoker is walked.- Parameters:
focusOwner-parent-- Returns:
- true if the component is contained under the parent's hierarchy, coping with JPopupMenus.
-
getTranslucentRepaintManager
static javax.swing.RepaintManager getTranslucentRepaintManager(javax.swing.RepaintManager delegate)
Obtains aTranslucentRepaintManagerfrom the specified manager. If the current manager is aTranslucentRepaintManageror aForwardingRepaintManagerthat contains aTranslucentRepaintManager, then the passed in manager is returned. Otherwise a new repaint manager is created and returned.- Parameters:
delegate- the current repaint manager- Returns:
- a non-
nullTranslucentRepaintManager - Throws:
java.lang.NullPointerException- ifdelegateisnull
-
isUIInstallable
public static boolean isUIInstallable(java.lang.Object property)
Checks and returns whether the given property should be replaced by the UI's default value.- Parameters:
property- the property to check.- Returns:
- true if the given property should be replaced by the UI's default value, false otherwise.
-
setLeadAnchorWithoutSelection
public static void setLeadAnchorWithoutSelection(javax.swing.ListSelectionModel selectionModel, int lead, int anchor)Updates lead and anchor selection index without changing the selection. Note: this is c&p'ed from SwingUtilities2 to not have any direct dependency.- Parameters:
selectionModel- the selection model to change lead/anchorlead- the lead selection indexanchor- the anchor selection index
-
shouldIgnore
public static boolean shouldIgnore(java.awt.event.MouseEvent mouseEvent, javax.swing.JComponent component)
-
loc2IndexFileList
public static int loc2IndexFileList(javax.swing.JList list, java.awt.Point point)
-
pointIsInActualBounds
private static boolean pointIsInActualBounds(javax.swing.JList list, int index, java.awt.Point point)
-
adjustFocus
public static void adjustFocus(javax.swing.JComponent component)
-
convertModifiersToDropAction
public static int convertModifiersToDropAction(int modifiers, int sourcActions)
-
-