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.

NativeButtonIconAndText.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.components.nativebutton;
  17. import com.vaadin.server.ThemeResource;
  18. import com.vaadin.server.VaadinRequest;
  19. import com.vaadin.tests.components.AbstractTestUI;
  20. import com.vaadin.ui.Button;
  21. import com.vaadin.ui.Button.ClickEvent;
  22. import com.vaadin.ui.Button.ClickListener;
  23. import com.vaadin.ui.NativeButton;
  24. public class NativeButtonIconAndText extends AbstractTestUI implements
  25. ClickListener {
  26. static final String UPDATED_ALTERNATE_TEXT = "Now has alternate text";
  27. static final String INITIAL_ALTERNATE_TEXT = "Initial alternate text";
  28. static final String BUTTON_TEXT = "buttonText";
  29. static final String BUTTON_TEXT_ICON = "buttonTextIcon";
  30. static final String BUTTON_TEXT_ICON_ALT = "buttonTextIconAlt";
  31. static final String NATIVE_BUTTON_TEXT = "nativeButtonText";
  32. static final String NATIVE_BUTTON_TEXT_ICON = "nativeButtonTextIcon";
  33. static final String NATIVE_BUTTON_TEXT_ICON_ALT = "nativeButtonTextIconAlt";
  34. @Override
  35. protected void setup(VaadinRequest request) {
  36. Button buttonText = new Button("Only text");
  37. Button buttonTextIcon = new Button("Text icon");
  38. buttonTextIcon.setIcon(new ThemeResource("../runo/icons/64/ok.png"));
  39. Button buttonTextIconAlt = new Button("Text icon alt");
  40. buttonTextIconAlt.setIcon(new ThemeResource(
  41. "../runo/icons/64/cancel.png"));
  42. buttonTextIconAlt.setIconAlternateText(INITIAL_ALTERNATE_TEXT);
  43. buttonText.addClickListener(this);
  44. buttonTextIcon.addClickListener(this);
  45. buttonTextIconAlt.addClickListener(this);
  46. buttonText.setId(BUTTON_TEXT);
  47. buttonTextIcon.setId(BUTTON_TEXT_ICON);
  48. buttonTextIconAlt.setId(BUTTON_TEXT_ICON_ALT);
  49. addComponent(buttonText);
  50. addComponent(buttonTextIcon);
  51. addComponent(buttonTextIconAlt);
  52. NativeButton nativeButtonText = new NativeButton("Only text");
  53. NativeButton nativeButtonTextIcon = new NativeButton("Text icon");
  54. nativeButtonTextIcon.setIcon(new ThemeResource(
  55. "../runo/icons/64/ok.png"));
  56. NativeButton nativeButtonTextIconAlt = new NativeButton("Text icon alt");
  57. nativeButtonTextIconAlt.setIcon(new ThemeResource(
  58. "../runo/icons/64/cancel.png"));
  59. nativeButtonTextIconAlt.setIconAlternateText(INITIAL_ALTERNATE_TEXT);
  60. nativeButtonText.addClickListener(this);
  61. nativeButtonTextIcon.addClickListener(this);
  62. nativeButtonTextIconAlt.addClickListener(this);
  63. nativeButtonText.setId(NATIVE_BUTTON_TEXT);
  64. nativeButtonTextIcon.setId(NATIVE_BUTTON_TEXT_ICON);
  65. nativeButtonTextIconAlt.setId(NATIVE_BUTTON_TEXT_ICON_ALT);
  66. addComponent(nativeButtonText);
  67. addComponent(nativeButtonTextIcon);
  68. addComponent(nativeButtonTextIconAlt);
  69. }
  70. /*
  71. * (non-Javadoc)
  72. *
  73. * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription()
  74. */
  75. @Override
  76. protected String getTestDescription() {
  77. return "Click the buttons to toggle icon alternate text";
  78. }
  79. /*
  80. * (non-Javadoc)
  81. *
  82. * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber()
  83. */
  84. @Override
  85. protected Integer getTicketNumber() {
  86. return 12780;
  87. }
  88. /*
  89. * (non-Javadoc)
  90. *
  91. * @see com.vaadin.ui.Button.ClickListener#buttonClick(com.vaadin.ui.Button.
  92. * ClickEvent)
  93. */
  94. @Override
  95. public void buttonClick(ClickEvent event) {
  96. Button b = event.getButton();
  97. String was = b.getIconAlternateText();
  98. if (was == null || was.isEmpty()) {
  99. b.setIconAlternateText(UPDATED_ALTERNATE_TEXT);
  100. } else {
  101. b.setIconAlternateText(null);
  102. }
  103. }
  104. }