Package utils

Class AWTUtils

java.lang.Object
utils.AWTUtils

public class AWTUtils extends Object
Misc helper methods for AWT that don't require Thinlet.
Author:
Dirk Moebius
  • Constructor Details

    • AWTUtils

      public AWTUtils()
  • Method Details

    • getColorString

      public static String getColorString(Color c)
    • getFontString

      public static String getFontString(Font font)
      Returns a thinlet font description for the given font.
      Parameters:
      font - the font
      Returns:
      a thinlet font description such as "Serif 10 bold italic"
    • getFontString

      public static String getFontString(Font font, Font defaultFont)
      Returns a thinlet font description for the given font, containing only the font properties that differ from the given default font.
      Parameters:
      font - the font
      defaultFont - the default font
      Returns:
      a thinlet font description such as "serif 10 bold italic"
    • getFrame

      public static Frame getFrame(Component comp)
      Get the frame that the specified component resides in, or null if the component has no ancestor of type Frame.
    • getBounds

      public static Dimension getBounds(String text, Component component)
      Returns the dimension of the specified text string, if it would be rendered with the font and the rendering context of the specified component.
    • getIcon

      public static Image getIcon(Component component, String path)
      Load an icon. Use a MediaTracker synchronizing on the specified component to wait for the icon to load.
      Parameters:
      component - the component that the MediaTracker uses to control the loading of the icon.
      path - the path relative to the package path of the class of the component, e.g. "icons/icon.gif".
    • getIcon

      public static Image getIcon(Component component, URL url)
      Load an icon. Use a MediaTracker synchronizing on the specified component to wait for the icon to load.
      Parameters:
      component - the component that the MediaTracker uses to control the loading of the icon.
      url - the URL of the icon.
    • getAWTKeyStrokeDescription

      public static String getAWTKeyStrokeDescription(AWTKeyStroke k)
      Given an AWTKeyStroke, returns a keystroke description that can be parsed by AWTKeyStroke.getAWTKeyStroke(String s).

      Examples: "ctrl O", "alt shift F4", "altGraph Q"

    • getKeyText

      public static String getKeyText(int keyCode)
      Return the key description for a key code, according to the key names in java.awt.event.KeyEvent, omitting the prefix "VK_". For example the strings returned may be "A" - "Z", "F1" - "F24", "RIGHT", "BACK_SPACE", "DEAD_TILDE" and so on.
      Parameters:
      keyCode -
      Returns: