Class StaticUIUtils

java.lang.Object
org.omegat.util.gui.StaticUIUtils

public final class StaticUIUtils extends Object
  • Method Details

    • setEscapeClosable

      public static void setEscapeClosable(JDialog dialog)
      Make a dialog closeable by pressing the Esc key. Window.dispose() will be called.
      Parameters:
      dialog - to configure.
    • setEscapeClosable

      public static void setEscapeClosable(JFrame frame)
      Make a dialog closeable by pressing the Esc key. Window.dispose() will be called.
      Parameters:
      frame - to configure.
    • closeWindowByEvent

      public static void closeWindowByEvent(Window window)
      Send a WindowEvent.WINDOW_CLOSING event to the supplied window. This mimics closing by clicking the window close button.
    • setEscapeAction

      public static void setEscapeAction(JDialog dialog, Action action)
      Associate a custom action to be called when the Esc key is pressed.
      Parameters:
      dialog - target dialog.
      action - object to set.
    • setEscapeAction

      public static void setEscapeAction(JFrame frame, Action action)
      Associate a custom action to be called when the Esc key is pressed.
      Parameters:
      frame - target frame.
      action - object to set.
    • setEscapeAction

      public static void setEscapeAction(JRootPane pane, Action action)
      Associate a custom action to be called when the Esc key is pressed.
      Parameters:
      pane - target UI pane.
      action - object to set.
    • truncateToFit

      public static String truncateToFit(String text, JComponent comp, int margin)
      Truncate the supplied text so that it fits within the width (minus margin) of the supplied component. Truncation is achieved by replacing a chunk from the center of the string with an ellipsis.
      Parameters:
      text - Text to truncate
      comp - Component to fit text into
      margin - Additional space to leave empty
      Returns:
      A truncated string
    • forwardMouseWheelEvent

      public static void forwardMouseWheelEvent(Component target, MouseWheelEvent evt)
    • fitInScreen

      public static void fitInScreen(Component comp)
    • setCaretUpdateEnabled

      public static void setCaretUpdateEnabled(JTextComponent comp, boolean updateEnabled)
    • makeCaretAlwaysVisible

      public static FocusListener makeCaretAlwaysVisible(JTextComponent comp)
      Make caret visible even when the JTextComponent is not editable.
    • correctFrameWidth

      public static int correctFrameWidth(int width)
      Ensure the frame width is OK. This is really just a workaround for JDK-8065739 , a Java bug specific to Java 1.8 on OS X whereby a frame too close to the width of the screen will warp to one corner with tiny dimensions.
      Parameters:
      width - Proposed window width
      Returns:
      A safe window width
    • setHierarchyEnabled

      public static void setHierarchyEnabled(Component parent, boolean isEnabled)
      Toggle the enabled property of an entire hierarchy of components.
      Parameters:
      parent - The parent component, which will also be toggled
      isEnabled - Enabled or not
    • visitHierarchy

      public static void visitHierarchy(Component parent, Consumer<Component> consumer)
    • visitHierarchy

      public static void visitHierarchy(Component parent, Predicate<Component> filter, Consumer<Component> consumer)
    • listHierarchy

      public static List<Component> listHierarchy(Component parent)
      list hierarchy for debug.
      Parameters:
      parent - component to determine.
      Returns:
      list of components.
    • persistGeometry

      public static void persistGeometry(Window window, String key)
    • persistGeometry

      public static void persistGeometry(Window window, String key, Runnable extraProcessing)
    • setWindowIcon

      public static void setWindowIcon(Window window)
    • getHighlightColor

      public static Color getHighlightColor(Color base, int adjustment)
      Calculate a highlight color from a base color, with a given amount of adjustment.

      The adjustment is added to each of the base color's RGB values and rebounds from the boundaries [0, 255]. E.g. 250 + 4 -> 254 but 250 + 11 -> 249, and 5 - 4 -> 1 but 5 - 11 -> 6.

    • getHighlightColor

      public static Color getHighlightColor(Color base)
      Convenience method for getHighlightColor(Color, int) using the default adjustment (10 darker than base).
    • getKeyStrokeText

      public static String getKeyStrokeText(KeyStroke ks)
    • makeUndoable

      public static void makeUndoable(JTextComponent comp)
    • requestVisible

      public static void requestVisible(DockableScrollPane scrollPane)
      Request to show the pane when it is hidden as a tab.
    • isGUI

      public static boolean isGUI()
      Whether run on GUI or not.