|
|
Sometimes you don't know what UI widgets need to appear in a window until runtime.
In the Droplets Platform, the first time your application instantiates each of its window classes, it builds a description of the components in the window and sends it to the client. As an optimization, it stores the description in a cache, keyed on the window class name. This eliminates the overhead of constructing the description and sending it to the client each time the window class is instantiated -- a major performance gain.
As a consequence, when you use the same window class to create windows with different layouts, you need to provide a key other than the class name for the cache to use. You can accomplish this by overriding the getTypeName() method of the Window class:
public class MyWindow extends Window {
private static int windowNum = 0;
protected String getTypeName()
{
windowNum++;
return "w" + windowNum;
}
}
The framework calls getTypeName() once on each new window object. By returning a different string each time, you are indicating that each window object has a different set of components.
Of course, you may have only a few different layouts for all the windows of a class. By returning one of a fixed set of names, one per layout, you maximize the benefit of the cache.
|
|
|