public class SwtMisc extends Object
Miscellaneous SWT functions.
Constructor and Description |
---|
SwtMisc() |
Modifier and Type | Method and Description |
---|---|
static Listener |
asListener(Runnable runnable)
|
static void |
assertClean(Composite cmp)
Throws an
IllegalArgumentException iff the given Composite has any children or a non-null layout. |
static void |
assertNotUI()
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 |
asyncLayoutOnResize(Composite cmp)
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 |
clean(Composite cmp)
Disposes all children of the given composite, and sets the layout to null.
|
static Event |
copyEvent(Event event)
Returns a deep copy of the given SWT event.
|
static int |
defaultButtonWidth()
Returns the default width of a button, scaled for the system font.
|
static int |
defaultDialogWidth()
Returns the default width of a dialog.
|
static boolean |
flagIsSet(int flag,
int style)
Returns true if
flag is set in style . |
static boolean |
flagIsSet(int flag,
Widget widget)
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(Control control)
Returns the bounds of the given control in global coordinates.
|
static Rectangle |
globalBounds(ControlWrapper control)
Returns the global bounds of the given ControlWrapper.
|
static void |
loopUntil(Predicate<Display> until)
Runs the display loop until the given
Predicate<Display> 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.
|
static Optional<Monitor> |
monitorFor(Point p)
Returns the monitor (if any) which contains the given point.
|
static void |
requestLayout(Control control)
Deprecated.
As of SWT 4.6 (Neon), this functionality is
Control.requestLayout() . |
static Shell |
rootShell(Control ctl)
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 |
systemFontHeight()
Returns the height of the system font.
|
static int |
systemFontSnug()
Returns a distance which is a snug fit for a line of text in the system font.
|
static int |
systemFontWidth()
Returns the width of the system font.
|
static Rectangle |
toDisplay(Control control,
Rectangle rect)
Converts a rectangle to global coordinates using the given control as a reference frame.
|
static TreeDef.Parented<Composite> |
treeDefComposite()
|
static TreeDef.Parented<Control> |
treeDefControl()
|
static TreeDef.Parented<Shell> |
treeDefShell()
|
static <T> T |
withGcCompute(Function<GC,T> function)
Computes some function using a temporary GC.
|
static void |
withGcRun(Consumer<GC> consumer)
Runs some function using a temporary GC.
|
public static boolean flagIsSet(int flag, int style)
Returns true if flag
is set in style
.
public static boolean flagIsSet(int flag, Widget widget)
Returns true if flag
is set in the style value of widget
.
public static int setFlag(int flag, boolean isSet, int style)
Sets whether the flag is set for the given style.
public static Display assertUI()
Returns the Display instance, asserting that the method was called from the UI thread.
public static void assertNotUI()
Asserts that the user didn’t call this from the UI thread.
public static Color getSystemColor(int code)
Returns the given system color. SWT.COLOR_*
public static Cursor getSystemCursor(int cursor)
Returns the given system color. SWT.CURSOR_*
public static Image getSystemIcon(int icon)
Returns the given system icon. SWT.ICON_*
@Deprecated public static void requestLayout(Control control)
Control.requestLayout()
.public static void asyncLayout(Composite cmp)
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.
public static void asyncLayoutOnResize(Composite cmp)
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`.
public static void clean(Composite cmp)
Disposes all children of the given composite, and sets the layout to null.
public static void assertClean(Composite cmp)
Throws an IllegalArgumentException
iff the given Composite
has any children or a non-null layout.
public static void withGcRun(Consumer<GC> consumer)
Runs some function using a temporary GC.
public static <T> T withGcCompute(Function<GC,T> function)
Computes some function using a temporary GC.
public static void loopUntil(Predicate<Display> until)
Runs the display loop until the given Predicate<Display>
returns false.
public static void loopUntilDisposed(Widget widget)
Runs the display loop until the widget
has been disposed.
public static <T> T loopUntilGet(CompletionStage<T> future)
Runs the display loop until the given future has returned.
public static void blockForSuccess(String title, String msg, @Nullable Shell parent)
Blocks to notify about a success. Can be called from any thread.
public static void blockForSuccess(String title, String msg)
Blocks to notify about a success. Can be called from any thread.
public static void blockForError(String title, String msg, @Nullable Shell parent)
Blocks to notify about an error. Can be called from any thread.
public static void blockForError(String title, String msg)
Blocks to notify about an error. Can be called from any thread.
public static boolean blockForQuestion(String title, String message, @Nullable Shell parent)
Blocks to ask a yes/no question. Can be called from any thread.
public static boolean blockForQuestion(String title, String message)
Blocks to ask a yes/no question. Can be called from any thread.
public static boolean blockForOkCancel(String title, String message, @Nullable Shell parent)
Blocks to ask an Ok/Cancel question. Can be called from any thread.
public static boolean blockForOkCancel(String title, String message)
Blocks to ask an Ok/Cancel question. Can be called from any thread.
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.
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_*public static int blockForMessageBox(String title, String message, int style)
Opens a message box with the given title, message, and style and returns its result. Can be called from any thread.
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_*public static int systemFontHeight()
Returns the height of the system font.
public static int systemFontWidth()
Returns the width of the system font.
public static int systemFontSnug()
Returns a distance which is a snug fit for a line of text in the system font.
public static int defaultButtonWidth()
Returns the default width of a button, scaled for the system font.
public static int defaultDialogWidth()
Returns the default width of a dialog.
public static Point scaleByFontHeight(int cols, int rows)
Returns a size which is scaled by the system font’s height.
public static int scaleByFontHeight(int rows)
Returns a dimension which is scaled by the system font’s height.
public 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.
public static Point scaleByFont(String str)
Returns a dimension which is guaranteed to be comfortable for the given string.
public static Rectangle globalBounds(Control control)
Returns the bounds of the given control in global coordinates.
public static Rectangle globalBounds(ControlWrapper control)
Returns the global bounds of the given ControlWrapper.
public static Rectangle toDisplay(Control control, Rectangle rect)
Converts a rectangle to global coordinates using the given control as a reference frame.
public static Optional<Monitor> monitorFor(Point p)
Returns the monitor (if any) which contains the given point.
public static void setEnabledDeep(Composite root, boolean enabled)
Sets the enabled status of every child, grandchild, etc. of the given composite. Skips plain-jane Composites.
public static void forEachDeep(Composite root, Consumer<Control> ctlSetter)
Calls the given consumer on the given composite and all of its children, recursively.
public static void setForegroundDeep(Composite root, Color foreground)
Sets the foreground color of the given composite and all of its children, recursively.
public static void setBackgroundDeep(Composite root, Color background)
Sets the background color of the given composite and all of its children, recursively.
public static TreeDef.Parented<Composite> treeDefComposite()
public static TreeDef.Parented<Control> treeDefControl()
public static TreeDef.Parented<Shell> treeDefShell()