Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Flash.java 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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.ArrayList;
  18. import java.util.Collections;
  19. import java.util.HashMap;
  20. import java.util.List;
  21. import java.util.Map;
  22. import org.jsoup.nodes.Element;
  23. import com.vaadin.server.Resource;
  24. import com.vaadin.shared.ui.flash.FlashState;
  25. import com.vaadin.ui.declarative.DesignContext;
  26. /**
  27. * A component for displaying Adobe® Flash® content.
  28. *
  29. * @author Vaadin Ltd.
  30. * @since 7.0
  31. */
  32. @SuppressWarnings("serial")
  33. public class Flash extends AbstractEmbedded {
  34. /**
  35. * Creates a new empty Flash component.
  36. */
  37. public Flash() {
  38. }
  39. /**
  40. * Creates a new empty Flash component with the given caption.
  41. *
  42. * @param caption
  43. * The caption for the component
  44. */
  45. public Flash(String caption) {
  46. setCaption(caption);
  47. }
  48. /**
  49. * Creates a new Flash component with the given caption and content.
  50. *
  51. * @param caption
  52. * The caption for the component
  53. * @param source
  54. * A Resource representing the Flash content that should be
  55. * displayed
  56. */
  57. public Flash(String caption, Resource source) {
  58. this(caption);
  59. setSource(source);
  60. }
  61. @Override
  62. protected FlashState getState() {
  63. return (FlashState) super.getState();
  64. }
  65. @Override
  66. protected FlashState getState(boolean markAsDirty) {
  67. return (FlashState) super.getState(markAsDirty);
  68. }
  69. /**
  70. * This attribute specifies the base path used to resolve relative URIs
  71. * specified by the classid, data, and archive attributes. When absent, its
  72. * default value is the base URI of the current document.
  73. *
  74. * @param codebase
  75. * The base path
  76. */
  77. public void setCodebase(String codebase) {
  78. if (codebase != getState().codebase || (codebase != null
  79. && !codebase.equals(getState().codebase))) {
  80. getState().codebase = codebase;
  81. requestRepaint();
  82. }
  83. }
  84. /**
  85. * Returns the codebase.
  86. *
  87. * @see #setCodebase(String)
  88. * @since 7.4.1
  89. * @return Current codebase.
  90. */
  91. public String getCodebase() {
  92. return getState(false).codebase;
  93. }
  94. /**
  95. * This attribute specifies the content type of data expected when
  96. * downloading the object specified by classid. This attribute is optional
  97. * but recommended when classid is specified since it allows the user agent
  98. * to avoid loading information for unsupported content types. When absent,
  99. * it defaults to the value of the type attribute.
  100. *
  101. * @param codetype
  102. * the codetype to set.
  103. */
  104. public void setCodetype(String codetype) {
  105. if (codetype != getState().codetype || (codetype != null
  106. && !codetype.equals(getState().codetype))) {
  107. getState().codetype = codetype;
  108. requestRepaint();
  109. }
  110. }
  111. /**
  112. * Returns the current codetype.
  113. *
  114. * @see #setCodetype(String)
  115. * @since 7.4.1
  116. * @return Current codetype.
  117. */
  118. public String getCodetype() {
  119. return getState(false).codetype;
  120. }
  121. /**
  122. * This attribute may be used to specify a space-separated list of URIs for
  123. * archives containing resources relevant to the object, which may include
  124. * the resources specified by the classid and data attributes. Preloading
  125. * archives will generally result in reduced load times for objects.
  126. * Archives specified as relative URIs should be interpreted relative to the
  127. * codebase attribute.
  128. *
  129. * @param archive
  130. * Space-separated list of URIs with resources relevant to the
  131. * object
  132. */
  133. public void setArchive(String archive) {
  134. if (archive != getState().archive
  135. || (archive != null && !archive.equals(getState().archive))) {
  136. getState().archive = archive;
  137. requestRepaint();
  138. }
  139. }
  140. /**
  141. * Returns current archive.
  142. *
  143. * @see #setArchive(String)
  144. * @since 7.4.1
  145. * @return Current archive.
  146. */
  147. public String getArchive() {
  148. return getState(false).archive;
  149. }
  150. /**
  151. * Sets standby.
  152. *
  153. * @param standby
  154. * Standby string.
  155. */
  156. public void setStandby(String standby) {
  157. if (standby != getState().standby
  158. || (standby != null && !standby.equals(getState().standby))) {
  159. getState().standby = standby;
  160. requestRepaint();
  161. }
  162. }
  163. /**
  164. * Returns standby.
  165. *
  166. * @since 7.4.1
  167. * @return Standby string.
  168. */
  169. public String getStandby() {
  170. return getState(false).standby;
  171. }
  172. /**
  173. * Sets an object parameter. Parameters are optional information, and they
  174. * are passed to the instantiated object. Parameters are are stored as name
  175. * value pairs. This overrides the previous value assigned to this
  176. * parameter.
  177. *
  178. * @param name
  179. * the name of the parameter.
  180. * @param value
  181. * the value of the parameter.
  182. */
  183. public void setParameter(String name, String value) {
  184. if (getState().embedParams == null) {
  185. getState().embedParams = new HashMap<>();
  186. }
  187. getState().embedParams.put(name, value);
  188. requestRepaint();
  189. }
  190. /**
  191. * Gets the value of an object parameter. Parameters are optional
  192. * information, and they are passed to the instantiated object. Parameters
  193. * are are stored as name value pairs.
  194. *
  195. * @return the Value of parameter or null if not found.
  196. */
  197. public String getParameter(String name) {
  198. return getState(false).embedParams != null
  199. ? getState(false).embedParams.get(name)
  200. : null;
  201. }
  202. /**
  203. * Removes an object parameter from the list.
  204. *
  205. * @param name
  206. * the name of the parameter to remove.
  207. */
  208. public void removeParameter(String name) {
  209. if (getState().embedParams == null) {
  210. return;
  211. }
  212. getState().embedParams.remove(name);
  213. requestRepaint();
  214. }
  215. @Override
  216. public void writeDesign(Element design, DesignContext designContext) {
  217. super.writeDesign(design, designContext);
  218. // Parameters, in alphabetic order
  219. List<String> paramNames = new ArrayList<>();
  220. for (String param : getParameterNames()) {
  221. paramNames.add(param);
  222. }
  223. Collections.sort(paramNames);
  224. for (String param : paramNames) {
  225. design.appendElement("parameter").attr("name", param).attr("value",
  226. getParameter(param));
  227. }
  228. }
  229. /**
  230. * Returns an iterable with declared parameter names.
  231. *
  232. * @see #setParameter(String, String)
  233. * @see #getParameter(String)
  234. * @since 7.4.1
  235. * @return An iterable with declared parameter names.
  236. */
  237. public Iterable<String> getParameterNames() {
  238. Map<String, String> map = getState(false).embedParams;
  239. if (map == null) {
  240. return Collections.emptySet();
  241. } else {
  242. return Collections.unmodifiableSet(map.keySet());
  243. }
  244. }
  245. @Override
  246. public void readDesign(Element design, DesignContext designContext) {
  247. super.readDesign(design, designContext);
  248. for (Element paramElement : design.getElementsByTag("parameter")) {
  249. setParameter(paramElement.attr("name"), paramElement.attr("value"));
  250. }
  251. }
  252. }