diva.gui
Class GUIUtilities

java.lang.Object
  extended by diva.gui.GUIUtilities

public class GUIUtilities
extends Object

A collection of utilities for the GUI.

Version:
$Revision: 1.17 $
Author:
John Reekie (johnr@eecs.berkeley.edu), Steve Neuendorffer (neuendor@eecs.berkeley.edu)

Field Summary
static String ACCELERATOR_KEY
          JDK1.2 doesn't have this string defined in javax.swing.Action.
static String LARGE_ICON
          This key is used in an action to specify an icon used in toolbars.
static String MNEMONIC_KEY
          JDK1.2 doesn't have this string defined in javax.swing.Action.
 
Constructor Summary
GUIUtilities()
           
 
Method Summary
static void addHotKey(JComponent pane, Action action)
          Add a quick keystroke on the given pane for the given action.
static void addHotKey(JComponent pane, Action action, KeyStroke key)
          Add a quick keystroke on the given pane for the given action.
static JMenuItem addMenuItem(JMenu menu, Action action)
          Add an action to a menu and return the menu item created.
static JMenuItem addMenuItem(JMenu menu, Action action, int mnemonic, String tooltip)
          Add an action to a menu and return the menu item created.
static JMenuItem addMenuItem(JMenu menu, String label, Action action, int mnemonic, String tooltip, boolean isEnabled)
          Add an action to a menu and return the menu item created.
static JButton addToolBarButton(JToolBar toolbar, Action action)
          Add the action to the given toolbar.
static JButton addToolBarButton(JToolBar toolbar, Action action, String tooltip, Icon icon)
          Add an action to the toolbar.
static JButton addToolBarButton(JToolBar toolbar, Action action, String tooltip, Icon icon, boolean isEnabled)
          Add an action to the toolbar.
static JButton addToolBarButton(JToolBar toolbar, Action action, String tooltip, Icon icon, String lbl)
          Add an action to the toolbar.
static JButton addToolBarButton(JToolBar toolbar, Action action, String tooltip, Icon icon, String lbl, boolean isEnabled)
          Add an action to the toolbar.
static JButton addToolBarButton(JToolBar toolbar, Action action, String tooltip, String lbl)
          Add an action to the toolbar.
static String ellipsis(String string, int length)
          Return a string that contains the original string, limited to the given number of characters.
static String getFileExtension(File file)
          Get the extension of a file.
static String keyStrokeToString(KeyStroke key)
          Return a good string representation of the given keystroke, since the toString method returns more garbage than we want to see in a user interface.
static void showException(Component parent, Exception e, String info)
          Display an exception in a nice user-oriented way.
static void showStackTrace(Component parent, Exception e)
          Display a stack trace dialog.
static void showStackTrace(Component parent, Exception e, String info)
          Display a stack trace dialog.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACCELERATOR_KEY

public static final String ACCELERATOR_KEY
JDK1.2 doesn't have this string defined in javax.swing.Action. This is the value that JDK1.3 uses.

See Also:
Constant Field Values

MNEMONIC_KEY

public static final String MNEMONIC_KEY
JDK1.2 doesn't have this string defined in javax.swing.Action. This is the value that JDK1.3 uses.

See Also:
Constant Field Values

LARGE_ICON

public static final String LARGE_ICON
This key is used in an action to specify an icon used in toolbars.

See Also:
Constant Field Values
Constructor Detail

GUIUtilities

public GUIUtilities()
Method Detail

addHotKey

public static void addHotKey(JComponent pane,
                             Action action)
Add a quick keystroke on the given pane for the given action. The keystroke that is added is given in the ACCELERATOR_KEY property that has been set in the action. If the ACCELERATOR_KEY property has not been set, then do not add a hotkey.


addHotKey

public static void addHotKey(JComponent pane,
                             Action action,
                             KeyStroke key)
Add a quick keystroke on the given pane for the given action. If the given keystroke is null, then use the ACCELERATOR_KEY property that has been set in the action. If the given keystroke is null, Otherwise, set the ACCELERATOR_KEY property to the given key stroke.


addMenuItem

public static JMenuItem addMenuItem(JMenu menu,
                                    Action action)
Add an action to a menu and return the menu item created. If the tool tip is null, use the "tooltip" property already in the action, otherwise add the property to the action. (The mnemonic isn't added.) The new menu item is added to the action as the "menuItem" property. The menu item's text is set using the action's name, concatenated with a description of a keyboard accelerator, if one has been set previously on the action. The item will be enabled by default.


addMenuItem

public static JMenuItem addMenuItem(JMenu menu,
                                    Action action,
                                    int mnemonic,
                                    String tooltip)
Add an action to a menu and return the menu item created. If the tool tip is null, use the "tooltip" property already in the action, otherwise add the property to the action. (The mnemonic isn't added.) The new menu item is added to the action as the "menuItem" property. The menu item's text is set using the action's name, concatenated with a description of a keyboard accelerator, if one has been set previously on the action. The item will be enabled by default.


addMenuItem

public static JMenuItem addMenuItem(JMenu menu,
                                    String label,
                                    Action action,
                                    int mnemonic,
                                    String tooltip,
                                    boolean isEnabled)
Add an action to a menu and return the menu item created. If the tool tip is null, use the "tooltip" property already in the action, otherwise add the property to the action. (The mnemonic isn't added.) The new menu item is added to the action as the "menuItem" property. The menu item's text is set to be "label", and is disabled or enabled according to "isEnabled."


addToolBarButton

public static JButton addToolBarButton(JToolBar toolbar,
                                       Action action)
Add the action to the given toolbar. If the LARGE_ICON property is specified in the Action, then use it for the button. We use this instead of SMALL_ICON, because SMALL_ICON shows up when the action is added to a menu, and in most cases we don't actually want an icon there. If no icon is specified, then the button will just have the name of the action. If the "tooltip" property is specified in the action, then create a tooltip for the button with the string. The new button is added to the action as the "toolButton" property. The button is enabled by default.


addToolBarButton

public static JButton addToolBarButton(JToolBar toolbar,
                                       Action action,
                                       String tooltip,
                                       Icon icon)
Add an action to the toolbar. If the tool tip is null, use the "tooltip" property already in the action, otherwise add the property to the action. The new button is added to the action as the "toolButton" property. The button represented by an icon (no text) and is enabled by default.


addToolBarButton

public static JButton addToolBarButton(JToolBar toolbar,
                                       Action action,
                                       String tooltip,
                                       Icon icon,
                                       boolean isEnabled)
Add an action to the toolbar. If the tool tip is null, use the "tooltip" property already in the action, otherwise add the property to the action. The new button is added to the action as the "toolButton" property. The button represented by an icon (no text) and is enabled by default.


addToolBarButton

public static JButton addToolBarButton(JToolBar toolbar,
                                       Action action,
                                       String tooltip,
                                       String lbl)
Add an action to the toolbar. If the tool tip is null, use the "tooltip" property already in the action, otherwise add the property to the action. The new button is added to the action as the "toolButton" property. The button represented by text (no icon) and is enabled by default.


addToolBarButton

public static JButton addToolBarButton(JToolBar toolbar,
                                       Action action,
                                       String tooltip,
                                       Icon icon,
                                       String lbl)
Add an action to the toolbar. If either an icon or a text string are specified (non-null), they are added. The button is enabled by default.


addToolBarButton

public static JButton addToolBarButton(JToolBar toolbar,
                                       Action action,
                                       String tooltip,
                                       Icon icon,
                                       String lbl,
                                       boolean isEnabled)
Add an action to the toolbar. If the tool tip is null, use the "tooltip" property already in the action, otherwise add the property to the action. The new button is added to the action as the "toolButton" property. If either an icon or a text string are specified (non-null), they are added.


ellipsis

public static String ellipsis(String string,
                              int length)
Return a string that contains the original string, limited to the given number of characters. If the string is truncated, elipses will be appended to the end of the string


getFileExtension

public static String getFileExtension(File file)
Get the extension of a file. Return a null string is there is no extension.


keyStrokeToString

public static String keyStrokeToString(KeyStroke key)
Return a good string representation of the given keystroke, since the toString method returns more garbage than we want to see in a user interface.


showException

public static void showException(Component parent,
                                 Exception e,
                                 String info)
Display an exception in a nice user-oriented way. Instead of displaying the whole stack trace, just display the exception message and a button for displaying the whole stack trace.


showStackTrace

public static void showStackTrace(Component parent,
                                  Exception e)
Display a stack trace dialog. Eventually, the dialog should be able to email us a bug report.


showStackTrace

public static void showStackTrace(Component parent,
                                  Exception e,
                                  String info)
Display a stack trace dialog. Eventually, the dialog should be able to email us a bug report. The "info" argument is a string printed at the top of the dialog instead of the Exception message.



Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.