Class GuiUtils

java.lang.Object
org.jppf.ui.utils.GuiUtils

public final class GuiUtils extends Object
Collection of GUI utility methods.
Author:
Laurent Cohen
  • Field Details

    • JPPF_ICON

      public static final String JPPF_ICON
      Path to the JPPF icon used in the GUI.
      See Also:
    • DEFAULT_SCROLLBAR_THICKNESS

      public static final int DEFAULT_SCROLLBAR_THICKNESS
      Default thickness for adjusted scrollbars.
  • Constructor Details

    • GuiUtils

      public GuiUtils()
  • Method Details

    • createBoxPanel

      public static JPanel createBoxPanel(int orientation)
      Create a chartPanel with a box layout with the specified orientation.
      Parameters:
      orientation - the box orientation, one of BoxLayout.Y_AXIS or BoxLayout.X_AXIS.
      Returns:
      a JPanel instance.
    • loadIcon

      public static ImageIcon loadIcon(String path)
      Load and cache an icon from the file system or classpath.
      Parameters:
      path - the path to the icon.
      Returns:
      the loaded icon as an ImageIcon instance, or null if the icon could not be loaded.
    • loadIcon

      public static ImageIcon loadIcon(String path, boolean useCache)
      Load and cache an icon from the file system or classpath.
      Parameters:
      path - the path to the icon.
      useCache - specifies whether the icon should be retrieved from and/or put in the icon cache.
      Returns:
      the loaded icon as an ImageIcon instance, or null if the icon could not be loaded.
    • cacheIcon

      public static void cacheIcon(String path, ImageIcon icon)
      Put the specified icon in the cache wiht the specified path.
      Parameters:
      path - the cache key for the icon.
      icon - the icon to cache.
    • createCursor

      public static Cursor createCursor(String name, String imagePath, Point hotspot)
      Create or get a custom mouse cursor.
      Parameters:
      name - the name given to the cursor.
      imagePath - the path to the image.
      hotspot - the cursor's hotspot.
      Returns:
      the create cursor, or null if it couldn't be created.
    • getCursor

      public static Cursor getCursor(String name)
      Get a custom mouse cursor.
      Parameters:
      name - the name given to the cursor.
      Returns:
      a Cursor object, or null if it couldn't be retrieved.
    • mergeIcons

      public static ImageIcon mergeIcons(String source, String... toMerge)
      Merge the specified images into one.All images are assumed to be of the same size.
      Parameters:
      source - the source image, upon which all others will overwrite.
      toMerge - the images that overwrite the source, int he specified order.
      Returns:
      a new ImageIcon whose image is the result of merging all specified images.
    • initNodeIcons

      public static void initNodeIcons()
      Initialize the possible icons for the nodes.
    • computeNodeIconKey

      public static String computeNodeIconKey(org.jppf.client.monitoring.topology.TopologyNode node)
      Compute the cache key for the specified node, to determine which icon to dispaly.
      Parameters:
      node - the node for which to compute the key.
      Returns:
      the icon cache key as a string.
    • createFiller

      public static JComponent createFiller(int width, int height)
      Create a filler component with the specified fixed size. The resulting component can be used as a separator for layout purposes.
      Parameters:
      width - the component's width.
      height - the component's height.
      Returns:
      a JComponent instance.
    • formatToolTipText

      public static String formatToolTipText(String tooltip)
      Format a possibly multi-line text into a a string that can be properly displayed as a tooltip.
      Parameters:
      tooltip - the non-formatted text of the tooltip.
      Returns:
      the input text if it does not contain any line break, otherwise the input text wrapped in <html> ... </html> tags, with the line breaks transformed into <br> tags.
    • getTopFrame

      public static Frame getTopFrame(Component comp)
      Retrieve the top frame ro which a component belongs.
      Parameters:
      comp - the component whose frame to retrieve.
      Returns:
      a Frame instance if it can be found, null otherwise.
    • shortenLabel

      public static String shortenLabel(String key)
      Replace pre-determined keywords in a string, with shorter ones.
      Parameters:
      key - the string to shorten.
      Returns:
      the string with its keywords replaced.
    • runAction

      public static void runAction(Runnable r, String name)
      Execute the specified runnable in a new thread.
      Parameters:
      r - the Runnable to execute.
      name - the thread name.
    • getTabComponent

      public static Component getTabComponent(OptionElement option)
      Get the component used in the tab to which the specified option belongs.
      Parameters:
      option - the option for which to find the tab component.
      Returns:
      the tab component, or null if the option is not in a tab.
    • adjustScrollbarsThickness

      public static void adjustScrollbarsThickness(JScrollPane scrollPane)
      Change the thickness of the horizontal and vertical scrollbars in the specified scroll pane to the default value.
      Parameters:
      scrollPane - the scroll pane to change.
    • adjustScrollbarsThickness

      public static void adjustScrollbarsThickness(JScrollPane scrollPane, int thickness)
      Change the thickness of the horizontal and vertical scrollbars in the specified scroll pane.
      Parameters:
      scrollPane - the scroll pane to change.
      thickness - the desried scrollbar thickness.
    • invokeOnAWTThread

      public static void invokeOnAWTThread(Runnable action)
      Perform the specified action on the AWT event dispatch thread.
      Parameters:
      action - the action to perform.