public class SwtMisc extends Object
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
|
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)
public static boolean flagIsSet(int flag, Widget widget)
public static int setFlag(int flag, boolean isSet, int style)
public static Display assertUI()
public static void assertNotUI()
public static Color getSystemColor(int code)
public static Cursor getSystemCursor(int cursor)
public static Image getSystemIcon(int icon)
@Deprecated public static void requestLayout(Control control)
Control.requestLayout()
.public static void asyncLayout(Composite cmp)
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)
This can often fix graphical glitches with resize-to-fit layouts, such as a `TableColumnLayout`.
public static void clean(Composite cmp)
public static void assertClean(Composite cmp)
IllegalArgumentException
iff the given `Composite` has any children or a non-null layout.public static void withGcRun(Consumer<GC> consumer)
public static <T> T withGcCompute(Function<GC,T> function)
public static void loopUntil(Predicate<Display> until)
public static void loopUntilDisposed(Widget widget)
public static <T> T loopUntilGet(CompletionStage<T> future)
public static void blockForSuccess(String title, String msg, @Nullable Shell parent)
public static void blockForSuccess(String title, String msg)
public static void blockForError(String title, String msg, @Nullable Shell parent)
public static void blockForError(String title, String msg)
public static boolean blockForQuestion(String title, String message, @Nullable Shell parent)
public static boolean blockForQuestion(String title, String message)
public static boolean blockForOkCancel(String title, String message, @Nullable Shell parent)
public static boolean blockForOkCancel(String title, String message)
public static int blockForMessageBox(String title, String message, @Nullable Shell parent, int style)
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)
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()
public static int systemFontWidth()
public static int systemFontSnug()
public static int defaultButtonWidth()
public static int defaultDialogWidth()
public static Point scaleByFontHeight(int cols, int rows)
public static int scaleByFontHeight(int rows)
public static Point scaleByFont(int cols, int rows)
public static Point scaleByFont(String str)
public static Rectangle globalBounds(Control control)
public static Rectangle globalBounds(ControlWrapper control)
public static Rectangle toDisplay(Control control, Rectangle rect)
public static Optional<Monitor> monitorFor(Point p)
public static void setEnabledDeep(Composite root, boolean enabled)
public static void forEachDeep(Composite root, Consumer<Control> ctlSetter)
public static void setForegroundDeep(Composite root, Color foreground)
public static void setBackgroundDeep(Composite root, Color background)
public static TreeDef.Parented<Composite> treeDefComposite()
public static TreeDef.Parented<Control> treeDefControl()
public static TreeDef.Parented<Shell> treeDefShell()