Package com.diffplug.common.swt
Interface ControlWrapper
-
- All Known Implementing Classes:
ButtonPanel,CoatMux,ControlWrapper.AroundControl,ControlWrapper.AroundWrapper,ControlWrapper.Transparent,FlatBtn,LinkBtn,NoBorderBtn,ScaleCtl,VScrollCtl
public interface ControlWrapperWraps an SWTControlto encapsulate its API.The traditional way to make a custom class is this:
class CustomControl extendsCompositeThis has three main problems:
- Users can add random widgets to your "Control" because it exposes the
Compositeinterface. - Users can set the layout to your "Control" because it exposes the
Compositeinterface. - Users can add random listeners to your "Control", and overridding
Widget.addListenerto 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 classControlWrapper.AroundControl<T extends Control>Default implementation of aControlWrapperwhich wraps aControl.static classControlWrapper.AroundWrapper<T extends ControlWrapper>Default implementation of aControlWrapperwhich wraps some other form of `ControlWrapper` with a new interface.static classControlWrapper.Transparent<T extends Control>
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default voiddispose()Disposes the underlying control.default java.lang.ObjectgetLayoutData()Returns the LayoutData for this control.default CompositegetParent()Returns the parent of this Control.ControlgetRootControl()Returns the wrappedControl(only appropriate for limited purposes!).default ShellgetShell()Returns the parent Shell of this Control.default booleanisDisposed()Returns true iff the underlying control is disposed.default voidsetLayoutData(java.lang.Object layoutData)Sets the LayoutData for this control.default booleansetParent(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(java.lang.Object layoutData)
Sets the LayoutData for this control.
-
getLayoutData
default java.lang.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. Returnstrueif 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.
-
-