Class CommonUI


  • public class CommonUI
    extends java.lang.Object
    A collection of static methods and constants to make the UI uniform.
    • Constructor Summary

      Constructors 
      Constructor Description
      CommonUI()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.awt.Point adjustPopupLocationToFitScreen​(int xposition, int yposition, javax.swing.JComponent component, java.awt.Component invoker)
      Adjusts a desired popup location to fit within the screen, given the component's preferred size.
      static void centerComponent​(java.awt.Component source)
      Centers the Component on the screen.
      static void centerComponent​(java.awt.Component source, java.awt.Component parent)
      Centers a component (source) in it's parent component.
      static javax.swing.JButton createAccessoryButton​(javax.swing.Action action)
      Creates a small button for the given action with a 2px margin.
      static javax.swing.border.Border createBorder()
      Creates an blank border with the displayed text
      static javax.swing.border.Border createBorder​(java.lang.String text)
      Creates an etched border with the displayed text
      static javax.swing.JButton createButton​(java.lang.String text, java.awt.event.ActionListener listener)  
      static javax.swing.JButton createButton​(java.lang.String text, java.awt.event.ActionListener listener, java.lang.String mnemonic)
      Creates a JButton
      static javax.swing.JButton createButton​(java.lang.String text, java.awt.event.ActionListener listener, java.lang.String mnemonic, java.lang.String actionCommand)  
      static javax.swing.JCheckBox createCheckBox​(java.lang.String text)  
      static javax.swing.JCheckBox createCheckBox​(java.lang.String text, int mnemonic)  
      static javax.swing.JCheckBox createCheckBox​(java.lang.String text, int mnemonic, boolean selected)  
      static javax.swing.JCheckBox createCheckBox​(java.lang.String text, int mnemonic, java.awt.event.ActionListener listener)  
      static javax.swing.JCheckBox createCheckBox​(java.lang.String text, int mnemonic, java.awt.event.ActionListener listener, boolean selected)
      Create a checkbox
      static javax.swing.JComboBox createComboBox​(java.lang.Object[] items, boolean editable)  
      static javax.swing.JComboBox createComboBox​(java.lang.Object[] items, java.awt.event.ActionListener listener, boolean editable)
      Creates a JComboBox
      static javax.swing.JLabel createLabel​(java.lang.String text)  
      static javax.swing.JLabel createLabel​(java.lang.String text, int mnemonic, java.awt.Component comp)
      Creates a label which will be displayed.
      static javax.swing.JScrollPane createListPane​(javax.swing.JList list, java.lang.String text)
      Wraps a scrollpane with and etched border and a title around a JList.
      static javax.swing.JRadioButton createRadioButton​(java.lang.String text)  
      static javax.swing.JRadioButton createRadioButton​(java.lang.String text, int mnemonic)  
      static javax.swing.JRadioButton createRadioButton​(java.lang.String text, int mnemonic, boolean selected)  
      static javax.swing.JRadioButton createRadioButton​(java.lang.String text, int mnemonic, java.awt.event.ActionListener listener)  
      static javax.swing.JRadioButton createRadioButton​(java.lang.String text, int mnemonic, java.awt.event.ActionListener listener, boolean selected)
      Creates a Radio Button
      static javax.swing.JButton createSmallButton​(java.lang.String text, java.awt.event.ActionListener listener)  
      static javax.swing.JButton createSmallButton​(java.lang.String text, java.awt.event.ActionListener listener, java.lang.String mnemonic)
      Creates a Smaller JButton
      static javax.swing.JTextField createTextField​(java.lang.String text)  
      static javax.swing.JTextField createTextField​(java.lang.String text, boolean numbers)  
      static javax.swing.JTextField createTextField​(java.lang.String text, java.awt.event.KeyListener listener)  
      static javax.swing.JTextField createTextField​(java.lang.String text, java.awt.event.KeyListener listener, boolean numbers)
      Creates a text field
      static javax.swing.AbstractButton createToolbarButton​(javax.swing.Action action, java.lang.String componentTestName)
      Returns a minimalized toolbar button with no text.
      static java.lang.String eventModifiersToString​(int event)  
      static javax.swing.JFrame getParentFrame​(java.awt.Component source)
      Retrieves the parent JFrame for a component.
      static java.lang.String getTooltipPrefix​(int width)  
      static void initButtonGroup​(javax.swing.JRadioButton... buttons)  
      static java.lang.Integer msToSec​(java.lang.Integer ms)
      Converts miliseconds to seconds
      static java.lang.Integer secToMs​(java.lang.Integer sec)
      Converts seconds to miliseconds
      static void setDefaultCursor​(java.awt.Component comp)  
      static void setDropCursor​(java.awt.Component comp)  
      static void setupCancelButton​(javax.swing.JButton btn)
      Sets up the ESC-key binding for a cancel button
      static void setWaitCursor​(java.awt.Component comp)  
      static java.lang.String[] stringArrayFromString​(java.lang.String string)  
      static java.lang.String[] stringArrayFromString​(java.lang.String string, java.lang.String delim)
      Parses the string into an array of strings
      static java.lang.String stringFromStringArray​(java.lang.String[] strings)  
      static java.lang.String stringFromStringArray​(java.lang.String[] strings, java.lang.String delim)
      Takes an array of strings and returns a concatenation
      static javax.swing.JPanel wrapInTitledPanel​(javax.swing.JComponent component, java.lang.String bundleKey)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • TOOLTIP_PREFIX

        public static final java.lang.String TOOLTIP_PREFIX
        <html><p style=\"width:300px;\">
        See Also:
        Constant Field Values
      • BUTTONTEXT_APPLY

        public static final java.lang.String BUTTONTEXT_APPLY
      • BUTTONTEXT_OK

        public static final java.lang.String BUTTONTEXT_OK
      • BUTTONTEXT_CANCEL

        public static final java.lang.String BUTTONTEXT_CANCEL
      • BUTTONTEXT_REMOVE

        public static final java.lang.String BUTTONTEXT_REMOVE
      • BUTTONTEXT_ADD

        public static final java.lang.String BUTTONTEXT_ADD
      • MNEMONIC_APPLY

        public static final java.lang.String MNEMONIC_APPLY
      • MNEMONIC_OK

        public static final java.lang.String MNEMONIC_OK
      • MNEMONIC_CANCEL

        public static final java.lang.String MNEMONIC_CANCEL
      • MNEMONIC_REMOVE

        public static final java.lang.String MNEMONIC_REMOVE
      • MNEMONIC_ADD

        public static final java.lang.String MNEMONIC_ADD
      • BACKGROUND_COLOR

        public static final java.awt.Color BACKGROUND_COLOR
      • BUTTON_CMD_CANCEL

        public static final java.lang.String BUTTON_CMD_CANCEL
        See Also:
        Constant Field Values
      • BUTTON_CMD_FINISH

        public static final java.lang.String BUTTON_CMD_FINISH
        See Also:
        Constant Field Values
      • BUTTON_CMD_REMOVE

        public static final java.lang.String BUTTON_CMD_REMOVE
        See Also:
        Constant Field Values
      • BUTTON_CMD_MOVEUP

        public static final java.lang.String BUTTON_CMD_MOVEUP
        See Also:
        Constant Field Values
      • BUTTON_CMD_MOVEDOWN

        public static final java.lang.String BUTTON_CMD_MOVEDOWN
        See Also:
        Constant Field Values
      • buttonPrefSize

        public static java.awt.Dimension buttonPrefSize
      • buttconPrefSize

        public static java.awt.Dimension buttconPrefSize
      • smbuttonPrefSize

        public static java.awt.Dimension smbuttonPrefSize
      • labelPrefSize

        public static java.awt.Dimension labelPrefSize
      • textPrefSize

        public static java.awt.Dimension textPrefSize
    • Constructor Detail

      • CommonUI

        public CommonUI()
    • Method Detail

      • getTooltipPrefix

        public static final java.lang.String getTooltipPrefix​(int width)
      • wrapInTitledPanel

        public static javax.swing.JPanel wrapInTitledPanel​(javax.swing.JComponent component,
                                                           java.lang.String bundleKey)
      • createLabel

        public static javax.swing.JLabel createLabel​(java.lang.String text,
                                                     int mnemonic,
                                                     java.awt.Component comp)
        Creates a label which will be displayed.
        Parameters:
        text - Text for the label
        mnemonic - Hot key
        comp - Component that this label represents.
      • createLabel

        public static javax.swing.JLabel createLabel​(java.lang.String text)
      • createAccessoryButton

        public static javax.swing.JButton createAccessoryButton​(javax.swing.Action action)
        Creates a small button for the given action with a 2px margin.
      • createToolbarButton

        public static javax.swing.AbstractButton createToolbarButton​(javax.swing.Action action,
                                                                     java.lang.String componentTestName)
        Returns a minimalized toolbar button with no text. The componentTestName parameter is used to set the component name for automated testing. It can be anything unique.
      • createTextField

        public static javax.swing.JTextField createTextField​(java.lang.String text,
                                                             java.awt.event.KeyListener listener,
                                                             boolean numbers)
        Creates a text field
        Parameters:
        text - Text for the field
        listener - KeyListener
        numbers - Indicates that this field represents numbers only
      • createTextField

        public static javax.swing.JTextField createTextField​(java.lang.String text,
                                                             boolean numbers)
      • createTextField

        public static javax.swing.JTextField createTextField​(java.lang.String text,
                                                             java.awt.event.KeyListener listener)
      • createTextField

        public static javax.swing.JTextField createTextField​(java.lang.String text)
      • createRadioButton

        public static javax.swing.JRadioButton createRadioButton​(java.lang.String text,
                                                                 int mnemonic,
                                                                 java.awt.event.ActionListener listener,
                                                                 boolean selected)
        Creates a Radio Button
        Parameters:
        text - Text to display
        mnemonic - Hot key
        listener - ActionListener
        selected - Flag to indicate if button should be selected
      • createRadioButton

        public static javax.swing.JRadioButton createRadioButton​(java.lang.String text,
                                                                 int mnemonic,
                                                                 boolean selected)
      • createRadioButton

        public static javax.swing.JRadioButton createRadioButton​(java.lang.String text,
                                                                 int mnemonic,
                                                                 java.awt.event.ActionListener listener)
      • createRadioButton

        public static javax.swing.JRadioButton createRadioButton​(java.lang.String text,
                                                                 int mnemonic)
      • createRadioButton

        public static javax.swing.JRadioButton createRadioButton​(java.lang.String text)
      • initButtonGroup

        public static void initButtonGroup​(javax.swing.JRadioButton... buttons)
      • createCheckBox

        public static javax.swing.JCheckBox createCheckBox​(java.lang.String text,
                                                           int mnemonic,
                                                           java.awt.event.ActionListener listener,
                                                           boolean selected)
        Create a checkbox
        Parameters:
        text - to display
        mnemonic - Hot key
        listener - ActionListener
        selected - Flag to indicate if button should be selected
      • createCheckBox

        public static javax.swing.JCheckBox createCheckBox​(java.lang.String text,
                                                           int mnemonic,
                                                           java.awt.event.ActionListener listener)
      • createCheckBox

        public static javax.swing.JCheckBox createCheckBox​(java.lang.String text,
                                                           int mnemonic,
                                                           boolean selected)
      • createCheckBox

        public static javax.swing.JCheckBox createCheckBox​(java.lang.String text,
                                                           int mnemonic)
      • createCheckBox

        public static javax.swing.JCheckBox createCheckBox​(java.lang.String text)
      • createComboBox

        public static javax.swing.JComboBox createComboBox​(java.lang.Object[] items,
                                                           java.awt.event.ActionListener listener,
                                                           boolean editable)
        Creates a JComboBox
        Parameters:
        items - Object array
        listener - The action listener which handles events
        editable - Flag that indicates if this combo box is editable
      • createComboBox

        public static javax.swing.JComboBox createComboBox​(java.lang.Object[] items,
                                                           boolean editable)
      • createButton

        public static javax.swing.JButton createButton​(java.lang.String text,
                                                       java.awt.event.ActionListener listener,
                                                       java.lang.String mnemonic)
        Creates a JButton
        Parameters:
        text - to display
        listener - The action listener which handles events
        mnemonic - Letter combination
      • createButton

        public static javax.swing.JButton createButton​(java.lang.String text,
                                                       java.awt.event.ActionListener listener,
                                                       java.lang.String mnemonic,
                                                       java.lang.String actionCommand)
      • createButton

        public static javax.swing.JButton createButton​(java.lang.String text,
                                                       java.awt.event.ActionListener listener)
      • createSmallButton

        public static javax.swing.JButton createSmallButton​(java.lang.String text,
                                                            java.awt.event.ActionListener listener,
                                                            java.lang.String mnemonic)
        Creates a Smaller JButton
        Parameters:
        text - to display
        listener - The action listener which handles events
        mnemonic - Letter combination
      • createSmallButton

        public static javax.swing.JButton createSmallButton​(java.lang.String text,
                                                            java.awt.event.ActionListener listener)
      • createBorder

        public static javax.swing.border.Border createBorder​(java.lang.String text)
        Creates an etched border with the displayed text
      • createBorder

        public static javax.swing.border.Border createBorder()
        Creates an blank border with the displayed text
      • createListPane

        public static javax.swing.JScrollPane createListPane​(javax.swing.JList list,
                                                             java.lang.String text)
        Wraps a scrollpane with and etched border and a title around a JList.
        Parameters:
        list - JList to wrap.
        text - Text to display in the border.
      • centerComponent

        public static void centerComponent​(java.awt.Component source,
                                           java.awt.Component parent)
        Centers a component (source) in it's parent component. If parent is null then the window is centered in screen.

        The source and parent components should be correctly sized

      • centerComponent

        public static void centerComponent​(java.awt.Component source)
        Centers the Component on the screen.
      • setupCancelButton

        public static void setupCancelButton​(javax.swing.JButton btn)
        Sets up the ESC-key binding for a cancel button
      • getParentFrame

        public static javax.swing.JFrame getParentFrame​(java.awt.Component source)
        Retrieves the parent JFrame for a component. This is handy when you want the frame as an owner for modal dialogs.
        Parameters:
        source - - Source component.
        Returns:
        The JFrame which contains the component or null if not found.
      • msToSec

        public static java.lang.Integer msToSec​(java.lang.Integer ms)
        Converts miliseconds to seconds
      • secToMs

        public static java.lang.Integer secToMs​(java.lang.Integer sec)
        Converts seconds to miliseconds
      • stringFromStringArray

        public static java.lang.String stringFromStringArray​(java.lang.String[] strings,
                                                             java.lang.String delim)
        Takes an array of strings and returns a concatenation

        Parameters:
        strings - - Array to concatenate
        delim - - Delimiter to use. If this is null or empty then then a space will be used
      • stringFromStringArray

        public static java.lang.String stringFromStringArray​(java.lang.String[] strings)
      • stringArrayFromString

        public static java.lang.String[] stringArrayFromString​(java.lang.String string,
                                                               java.lang.String delim)
        Parses the string into an array of strings

        Parameters:
        string - - String to parse
        delim - - Delimiter to use. If this is null or empty then then the set [ ' ', '\t', '\n', '\r' ] is used.
      • stringArrayFromString

        public static java.lang.String[] stringArrayFromString​(java.lang.String string)
      • setWaitCursor

        public static void setWaitCursor​(java.awt.Component comp)
      • setDefaultCursor

        public static void setDefaultCursor​(java.awt.Component comp)
      • setDropCursor

        public static void setDropCursor​(java.awt.Component comp)
      • adjustPopupLocationToFitScreen

        public static java.awt.Point adjustPopupLocationToFitScreen​(int xposition,
                                                                    int yposition,
                                                                    javax.swing.JComponent component,
                                                                    java.awt.Component invoker)
        Adjusts a desired popup location to fit within the screen, given the component's preferred size. Implementation copied from JPopupMenu.
      • eventModifiersToString

        public static java.lang.String eventModifiersToString​(int event)