org.fife.ui
Class UIUtil

java.lang.Object
  extended byorg.fife.ui.UIUtil

public class UIUtil
extends java.lang.Object

Utility methods for org.fife.ui GUI components.

Version:
1.0
Author:
Robert Futrell

Method Summary
static boolean browse(java.lang.String uri)
          Attempts to open a web browser to the specified URI.
static boolean browse(java.net.URI uri)
          Attempts to open a web browser to the specified URI.
static javax.swing.JLabel createLabel(java.util.ResourceBundle msg, java.lang.String textKey, java.lang.String mnemonicKey)
          Returns an JLabel with the specified text and mnemonic.
static javax.swing.JRadioButton createRadioButton(java.util.ResourceBundle bundle, java.lang.String textKey, java.lang.String mnemonicKey)
          Returns an JRadioButton with the specified text and mnemonic.
static RButton createRButton(javax.swing.Action action, java.util.ResourceBundle bundle, java.lang.String mnemonicKey)
          Returns an org.fife.ui.RButton created from the specified action and with the specified mnemonic.
static RButton createRButton(java.util.ResourceBundle bundle, java.lang.String textKey, java.lang.String mnemonicKey)
          Returns an org.fife.ui.RButton with the specified text and mnemonic.
static RButton createTabbedPaneButton(java.lang.String text)
          Returns a button to add to a panel in a tabbed pane.
static javax.swing.JPanel createTabbedPanePanel()
          Returns an opaque panel so we get the cool gradient effect on Windows XP and Vista.
static javax.swing.JPanel createTabbedPanePanel(java.awt.LayoutManager layout)
          Returns an opaque panel so we get the cool gradient effect on Windows XP and Vista.
static java.awt.Color deriveColor(java.awt.Color orig, int darker)
          Derives a color from another color by linearly shifting its blue, green, and blue values.
static void expandAllNodes(javax.swing.JTree tree)
          Expands all nodes in the specified tree.
static void fixComboOrientation(javax.swing.JComboBox combo)
          Fixes the orientation of the renderer of a combo box.
static void fixJTableRendererOrientations(javax.swing.JTable table)
          Fixes the orientation of the default JTable renderers (for Object, Number and Boolean) to match that of the current Locale (e.g.
static javax.swing.border.Border getEmpty5Border()
          Returns an empty border of width 5 on all sides.
static java.lang.String getHTMLFormatForColor(java.awt.Color color)
          Returns a String of the form "#xxxxxx" good for use in HTML, representing the given color.
static void installOsSpecificLafTweaks()
          Tweaks certain LookAndFeels (i.e., Windows XP) to look just a tad more like the native Look.
static void makeSpringCompactGrid(java.awt.Container parent, int rows, int cols, int initialX, int initialY, int xPad, int yPad)
          This method is ripped off from SpringUtilities.java found on Sun's Java Tutorial pages.
static void setDescription(javax.swing.JComponent comp, java.util.ResourceBundle msg, java.lang.String key)
          Sets the accessible description on the specified component.
static java.util.Map setNativeRenderingHints(java.awt.Graphics2D g2d)
          Sets the rendering hints on a graphics object to those closest to the system's desktop values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

browse

public static boolean browse(java.lang.String uri)
Attempts to open a web browser to the specified URI.

Parameters:
uri - The URI to open. If this is null, nothing happens and this method returns false.
Returns:
Whether the operation was successful. This will be false on JRE's older than 1.6.
See Also:
browse(URI)

browse

public static boolean browse(java.net.URI uri)
Attempts to open a web browser to the specified URI.

Parameters:
uri - The URI to open. If this is null, nothing happens and this method returns false.
Returns:
Whether the operation was successful. This will be false on JRE's older than 1.6.
See Also:
browse(String)

createLabel

public static final javax.swing.JLabel createLabel(java.util.ResourceBundle msg,
                                                   java.lang.String textKey,
                                                   java.lang.String mnemonicKey)
Returns an JLabel with the specified text and mnemonic.

Parameters:
msg - The resource bundle in which to get the int.
textKey - The key into the bundle containing the string text value.
mnemonicKey - The key into the bundle containing a single-char String value for the mnemonic.
Returns:
The JLabel.

createRadioButton

public static final javax.swing.JRadioButton createRadioButton(java.util.ResourceBundle bundle,
                                                               java.lang.String textKey,
                                                               java.lang.String mnemonicKey)
Returns an JRadioButton with the specified text and mnemonic.

Parameters:
bundle - The resource bundle in which to get the int.
textKey - The key into the bundle containing the string text value.
mnemonicKey - The key into the bundle containing a single-char String value for the mnemonic.
Returns:
The JRadioButton.

createRButton

public static final RButton createRButton(java.util.ResourceBundle bundle,
                                          java.lang.String textKey,
                                          java.lang.String mnemonicKey)
Returns an org.fife.ui.RButton with the specified text and mnemonic.

Parameters:
bundle - The resource bundle in which to get the int.
textKey - The key into the bundle containing the string text value.
mnemonicKey - The key into the bundle containing a single-char String value for the mnemonic.
Returns:
The RButton.

createRButton

public static final RButton createRButton(javax.swing.Action action,
                                          java.util.ResourceBundle bundle,
                                          java.lang.String mnemonicKey)
Returns an org.fife.ui.RButton created from the specified action and with the specified mnemonic.

Parameters:
action - The action for the button.
bundle - The resource bundle in which to get the int.
mnemonicKey - The key into the bundle containing a single-char String value for the mnemonic.
Returns:
The RButton.

createTabbedPaneButton

public static RButton createTabbedPaneButton(java.lang.String text)
Returns a button to add to a panel in a tabbed pane. This method checks system properties to determine the operating system this JVM is running in; if it is determined that this OS paints its tabbed panes in a special way (such as the gradient tabbed panes in Windows XP), then the button returned is not opaque. Otherwise, a regular (opaque) button is returned.

Returns:
A button to add to a JTabbedPane.
See Also:
createTabbedPanePanel()

createTabbedPanePanel

public static javax.swing.JPanel createTabbedPanePanel()
Returns an opaque panel so we get the cool gradient effect on Windows XP and Vista.

Returns:
A panel to add to a JTabbedPane.
See Also:
createTabbedPaneButton(String)

createTabbedPanePanel

public static javax.swing.JPanel createTabbedPanePanel(java.awt.LayoutManager layout)
Returns an opaque panel so we get the cool gradient effect on Windows XP and Vista.

Parameters:
layout - The layout for the panel.
Returns:
A panel to add to a JTabbedPane.
See Also:
createTabbedPaneButton(String)

deriveColor

public static final java.awt.Color deriveColor(java.awt.Color orig,
                                               int darker)
Derives a color from another color by linearly shifting its blue, green, and blue values.

Parameters:
orig - The original color.
darker - The amount by which to decrease its r, g, and b values. Note that you can use negative values for making a color component "brighter." If this makes any of the three values less than zero, zero is used for that component value; similarly, if it makes any value greater than 255, 255 is used for that component's value.

expandAllNodes

public static void expandAllNodes(javax.swing.JTree tree)
Expands all nodes in the specified tree.

Parameters:
tree - The tree.

fixComboOrientation

public static void fixComboOrientation(javax.swing.JComboBox combo)
Fixes the orientation of the renderer of a combo box. I can't believe Swing standard LaFs don't handle this on their own.

Parameters:
combo - The combo box.

fixJTableRendererOrientations

public static void fixJTableRendererOrientations(javax.swing.JTable table)
Fixes the orientation of the default JTable renderers (for Object, Number and Boolean) to match that of the current Locale (e.g. ComponentOrientation.getOrientation(table.getLocale())). This is needed because DefaultTableCellRenderer does not do this, even though DefaultListCellRenderer and DefaultTreeCellRenderer do.

See Sun bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6333197 for more information.

Parameters:
table - The table to update.

getEmpty5Border

public static javax.swing.border.Border getEmpty5Border()
Returns an empty border of width 5 on all sides. Since this is a very common border in GUI's, the border returned is a singleton.

Returns:
The border.

getHTMLFormatForColor

public static final java.lang.String getHTMLFormatForColor(java.awt.Color color)
Returns a String of the form "#xxxxxx" good for use in HTML, representing the given color.

Parameters:
color - The color to get a string for.
Returns:
The HTML form of the color. If color is null, #000000 is returned.

installOsSpecificLafTweaks

public static void installOsSpecificLafTweaks()
Tweaks certain LookAndFeels (i.e., Windows XP) to look just a tad more like the native Look.


makeSpringCompactGrid

public static final void makeSpringCompactGrid(java.awt.Container parent,
                                               int rows,
                                               int cols,
                                               int initialX,
                                               int initialY,
                                               int xPad,
                                               int yPad)
This method is ripped off from SpringUtilities.java found on Sun's Java Tutorial pages. It takes a component whose layout is SpringLayout and organizes the components it contains into a nice grid. Aligns the first rows * cols components of parent in 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.

Parameters:
parent - The container whose layout is SpringLayout.
rows - The number of rows of components to make in the container.
cols - The umber of columns of components to make.
initialX - The x-location to start the grid at.
initialY - The y-location to start the grid at.
xPad - The x-padding between cells.
yPad - The y-padding between cells.

setDescription

public static void setDescription(javax.swing.JComponent comp,
                                  java.util.ResourceBundle msg,
                                  java.lang.String key)
Sets the accessible description on the specified component.

Parameters:
comp - The component on which to set the accessible description.
msg - A resource bundle from which to get the description.
key - The key for the description in the resource bundle.

setNativeRenderingHints

public static java.util.Map setNativeRenderingHints(java.awt.Graphics2D g2d)
Sets the rendering hints on a graphics object to those closest to the system's desktop values.

See AWT Desktop Properties for more information.

Parameters:
g2d - The graphics context.
Returns:
The old rendering hints.