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.3KB

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