Package org.omegat.util.gui
Class StaticUIUtils
- java.lang.Object
-
- org.omegat.util.gui.StaticUIUtils
-
public final class StaticUIUtils extends java.lang.Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcloseWindowByEvent(java.awt.Window window)Send aWindowEvent.WINDOW_CLOSINGevent to the supplied window.static intcorrectFrameWidth(int width)Ensure the frame width is OK.static voidfitInScreen(java.awt.Component comp)static voidforwardMouseWheelEvent(java.awt.Component target, java.awt.event.MouseWheelEvent evt)static java.awt.ColorgetHighlightColor(java.awt.Color base)Convenience method forgetHighlightColor(Color, int)using the default adjustment (10 darker than base).static java.awt.ColorgetHighlightColor(java.awt.Color base, int adjustment)Calculate a highlight color from a base color, with a given amount of adjustment.static java.lang.StringgetKeyStrokeText(javax.swing.KeyStroke ks)static java.util.List<java.awt.Component>listHierarchy(java.awt.Component parent)static java.awt.event.FocusListenermakeCaretAlwaysVisible(javax.swing.text.JTextComponent comp)Make caret visible even when theJTextComponentis not editable.static javax.swing.ActionmakeCloseAction(java.awt.Window window)static voidmakeUndoable(javax.swing.text.JTextComponent comp)static voidpersistGeometry(java.awt.Window window, java.lang.String key)static voidpersistGeometry(java.awt.Window window, java.lang.String key, java.lang.Runnable extraProcessing)static voidrequestVisible(DockableScrollPane scrollPane)Request to show the pane when it is hidden as a tab.static voidsetCaretUpdateEnabled(javax.swing.text.JTextComponent comp, boolean updateEnabled)static voidsetEscapeAction(javax.swing.JDialog dialog, javax.swing.Action action)Associate a custom action to be called when the Esc key is pressed.static voidsetEscapeAction(javax.swing.JFrame frame, javax.swing.Action action)Associate a custom action to be called when the Esc key is pressed.static voidsetEscapeAction(javax.swing.JRootPane pane, javax.swing.Action action)Associate a custom action to be called when the Esc key is pressed.static voidsetEscapeClosable(javax.swing.JDialog dialog)Make a dialog closeable by pressing the Esc key.static voidsetEscapeClosable(javax.swing.JFrame frame)Make a dialog closeable by pressing the Esc key.static voidsetHierarchyEnabled(java.awt.Component parent, boolean isEnabled)Toggle the enabled property of an entire hierarchy of components.static voidsetWindowIcon(java.awt.Window window)static java.lang.StringtruncateToFit(java.lang.String text, javax.swing.JComponent comp, int margin)Truncate the supplied text so that it fits within the width (minus margin) of the supplied component.static voidvisitHierarchy(java.awt.Component parent, java.util.function.Consumer<java.awt.Component> consumer)static voidvisitHierarchy(java.awt.Component parent, java.util.function.Predicate<java.awt.Component> filter, java.util.function.Consumer<java.awt.Component> consumer)
-
-
-
Method Detail
-
setEscapeClosable
public static void setEscapeClosable(javax.swing.JDialog dialog)
Make a dialog closeable by pressing the Esc key.Window.dispose()will be called.- Parameters:
dialog-
-
setEscapeClosable
public static void setEscapeClosable(javax.swing.JFrame frame)
Make a dialog closeable by pressing the Esc key.Window.dispose()will be called.- Parameters:
frame-
-
makeCloseAction
public static javax.swing.Action makeCloseAction(java.awt.Window window)
-
closeWindowByEvent
public static void closeWindowByEvent(java.awt.Window window)
Send aWindowEvent.WINDOW_CLOSINGevent to the supplied window. This mimics closing by clicking the window close button.
-
setEscapeAction
public static void setEscapeAction(javax.swing.JDialog dialog, javax.swing.Action action)Associate a custom action to be called when the Esc key is pressed.- Parameters:
dialog-action-
-
setEscapeAction
public static void setEscapeAction(javax.swing.JFrame frame, javax.swing.Action action)Associate a custom action to be called when the Esc key is pressed.- Parameters:
frame-action-
-
setEscapeAction
public static void setEscapeAction(javax.swing.JRootPane pane, javax.swing.Action action)Associate a custom action to be called when the Esc key is pressed.- Parameters:
pane-action-
-
truncateToFit
public static java.lang.String truncateToFit(java.lang.String text, javax.swing.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 truncatecomp- Component to fit text intomargin- Additional space to leave empty- Returns:
- A truncated string
-
forwardMouseWheelEvent
public static void forwardMouseWheelEvent(java.awt.Component target, java.awt.event.MouseWheelEvent evt)
-
fitInScreen
public static void fitInScreen(java.awt.Component comp)
-
setCaretUpdateEnabled
public static void setCaretUpdateEnabled(javax.swing.text.JTextComponent comp, boolean updateEnabled)
-
makeCaretAlwaysVisible
public static java.awt.event.FocusListener makeCaretAlwaysVisible(javax.swing.text.JTextComponent comp)
Make caret visible even when theJTextComponentis 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(java.awt.Component parent, boolean isEnabled)Toggle the enabled property of an entire hierarchy of components.- Parameters:
parent- The parent component, which will also be toggledisEnabled- Enabled or not
-
visitHierarchy
public static void visitHierarchy(java.awt.Component parent, java.util.function.Consumer<java.awt.Component> consumer)
-
visitHierarchy
public static void visitHierarchy(java.awt.Component parent, java.util.function.Predicate<java.awt.Component> filter, java.util.function.Consumer<java.awt.Component> consumer)
-
listHierarchy
public static java.util.List<java.awt.Component> listHierarchy(java.awt.Component parent)
-
persistGeometry
public static void persistGeometry(java.awt.Window window, java.lang.String key)
-
persistGeometry
public static void persistGeometry(java.awt.Window window, java.lang.String key, java.lang.Runnable extraProcessing)
-
setWindowIcon
public static void setWindowIcon(java.awt.Window window)
-
getHighlightColor
public static java.awt.Color getHighlightColor(java.awt.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 java.awt.Color getHighlightColor(java.awt.Color base)
Convenience method forgetHighlightColor(Color, int)using the default adjustment (10 darker than base).
-
getKeyStrokeText
public static java.lang.String getKeyStrokeText(javax.swing.KeyStroke ks)
-
makeUndoable
public static void makeUndoable(javax.swing.text.JTextComponent comp)
-
requestVisible
public static void requestVisible(DockableScrollPane scrollPane)
Request to show the pane when it is hidden as a tab.
-
-