Package com.diffplug.common.swt
Interface ControlWrapper
-
- All Known Implementing Classes:
ButtonPanel
,CoatMux
,ControlWrapper.AroundControl
,ControlWrapper.AroundWrapper
,ControlWrapper.Transparent
,FlatBtn
,LinkBtn
,NoBorderBtn
,ScaleCtl
public interface ControlWrapper
Wraps an SWTControl
to encapsulate its API.The traditional way to make a custom class is this:
class CustomControl extends
Composite
This has three main problems:
- Users can add random widgets to your "Control" because it exposes the
Composite
interface. - Users can set the layout to your "Control" because it exposes the
Composite
interface. - Users can add random listeners to your "Control", and overridding
Widget.addListener
to intercept them is a very dangerous plan.
ControlWrapper fixes this by providing an low-overhead skeleton which encapsulates the SWT Control that you're using as the base of your custom control, which allows you to only expose the APIs that are appropriate.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
ControlWrapper.AroundControl<T extends Control>
Default implementation of aControlWrapper
which wraps aControl
.static class
ControlWrapper.AroundWrapper<T extends ControlWrapper>
Default implementation of aControlWrapper
which wraps some other form of `ControlWrapper` with a new interface.static class
ControlWrapper.Transparent<T extends Control>
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
dispose()
Disposes the underlying control.default Object
getLayoutData()
Returns the LayoutData for this control.default Composite
getParent()
Returns the parent of this Control.Control
getRootControl()
Returns the wrappedControl
(only appropriate for limited purposes!).default Shell
getShell()
Returns the parent Shell of this Control.default boolean
isDisposed()
Returns true iff the underlying control is disposed.default void
setLayoutData(Object layoutData)
Sets the LayoutData for this control.default boolean
setParent(Composite parent)
Changes the parent of the widget to be the one provided.static <T extends Control>
ControlWrapper.Transparent<T>transparent(T control)
Most-efficient way to transparently pass a Control to a ControlWrapper API.
-
-
-
Method Detail
-
setLayoutData
default void setLayoutData(Object layoutData)
Sets the LayoutData for this control.
-
getLayoutData
default Object getLayoutData()
Returns the LayoutData for this control.
-
getParent
default Composite getParent()
Returns the parent of this Control.
-
getShell
default Shell getShell()
Returns the parent Shell of this Control.
-
dispose
default void dispose()
Disposes the underlying control.
-
isDisposed
default boolean isDisposed()
Returns true iff the underlying control is disposed.
-
setParent
default boolean setParent(Composite parent)
Changes the parent of the widget to be the one provided. Returnstrue
if the parent is successfully changed
-
getRootControl
Control getRootControl()
Returns the wrappedControl
(only appropriate for limited purposes!).The implementor of this ControlWrapper is free to change the wrapped Control as she sees fit, and she doesn't have to tell you about it! You shouldn't rely on this control being anything in particular.
You can rely on this Control for:
- Managing lifetimes: `wrapped.getRootControl().addListener(SWT.Dispose, ...`
But that's all. If you use it for something else, it's on you when it breaks.
-
transparent
static <T extends Control> ControlWrapper.Transparent<T> transparent(T control)
Most-efficient way to transparently pass a Control to a ControlWrapper API.
-
-