org.jorion.balboa.common
Class GuiUtils

java.lang.Object
  extended by org.jorion.balboa.common.GuiUtils

public final class GuiUtils
extends java.lang.Object

Set of static utility function to create the GUI.

Author:
Bernard Jorion, www.jorion.org

Nested Class Summary
static class GuiUtils.StatusBar
          Component to create a status bar.
 
Field Summary
static java.awt.Font FNT_BOLD
          Default bold font.
static java.awt.Font FNT_PLAIN
          Default plain font.
static java.lang.String SUFFIX_ACTION
          Suffix applied to the key used in resource file lookups for an action.
static java.lang.String SUFFIX_IMAGE
          Suffix applied to the key used in resource file lookups for an image.
static java.lang.String SUFFIX_LABEL
          Suffix applied to the key used in resource file lookups for a label.
static java.lang.String SUFFIX_TIP
          Suffix applied to the key used in resource file lookups for tooltip text.
 
Method Summary
static javax.swing.JButton createButton(java.lang.String text, java.util.ResourceBundle rb)
          Create a JButton.
static javax.swing.JButton createButton(java.lang.String text, java.util.ResourceBundle rb, java.awt.Font font)
          Create a JButton.
static javax.swing.JCheckBox createCheckBox(java.lang.String text, java.util.ResourceBundle rb, java.awt.Font font)
          Create a JCheckbox.
static java.awt.datatransfer.ClipboardOwner createDefaultClipboardOwner()
           
static javax.swing.JLabel createLabel(java.lang.String text)
          Create a JLabel.
static javax.swing.JLabel createLabel(java.lang.String text, java.util.ResourceBundle rb)
          Create a JLabel.
static javax.swing.JLabel createLabel(java.lang.String text, java.util.ResourceBundle rb, java.awt.Font font)
          Create a JLabel.
static javax.swing.JMenuBar createMenuBar(java.util.ResourceBundle rb, java.util.Map<java.lang.String,javax.swing.Action> commands, java.lang.String menuKey)
          Create a JMenu Bar.
static GuiUtils.StatusBar createStatusbar()
          Create a status bar.
static javax.swing.JToolBar createToolbar(java.util.ResourceBundle rb, java.util.Map<java.lang.String,javax.swing.Action> commands, java.lang.String toolbarKey)
          Create a JToolBar.
static java.net.URL getResource(java.util.ResourceBundle rb, java.lang.String key)
           
static java.lang.String getResourceString(java.util.ResourceBundle rb, java.lang.String key)
          Retrieve the string corresponding to the given key in the given resource bundle.
static java.awt.GridBagConstraints makeConstraints(int gridx, int gridy, int gridwidth, int fill)
          Helper function to build the GridBagConstraints.
static void setLocation(java.awt.Window window)
          Center the given window on the screen.
static boolean setLookAndFeel(java.awt.Component c, java.lang.String classname)
          Update the given component's look and feel.
static java.lang.String[] tokenize(java.lang.String input)
          Take the given string and chop it up into a series of strings on whitespace boundaries.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SUFFIX_IMAGE

public static final java.lang.String SUFFIX_IMAGE
Suffix applied to the key used in resource file lookups for an image.

See Also:
Constant Field Values

SUFFIX_LABEL

public static final java.lang.String SUFFIX_LABEL
Suffix applied to the key used in resource file lookups for a label.

See Also:
Constant Field Values

SUFFIX_ACTION

public static final java.lang.String SUFFIX_ACTION
Suffix applied to the key used in resource file lookups for an action.

See Also:
Constant Field Values

SUFFIX_TIP

public static final java.lang.String SUFFIX_TIP
Suffix applied to the key used in resource file lookups for tooltip text.

See Also:
Constant Field Values

FNT_PLAIN

public static final java.awt.Font FNT_PLAIN
Default plain font.


FNT_BOLD

public static final java.awt.Font FNT_BOLD
Default bold font.

Method Detail

tokenize

public static java.lang.String[] tokenize(java.lang.String input)
Take the given string and chop it up into a series of strings on whitespace boundaries. This is useful for trying to get an array of strings out of the resource file.

Parameters:
input - The given string.
Returns:
An array of strings.

getResourceString

public static java.lang.String getResourceString(java.util.ResourceBundle rb,
                                                 java.lang.String key)
Retrieve the string corresponding to the given key in the given resource bundle. If the key is not found, the string is returned with "@" pre-pended.

Parameters:
rb - The resource bundle.
key - The resource key.
Returns:
The resource value from the bundle.

getResource

public static java.net.URL getResource(java.util.ResourceBundle rb,
                                       java.lang.String key)
Parameters:
rb - The resource bundle.
key - The resource key.
Returns:
The resource URL from the bundle.

setLocation

public static void setLocation(java.awt.Window window)
Center the given window on the screen.

Parameters:
window - The window.

setLookAndFeel

public static boolean setLookAndFeel(java.awt.Component c,
                                     java.lang.String classname)
Update the given component's look and feel. Nothing happens if classname is empty.

Parameters:
c - The component to update.
classname - The classname of the Look & Feel.
Returns:
True If the operation was successful.

makeConstraints

public static java.awt.GridBagConstraints makeConstraints(int gridx,
                                                          int gridy,
                                                          int gridwidth,
                                                          int fill)
Helper function to build the GridBagConstraints.

Parameters:
gridx - The x-coordinate in the grid.
gridy - The y-coordinate in the grid.
gridwidth - Specifies the number of cells in a row for the component's display area.
fill - This field is used when the component's display area is larger than the component's requested size.
Returns:
An instance of GridBagConstraints.

createDefaultClipboardOwner

public static java.awt.datatransfer.ClipboardOwner createDefaultClipboardOwner()
Returns:
A default (empty) clipboard owner.

createMenuBar

public static javax.swing.JMenuBar createMenuBar(java.util.ResourceBundle rb,
                                                 java.util.Map<java.lang.String,javax.swing.Action> commands,
                                                 java.lang.String menuKey)
Create a JMenu Bar.

Parameters:
rb - The resource bundle.
commands - A map of commands.
menuKey - The menu key.
Returns:
A JMenuBar.

createToolbar

public static javax.swing.JToolBar createToolbar(java.util.ResourceBundle rb,
                                                 java.util.Map<java.lang.String,javax.swing.Action> commands,
                                                 java.lang.String toolbarKey)
Create a JToolBar.

Parameters:
rb - The resource bundle.
commands - A map of commands.
toolbarKey - The toolbar key.
Returns:
A JToolBar.

createLabel

public static javax.swing.JLabel createLabel(java.lang.String text)
Create a JLabel.

Parameters:
text - The text or the key in the ResourceBundle.
Returns:
A JLabel with the given text.

createLabel

public static javax.swing.JLabel createLabel(java.lang.String text,
                                             java.util.ResourceBundle rb)
Create a JLabel.

Parameters:
text - The text or the key in the ResourceBundle.
rb - The ResourceBundle or null if not used.
Returns:
A JLabel with the given text.

createLabel

public static javax.swing.JLabel createLabel(java.lang.String text,
                                             java.util.ResourceBundle rb,
                                             java.awt.Font font)
Create a JLabel.

Parameters:
text - The text or the key in the ResourceBundle.
rb - The ResourceBundle or null if not used.
font - The font or null if the default font must be used.
Returns:
A JLabel with the text and the font set.

createCheckBox

public static javax.swing.JCheckBox createCheckBox(java.lang.String text,
                                                   java.util.ResourceBundle rb,
                                                   java.awt.Font font)
Create a JCheckbox.

Parameters:
text - The text or the key in the ResourceBundle.
rb - The ResourceBundle or null if not used.
font - The font or null if the default font must be used.
Returns:
A JCheckbox with the text and the font set.

createButton

public static javax.swing.JButton createButton(java.lang.String text,
                                               java.util.ResourceBundle rb)
Create a JButton.

Parameters:
text - The text or the key in the ResourceBundle.
rb - The ResourceBundle or null if not used.
Returns:
A JButton with the text and the font set.

createButton

public static javax.swing.JButton createButton(java.lang.String text,
                                               java.util.ResourceBundle rb,
                                               java.awt.Font font)
Create a JButton.

Parameters:
text - The text or the key in the ResourceBundle.
rb - The ResourceBundle or null if not used.
font - The font or null if the default font must be used.
Returns:
A JButton with the text and the font set.

createStatusbar

public static GuiUtils.StatusBar createStatusbar()
Create a status bar.

Returns:
A JComponent that can be used as a status bar.