import com.google.gwt.dom.client.AudioElement;
import com.google.gwt.dom.client.Document;
-import com.google.gwt.dom.client.Style;
-import com.google.gwt.dom.client.Style.Unit;
-import com.google.gwt.user.client.ui.Widget;
-import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.BrowserInfo;
-import com.vaadin.terminal.gwt.client.UIDL;
public class VAudio extends VMediaBase {
private static String CLASSNAME = "v-audio";
setStyleName(CLASSNAME);
}
- @Override
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- if (client.updateComponent(this, uidl, true)) {
- return;
- }
- super.updateFromUIDL(uidl, client);
- Style style = audio.getStyle();
-
- // Make sure that the controls are not clipped if visible.
- if (shouldShowControls(uidl)
- && (style.getHeight() == null || "".equals(style.getHeight()))) {
- if (BrowserInfo.get().isChrome()) {
- style.setHeight(32, Unit.PX);
- } else {
- style.setHeight(25, Unit.PX);
- }
- }
- }
-
@Override
protected String getDefaultAltHtml() {
return "Your browser does not support the <code>audio</code> element.";
}
- public Widget getWidgetForPaintable() {
- return this;
- }
-
}
--- /dev/null
+package com.vaadin.terminal.gwt.client.ui;\r
+\r
+import com.google.gwt.core.client.GWT;\r
+import com.google.gwt.dom.client.Style;\r
+import com.google.gwt.dom.client.Style.Unit;\r
+import com.google.gwt.user.client.ui.Widget;\r
+import com.vaadin.terminal.gwt.client.ApplicationConnection;\r
+import com.vaadin.terminal.gwt.client.BrowserInfo;\r
+import com.vaadin.terminal.gwt.client.UIDL;\r
+\r
+public class VAudioPaintable extends VMediaBasePaintable {\r
+\r
+ @Override\r
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
+ if (client.updateComponent(this, uidl, true)) {\r
+ return;\r
+ }\r
+ super.updateFromUIDL(uidl, client);\r
+ Style style = getWidgetForPaintable().getElement().getStyle();\r
+\r
+ // Make sure that the controls are not clipped if visible.\r
+ if (shouldShowControls(uidl)\r
+ && (style.getHeight() == null || "".equals(style.getHeight()))) {\r
+ if (BrowserInfo.get().isChrome()) {\r
+ style.setHeight(32, Unit.PX);\r
+ } else {\r
+ style.setHeight(25, Unit.PX);\r
+ }\r
+ }\r
+ }\r
+\r
+ @Override\r
+ protected Widget createWidget() {\r
+ return GWT.create(VAudio.class);\r
+ }\r
+\r
+}\r
import com.google.gwt.dom.client.MediaElement;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Widget;
-import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.VPaintableWidget;
-import com.vaadin.terminal.gwt.client.UIDL;
-import com.vaadin.terminal.gwt.client.Util;
-public abstract class VMediaBase extends Widget implements VPaintableWidget {
- public static final String ATTR_PAUSE = "pause";
- public static final String ATTR_PLAY = "play";
- public static final String ATTR_MUTED = "muted";
- public static final String ATTR_CONTROLS = "ctrl";
- public static final String ATTR_AUTOPLAY = "auto";
- public static final String TAG_SOURCE = "src";
- public static final String ATTR_RESOURCE = "res";
- public static final String ATTR_RESOURCE_TYPE = "type";
- public static final String ATTR_HTML = "html";
- public static final String ATTR_ALT_TEXT = "alt";
+public abstract class VMediaBase extends Widget {
private MediaElement media;
- protected ApplicationConnection client;
/**
* Sets the MediaElement that is to receive all commands and properties.
media = element;
}
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- if (client.updateComponent(this, uidl, true)) {
- return;
- }
-
- this.client = client;
-
- media.setControls(shouldShowControls(uidl));
- media.setAutoplay(shouldAutoplay(uidl));
- media.setMuted(isMediaMuted(uidl));
-
- // Add all sources
- for (int ix = 0; ix < uidl.getChildCount(); ix++) {
- UIDL child = uidl.getChildUIDL(ix);
- if (TAG_SOURCE.equals(child.getTag())) {
- Element src = Document.get().createElement("source").cast();
- src.setAttribute("src", getSourceUrl(child));
- src.setAttribute("type", getSourceType(child));
- media.appendChild(src);
- }
- }
- setAltText(uidl);
-
- evalPauseCommand(uidl);
- evalPlayCommand(uidl);
- }
-
- protected boolean shouldShowControls(UIDL uidl) {
- return uidl.getBooleanAttribute(ATTR_CONTROLS);
- }
-
- private boolean shouldAutoplay(UIDL uidl) {
- return uidl.getBooleanAttribute(ATTR_AUTOPLAY);
- }
-
- private boolean isMediaMuted(UIDL uidl) {
- return uidl.getBooleanAttribute(ATTR_MUTED);
- }
-
/**
- * @param uidl
- * @return the URL of a resource to be used as a source for the media
+ * @return the default HTML to show users with browsers that do not support
+ * HTML5 media markup.
*/
- private String getSourceUrl(UIDL uidl) {
- String url = client.translateVaadinUri(uidl
- .getStringAttribute(ATTR_RESOURCE));
- if (url == null) {
- return "";
- }
- return url;
- }
+ protected abstract String getDefaultAltHtml();
- /**
- * @param uidl
- * @return the mime type of the media
- */
- private String getSourceType(UIDL uidl) {
- return uidl.getStringAttribute(ATTR_RESOURCE_TYPE);
+ public void play() {
+ media.play();
}
- private void setAltText(UIDL uidl) {
- String alt = uidl.getStringAttribute(ATTR_ALT_TEXT);
+ public void pause() {
+ media.pause();
+ }
- if (alt == null || "".equals(alt)) {
- alt = getDefaultAltHtml();
- } else if (!allowHtmlContent(uidl)) {
- alt = Util.escapeHTML(alt);
- }
+ public void setAltText(String alt) {
media.appendChild(Document.get().createTextNode(alt));
}
- private boolean allowHtmlContent(UIDL uidl) {
- return uidl.getBooleanAttribute(ATTR_HTML);
+ public void setControls(boolean shouldShowControls) {
+ media.setControls(shouldShowControls);
}
- private void evalPlayCommand(UIDL uidl) {
- if (uidl.hasAttribute(ATTR_PLAY)) {
- media.play();
- }
+ public void setAutoplay(boolean shouldAutoplay) {
+ media.setAutoplay(shouldAutoplay);
}
- private void evalPauseCommand(UIDL uidl) {
- if (uidl.hasAttribute(ATTR_PAUSE)) {
- media.pause();
- }
+ public void setMuted(boolean mediaMuted) {
+ media.setMuted(mediaMuted);
}
- /**
- * @return the default HTML to show users with browsers that do not support
- * HTML5 media markup.
- */
- protected abstract String getDefaultAltHtml();
+ public void addSource(String sourceUrl, String sourceType) {
+ Element src = Document.get().createElement("source").cast();
+ src.setAttribute("src", sourceUrl);
+ src.setAttribute("type", sourceType);
+ media.appendChild(src);
+ }
}
--- /dev/null
+package com.vaadin.terminal.gwt.client.ui;\r
+\r
+import com.vaadin.terminal.gwt.client.ApplicationConnection;\r
+import com.vaadin.terminal.gwt.client.UIDL;\r
+import com.vaadin.terminal.gwt.client.Util;\r
+\r
+public abstract class VMediaBasePaintable extends VAbstractPaintableWidget {\r
+\r
+ public static final String TAG_SOURCE = "src";\r
+\r
+ public static final String ATTR_PAUSE = "pause";\r
+ public static final String ATTR_PLAY = "play";\r
+ public static final String ATTR_MUTED = "muted";\r
+ public static final String ATTR_CONTROLS = "ctrl";\r
+ public static final String ATTR_AUTOPLAY = "auto";\r
+ public static final String ATTR_RESOURCE = "res";\r
+ public static final String ATTR_RESOURCE_TYPE = "type";\r
+ public static final String ATTR_HTML = "html";\r
+ public static final String ATTR_ALT_TEXT = "alt";\r
+\r
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
+ if (client.updateComponent(this, uidl, true)) {\r
+ return;\r
+ }\r
+\r
+ getWidgetForPaintable().setControls(shouldShowControls(uidl));\r
+ getWidgetForPaintable().setAutoplay(shouldAutoplay(uidl));\r
+ getWidgetForPaintable().setMuted(isMediaMuted(uidl));\r
+\r
+ // Add all sources\r
+ for (int ix = 0; ix < uidl.getChildCount(); ix++) {\r
+ UIDL child = uidl.getChildUIDL(ix);\r
+ if (TAG_SOURCE.equals(child.getTag())) {\r
+ getWidgetForPaintable().addSource(getSourceUrl(child),\r
+ getSourceType(child));\r
+ }\r
+ }\r
+ setAltText(uidl);\r
+\r
+ evalPauseCommand(uidl);\r
+ evalPlayCommand(uidl);\r
+ }\r
+\r
+ protected boolean shouldShowControls(UIDL uidl) {\r
+ return uidl.getBooleanAttribute(ATTR_CONTROLS);\r
+ }\r
+\r
+ private boolean shouldAutoplay(UIDL uidl) {\r
+ return uidl.getBooleanAttribute(ATTR_AUTOPLAY);\r
+ }\r
+\r
+ private boolean isMediaMuted(UIDL uidl) {\r
+ return uidl.getBooleanAttribute(ATTR_MUTED);\r
+ }\r
+\r
+ private boolean allowHtmlContent(UIDL uidl) {\r
+ return uidl.getBooleanAttribute(ATTR_HTML);\r
+ }\r
+\r
+ private void evalPlayCommand(UIDL uidl) {\r
+ if (uidl.hasAttribute(ATTR_PLAY)) {\r
+ getWidgetForPaintable().play();\r
+ }\r
+ }\r
+\r
+ private void evalPauseCommand(UIDL uidl) {\r
+ if (uidl.hasAttribute(ATTR_PAUSE)) {\r
+ getWidgetForPaintable().pause();\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public VMediaBase getWidgetForPaintable() {\r
+ return (VMediaBase) super.getWidgetForPaintable();\r
+ }\r
+\r
+ /**\r
+ * @param uidl\r
+ * @return the URL of a resource to be used as a source for the media\r
+ */\r
+ private String getSourceUrl(UIDL uidl) {\r
+ String url = getConnection().translateVaadinUri(\r
+ uidl.getStringAttribute(VMediaBasePaintable.ATTR_RESOURCE));\r
+ if (url == null) {\r
+ return "";\r
+ }\r
+ return url;\r
+ }\r
+\r
+ /**\r
+ * @param uidl\r
+ * @return the mime type of the media\r
+ */\r
+ private String getSourceType(UIDL uidl) {\r
+ return uidl.getStringAttribute(VMediaBasePaintable.ATTR_RESOURCE_TYPE);\r
+ }\r
+\r
+ private void setAltText(UIDL uidl) {\r
+ String alt = uidl.getStringAttribute(VMediaBasePaintable.ATTR_ALT_TEXT);\r
+\r
+ if (alt == null || "".equals(alt)) {\r
+ alt = getWidgetForPaintable().getDefaultAltHtml();\r
+ } else if (!allowHtmlContent(uidl)) {\r
+ alt = Util.escapeHTML(alt);\r
+ }\r
+ getWidgetForPaintable().setAltText(alt);\r
+ }\r
+\r
+}\r
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.dom.client.VideoElement;
import com.google.gwt.user.client.Element;
-import com.google.gwt.user.client.ui.Widget;
-import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
public class VVideo extends VMediaBase {
- public static final String ATTR_POSTER = "poster";
private static String CLASSNAME = "v-video";
updateDimensionsWhenMetadataLoaded(getElement());
}
- @Override
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- if (client.updateComponent(this, uidl, true)) {
- return;
- }
- super.updateFromUIDL(uidl, client);
- setPosterFromUIDL(uidl);
- }
-
- private void setPosterFromUIDL(UIDL uidl) {
- if (uidl.hasAttribute(ATTR_POSTER)) {
- video.setPoster(client.translateVaadinUri(uidl
- .getStringAttribute(ATTR_POSTER)));
- }
- }
-
/**
* Registers a listener that updates the dimensions of the widget when the
* video metadata has been loaded.
return "Your browser does not support the <code>video</code> element.";
}
- public Widget getWidgetForPaintable() {
- return this;
+ public void setPoster(String poster) {
+ video.setPoster(poster);
}
+
}
--- /dev/null
+package com.vaadin.terminal.gwt.client.ui;\r
+\r
+import com.google.gwt.core.client.GWT;\r
+import com.google.gwt.user.client.ui.Widget;\r
+import com.vaadin.terminal.gwt.client.ApplicationConnection;\r
+import com.vaadin.terminal.gwt.client.UIDL;\r
+\r
+public class VVideoPaintable extends VMediaBasePaintable {\r
+ public static final String ATTR_POSTER = "poster";\r
+\r
+ @Override\r
+ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
+ if (client.updateComponent(this, uidl, true)) {\r
+ return;\r
+ }\r
+ super.updateFromUIDL(uidl, client);\r
+ setPosterFromUIDL(uidl);\r
+ }\r
+\r
+ private void setPosterFromUIDL(UIDL uidl) {\r
+ if (uidl.hasAttribute(ATTR_POSTER)) {\r
+ getWidgetForPaintable().setPoster(\r
+ getConnection().translateVaadinUri(\r
+ uidl.getStringAttribute(ATTR_POSTER)));\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public VVideo getWidgetForPaintable() {\r
+ return (VVideo) super.getWidgetForPaintable();\r
+ }\r
+\r
+ @Override\r
+ protected Widget createWidget() {\r
+ return GWT.create(VVideo.class);\r
+ }\r
+\r
+}\r