Class GUIHelper


  • public class GUIHelper
    extends Object
    A "little" helper class for GUI related stuff.
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    • Field Detail

      • MNEMONIC_INDICATOR

        public static final char MNEMONIC_INDICATOR
        the mnemonic character indicator.
        See Also:
        Constant Field Values
      • APPROVE_OPTION

        public static final int APPROVE_OPTION
        the approve option.
        See Also:
        Constant Field Values
      • DISCARD_OPTION

        public static final int DISCARD_OPTION
        the discard option.
        See Also:
        Constant Field Values
      • CANCEL_OPTION

        public static final int CANCEL_OPTION
        the cancel option.
        See Also:
        Constant Field Values
      • m_Properties

        protected static Properties m_Properties
        the properties.
      • m_KeystrokeReplacements

        protected static HashMap<String,​String> m_KeystrokeReplacements
        the mappings for replacing keystrokes.
      • AntiAliasingEnabled

        public static boolean AntiAliasingEnabled
        whether anti-aliasing is enabled.
      • HeadlessMode

        public static Boolean HeadlessMode
        whether we are running in headless mode.
      • m_DefaultHorizontalTextOffset

        protected static int m_DefaultHorizontalTextOffset
        the global horizontal offset for drawing text in boxes.
    • Constructor Detail

      • GUIHelper

        public GUIHelper()
    • Method Detail

      • initializeProperties

        protected static void initializeProperties()
        Initializes the properties if necessary.
      • setSize

        public static void setSize​(Component window,
                                   Component c)
        Sets size stored in the props file.
        Parameters:
        window - the frame to work on
        c - the component to use for lookup in the props file; null can be used to bypass the lookup in the props file
      • calcLeftPosition

        public static int calcLeftPosition​(Component window,
                                           int left)
        Determines the left location for a window.
        Parameters:
        window - the window to work on
        left - the left position, -1: centered, -2: right-justified
      • calcTopPosition

        public static int calcTopPosition​(Component window,
                                          int top)
        Determines the top location for a window.
        Parameters:
        window - the window to work on
        top - the top position, -1: centered, -2: bottom-justified
      • setSizeAndLocation

        public static void setSizeAndLocation​(Component window,
                                              Component c)
        Sets size and location stored in the props file.
        Parameters:
        window - the frame to work on
        c - the component to use for lookup in the props file; null can be used to bypass the lookup in the props file (in that case, "top" and "left" are initialized with 0)
        See Also:
        setSizeAndLocation(Component, int, int, Component)
      • setSizeAndLocation

        public static void setSizeAndLocation​(Component window,
                                              int top,
                                              int left)
        Sets size and location stored in the props file.

        Takes the following parameters from the props file into account as well: MaxPercentHeight, ScreenBorder.Bottom
        Parameters:
        window - the frame to work on
        top - the y position
        left - the x position
        See Also:
        setSizeAndLocation(Component, int, int, Component)
      • setSizeAndLocation

        public static void setSizeAndLocation​(Component window,
                                              int top,
                                              int left,
                                              Component c)
        Sets size and location stored in the props file.

        Takes the following parameters from the props file into account as well: MaxPercentHeight, ScreenBorder.Bottom
        Parameters:
        window - the frame to work on
        top - the y position
        left - the x position
        c - the component to use for lookup in the props file; null can be used to bypass the lookup in the props file
      • getScreenBounds

        public static Rectangle getScreenBounds​(Component window)
        Returns the actual screen real estate bounds according to ScreenBorder.Top/Left/Bottom/Right in the props file.
         +----------------------------+  physical screen
         |                            |
         |   +--------------------+   |
         |   |                    |   |
         |   |  available screen  |   |
         |   |                    |   |
         |   |                    |   |
         |   +--------------------+   |
         |                            |
         |                            |
         +----------------------------+
         
        Parameters:
        window - the window to get the graphics config from
        Returns:
        the "inner" rectangle where we can display stuff
      • getScreenBounds

        public static Rectangle getScreenBounds​(GraphicsConfiguration gc)
        Returns the actual screen real estate bounds according to ScreenBorder.Top/Left/Bottom/Right in the props file.
         +----------------------------+  physical screen
         |                            |
         |   +--------------------+   |
         |   |                    |   |
         |   |  available screen  |   |
         |   |                    |   |
         |   |                    |   |
         |   +--------------------+   |
         |                            |
         |                            |
         +----------------------------+
         
        Parameters:
        gc - the graphics config to use
        Returns:
        the "inner" rectangle where we can display stuff
      • adjustSize

        public static void adjustSize​(Component window)
        Adjusts the size of the window, that it fits onto the screen.
        Parameters:
        window - the window to adjust
        See Also:
        getScreenBounds(Component)
      • fixPosition

        public static void fixPosition​(Component window)
        Adjusts the position of the window, that it fits onto the screen.
        Parameters:
        window - the window to adjust
        See Also:
        getScreenBounds(Component)
      • getRelativeTop

        public int getRelativeTop​(Window window)
        Returns the relative top Y position in its screen.
        Parameters:
        window - the window to determine the top Y for
        Returns:
        the top Y
      • getRelativeLeft

        public int getRelativeLeft​(Window window)
        Returns the relative left X position in its screen.
        Parameters:
        window - the window to determine the left X for
        Returns:
        the left X
      • getStartupScript

        public static File getStartupScript​(Component c)
        Returns the startup script, if any, for the given component.
        Parameters:
        c - the component to look for a startup script for
        Returns:
        the script file or null if none listed or none-existing
      • getString

        public static String getString​(String key,
                                       String defValue)
        Returns the string value listed in the props file, or the default value if not found.
        Parameters:
        key - the key of the property
        defValue - the default value to return if property is not stored in props file
        Returns:
        the value
      • getString

        public static String getString​(Class cls,
                                       String key,
                                       String defValue)
        Returns the string value listed in the props file, or the default value if not found. The key used is this: classname + "." + key.
        Parameters:
        cls - the class to retrieve the key for
        key - the key of the property
        defValue - the default value to return if property is not stored in props file
        Returns:
        the value
      • getInteger

        public static Integer getInteger​(String key,
                                         Integer defValue)
        Returns the integer value listed in the props file, or the default value if not found.
        Parameters:
        key - the key of the property
        defValue - the default value to return if property is not stored in props file
        Returns:
        the value
      • getInteger

        public static Integer getInteger​(Class cls,
                                         String key,
                                         Integer defValue)
        Returns the integer value listed in the props file, or the default value if not found. The key used is this: classname + "." + key.
        Parameters:
        cls - the class to retrieve the key for
        key - the key of the property
        defValue - the default value to return if property is not stored in props file
        Returns:
        the value
      • getColor

        public static Color getColor​(String key,
                                     Color defValue)
        Returns the color value listed in the props file, or the default value if not found.
        Parameters:
        key - the key of the property
        defValue - the default value to return if property is not stored in props file
        Returns:
        the value
      • getColor

        public static Color getColor​(Class cls,
                                     String key,
                                     Color defValue)
        Returns the color value listed in the props file, or the default value if not found. The key used is this: classname + "." + key.
        Parameters:
        cls - the class to retrieve the key for
        key - the key of the property
        defValue - the default value to return if property is not stored in props file
        Returns:
        the value
      • getDouble

        public static Double getDouble​(String key,
                                       Double defValue)
        Returns the double value listed in the props file, or the default value if not found.
        Parameters:
        key - the key of the property
        defValue - the default value to return if property is not stored in props file
        Returns:
        the value
      • getDouble

        public static Double getDouble​(Class cls,
                                       String key,
                                       Double defValue)
        Returns the double value listed in the props file, or the default value if not found. The key used is this: classname + "." + key.
        Parameters:
        cls - the class to retrieve the key for
        key - the key of the property
        defValue - the default value to return if property is not stored in props file
        Returns:
        the value
      • getBoolean

        public static Boolean getBoolean​(String key,
                                         Boolean defValue)
        Returns the boolean value listed in the props file, or the default value if not found.
        Parameters:
        key - the key of the property
        defValue - the default value to return if property is not stored in props file
        Returns:
        the value
      • getBoolean

        public static Boolean getBoolean​(Class cls,
                                         String key,
                                         Boolean defValue)
        Returns the boolean value listed in the props file, or the default value if not found. The key used is this: classname + "." + key.
        Parameters:
        cls - the class to retrieve the key for
        key - the key of the property
        defValue - the default value to return if property is not stored in props file
        Returns:
        the value
      • getFont

        public static Font getFont​(String key,
                                   Font defValue)
        Returns the Font value listed in the props file, or the default value if not found.
        Parameters:
        key - the key of the property
        defValue - the default value to return if property is not stored in props file
        Returns:
        the value
      • getFont

        public static Font getFont​(Class cls,
                                   String key,
                                   Font defValue)
        Returns the Font value listed in the props file, or the default value if not found. The key used is this: classname + "." + key.
        Parameters:
        cls - the class to retrieve the key for
        key - the key of the property
        defValue - the default value to return if property is not stored in props file
        Returns:
        the value
      • getOptionHandler

        public static OptionHandler getOptionHandler​(String key,
                                                     OptionHandler defValue)
        Returns the OptionHandler value listed in the props file, or the default value if not found.
        Parameters:
        key - the key of the property
        defValue - the default value to return if property is not stored in props file
        Returns:
        the value
      • getOptionHandler

        public static OptionHandler getOptionHandler​(Class cls,
                                                     String key,
                                                     OptionHandler defValue)
        Returns the OptionHandler value listed in the props file, or the default value if not found. The key used is this: classname + "." + key.
        Parameters:
        cls - the class to retrieve the key for
        key - the key of the property
        defValue - the default value to return if property is not stored in props file
        Returns:
        the value
      • getParent

        public static Object getParent​(Container cont,
                                       Class parentClass)
        Tries to determine the parent this panel is part of.
        Parameters:
        cont - the container to get the parent for
        parentClass - the class of the parent to obtain
        Returns:
        the parent if one exists or null if not
      • getParentFrame

        public static Frame getParentFrame​(Container cont)
        Tries to determine the frame the container is part of.
        Parameters:
        cont - the container to get the frame for
        Returns:
        the parent frame if one exists or null if not
      • getParentFrame

        public static Frame getParentFrame​(Component comp)
        Tries to determine the frame the component is part of.
        Parameters:
        comp - the component to get the frame for
        Returns:
        the parent frame if one exists or null if not
      • getParentDialog

        public static Dialog getParentDialog​(Container cont)
        Tries to determine the dialog this container is part of.
        Parameters:
        cont - the container to get the dialog for
        Returns:
        the parent dialog if one exists or null if not
      • getParentDialog

        public static Dialog getParentDialog​(Component comp)
        Tries to determine the dialog this component is part of.
        Parameters:
        comp - the component to get the dialog for
        Returns:
        the parent dialog if one exists or null if not
      • getParentInternalFrame

        public static JInternalFrame getParentInternalFrame​(Container cont)
        Tries to determine the internal frame this container is part of.
        Parameters:
        cont - the container to start with
        Returns:
        the parent internal frame if one exists or null if not
      • getParentInternalFrame

        public static JInternalFrame getParentInternalFrame​(Component comp)
        Tries to determine the internal frame this component is part of.
        Parameters:
        comp - the component to start with
        Returns:
        the parent internal frame if one exists or null if not
      • getParentChild

        public static Child getParentChild​(Container cont)
        Tries to determine the child window/frame this container is part of.
        Parameters:
        cont - the container to get the child window/frame for
        Returns:
        the parent child window/frame if one exists or null if not
      • getParentChild

        public static Child getParentChild​(Component comp)
        Tries to determine the child window/frame this component is part of.
        Parameters:
        comp - the component to get the child window/frame for
        Returns:
        the parent child window/frame if one exists or null if not
      • closeParent

        public static void closeParent​(Container cont)
        Closes the parent dialog/frame of this container.
        Parameters:
        cont - the container to close the parent for
      • toFront

        public static void toFront​(Container cont)
        Attempts to bring the enclosing window to the front. Note: does not work on all platforms.
        Parameters:
        cont - the container whose parent window to bring to front
      • getMnemonics

        public static char[] getMnemonics​(String[] labels)
        Suggests mnemonics for the given labels.
        Parameters:
        labels - the labels to set the mnemonics for
        Returns:
        the mnemonics
      • hasMnemonic

        public static boolean hasMnemonic​(String caption)
        Checks the caption whether an underscore "_" is present to indicate that the following character is to act as mnemonic.
        Parameters:
        caption - the caption to analyze
        Returns:
        true if an underscore is present
        See Also:
        MNEMONIC_INDICATOR
      • getMnemonic

        public static char getMnemonic​(String caption)
        Returns the mnemonic for this caption, preceded by an underscore "_".
        Parameters:
        caption - the caption to extract
        Returns:
        the extracted mnemonic, \0 if none available
        See Also:
        MNEMONIC_INDICATOR
      • stripMnemonic

        public static String stripMnemonic​(String caption)
        Removes the mnemonic indicator in this caption.
        Parameters:
        caption - the caption to process
        Returns:
        the processed caption
        See Also:
        MNEMONIC_INDICATOR
      • showErrorMessage

        public static void showErrorMessage​(Component parent,
                                            String msg,
                                            Throwable t)
        Displays an error message with the default title "Error".
        Parameters:
        parent - the parent, to make the dialog modal; can be null
        msg - the error message to display
        t - the exception to append to the message
      • showErrorMessage

        public static void showErrorMessage​(Component parent,
                                            String msg)
        Displays an error message with the default title "Error".
        Parameters:
        parent - the parent, to make the dialog modal; can be null
        msg - the error message to display
      • showErrorMessage

        public static void showErrorMessage​(Component parent,
                                            String msg,
                                            Throwable t,
                                            String title)
        Displays an error message.
        Parameters:
        parent - the parent, to make the dialog modal; can be null
        msg - the error message to display
        title - the title of the error message
        t - the exception to append to the message
      • showErrorMessage

        public static void showErrorMessage​(Component parent,
                                            String msg,
                                            String title)
        Displays an error message.
        Parameters:
        parent - the parent, to make the dialog modal; can be null
        msg - the error message to display
        title - the title of the error message
      • showInformationMessage

        public static void showInformationMessage​(Component parent,
                                                  String msg)
        Displays an information message with the default title "Information".
        Parameters:
        parent - the parent, to make the dialog modal; can be null
        msg - the information message to display
      • showInformationMessage

        public static void showInformationMessage​(Component parent,
                                                  String msg,
                                                  String title)
        Displays an information message.
        Parameters:
        parent - the parent, to make the dialog modal; can be null
        msg - the information message to display
        title - the title of the information message
      • showInformationMessage

        public static void showInformationMessage​(Component parent,
                                                  String msg,
                                                  String title,
                                                  boolean html,
                                                  Dimension size)
        Displays an information message.
        Parameters:
        parent - the parent, to make the dialog modal; can be null
        msg - the information message to display
        title - the title of the information message
        html - whether to display HTML or plain text
        size - the size of the dialog, can be null
      • showConfirmMessage

        public static int showConfirmMessage​(Component parent,
                                             String header,
                                             String msg,
                                             String title,
                                             String labelYes,
                                             String labelNo,
                                             String labelCancel)
        Displays a confirmation dialog (yes/no/cancel).
        Parameters:
        parent - the parent, to make the dialog modal; can be null
        header - the text explaining the message, null to ignore
        msg - the error message to display
        title - the title of the error message
        labelYes - the label for the "Yes" button, null to use default
        labelNo - the label for the "No" button, null to use default
        labelCancel - the label for the "Cancel" button, null to use default
        Returns:
        the selected option
        See Also:
        ApprovalDialog.APPROVE_OPTION, ApprovalDialog.DISCARD_OPTION, ApprovalDialog.CANCEL_OPTION
      • showConfirmMessage

        public static int showConfirmMessage​(Component parent,
                                             String header,
                                             String msg,
                                             String title,
                                             String labelYes,
                                             String labelNo,
                                             String labelCancel,
                                             GUIHelper.DialogCommunication comm)
        Displays a confirmation dialog (yes/no/cancel).
        Parameters:
        parent - the parent, to make the dialog modal; can be null
        header - the text explaining the message, null to ignore
        msg - the error message to display
        title - the title of the error message
        labelYes - the label for the "Yes" button, null to use default
        labelNo - the label for the "No" button, null to use default
        labelCancel - the label for the "Cancel" button, null to use default
        comm - for communicating with the dialog, can be null
        Returns:
        the selected option
        See Also:
        ApprovalDialog.APPROVE_OPTION, ApprovalDialog.DISCARD_OPTION, ApprovalDialog.CANCEL_OPTION
      • showInputDialog

        public static String showInputDialog​(Component parent,
                                             String msg)
        A simple dialog for entering a string.
        Parameters:
        parent - the parent for this dialog
        msg - the message to display, can be null (uses "Enter value" in that case)
        Returns:
        the value entered, null if cancelled
      • showInputDialog

        public static String showInputDialog​(Component parent,
                                             String msg,
                                             String initial)
        A simple dialog for entering a string.
        Parameters:
        parent - the parent for this dialog
        msg - the message to display, can be null (uses "Enter value" in that case)
        initial - the initial selection, can be null
        Returns:
        the value entered, null if cancelled
      • showInputDialog

        public static String showInputDialog​(Component parent,
                                             String msg,
                                             String initial,
                                             String title)
        A simple dialog for entering a string.
        Parameters:
        parent - the parent for this dialog
        msg - the message to display, can be null (uses "Enter value" in that case)
        initial - the initial selection, can be null
        title - the title of the input dialog, can be null (uses "Enter value" in that case)
        Returns:
        the value entered, null if cancelled
      • showInputDialog

        public static String showInputDialog​(Component parent,
                                             String msg,
                                             String initial,
                                             String title,
                                             GUIHelper.DialogCommunication comm)
        A simple dialog for entering a string. If "comm" is null simple modal dialogs are used, otherwise modeless ones with blocking till dialog closed (or closing requested via communication object).
        Parameters:
        parent - the parent for this dialog
        msg - the message to display, can be null (uses "Enter value" in that case)
        initial - the initial selection, can be null
        title - the title of the input dialog, can be null (uses "Enter value" in that case)
        comm - for communicating with the dialog, can be null
        Returns:
        the value entered, null if cancelled
      • showInputDialog

        public static String showInputDialog​(Component parent,
                                             String msg,
                                             String initial,
                                             String title,
                                             GUIHelper.DialogCommunication comm,
                                             int minCols,
                                             int minRows)
        A simple dialog for entering a string. If "comm" is null simple modal dialogs are used, otherwise modeless ones with blocking till dialog closed (or closing requested via communication object).
        Parameters:
        parent - the parent for this dialog
        msg - the message to display, can be null (uses "Enter value" in that case)
        initial - the initial selection, can be null
        title - the title of the input dialog, can be null (uses "Enter value" in that case)
        comm - for communicating with the dialog, can be null
        minCols - the minimum number of columns in the text box
        minRows - the minimum number of rows in the text box
        Returns:
        the value entered, null if cancelled
      • showInputDialog

        public static String showInputDialog​(Component parent,
                                             String msg,
                                             String initial,
                                             String[] options)
        A simple dialog for selecting a string.
        Parameters:
        parent - the parent for this dialog
        msg - the message to display, can be null (uses "Select value" in that case)
        initial - the initial selection, can be null
        options - the available options
        Returns:
        the value entered, null if cancelled
      • showInputDialog

        public static String showInputDialog​(Component parent,
                                             String msg,
                                             String initial,
                                             String[] options,
                                             String title)
        A simple dialog for selecting a string.
        Parameters:
        parent - the parent for this dialog
        msg - the message to display, can be null (uses "Select value" in that case)
        initial - the initial selection, can be null
        options - the available options
        title - the title of the input dialog, can be null (uses "Select value" in that case)
        Returns:
        the value entered, null if cancelled
      • showInputDialogComboBox

        protected static String showInputDialogComboBox​(Component parent,
                                                        String msg,
                                                        String initial,
                                                        String[] options,
                                                        String title,
                                                        GUIHelper.DialogCommunication comm)
        A simple dialog for selecting a string. If "comm" is null simple modal dialogs are used, otherwise modeless ones with blocking till dialog closed (or closing requested via communication object).
        Parameters:
        parent - the parent for this dialog
        title - the title of the input dialog, can be null (uses "Select value" in that case)
        msg - the message to display, can be null (uses "Select value" in that case)
        initial - the initial selection, can be null
        options - the available options
        comm - for communicating with the caller, can be null
        Returns:
        the value entered, null if cancelled
      • showInputDialogButtons

        protected static String showInputDialogButtons​(Component parent,
                                                       String msg,
                                                       String initial,
                                                       String[] options,
                                                       String title,
                                                       boolean horizontal,
                                                       GUIHelper.DialogCommunication comm)
        A simple dialog for selecting a string by clicking on a button. If "comm" is null simple modal dialogs are used, otherwise modeless ones with blocking till dialog closed (or closing requested via communication object).
        Parameters:
        parent - the parent for this dialog
        title - the title of the input dialog, can be null (uses "Select value" in that case)
        msg - the message to display, can be null (uses "Select value" in that case)
        initial - the initial selection, can be null
        options - the available options
        horizontal - whether the buttons are horizontal or vertical
        comm - for communicating with the caller, can be null
        Returns:
        the value entered, null if cancelled
      • showInputDialog

        public static String showInputDialog​(Component parent,
                                             String msg,
                                             String initial,
                                             String[] options,
                                             GUIHelper.InputDialogMultiValueSelection view,
                                             String title)
        A simple dialog for entering a string.
        Parameters:
        parent - the parent for this dialog
        title - the title of the input dialog, can be null
        msg - the message to display
        initial - the initial selection, can be null
        options - the available options
        view - how to display the values
        Returns:
        the value entered, null if cancelled
      • showInputDialog

        public static String showInputDialog​(Component parent,
                                             String msg,
                                             String initial,
                                             String[] options,
                                             GUIHelper.InputDialogMultiValueSelection view,
                                             String title,
                                             GUIHelper.DialogCommunication comm)
        A simple dialog for entering a string. If "comm" is null simple modal dialogs are used, otherwise modeless ones with blocking till dialog closed (or closing requested via communication object).
        Parameters:
        parent - the parent for this dialog
        title - the title of the input dialog, can be null
        msg - the message to display
        initial - the initial selection, can be null
        options - the available options
        view - how to display the values
        comm - for communicating with the dialog, can be null
        Returns:
        the value entered, null if cancelled
      • processTipText

        public static String processTipText​(String text,
                                            int width)
        Parses the tool tip and breaks it up into multiple lines if longer than width characters. No limit on number of rows.
        Parameters:
        text - the tiptext to parse, can be null
        width - the maximum width
        Returns:
        the processed tiptext
      • processTipText

        public static String processTipText​(String text,
                                            int width,
                                            int maxLines)
        Parses the tool tip and breaks it up into multiple lines if longer than width characters.
        Parameters:
        text - the tiptext to parse, can be null
        width - the maximum width
        maxLines - the maximum number of lines to allow, -1 for no limit
        Returns:
        the processed tiptext
      • processTipText

        public static String processTipText​(String text)
        Parses the tool tip and turns it into HTML if it contains line breaks.
        Parameters:
        text - the tiptext to parse, can be null
        Returns:
        the processed tiptext
      • getKeystrokeReplacements

        protected static HashMap<String,​String> getKeystrokeReplacements()
        Returns the replacements for the keystrokes.
        Returns:
        the replacements
      • processKeyStroke

        public static String processKeyStroke​(String keystroke)
        Processes the keystrokes. For Macs, "ctrl/control" is replaced by "meta". Also, if no "ctrl/control/alt" is present, a "meta" is prefix. All other platforms simply return the string.
        Parameters:
        keystroke - the keystroke string to process
        Returns:
        the (potentially) processed keystroke definition
      • getKeyStroke

        public static KeyStroke getKeyStroke​(String keystroke)
        Creates a keystroke from the string.
        Parameters:
        keystroke - the keystroke string to turn into a
        Returns:
        the generated keystroke
        See Also:
        processKeyStroke(String)
      • findComponents

        protected static void findComponents​(Container parent,
                                             Class type,
                                             boolean recursive,
                                             boolean exact,
                                             List<Component> list,
                                             boolean onlyFirst)
        Retrieves all components of the specified type starting with the given parent container.
        Parameters:
        parent - the container to start the search in
        recursive - whether to recurse into other containers
        exact - whether the class must be exactly this type of merely derived
        onlyFirst - whether to stop search once the first component was found
      • findAllComponents

        public static List<Component> findAllComponents​(Container parent,
                                                        Class type,
                                                        boolean recursive,
                                                        boolean exact)
        Retrieves all components of the specified type starting with the given parent container.
        Parameters:
        parent - the container to start the search in
        recursive - whether to recurse into other containers
        exact - whether the class must be exactly this type of merely derived
        Returns:
        the list of located components
      • findFirstComponent

        public static Component findFirstComponent​(Container parent,
                                                   Class type,
                                                   boolean recursive,
                                                   boolean exact)
        Retrieves the first component of the specified type starting with the given parent container.
        Parameters:
        parent - the container to start the search in
        recursive - whether to recurse into other containers
        exact - whether the class must be exactly this type of merely derived
        Returns:
        the located component or null if none found
      • configureAntiAliasing

        public static void configureAntiAliasing​(Graphics g,
                                                 boolean enable)
        Enables/disables anti-aliasing in the Graphics context.
        Parameters:
        g - the graphics context to enable/disable anti-aliasing for
        enable - if true anti-aliasing gets enabled, otherwise disabled
      • getTopLevelMenu

        public static JMenu getTopLevelMenu​(JMenuItem menuitem)
        Determines the top-level menu (the one sitting inside the JMenuBar) that is associated with a menu item.
        Parameters:
        menuitem - the menu item to get the menu bar for
        Returns:
        the menu, null if not found
      • launchMenuItem

        public static boolean launchMenuItem​(Container source,
                                             Class menuitem)
        Attempts to launch the specified menuitem. Requires to find the overall application frame in order to launch the menu item.
        Parameters:
        source - where the menuitem launch originated from
        menuitem - the menuitem class to launch
        Returns:
        true if successfully launched
      • showPopupMenu

        public static void showPopupMenu​(JPopupMenu menu,
                                         Component invoker,
                                         MouseEvent e)
        Displays a popup menu.
        Parameters:
        menu - the menu to show
        invoker - the invoking component
        e - the absolute positions on screen of the event are used
      • showPopupMenu

        public static void showPopupMenu​(JPopupMenu menu,
                                         Component invoker,
                                         int x,
                                         int y)
        Displays a popup menu.
        Parameters:
        menu - the menu to show
        invoker - the invoking component
        x - the absolute X position on screen
        y - the absolute Y position on screen
      • getGraphicsConfiguration

        public static GraphicsConfiguration getGraphicsConfiguration​(Component comp)
        Tries to determine the GraphicsConfiguration that the specified component is located on.
        Parameters:
        comp - the component to determine the graphics config for
        Returns:
        the config, null if failed to determine
      • getGraphicsDevice

        public static GraphicsDevice getGraphicsDevice​(Component comp)
        Tries to determine the GraphicsDevice that the specified component is located on.
        Parameters:
        comp - the component to determine the graphics device for
        Returns:
        the device, null if failed to determine
      • getDefaultDialogDimension

        public static Dimension getDefaultDialogDimension()
        Returns the default dimensions for a dialog.
        Returns:
        the default
      • getDefaultSmallDialogDimension

        public static Dimension getDefaultSmallDialogDimension()
        Returns the default dimensions for a small dialog.
        Returns:
        the default
      • getDefaultTinyDialogDimension

        public static Dimension getDefaultTinyDialogDimension()
        Returns the default dimensions for a tiny dialog.
        Returns:
        the default
      • getDefaultLargeDialogDimension

        public static Dimension getDefaultLargeDialogDimension()
        Returns the default dimensions for a large dialog.
        Returns:
        the default
      • makeWider

        public static Dimension makeWider​(Dimension size)
        Widens the rectangle by 20%.
        Parameters:
        size - the current size
        Returns:
        the widened rectangle
      • makeWider

        public static Dimension makeWider​(Dimension size,
                                          double percent)
        Widens the rectangle by the specified percentage.
        Parameters:
        size - the current size
        percent - the percentage to make it wider (0-1)
        Returns:
        the widened rectangle
      • makeNarrower

        public static Dimension makeNarrower​(Dimension size)
        Narrows the rectangle by 20%.
        Parameters:
        size - the current size
        Returns:
        the narrowed rectangle
      • makeNarrower

        public static Dimension makeNarrower​(Dimension size,
                                             double percent)
        Narrows the rectangle by the specified percentage.
        Parameters:
        size - the current size
        percent - the percentage to make it narrower (0-1)
        Returns:
        the narrowed rectangle
      • makeTaller

        public static Dimension makeTaller​(Dimension size)
        Males the rectangle taller by 20%.
        Parameters:
        size - the current size
        Returns:
        the taller rectangle
      • makeTaller

        public static Dimension makeTaller​(Dimension size,
                                           double percent)
        Makes the rectangle taller by the specified percentage.
        Parameters:
        size - the current size
        percent - the percentage to make it taller (0-1)
        Returns:
        the taller rectangle
      • makeSmaller

        public static Dimension makeSmaller​(Dimension size)
        Makes the rectangle smaller by 20%.
        Parameters:
        size - the current size
        Returns:
        the smaller rectangle
      • makeSmaller

        public static Dimension makeSmaller​(Dimension size,
                                            double percent)
        Makes the rectangle smaller by the specified percentage.
        Parameters:
        size - the current size
        percent - the percentage to make it smaller (0-1)
        Returns:
        the smaller rectangle
      • makeAtLeast

        public static Dimension makeAtLeast​(Dimension current,
                                            Dimension min)
        Makes the dimensions at least the specified size.
        Parameters:
        current - the current dimensions to potentially resize
        min - the minimum dimensions
        Returns:
        null if no update necessary, otherwise the new dimensions
      • makeAtLeast

        public static boolean makeAtLeast​(Component window,
                                          Dimension min)
        Makes the window at least the specified size.
        Parameters:
        window - the window to potentially resize
        min - the minimum dimensions
        Returns:
        true if updated
      • makeAtMost

        public static Dimension makeAtMost​(Dimension current,
                                           Dimension max)
        Makes the dimensions at most the specified size.
        Parameters:
        current - the current dimensions to potentially resize
        max - the maximum dimensions
        Returns:
        null if no update necessary, otherwise the new dimensions
      • makeAtMost

        public static boolean makeAtMost​(Component window,
                                         Dimension max)
        Makes the window at most the specified size.
        Parameters:
        window - the window to potentially resize
        max - the maximum dimensions
        Returns:
        true if updated
      • makeFit

        public static Dimension makeFit​(Dimension current,
                                        Dimension min,
                                        Dimension max)
        Fits the dimensions between min/max.
        Parameters:
        current - the dimensions to adjust
        min - the minimum size, ignored if null
        max - the maximum size, ignored if null
        Returns:
        null if no need to update, otherwise the recommended dimensions
      • pack

        public static boolean pack​(Window window,
                                   Dimension min,
                                   Dimension max)
        Packs the window, but ensures that it fits between min/max.
        Parameters:
        window - the window to adjust
        min - the minimum size, ignored if null
        max - the maximum size, ignored if null
        Returns:
        true if updated
      • makeHalfScreenWidth

        public static void makeHalfScreenWidth​(Component c)
        Changes the width of the window to half of the screen width.
        Parameters:
        c - the component whose window to adjust
      • makeHalfScreenHeight

        public static void makeHalfScreenHeight​(Component c)
        Changes the height of the window to half of the screen width.
        Parameters:
        c - the component whose window to adjust
      • rotate

        public static Dimension rotate​(Dimension rect)
        Rotates the rectangle by 90 degrees.
        Parameters:
        rect - the rectangle
        Returns:
        the rotated rectangle
      • getPreferredButtonHeight

        public static int getPreferredButtonHeight()
        Returns the preferred button height.
        Returns:
        the button height
      • getPreferredTextFieldHeight

        public static int getPreferredTextFieldHeight()
        Returns the preferred textfield height.
        Returns:
        the textfield height
      • getPreferredSpinnerHeight

        public static int getPreferredSpinnerHeight()
        Returns the preferred spinner height.
        Returns:
        the spinner height
      • getPreferredCheckBoxHeight

        public static int getPreferredCheckBoxHeight()
        Returns the preferred checkbox height.
        Returns:
        the checkbox height
      • getPreferredComboBoxHeight

        public static int getPreferredComboBoxHeight()
        Returns the preferred combobox height.
        Returns:
        the combobox height
      • getDisplayScaleFactor

        public static double getDisplayScaleFactor()
        Returns the scale factor for the display.
        Returns:
        the scale factor
      • scale

        public static int scale​(int size)
        Applies the global scale factor to the size.
        Parameters:
        size - the size to scale
        Returns:
        the scaled size
      • scale

        public static double scale​(double size)
        Applies the global scale factor to the size.
        Parameters:
        size - the size to scale
        Returns:
        the scaled size
      • scale

        public static Dimension scale​(Dimension size)
        Applies the global scale factor to the size.
        Parameters:
        size - the size to scale
        Returns:
        the scaled size
      • isHeadless

        public static boolean isHeadless()
        Returns whether we are running in headless mode.
        Returns:
        true if in headless mode
      • setHeadless

        public static void setHeadless​(boolean value)
        Sets the headless mode.
        Parameters:
        value - true if in headless mode
      • screenshot

        public static BufferedImage screenshot​(JComponent comp)
        Takes a screenshot of the component.
        Parameters:
        comp - the component to take a screenshot of
        Returns:
        the screenshot
      • getMaxTooltipWidth

        public static int getMaxTooltipWidth()
        Returns the maximum width for tool tips.
        Returns:
        the maximum
      • calculateFontOffset

        public static int[] calculateFontOffset​(Graphics g,
                                                Rectangle box)
        Calculates the horizontal and vertical offsets for drawing text.
        Parameters:
        g - the graphics context to get the font metrics from
        box - the rectangle to draw the text int
        Returns:
        hoff=0, voff=1
      • setDefaultHorizontalTextOffset

        public static void setDefaultHorizontalTextOffset​(int value)
        Sets the default horizontal offset for drawing strings in boxes.
        Parameters:
        value - the offset
        See Also:
        calculateFontOffset(Graphics, Rectangle)
      • getDefaultHorizontalTextOffset

        public int getDefaultHorizontalTextOffset()
        Returns the default horizontal offset for drawing strings in boxes.
        Returns:
        the offset
        See Also:
        calculateFontOffset(Graphics, Rectangle)