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.

Feature.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /* *************************************************************************
  2. IT Mill Toolkit
  3. Development of Browser User Interfaces Made Easy
  4. Copyright (C) 2000-2006 IT Mill Ltd
  5. *************************************************************************
  6. This product is distributed under commercial license that can be found
  7. from the product package on license.pdf. Use of this product might
  8. require purchasing a commercial license from IT Mill Ltd. For guidelines
  9. on usage, see licensing-guidelines.html
  10. *************************************************************************
  11. For more information, contact:
  12. IT Mill Ltd phone: +358 2 4802 7180
  13. Ruukinkatu 2-4 fax: +358 2 4802 7181
  14. 20540, Turku email: info@itmill.com
  15. Finland company www: www.itmill.com
  16. Primary source for information and releases: www.itmill.com
  17. ********************************************************************** */
  18. package com.itmill.toolkit.demo.features;
  19. import com.itmill.toolkit.terminal.ClassResource;
  20. import com.itmill.toolkit.terminal.Resource;
  21. import com.itmill.toolkit.ui.*;
  22. public abstract class Feature extends CustomComponent {
  23. private static final String PROP_REMINDER_TEXT = ""
  24. + "<br /><br />Note: Use <b>Properties</b> panel located at the top"
  25. + " right corner to try out how different properties affect"
  26. + " the presentation or functionality of currently selected component.";
  27. private boolean propsReminder = true;
  28. private OrderedLayout layout;
  29. private TabSheet ts;
  30. private boolean initialized = false;
  31. private static Resource sampleIcon;
  32. protected PropertyPanel propertyPanel;
  33. private Label javadoc;
  34. private Label description;
  35. /** Constuctor for the feature component */
  36. public Feature() {
  37. layout = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL);
  38. setCompositionRoot(layout);
  39. }
  40. /**
  41. * Actual URL consists of "/doc/api/com/itmill/toolkit/"+url
  42. *
  43. * @param url
  44. */
  45. public void setJavadocURL(String url) {
  46. javadoc
  47. .setValue("<iframe width=\"100%\" src=\"../doc/api/com/itmill/toolkit/"
  48. + url + "\"></iframe>");
  49. }
  50. /**
  51. * Feature component initialization is lazily done when the feature is
  52. * attached to application
  53. */
  54. public void attach() {
  55. super.attach();
  56. // Check if the feature is already initialized
  57. if (initialized)
  58. return;
  59. initialized = true;
  60. // Javadoc
  61. javadoc = new Label();
  62. javadoc.setContentMode(Label.CONTENT_XHTML);
  63. // Demo
  64. Component demo = getDemoComponent();
  65. if (demo != null)
  66. layout.addComponent(demo);
  67. ts = new TabSheet();
  68. ts.setWidth(100);
  69. ts.setWidthUnits(TabSheet.UNITS_PERCENTAGE);
  70. ts.setHeight(100);
  71. ts.setHeightUnits(TabSheet.UNITS_PERCENTAGE);
  72. // Description tab
  73. String title = getTitle();
  74. if (getDescriptionXHTML() != null) {
  75. OrderedLayout mainLayout = new OrderedLayout(
  76. OrderedLayout.ORIENTATION_VERTICAL);
  77. OrderedLayout layout = new OrderedLayout(
  78. OrderedLayout.ORIENTATION_HORIZONTAL);
  79. mainLayout.addComponent(layout);
  80. if (getImage() != null)
  81. layout.addComponent(new Embedded("", new ClassResource(
  82. getImage(), this.getApplication())));
  83. String label = "";
  84. label += getDescriptionXHTML();
  85. if (propsReminder)
  86. label += PROP_REMINDER_TEXT;
  87. if (title != null) {
  88. layout.addComponent(new Label("<h3>" + title + "</h3>",
  89. Label.CONTENT_XHTML));
  90. }
  91. description = new Label(label, Label.CONTENT_XHTML);
  92. mainLayout.addComponent(description);
  93. ts.addTab(mainLayout, "Description", null);
  94. }
  95. // Properties table tab
  96. ts.addTab(getPropertyPanel().getAllProperties(), "Properties", null);
  97. // Javadoc tab
  98. if (!javadoc.getValue().equals(""))
  99. ts.addTab(javadoc, "Javadoc", null);
  100. // Code Sample tab
  101. String example = getExampleSrc();
  102. if (example != null) {
  103. OrderedLayout l = new OrderedLayout();
  104. if (getTitle() != null)
  105. l.addComponent(new Label(
  106. "<b>// " + getTitle() + " example</b>",
  107. Label.CONTENT_XHTML));
  108. l.addComponent(new Label(example, Label.CONTENT_PREFORMATTED));
  109. ts.addTab(l, "Code Sample", null);
  110. }
  111. }
  112. /** Get the desctiption of the feature as XHTML fragment */
  113. protected String getDescriptionXHTML() {
  114. return "<h2>Feature description is under construction</h2>";
  115. }
  116. /** Get the title of the feature */
  117. protected String getTitle() {
  118. return this.getClass().getName();
  119. }
  120. public TabSheet getTabSheet() {
  121. return ts;
  122. }
  123. /** Get the name of the image file that will be put on description page */
  124. protected String getImage() {
  125. return null;
  126. }
  127. /** Get the example application source code */
  128. protected String getExampleSrc() {
  129. return null;
  130. }
  131. /** Get the feature demo component */
  132. protected Component getDemoComponent() {
  133. return null;
  134. }
  135. /** Get sample icon resource */
  136. protected Resource getSampleIcon() {
  137. if (sampleIcon == null)
  138. sampleIcon = new ClassResource("m.gif", this.getApplication());
  139. return sampleIcon;
  140. }
  141. public PropertyPanel getPropertyPanel() {
  142. return propertyPanel;
  143. }
  144. public void setPropsReminder(boolean propsReminder) {
  145. this.propsReminder = propsReminder;
  146. }
  147. public void updateDescription() {
  148. String label = "";
  149. label += getDescriptionXHTML();
  150. if (propsReminder)
  151. label += PROP_REMINDER_TEXT;
  152. description.setValue(label);
  153. }
  154. // Fix for #512
  155. public Label getDescription() {
  156. return description;
  157. }
  158. }