Package de.sciss.gui
Class GUIUtil
- java.lang.Object
-
- de.sciss.gui.GUIUtil
-
public class GUIUtil extends java.lang.ObjectThis is a helper class containing utility static functions for common Swing / GUI operations
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidconstrainHeight(javax.swing.JComponent c, int h)Adjusts minimum, maximum and preferred size of a component so as to constrain its height to a given value.static voidconstrainSize(javax.swing.JComponent c, int w, int h)Sets minimum, maximum and preferred size to given values.static voidconstrainWidth(javax.swing.JComponent c, int w)Adjusts minimum, maximum and preferred size of a component so as to constrain its width to a given value.static java.awt.PointconvertPoint(java.awt.Component source, java.awt.Point aPoint, java.awt.Component destination)Same as SwingUtilities.convertPoint, but handles JViewports properlystatic voidconvertPointFromScreen(java.awt.Point p, java.awt.Component c)Same as SwingUtilities.convertPointFromScreen, but handles JViewports properlystatic voidconvertPointToScreen(java.awt.Point p, java.awt.Component c)Same as SwingUtilities.convertPointToScreen, but handles JViewports properlystatic java.awt.RectangleconvertRectangle(java.awt.Component source, java.awt.Rectangle r, java.awt.Component destination)static GradientPanelcreateGradientPanel()static voidcreateKeyAction(javax.swing.AbstractButton comp, javax.swing.KeyStroke stroke)Convenience method that will add new corresponding entries in a button's input and action map, such that a givenKeyStrokewill cause aDoClickActionto be performed on that button.static voiddisplayError(java.awt.Component component, java.lang.Exception exception, java.lang.String title)Displays an error message dialog by examining a givenException.static javax.swing.IcongetNoWriteIcon()Returns anIconfor a no-write or write-protection indicator.static java.lang.StringgetResourceString(java.lang.String key)static java.util.prefs.PreferencesgetUserPrefs()static doublegetVersion()static booleanisAlwaysOnTop(java.awt.Component c)static voidmakeCompactSpringGrid(java.awt.Container parent, int rows, int cols, int initialX, int initialY, int xPad, int yPad)Aligns the firstrows*colscomponents ofparentin a grid.static voidmakeSpringGrid(java.awt.Container parent, int rows, int cols, int initialX, int initialY, int xPad, int yPad)Aligns the firstrows*colscomponents ofparentin a grid.static voidprintSizes(java.awt.Component c)A debugging utility that prints to stdout the component's minimum, preferred, and maximum sizes.static voidremoveMenuModifierBindings(javax.swing.JComponent c, MenuGroup mg)Removes from a component's inputmap all bindings which may conflict with menu accelerators, that is those whose modifiers are equal to the secondary menu modifier, defined as control on mac and control+alt on windows and linux.static booleansetAlwaysOnTop(java.awt.Component c, boolean b)static voidsetDeepFont(java.awt.Container c, java.awt.Font fnt)Set a font for a container and all children we can find in this container (calling this method recursively).static voidsetInitialDialogFocus(javax.swing.JComponent c)Passes keyboard focus to a given component when that component is to be presented in a dialog.static voidsetPreferences(java.awt.Container c, java.util.prefs.Preferences prefs)static voidwrapWindowBounds(java.awt.Rectangle wr, java.awt.Rectangle sr)
-
-
-
Method Detail
-
getUserPrefs
public static final java.util.prefs.Preferences getUserPrefs()
-
getVersion
public static final double getVersion()
-
getResourceString
public static final java.lang.String getResourceString(java.lang.String key)
-
displayError
public static void displayError(java.awt.Component component, java.lang.Exception exception, java.lang.String title)Displays an error message dialog by examining a givenException. Returns after the dialog was closed by the user.- Parameters:
component- the component in which to open the dialog.nullis allowed in which case the dialog will appear centered on the screen.exception- the exception that was thrown. the message's text is displayed using thegetLocalizedMessagemethod.title- name of the action in which the error occurred- See Also:
JOptionPane.showOptionDialog( Component, Object, String, int, int, Icon, Object[], Object ),Throwable.getLocalizedMessage()
-
createKeyAction
public static void createKeyAction(javax.swing.AbstractButton comp, javax.swing.KeyStroke stroke)Convenience method that will add new corresponding entries in a button's input and action map, such that a givenKeyStrokewill cause aDoClickActionto be performed on that button. The key stroke is performed whenever the button is in the current focused window.- Parameters:
comp- anAbstractButtonto which a a new keyboard action is attached.stroke- theKeyStrokewhich causes a click on the button.- See Also:
DoClickAction,JComponent.getInputMap( int ),JComponent.getActionMap(),JComponent.WHEN_IN_FOCUSED_WINDOW
-
setDeepFont
public static void setDeepFont(java.awt.Container c, java.awt.Font fnt)Set a font for a container and all children we can find in this container (calling this method recursively). This is necessary because callingsetFonton aJPaneldoes not cause theFontof the gadgets contained in the panel to change their fonts.- Parameters:
c- the container to traverse for children whose font is to be changedfnt- the new font to apply; ifnullthe current application's window handler's default font is used- See Also:
Component.setFont( Font )
-
setPreferences
public static void setPreferences(java.awt.Container c, java.util.prefs.Preferences prefs)
-
printSizes
public static void printSizes(java.awt.Component c)
A debugging utility that prints to stdout the component's minimum, preferred, and maximum sizes. This is taken from the Sun Swing Tutorial Site.
-
makeSpringGrid
public static void makeSpringGrid(java.awt.Container parent, int rows, int cols, int initialX, int initialY, int xPad, int yPad)Aligns the firstrows*colscomponents ofparentin a grid. Each component is as big as the maximum preferred width and height of the components. The parent is made just big enough to fit them all.The code is taken from the Sun Swing Tutorial Site.
- Parameters:
rows- number of rowscols- number of columnsinitialX- x location to start the grid atinitialY- y location to start the grid atxPad- x padding between cellsyPad- y padding between cells
-
makeCompactSpringGrid
public static void makeCompactSpringGrid(java.awt.Container parent, int rows, int cols, int initialX, int initialY, int xPad, int yPad)Aligns the firstrows*colscomponents ofparentin a grid. Each component in a column is as wide as the maximum preferred width of the components in that column; height is similarly determined for each row. The parent is made just big enough to fit them all.The code is based on one from the Sun Swing Tutorial Site. It was optimized and includes support for hidden components. Warning: the spring layout seems to accumulate information; this method should not be called many times on the same spring layout, it will substantially slow down the layout process. though it's not very elegant, to solve this problem - e.g. in TimelineFrame -, simply create set a panel's layout manager to a new SpringLayout before calling this method!
- Parameters:
rows- number of rowscols- number of columnsinitialX- x location to start the grid atinitialY- y location to start the grid atxPad- x padding between cellsyPad- y padding between cells
-
getNoWriteIcon
public static javax.swing.Icon getNoWriteIcon()
Returns anIconfor a no-write or write-protection indicator. The icon has a dimension of 16x16 pixels with transparent background.- Returns:
- the write-protected icon
-
createGradientPanel
public static GradientPanel createGradientPanel()
-
constrainWidth
public static void constrainWidth(javax.swing.JComponent c, int w)Adjusts minimum, maximum and preferred size of a component so as to constrain its width to a given value.- Parameters:
c- the component to constrainw- the width in pixels
-
constrainHeight
public static void constrainHeight(javax.swing.JComponent c, int h)Adjusts minimum, maximum and preferred size of a component so as to constrain its height to a given value.- Parameters:
c- the component to constrainh- the height in pixels
-
constrainSize
public static void constrainSize(javax.swing.JComponent c, int w, int h)Sets minimum, maximum and preferred size to given values.- Parameters:
c- the component to constrainw- the width in pixelsh- the height in pixels
-
wrapWindowBounds
public static void wrapWindowBounds(java.awt.Rectangle wr, java.awt.Rectangle sr)
-
setInitialDialogFocus
public static void setInitialDialogFocus(javax.swing.JComponent c)
Passes keyboard focus to a given component when that component is to be presented in a dialog. This temporarily adds anAncestorListenerto the component, detecting when its parent container is made visible. This is useful for defining an initial focus owner inJOptionPanecalls for example.- Parameters:
c- the component to make focused once its parent container is shown
-
setAlwaysOnTop
public static boolean setAlwaysOnTop(java.awt.Component c, boolean b)
-
isAlwaysOnTop
public static boolean isAlwaysOnTop(java.awt.Component c)
-
convertPoint
public static java.awt.Point convertPoint(java.awt.Component source, java.awt.Point aPoint, java.awt.Component destination)Same as SwingUtilities.convertPoint, but handles JViewports properly
-
convertPointToScreen
public static void convertPointToScreen(java.awt.Point p, java.awt.Component c)Same as SwingUtilities.convertPointToScreen, but handles JViewports properly
-
convertPointFromScreen
public static void convertPointFromScreen(java.awt.Point p, java.awt.Component c)Same as SwingUtilities.convertPointFromScreen, but handles JViewports properly
-
convertRectangle
public static java.awt.Rectangle convertRectangle(java.awt.Component source, java.awt.Rectangle r, java.awt.Component destination)
-
removeMenuModifierBindings
public static void removeMenuModifierBindings(javax.swing.JComponent c, MenuGroup mg)Removes from a component's inputmap all bindings which may conflict with menu accelerators, that is those whose modifiers are equal to the secondary menu modifier, defined as control on mac and control+alt on windows and linux.- Parameters:
c- the component to inspect
-
-