Package diva.gui

Class GUIUtilities


  • public class GUIUtilities
    extends java.lang.Object
    A collection of utilities for the GUI.
    Version:
    $Id$
    Author:
    John Reekie, Steve Neuendorffer
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String ACCELERATOR_KEY
      JDK1.2 doesn't have this string defined in javax.swing.Action.
      static java.lang.String LARGE_ICON
      This key is used in an action to specify an icon used in toolbars.
      static java.lang.String MNEMONIC_KEY
      JDK1.2 doesn't have this string defined in javax.swing.Action.
      static java.lang.String ROLLOVER_ICON
      This key is used in an action to specify a rollover icon used in toolbars.
      static java.lang.String ROLLOVER_SELECTED_ICON
      This key is used in an action to specify a rollover selected icon used in toolbars.
      static java.lang.String SELECTED_ICON
      This key is used in an action to specify a selected icon used in toolbars.
    • Constructor Summary

      Constructors 
      Constructor Description
      GUIUtilities()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addHotKey​(javax.swing.JComponent pane, javax.swing.Action action)
      Add a quick keystroke on the given pane for the given action.
      static void addHotKey​(javax.swing.JComponent pane, javax.swing.Action action, javax.swing.KeyStroke key)
      Add a quick keystroke on the given pane for the given action.
      static void addIcons​(javax.swing.Action action, java.lang.String[][] iconRoles)
      Add icons to an action.
      static javax.swing.JMenuItem addMenuItem​(javax.swing.JMenu menu, java.lang.String label, javax.swing.Action action, int mnemonic, java.lang.String tooltip, boolean isEnabled)
      Add an action to a menu and return the menu item created.
      static javax.swing.JMenuItem addMenuItem​(javax.swing.JMenu menu, javax.swing.Action action)
      Add an action to a menu and return the menu item created.
      static javax.swing.JMenuItem addMenuItem​(javax.swing.JMenu menu, javax.swing.Action action, int mnemonic, java.lang.String tooltip)
      Add an action to a menu and return the menu item created.
      static javax.swing.JButton addToolBarButton​(javax.swing.JToolBar toolbar, javax.swing.Action action)
      Add the action to the given toolbar.
      static javax.swing.JButton addToolBarButton​(javax.swing.JToolBar toolbar, javax.swing.Action action, java.lang.String tooltip, java.lang.String lbl)
      Add an action to the toolbar.
      static javax.swing.JButton addToolBarButton​(javax.swing.JToolBar toolbar, javax.swing.Action action, java.lang.String tooltip, javax.swing.Icon icon)
      Add an action to the toolbar.
      static javax.swing.JButton addToolBarButton​(javax.swing.JToolBar toolbar, javax.swing.Action action, java.lang.String tooltip, javax.swing.Icon icon, boolean isEnabled)
      Add an action to the toolbar.
      static javax.swing.JButton addToolBarButton​(javax.swing.JToolBar toolbar, javax.swing.Action action, java.lang.String tooltip, javax.swing.Icon icon, java.lang.String lbl)
      Add an action to the toolbar.
      static javax.swing.JButton addToolBarButton​(javax.swing.JToolBar toolbar, javax.swing.Action action, java.lang.String tooltip, javax.swing.Icon icon, java.lang.String lbl, boolean isEnabled)
      Add an action to the toolbar.
      static java.lang.String ellipsis​(java.lang.String string, int length)
      Return a string that contains the original string, limited to the given number of characters.
      static java.lang.String getFileExtension​(java.io.File file)
      Get the extension of a file.
      static java.lang.String keyStrokeToString​(javax.swing.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​(java.awt.Component parent, java.lang.Exception e, java.lang.String info)
      Display an exception in a nice user-oriented way.
      static void showStackTrace​(java.awt.Component parent, java.lang.Exception e)
      Display a stack trace dialog.
      static void showStackTrace​(java.awt.Component parent, java.lang.Exception e, java.lang.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 java.lang.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 java.lang.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 java.lang.String LARGE_ICON
        This key is used in an action to specify an icon used in toolbars.
        See Also:
        Constant Field Values
      • ROLLOVER_ICON

        public static final java.lang.String ROLLOVER_ICON
        This key is used in an action to specify a rollover icon used in toolbars.
        See Also:
        Constant Field Values
      • ROLLOVER_SELECTED_ICON

        public static final java.lang.String ROLLOVER_SELECTED_ICON
        This key is used in an action to specify a rollover selected icon used in toolbars.
        See Also:
        Constant Field Values
      • SELECTED_ICON

        public static final java.lang.String SELECTED_ICON
        This key is used in an action to specify a selected icon used in toolbars.
        See Also:
        Constant Field Values
    • Constructor Detail

      • GUIUtilities

        public GUIUtilities()
    • Method Detail

      • addHotKey

        public static void addHotKey​(javax.swing.JComponent pane,
                                     javax.swing.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​(javax.swing.JComponent pane,
                                     javax.swing.Action action,
                                     javax.swing.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.
      • addIcons

        public static void addIcons​(javax.swing.Action action,
                                    java.lang.String[][] iconRoles)
        Add icons to an action. This method is used to associate icons with the different states: unselected, rollover, rollover selected, selected etc.
        Parameters:
        action - The action to which the icons are added.
        iconRoles - A matrix of Strings, where each element consists of two Strings, the absolute URL of the icon and the key that represents the role of the icon. The keys are usually static fields from this class, such as LARGE_ICON, ROLLOVER_ICON, ROLLOVER_SELECTED_ICON or SELECTED_ICON.
      • addMenuItem

        public static javax.swing.JMenuItem addMenuItem​(javax.swing.JMenu menu,
                                                        javax.swing.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 javax.swing.JMenuItem addMenuItem​(javax.swing.JMenu menu,
                                                        javax.swing.Action action,
                                                        int mnemonic,
                                                        java.lang.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 javax.swing.JMenuItem addMenuItem​(javax.swing.JMenu menu,
                                                        java.lang.String label,
                                                        javax.swing.Action action,
                                                        int mnemonic,
                                                        java.lang.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 javax.swing.JButton addToolBarButton​(javax.swing.JToolBar toolbar,
                                                           javax.swing.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 javax.swing.JButton addToolBarButton​(javax.swing.JToolBar toolbar,
                                                           javax.swing.Action action,
                                                           java.lang.String tooltip,
                                                           javax.swing.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 javax.swing.JButton addToolBarButton​(javax.swing.JToolBar toolbar,
                                                           javax.swing.Action action,
                                                           java.lang.String tooltip,
                                                           javax.swing.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 javax.swing.JButton addToolBarButton​(javax.swing.JToolBar toolbar,
                                                           javax.swing.Action action,
                                                           java.lang.String tooltip,
                                                           java.lang.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 javax.swing.JButton addToolBarButton​(javax.swing.JToolBar toolbar,
                                                           javax.swing.Action action,
                                                           java.lang.String tooltip,
                                                           javax.swing.Icon icon,
                                                           java.lang.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 javax.swing.JButton addToolBarButton​(javax.swing.JToolBar toolbar,
                                                           javax.swing.Action action,
                                                           java.lang.String tooltip,
                                                           javax.swing.Icon icon,
                                                           java.lang.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 java.lang.String ellipsis​(java.lang.String string,
                                                int length)
        Return a string that contains the original string, limited to the given number of characters. If the string is truncated, ellipses will be appended to the end of the string
      • getFileExtension

        public static java.lang.String getFileExtension​(java.io.File file)
        Get the extension of a file. Return a null string is there is no extension.
      • keyStrokeToString

        public static java.lang.String keyStrokeToString​(javax.swing.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​(java.awt.Component parent,
                                         java.lang.Exception e,
                                         java.lang.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​(java.awt.Component parent,
                                          java.lang.Exception e)
        Display a stack trace dialog. Eventually, the dialog should be able to email us a bug report.
      • showStackTrace

        public static void showStackTrace​(java.awt.Component parent,
                                          java.lang.Exception e,
                                          java.lang.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.