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.

Flash.java 8.0KB

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