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.

AbstractEmbedded.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright 2000-2018 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.ui;
  17. import java.util.Collection;
  18. import org.jsoup.nodes.Element;
  19. import com.vaadin.server.Resource;
  20. import com.vaadin.shared.ui.AbstractEmbeddedState;
  21. import com.vaadin.ui.declarative.DesignAttributeHandler;
  22. import com.vaadin.ui.declarative.DesignContext;
  23. /**
  24. * Abstract base for embedding components.
  25. *
  26. * @author Vaadin Ltd.
  27. * @since 7.0
  28. */
  29. @SuppressWarnings("serial")
  30. public abstract class AbstractEmbedded extends AbstractComponent {
  31. @Override
  32. protected AbstractEmbeddedState getState() {
  33. return (AbstractEmbeddedState) super.getState();
  34. }
  35. @Override
  36. protected AbstractEmbeddedState getState(boolean markAsDirty) {
  37. return (AbstractEmbeddedState) super.getState(markAsDirty);
  38. }
  39. /**
  40. * Sets the object source resource. The dimensions are assumed if possible.
  41. * The type is guessed from resource.
  42. *
  43. * @param source
  44. * the source to set.
  45. */
  46. public void setSource(Resource source) {
  47. setResource(AbstractEmbeddedState.SOURCE_RESOURCE, source);
  48. }
  49. /**
  50. * Get the object source resource.
  51. *
  52. * @return the source
  53. */
  54. public Resource getSource() {
  55. return getResource(AbstractEmbeddedState.SOURCE_RESOURCE);
  56. }
  57. /**
  58. * Sets this component's alternate text that can be presented instead of the
  59. * component's normal content for accessibility purposes.
  60. *
  61. * @param altText
  62. * A short, human-readable description of this component's
  63. * content.
  64. */
  65. public void setAlternateText(String altText) {
  66. getState().alternateText = altText;
  67. }
  68. /**
  69. * Gets this component's alternate text that can be presented instead of the
  70. * component's normal content for accessibility purposes.
  71. *
  72. * @returns Alternate text
  73. */
  74. public String getAlternateText() {
  75. return getState(false).alternateText;
  76. }
  77. @Override
  78. public void readDesign(Element design, DesignContext designContext) {
  79. super.readDesign(design, designContext);
  80. if (design.hasAttr("alt")) {
  81. setAlternateText(DesignAttributeHandler.readAttribute("alt",
  82. design.attributes(), String.class));
  83. }
  84. }
  85. @Override
  86. public void writeDesign(Element design, DesignContext designContext) {
  87. super.writeDesign(design, designContext);
  88. AbstractEmbedded def = designContext.getDefaultInstance(this);
  89. DesignAttributeHandler.writeAttribute("alt", design.attributes(),
  90. getAlternateText(), def.getAlternateText(), String.class,
  91. designContext);
  92. }
  93. @Override
  94. protected Collection<String> getCustomAttributes() {
  95. Collection<String> c = super.getCustomAttributes();
  96. c.add("alternate-text");
  97. c.add("alt");
  98. return c;
  99. }
  100. }