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 void
closeWindowByEvent(java.awt.Window window)
Send aWindowEvent.WINDOW_CLOSING
event to the supplied window.static int
correctFrameWidth(int width)
Ensure the frame width is OK.static void
fitInScreen(java.awt.Component comp)
static void
forwardMouseWheelEvent(java.awt.Component target, java.awt.event.MouseWheelEvent evt)
static java.awt.Color
getHighlightColor(java.awt.Color base)
Convenience method forgetHighlightColor(Color, int)
using the default adjustment (10 darker than base).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.static java.lang.String
getKeyStrokeText(javax.swing.KeyStroke ks)
static java.util.List<java.awt.Component>
listHierarchy(java.awt.Component parent)
static java.awt.event.FocusListener
makeCaretAlwaysVisible(javax.swing.text.JTextComponent comp)
Make caret visible even when theJTextComponent
is not editable.static javax.swing.Action
makeCloseAction(java.awt.Window window)
static void
makeUndoable(javax.swing.text.JTextComponent comp)
static void
persistGeometry(java.awt.Window window, java.lang.String key)
static void
persistGeometry(java.awt.Window window, java.lang.String key, java.lang.Runnable extraProcessing)
static void
requestVisible(DockableScrollPane scrollPane)
Request to show the pane when it is hidden as a tab.static void
setCaretUpdateEnabled(javax.swing.text.JTextComponent comp, boolean updateEnabled)
static void
setEscapeAction(javax.swing.JDialog dialog, javax.swing.Action action)
Associate a custom action to be called when the Esc key is pressed.static void
setEscapeAction(javax.swing.JFrame frame, javax.swing.Action action)
Associate a custom action to be called when the Esc key is pressed.static void
setEscapeAction(javax.swing.JRootPane pane, javax.swing.Action action)
Associate a custom action to be called when the Esc key is pressed.static void
setEscapeClosable(javax.swing.JDialog dialog)
Make a dialog closeable by pressing the Esc key.static void
setEscapeClosable(javax.swing.JFrame frame)
Make a dialog closeable by pressing the Esc key.static void
setHierarchyEnabled(java.awt.Component parent, boolean isEnabled)
Toggle the enabled property of an entire hierarchy of components.static void
setWindowIcon(java.awt.Window window)
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.static void
visitHierarchy(java.awt.Component parent, java.util.function.Consumer<java.awt.Component> consumer)
static void
visitHierarchy(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_CLOSING
event 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 theJTextComponent
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(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.
-
-