blob: 840f153ed2e95762b70288cbf82dc3f9dd74ea90 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
package com.itmill.toolkit.demo;
import java.util.HashMap;
import java.util.Iterator;
import com.itmill.toolkit.terminal.ExternalResource;
import com.itmill.toolkit.ui.Button;
import com.itmill.toolkit.ui.Window;
import com.itmill.toolkit.ui.Button.ClickEvent;
/**
* Embeds other demos in windows using an ExternalResource ("application in
* application").
*
* @author IT Mill Ltd.
* @see com.itmill.toolkit.ui.Window
*/
public class WindowedDemos extends com.itmill.toolkit.Application {
// keeps track of created windows
private final HashMap windows = new HashMap();
// mapping demo name to URL
private static final HashMap servlets = new HashMap();
static {
servlets.put("Caching demo", "CachingDemo/");
servlets.put("Calculator", "Calc/");
servlets.put("Calendar demo", "CalendarDemo/");
servlets.put("Select demo", "SelectDemo/");
servlets.put("Table demo", "TableDemo/");
servlets.put("Browser demo", "BrowserDemo/");
servlets.put("Notification demo", "NotificationDemo/");
}
public void init() {
// Create new window for the application and give the window a visible.
Window main = new Window("IT Mill Toolkit 5 Windowed Demos");
// set as main window
setMainWindow(main);
// Create menu window.
Window menu = new Window("Select demo");
menu.setWidth(200);
menu.setHeight(400);
main.addWindow(menu); // add to layout
// Create a menu button for each demo
for (Iterator it = servlets.keySet().iterator(); it.hasNext();) {
String name = (String) it.next();
Button b = new Button(name, new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
show(event.getButton().getCaption());
}
});
b.setStyleName("link");
menu.addComponent(b);
}
}
/**
* Shows the specified demo in a separate window. Creates a new window if
* the demo has not been shown already, re-uses old window otherwise.
*
* @param demoName
* the name of the demo to be shown
*/
private void show(String demoName) {
Window w = (Window) windows.get(demoName);
if (w == null) {
w = new Window(demoName);
w.setWidth(520);
w.setHeight(500);
w.setPositionX(202);
windows.put(demoName, w);
getMainWindow().addWindow(w);
} else {
w.setVisible(true);
}
w.open(new ExternalResource((String) servlets.get(demoName)));
}
}
|