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.

IntroWelcome.java 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.tests.featurebrowser;
  5. import java.net.URL;
  6. import java.util.Date;
  7. import java.util.Iterator;
  8. import java.util.Map;
  9. import com.vaadin.terminal.DownloadStream;
  10. import com.vaadin.terminal.ParameterHandler;
  11. import com.vaadin.terminal.URIHandler;
  12. import com.vaadin.terminal.gwt.server.ApplicationServlet;
  13. import com.vaadin.ui.Component;
  14. import com.vaadin.ui.Form;
  15. import com.vaadin.ui.Label;
  16. import com.vaadin.ui.OrderedLayout;
  17. import com.vaadin.ui.Panel;
  18. import com.vaadin.ui.Select;
  19. public class IntroWelcome extends Feature implements URIHandler,
  20. ParameterHandler {
  21. Panel panel = new Panel();
  22. private static final String WELCOME_TEXT_UPPER = ""
  23. + "This application lets you view and play with some features of "
  24. + "Vaadin. Use menu on the left to select component."
  25. + "<br /><br />Note the <b>Properties selection</b> on the top "
  26. + "right corner. Click it open to access component properties and"
  27. + " feel free to edit properties at any time."
  28. + "<br /><br />The area that you are now reading is the component"
  29. + " demo area. Lower area from here contains component description, API"
  30. + " documentation and optional code sample. Note that not all selections"
  31. + " contain demo, only description and API documentation is shown."
  32. + "<br /><br />You may also change application's theme from below the menu."
  33. + " This example application is designed to work best with"
  34. + " <em>Demo</em> theme, other themes are for demonstration purposes only."
  35. + "<br /><br />Vaadin enables you to construct complex Web"
  36. + " applications using plain Java, no knowledge of other Web technologies"
  37. + " such as XML, HTML, DOM, JavaScript or browser differences is required."
  38. + "<br /><br />For more information, point your browser to"
  39. + " <a href=\"http://www.vaadin.com\" target=\"_new\">www.vaadin.com</a>.";
  40. private static final String WELCOME_TEXT_LOWER = ""
  41. + "This area contains the selected component's description, list of properties, javadoc"
  42. + " and optional code sample. "
  43. + "Start your tour now by selecting features from the list"
  44. + " on the left and remember to experiment with the <b>Properties panel</b>"
  45. + " located at the top right corner area.";
  46. // TODO Add browser agent string
  47. private final String description = WELCOME_TEXT_LOWER
  48. + "<br /><br />Vaadin version: " + ApplicationServlet.VERSION;
  49. public IntroWelcome() {
  50. super();
  51. }
  52. @Override
  53. protected Component getDemoComponent() {
  54. final OrderedLayout l = new OrderedLayout();
  55. panel.setCaption("Welcome to the Vaadin feature tour!");
  56. l.addComponent(panel);
  57. final Label label = new Label();
  58. panel.addComponent(label);
  59. label.setContentMode(Label.CONTENT_XHTML);
  60. label.setValue(WELCOME_TEXT_UPPER);
  61. propertyPanel = new PropertyPanel(panel);
  62. final Form ap = propertyPanel.createBeanPropertySet(new String[] {
  63. "width", "height" });
  64. final Select themes = (Select) propertyPanel.getField("style");
  65. themes.addItem("light").getItemProperty(
  66. themes.getItemCaptionPropertyId()).setValue("light");
  67. themes.addItem("strong").getItemProperty(
  68. themes.getItemCaptionPropertyId()).setValue("strong");
  69. propertyPanel.addProperties("Panel Properties", ap);
  70. setJavadocURL("package-summary.html");
  71. setPropsReminder(false);
  72. return l;
  73. }
  74. @Override
  75. protected String getExampleSrc() {
  76. return "" + "package com.vaadin.demo;\n"
  77. + "import com.vaadin.ui.*;\n\n"
  78. + "public class HelloWorld extends com.vaadin.Application {\n"
  79. + " public void init() {\n"
  80. + " Window main = new Window(\"Hello window\");\n"
  81. + " setMainWindow(main);\n"
  82. + " main.addComponent(new Label(\"Hello World!\"));\n"
  83. + " }\n" + "}\n";
  84. }
  85. // not ready yet to give description, see paint instead
  86. @Override
  87. protected String getDescriptionXHTML() {
  88. return description;
  89. }
  90. @Override
  91. protected String getImage() {
  92. return "icon_intro.png";
  93. }
  94. @Override
  95. protected String getTitle() {
  96. return "Welcome";
  97. }
  98. /**
  99. * Add URI and parametes handlers to window.
  100. *
  101. * @see com.vaadin.ui.Component#attach()
  102. */
  103. @Override
  104. public void attach() {
  105. super.attach();
  106. getWindow().addURIHandler(this);
  107. getWindow().addParameterHandler(this);
  108. }
  109. /**
  110. * Remove all handlers from window
  111. *
  112. * @see com.vaadin.ui.Component#detach()
  113. */
  114. @Override
  115. public void detach() {
  116. super.detach();
  117. getWindow().removeURIHandler(this);
  118. getWindow().removeParameterHandler(this);
  119. }
  120. /**
  121. * Update URI
  122. *
  123. * @see com.vaadin.terminal.URIHandler#handleURI(URL, String)
  124. */
  125. public DownloadStream handleURI(URL context, String relativeUri) {
  126. return null;
  127. }
  128. /**
  129. * Show system status if systemStatus is given on URL
  130. *
  131. * @see com.vaadin.terminal.ParameterHandler#handleParameters(Map)
  132. */
  133. public void handleParameters(Map parameters) {
  134. for (final Iterator i = parameters.keySet().iterator(); i.hasNext();) {
  135. final String name = (String) i.next();
  136. if (name.equals("systemStatus")) {
  137. String status = "";
  138. status += "timestamp=" + new Date() + " ";
  139. status += "free=" + Runtime.getRuntime().freeMemory() + ", ";
  140. status += "total=" + Runtime.getRuntime().totalMemory() + ", ";
  141. status += "max=" + Runtime.getRuntime().maxMemory() + "\n";
  142. System.out.println(status);
  143. }
  144. }
  145. }
  146. }