-
Notifications
You must be signed in to change notification settings - Fork 4
Decorators
###The decorator pattern
The decorator pattern does pretty much what it says on the tin, it decorates. In the case of objects, it decorates by changing behaviour or properties. A UIElement has some built-in decorators.
Decorators are either commutative or non-commutative. This means the order in which they are applied either doesn't matter or it does. Most of the built-in decorators are commutative and therefore means the order in which they are applied doesn't matter. The non-commutative decorators are indeed hidden a way in components like Button and Label which are examples of UIElement components that can be found in the Toolkit.
###Chaining Commutative decorators can be chained, so it allows you to decorate a decorator and so forth. This is a very powerful feature of the decorator pattern as it allows the layering of features and functionality through composition but keeping the original component in tact.
###Layout Decorator The layout decorator is probably the most used and consist of quite a few variations. The most fundamental decorators are Vertical, Horizontal and Padded.
mockUIElement = new MockUIElement();
mockUIElement.layout = new VerticalLayout( mockUIElement );
mockUIElement.build();
mockUIElement.arrange();
###Shape Decorator Each UIElement has a built-int background that can be altered through decoration. The only Shape decorator that is applied currently the ShapeRectangle which will draw a rectangle shape on the UIElement background display obejct with the properties provided. This is useful for panels or containers who's sole job it is to look after their children.
###Interactive Decorator The interactive decorator changes the intended behaviour of a UIElement to interactive. An interactive decorator consist of two methods **activate() ** and deactivate()
###Scroll Decorator Does what it says on the tin. Decorates the UIElement with a scrollbar.