Package com.diffplug.common.swt
Class SwtMisc
java.lang.Object
com.diffplug.common.swt.SwtMisc
Miscellaneous SWT functions.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Listener
asListener
(Runnable runnable) static void
assertClean
(Composite cmp) Throws anIllegalArgumentException
iff the given `Composite` has any children or a non-null layout.static void
Asserts that the user didn't call this from the UI thread.static Display
assertUI()
Returns the Display instance, asserting that the method was called from the UI thread.static void
asyncLayout
(Composite cmp) Performs an asynchronous layout on the given composite.static void
Performs an asynchronous layout on the given composite anytime that it is resized.static void
blockForError
(String title, String msg) Blocks to notify about an error.static void
blockForError
(String title, String msg, Shell parent) Blocks to notify about an error.static int
blockForMessageBox
(String title, String message, int style) Opens a message box with the given title, message, and style and returns its result.static int
blockForMessageBox
(String title, String message, Shell parent, int style) Opens a message box with the given title, message, and style and returns its result.static boolean
blockForOkCancel
(String title, String message) Blocks to ask an Ok/Cancel question.static boolean
blockForOkCancel
(String title, String message, Shell parent) Blocks to ask an Ok/Cancel question.static boolean
blockForQuestion
(String title, String message) Blocks to ask a yes/no question.static boolean
blockForQuestion
(String title, String message, Shell parent) Blocks to ask a yes/no question.static void
blockForSuccess
(String title, String msg) Blocks to notify about a success.static void
blockForSuccess
(String title, String msg, Shell parent) Blocks to notify about a success.static void
Disposes all children of the given composite, and sets the layout to null.static Event
Returns a deep copy of the given SWT event.static int
Returns the default width of a button, scaled for the system font.static int
Returns the default width of a dialog.static boolean
flagIsSet
(int flag, int style) Returns true if `flag` is set in `style`.static boolean
Returns true if `flag` is set in the style value of `widget`.static void
forEachDeep
(Composite root, Consumer<Control> ctlSetter) Calls the given consumer on the given composite and all of its children, recursively.static Color
getSystemColor
(int code) Returns the given system color.static Cursor
getSystemCursor
(int cursor) Returns the given system color.static Image
getSystemIcon
(int icon) Returns the given system icon.static Rectangle
globalBounds
(com.diffplug.common.swt.ControlWrapper control) Returns the global bounds of the given ControlWrapper.static Rectangle
globalBounds
(Control control) Returns the bounds of the given control in global coordinates.static void
Runs the display loop until the given `Predicate` returns false. static void
loopUntilDisposed
(Widget widget) Runs the display loop until the `widget` has been disposed.static <T> T
loopUntilGet
(CompletionStage<T> future) Runs the display loop until the given future has returned.monitorFor
(Point p) Returns the monitor (if any) which contains the given point.static void
requestLayout
(Control control) Deprecated.static Shell
Returns the root shell of the given control.static Point
scaleByFont
(int cols, int rows) Returns a point that represents the size of a (cols x rows) grid of characters printed in the standard system font.static Point
scaleByFont
(String str) Returns a dimension which is guaranteed to be comfortable for the given string.static int
scaleByFontHeight
(int rows) Returns a dimension which is scaled by the system font's height.static Point
scaleByFontHeight
(int cols, int rows) Returns a size which is scaled by the system font's height.static void
setBackgroundDeep
(Composite root, Color background) Sets the background color of the given composite and all of its children, recursively.static void
setEnabledDeep
(Composite root, boolean enabled) Sets the enabled status of every child, grandchild, etc.static int
setFlag
(int flag, boolean isSet, int style) Sets whether the flag is set for the given style.static void
setForegroundDeep
(Composite root, Color foreground) Sets the foreground color of the given composite and all of its children, recursively.static int
Returns the height of the system font.static int
Returns a distance which is a snug fit for a line of text in the system font.static double
Returns the width of the system font.static int
systemFontWidthTimes
(int numChars) static int
static Rectangle
Converts a rectangle to global coordinates using the given control as a reference frame.static TreeDef.Parented<Composite>
static TreeDef.Parented<Control>
static TreeDef.Parented<Shell>
static <T> T
withGcCompute
(Function<GC, T> function) Computes some function using a temporary GC.static void
Runs some function using a temporary GC.
-
Constructor Details
-
SwtMisc
public SwtMisc()
-
-
Method Details
-
flagIsSet
public static boolean flagIsSet(int flag, int style) Returns true if `flag` is set in `style`. -
flagIsSet
Returns true if `flag` is set in the style value of `widget`. -
setFlag
public static int setFlag(int flag, boolean isSet, int style) Sets whether the flag is set for the given style. -
asListener
-
assertUI
Returns the Display instance, asserting that the method was called from the UI thread. -
assertNotUI
public static void assertNotUI()Asserts that the user didn't call this from the UI thread. -
getSystemColor
Returns the given system color. SWT.COLOR_* -
getSystemCursor
Returns the given system color. SWT.CURSOR_* -
getSystemIcon
Returns the given system icon. SWT.ICON_* -
requestLayout
Deprecated.As of SWT 4.6 (Neon), this functionality isControl.requestLayout()
. -
asyncLayout
Performs an asynchronous layout on the given composite.Oftentimes, a layout will not be successful unless it is performed in a
Display.asyncExec(Runnable)
call, because the current list of events must be processed before the layout can take place. -
asyncLayoutOnResize
Performs an asynchronous layout on the given composite anytime that it is resized.This can often fix graphical glitches with resize-to-fit layouts, such as a `TableColumnLayout`.
-
clean
Disposes all children of the given composite, and sets the layout to null. -
assertClean
Throws anIllegalArgumentException
iff the given `Composite` has any children or a non-null layout. -
copyEvent
Returns a deep copy of the given SWT event. -
withGcRun
Runs some function using a temporary GC. -
withGcCompute
Computes some function using a temporary GC. -
loopUntil
Runs the display loop until the given `Predicate` returns false. -
loopUntilDisposed
Runs the display loop until the `widget` has been disposed. -
loopUntilGet
Runs the display loop until the given future has returned. -
blockForSuccess
Blocks to notify about a success. Can be called from any thread. -
blockForSuccess
Blocks to notify about a success. Can be called from any thread. -
blockForError
Blocks to notify about an error. Can be called from any thread. -
blockForError
Blocks to notify about an error. Can be called from any thread. -
blockForQuestion
Blocks to ask a yes/no question. Can be called from any thread. -
blockForQuestion
Blocks to ask a yes/no question. Can be called from any thread. -
blockForOkCancel
Blocks to ask an Ok/Cancel question. Can be called from any thread. -
blockForOkCancel
Blocks to ask an Ok/Cancel question. Can be called from any thread. -
blockForMessageBox
public static int blockForMessageBox(String title, String message, @Nullable Shell parent, int style) Opens a message box with the given title, message, and style and returns its result. Can be called from any thread.- Parameters:
title
- The title of the box.message
- The message in the box.parent
- The parent shell. Null means it will be on the current active shell.style
- An OR'ed combination of SWT.YES/NO, SWT.OK/CANCEL, and SWT.ICON_*- Returns:
- The button that was pressed (e.g. SWT.YES, SWT.OK, etc)
-
blockForMessageBox
Opens a message box with the given title, message, and style and returns its result. Can be called from any thread.- Parameters:
title
- The title of the box.message
- The message in the box.style
- An OR'ed combination of SWT.YES/NO, SWT.OK/CANCEL, and SWT.ICON_*- Returns:
- The button that was pressed (e.g. SWT.YES, SWT.OK, etc)
-
systemFontHeight
public static int systemFontHeight()Returns the height of the system font. -
systemFontWidth
public static double systemFontWidth()Returns the width of the system font. -
systemFontWidthTimes
public static int systemFontWidthTimes(int numChars) -
systemFontWidthTimes
-
systemFontSnug
public static int systemFontSnug()Returns a distance which is a snug fit for a line of text in the system font. -
defaultButtonWidth
public static int defaultButtonWidth()Returns the default width of a button, scaled for the system font. -
defaultDialogWidth
public static int defaultDialogWidth()Returns the default width of a dialog. -
scaleByFontHeight
Returns a size which is scaled by the system font's height. -
scaleByFontHeight
public static int scaleByFontHeight(int rows) Returns a dimension which is scaled by the system font's height. -
scaleByFont
Returns a point that represents the size of a (cols x rows) grid of characters printed in the standard system font. -
scaleByFont
Returns a dimension which is guaranteed to be comfortable for the given string. -
globalBounds
Returns the bounds of the given control in global coordinates. -
globalBounds
Returns the global bounds of the given ControlWrapper. -
toDisplay
Converts a rectangle to global coordinates using the given control as a reference frame. -
monitorFor
Returns the monitor (if any) which contains the given point. -
setEnabledDeep
Sets the enabled status of every child, grandchild, etc. of the given composite. Skips plain-jane Composites. -
forEachDeep
Calls the given consumer on the given composite and all of its children, recursively. -
setForegroundDeep
Sets the foreground color of the given composite and all of its children, recursively. -
setBackgroundDeep
Sets the background color of the given composite and all of its children, recursively. -
rootShell
Returns the root shell of the given control. -
treeDefComposite
-
treeDefControl
-
treeDefShell
-
Control.requestLayout()
.