Class GUIHelper

java.lang.Object
nz.ac.waikato.cms.gui.core.GUIHelper

public class GUIHelper extends Object
Helper class for GUI related stuff.
Author:
FracPete (fracpete at waikato dot ac dot nz)
  • Field Details

    • MNEMONIC_INDICATOR

      public static final char MNEMONIC_INDICATOR
      the mnemonic character indicator.
      See Also:
  • Constructor Details

    • GUIHelper

      public GUIHelper()
  • Method Details

    • getImageFilename

      public static String getImageFilename(String name)
      Adds the path of the images directory to the name of the image.
      Parameters:
      name - the name of the image to add the path to
      Returns:
      the full path of the image
    • getIcon

      public static ImageIcon getIcon(String name)
      Returns an ImageIcon from the given name.
      Parameters:
      name - the filename without path
      Returns:
      the ImageIcon or null if not available
    • 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
    • getParentComponent

      public static Component getParentComponent(Component comp)
      Tries to determine the component this panel is part of in this order: 1. dialog, 2. child, 3. frame.
      Parameters:
      comp - the component to get the parent component for, must be a container actually
      Returns:
      the parent component if one exists or null if not
      See Also:
    • closeParent

      public static void closeParent(Container cont)
      Closes the parent dialog/frame of this container.
      Parameters:
      cont - the container to close the parent for
    • 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:
    • 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:
    • 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:
    • 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, 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