| This class wraps a control with a complex computeSize method. It uses caching
to reduce the number of times the control's computeSize method is called. This
allows controls (such as Coolbars and wrapping text) with slow computeSize
operations to be used inside layouts and composites that use inefficient caching.
For example, you want to use Coolbar A inside composite B. Rather than making A
a direct child of B, place it inside a CacheWrapper and insert the CacheWrapper
into B. Any layout data that would normally be attached to the control itself
should be attached to the wrapper instead:
// Unoptimized code
Toolbar myToolbar = new Toolbar(someParent, SWT.WRAP);
myToolbar.setLayoutData(someLayoutData);
// Optimized code
CacheWrapper myWrapper = new CacheWrapper(someParent);
Toolbar myToolbar = new Toolbar(myWrapper.getControl(), SWT.WRAP);
myWrapper.getControl().setLayoutData(someLayoutData);
CacheWrapper creates a Composite which should have exactly one child: the control
whose size should be cached. Note that CacheWrapper does NOT respect the flushCache
argument to layout() and computeSize(). This is intentional, since the whole point of
this class is to workaround layouts with poor caching, and such layouts will typically
be too eager about flushing the caches of their children. However, this means that you
MUST manually call flushCache() whenver the child's preferred size changes (and before
the parent is layed out).
since: 3.0 |