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.

ButtonExample.java 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.automatedtests.featurebrowser;
  5. import com.vaadin.terminal.ExternalResource;
  6. import com.vaadin.terminal.ThemeResource;
  7. import com.vaadin.ui.Button;
  8. import com.vaadin.ui.CheckBox;
  9. import com.vaadin.ui.CustomComponent;
  10. import com.vaadin.ui.HorizontalLayout;
  11. import com.vaadin.ui.Label;
  12. import com.vaadin.ui.Link;
  13. import com.vaadin.ui.Panel;
  14. import com.vaadin.ui.VerticalLayout;
  15. import com.vaadin.ui.Button.ClickEvent;
  16. /**
  17. * Shows a few variations of Buttons and Links.
  18. *
  19. * @author IT Mill Ltd.
  20. */
  21. @SuppressWarnings("serial")
  22. public class ButtonExample extends CustomComponent implements
  23. Button.ClickListener {
  24. public ButtonExample() {
  25. final VerticalLayout main = new VerticalLayout();
  26. main.setMargin(true);
  27. setCompositionRoot(main);
  28. final HorizontalLayout horiz = new HorizontalLayout();
  29. horiz.setWidth("100%");
  30. main.addComponent(horiz);
  31. final Panel basic = new Panel("Basic buttons");
  32. basic.setStyleName(Panel.STYLE_LIGHT);
  33. horiz.addComponent(basic);
  34. final Panel bells = new Panel("w/ bells & whistles");
  35. bells.setStyleName(Panel.STYLE_LIGHT);
  36. horiz.addComponent(bells);
  37. Button b = new Button("Basic button");
  38. b.setDebugId("Basic1");
  39. b.addListener(this);
  40. basic.addComponent(b);
  41. b = new Button("Button w/ icon + tooltip");
  42. b.setDebugId("Button2");
  43. b.addListener(this);
  44. b.setIcon(new ThemeResource("icons/ok.png"));
  45. b.setDescription("This button does nothing, fast");
  46. bells.addComponent(b);
  47. b = new CheckBox("CheckBox - a switch-button");
  48. b.setDebugId("Button3");
  49. b.setImmediate(true); // checkboxes are not immediate by default
  50. b.addListener(this);
  51. basic.addComponent(b);
  52. b = new CheckBox("CheckBox w/ icon + tooltip");
  53. b.setDebugId("Button4");
  54. b.setImmediate(true); // checkboxes are not immediate by default
  55. b.addListener(this);
  56. b.setIcon(new ThemeResource("icons/ok.png"));
  57. b.setDescription("This is a CheckBox");
  58. bells.addComponent(b);
  59. b = new Button("Link-style button");
  60. b.setDebugId("Button5");
  61. b.addListener(this);
  62. b.setStyleName(Button.STYLE_LINK);
  63. basic.addComponent(b);
  64. b = new Button("Link button w/ icon + tooltip");
  65. b.setDebugId("Button6");
  66. b.addListener(this);
  67. b.setStyleName(Button.STYLE_LINK);
  68. b.setIcon(new ThemeResource("icons/ok.png"));
  69. b.setDescription("Link-style, icon+tootip, no caption");
  70. bells.addComponent(b);
  71. b = new Button();
  72. b.setDebugId("Button7");
  73. b.addListener(this);
  74. b.setStyleName(Button.STYLE_LINK);
  75. b.setIcon(new ThemeResource("icons/ok.png"));
  76. b.setDescription("Link-style, icon+tootip, no caption");
  77. basic.addComponent(b);
  78. final Panel links = new Panel("Links");
  79. links.setStyleName(Panel.STYLE_LIGHT);
  80. main.addComponent(links);
  81. final Label desc = new Label(
  82. "The main difference between a Link and"
  83. + " a link-styled Button is that the Link works client-"
  84. + " side, whereas the Button works server side.<br/> This means"
  85. + " that the Button triggers some event on the server,"
  86. + " while the Link is a normal web-link. <br/><br/>Note that for"
  87. + " opening new windows, the Link might be a safer "
  88. + " choice, since popup-blockers might interfer with "
  89. + " server-initiated window opening.");
  90. desc.setContentMode(Label.CONTENT_XHTML);
  91. links.addComponent(desc);
  92. Link l = new Link("IT Mill home", new ExternalResource(
  93. "http://www.itmill.com"));
  94. l.setDebugId("Link1");
  95. l.setDescription("Link without target name, opens in this window");
  96. links.addComponent(l);
  97. l = new Link("IT Mill home (new window)", new ExternalResource(
  98. "http://www.itmill.com"));
  99. l.setDebugId("Link2");
  100. l.setTargetName("_blank");
  101. l.setDescription("Link with target name, opens in new window");
  102. links.addComponent(l);
  103. l = new Link("IT Mill home (new window, less decor)",
  104. new ExternalResource("http://www.itmill.com"));
  105. l.setDebugId("Link3");
  106. l.setTargetName("_blank");
  107. l.setTargetBorder(Link.TARGET_BORDER_MINIMAL);
  108. l.setTargetName("_blank");
  109. l
  110. .setDescription("Link with target name and BORDER_MINIMAL, opens in new window with less decor");
  111. links.addComponent(l);
  112. l = new Link("IT Mill home (new 200x200 window, no decor, icon)",
  113. new ExternalResource("http://www.itmill.com"), "_blank", 200,
  114. 200, Link.TARGET_BORDER_NONE);
  115. l.setDebugId("Link4");
  116. l.setTargetName("_blank");
  117. l
  118. .setDescription("Link with target name and BORDER_NONE, opens in new window with no decor");
  119. l.setIcon(new ThemeResource("icons/ok.png"));
  120. links.addComponent(l);
  121. }
  122. public void buttonClick(ClickEvent event) {
  123. final Button b = event.getButton();
  124. getWindow().showNotification(
  125. "Clicked"
  126. + (b instanceof CheckBox ? ", value: "
  127. + event.getButton().getValue() : ""));
  128. }
  129. }