- Creating Your Own Widgets using SWT
- SWT Custom Widgets
- Developing custom widgets with SWT - Tutorial
Tips, Tricks and Guidelines for Widget Authors
The following is a list of various tips, tricks, guidelines and other general information for developers writing custom widgets for Nebula. This is an unorganized list which will hopefully become larger and more organized over time. Many of the items below will also help your code and your widget more closely match SWT.
- Don't paint outside the paint event. When you want draw something new on your widget simply invalidate it (redraw) and allow it repainted by the OS.
- Be wary of ScrolledComposite. ScrolledComposite can allow you to quickly and easily add scrolling to your widget but there are limitations. Windows has a limitation on the maximum size of a control (32k pixels). Therefore your widget will have a maximum size to its content.
- Fail fast - use checkWidget. Each public method should be prefaced with a call to checkWidget.
- Use the SWT error methods. Stay consistent with SWT by using the SWT exception methods in the main SWT class.
- Don't override dispose. The dispose method is not called when an item is disposed as its parent is disposed. If you need to perform some dispose logic, listen for the dispose event.
- Dispose of items. If your widget contains items, you will need to dispose of the items when the main widget is disposed.
- checkStyle. SWT widgets are driven by style bits. As a general guideline, include a simple static method that filters those styles utilized by your widget (and call it checkStyle). This method should return the filtered style which can then be passed down to the super constructor. This will allow the getStyle method to answer correctly.
- Don't forget SWT.RIGHT_TO_LEFT and SWT.LEFT_TO_RIGHT. In the aforementioned checkStyle method, don't forget to accept the two BiDi styles.
- isXXX vs getXXX. Follow the proper conventions for boolean getters. Preface methods which simply return a property value with 'get'. Preface methods which return the status of a property based on more complex logic with 'is' (ex getVisible/setVisible/isVisible).
- Don't forget to redraw. When a method changes a value that affects the visual appearance of your widget it will need to be redrawn. Redraws can occur automatically for a variety of reasons and during testing it may not be obvious that a redraw was missing. All methods that affect the visual appearance need to end in redraw().
- Be transparent friendly. TODO
- Popups. TODO