You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WindowedDemos.java 2.7KB

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