--- /dev/null
+package com.itmill.toolkit.demo;\r
+\r
+import com.itmill.toolkit.terminal.PaintException;\r
+import com.itmill.toolkit.terminal.PaintTarget;\r
+import com.itmill.toolkit.ui.Label;\r
+import com.itmill.toolkit.ui.TabSheet;\r
+import com.itmill.toolkit.ui.Window;\r
+\r
+/**\r
+ * This example is a (simple) demonstration of client-side caching. The content\r
+ * in one tab is intentionally made very slow to produce server-side. When the\r
+ * user changes to this tab for the first time, there will be a 3 second wait\r
+ * before the content shows up, but the second time it shows up immediately\r
+ * since the content has not changed and is cached client-side.\r
+ * \r
+ * @author IT Mill Ltd.\r
+ */\r
+public class CachingDemo extends com.itmill.toolkit.Application {\r
+\r
+ public void init() {\r
+\r
+ Window main = new Window("Client-side caching example");\r
+ setMainWindow(main);\r
+\r
+ setTheme("example");\r
+\r
+ TabSheet ts = new TabSheet();\r
+ ts.setCaption("setHeigth(300)");\r
+ main.addComponent(ts);\r
+ ts.setHeight(300);\r
+ Label l = new Label(\r
+ "A normal label, quick to render. The second tab will be slow to render the first time, after that it will be as quick as this one.");\r
+ ts.addTab(l, "Normal", null);\r
+ l = new Label(\r
+ "The first time you change to this tab, this label is very slow to produce (server-side). However, it will seem fast the second time you change to this tab, because it has not changed and is cached client-side.") {\r
+ public void paintContent(PaintTarget target) throws PaintException {\r
+ try {\r
+ Thread.sleep(3000);\r
+ } catch (Exception e) {\r
+ // IGNORED\r
+ }\r
+ super.paintContent(target);\r
+ }\r
+\r
+ };\r
+ ts.addTab(l, "Slow", null);\r
+\r
+ }\r
+\r
+}\r