--- /dev/null
+package com.vaadin.terminal.gwt.client.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.vaadin.terminal.gwt.client.ComponentState;
+import com.vaadin.terminal.gwt.client.communication.URLReference;
+
+public class AbstractMediaState extends ComponentState {
+ private boolean showControls;
+
+ private String altText;
+
+ private boolean htmlContentAllowed;
+
+ private boolean autoplay;
+
+ private boolean muted;
+
+ private List<URLReference> sources = new ArrayList<URLReference>();
+ private List<String> sourceTypes = new ArrayList<String>();
+
+ public boolean isShowControls() {
+ return showControls;
+ }
+
+ public void setShowControls(boolean showControls) {
+ this.showControls = showControls;
+ }
+
+ public String getAltText() {
+ return altText;
+ }
+
+ public void setAltText(String altText) {
+ this.altText = altText;
+ }
+
+ public boolean isHtmlContentAllowed() {
+ return htmlContentAllowed;
+ }
+
+ public void setHtmlContentAllowed(boolean htmlContentAllowed) {
+ this.htmlContentAllowed = htmlContentAllowed;
+ }
+
+ public boolean isAutoplay() {
+ return autoplay;
+ }
+
+ public void setAutoplay(boolean autoplay) {
+ this.autoplay = autoplay;
+ }
+
+ public boolean isMuted() {
+ return muted;
+ }
+
+ public void setMuted(boolean muted) {
+ this.muted = muted;
+ }
+
+ public List<URLReference> getSources() {
+ return sources;
+ }
+
+ public void setSources(List<URLReference> sources) {
+ this.sources = sources;
+ }
+
+ public List<String> getSourceTypes() {
+ return sourceTypes;
+ }
+
+ public void setSourceTypes(List<String> sourceTypes) {
+ this.sourceTypes = sourceTypes;
+ }
+
+}
*/
package com.vaadin.terminal.gwt.client.ui;
-import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.Paintable;
-import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.communication.ClientRpc;
+import com.vaadin.terminal.gwt.client.communication.StateChangeEvent;
+import com.vaadin.terminal.gwt.client.communication.URLReference;
-public abstract class MediaBaseConnector extends AbstractComponentConnector
- implements Paintable {
-
- public static final String TAG_SOURCE = "src";
-
- 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 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 MediaBaseConnector extends AbstractComponentConnector {
/**
* Server to client RPC interface for controlling playback of the media.
});
}
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- if (!isRealUpdate(uidl)) {
- return;
- }
-
- getWidget().setControls(shouldShowControls(uidl));
- getWidget().setAutoplay(shouldAutoplay(uidl));
- getWidget().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())) {
- getWidget()
- .addSource(getSourceUrl(child), getSourceType(child));
- }
- }
- setAltText(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);
+ @Override
+ public AbstractMediaState getState() {
+ return (AbstractMediaState) super.getState();
}
- private boolean allowHtmlContent(UIDL uidl) {
- return uidl.getBooleanAttribute(ATTR_HTML);
+ @Override
+ public void onStateChanged(StateChangeEvent stateChangeEvent) {
+ super.onStateChanged(stateChangeEvent);
+
+ getWidget().setControls(getState().isShowControls());
+ getWidget().setAutoplay(getState().isAutoplay());
+ getWidget().setMuted(getState().isMuted());
+ for (int i = 0; i < getState().getSources().size(); i++) {
+ URLReference source = getState().getSources().get(i);
+ String sourceType = getState().getSourceTypes().get(i);
+ getWidget().addSource(source.getURL(), sourceType);
+ }
+ setAltText(getState().getAltText());
}
@Override
return (VMediaBase) super.getWidget();
}
- /**
- * @param uidl
- * @return the URL of a resource to be used as a source for the media
- */
- private String getSourceUrl(UIDL uidl) {
- String url = getConnection().translateVaadinUri(
- uidl.getStringAttribute(MediaBaseConnector.ATTR_RESOURCE));
- if (url == null) {
- return "";
+ private void setAltText(String altText) {
+
+ if (altText == null || "".equals(altText)) {
+ altText = getDefaultAltHtml();
+ } else if (!getState().isHtmlContentAllowed()) {
+ altText = Util.escapeHTML(altText);
}
- return url;
+ getWidget().setAltText(altText);
}
/**
- * @param uidl
- * @return the mime type of the media
+ * @return the default HTML to show users with browsers that do not support
+ * HTML5 media markup.
*/
- private String getSourceType(UIDL uidl) {
- return uidl.getStringAttribute(MediaBaseConnector.ATTR_RESOURCE_TYPE);
- }
-
- private void setAltText(UIDL uidl) {
- String alt = uidl.getStringAttribute(MediaBaseConnector.ATTR_ALT_TEXT);
-
- if (alt == null || "".equals(alt)) {
- alt = getWidget().getDefaultAltHtml();
- } else if (!allowHtmlContent(uidl)) {
- alt = Util.escapeHTML(alt);
- }
- getWidget().setAltText(alt);
- }
+ protected abstract String getDefaultAltHtml();
}
media = element;
}
- /**
- * @return the default HTML to show users with browsers that do not support
- * HTML5 media markup.
- */
- protected abstract String getDefaultAltHtml();
-
public void play() {
media.play();
}
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;
+import com.vaadin.terminal.gwt.client.communication.StateChangeEvent;
import com.vaadin.terminal.gwt.client.ui.Connect;
import com.vaadin.terminal.gwt.client.ui.MediaBaseConnector;
import com.vaadin.ui.Audio;
public class AudioConnector extends MediaBaseConnector {
@Override
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- super.updateFromUIDL(uidl, client);
- if (!isRealUpdate(uidl)) {
- return;
- }
+ public void onStateChanged(StateChangeEvent stateChangeEvent) {
+ super.onStateChanged(stateChangeEvent);
+
Style style = getWidget().getElement().getStyle();
// Make sure that the controls are not clipped if visible.
- if (shouldShowControls(uidl)
+ if (getState().isShowControls()
&& (style.getHeight() == null || "".equals(style.getHeight()))) {
if (BrowserInfo.get().isChrome()) {
style.setHeight(32, Unit.PX);
return GWT.create(VAudio.class);
}
+ @Override
+ protected String getDefaultAltHtml() {
+ return "Your browser does not support the <code>audio</code> element.";
+ }
}
setStyleName(CLASSNAME);
}
- @Override
- protected String getDefaultAltHtml() {
- return "Your browser does not support the <code>audio</code> element.";
- }
-
}
Util.notifyParentOfSizeChange(this, true);
}
- @Override
- protected String getDefaultAltHtml() {
- return "Your browser does not support the <code>video</code> element.";
- }
-
public void setPoster(String poster) {
video.setPoster(poster);
}
import com.google.gwt.core.client.GWT;
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.communication.StateChangeEvent;
+import com.vaadin.terminal.gwt.client.communication.URLReference;
import com.vaadin.terminal.gwt.client.ui.Connect;
import com.vaadin.terminal.gwt.client.ui.MediaBaseConnector;
import com.vaadin.ui.Video;
@Connect(Video.class)
public class VideoConnector extends MediaBaseConnector {
- public static final String ATTR_POSTER = "poster";
@Override
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- super.updateFromUIDL(uidl, client);
- if (!isRealUpdate(uidl)) {
- return;
- }
- super.updateFromUIDL(uidl, client);
- setPosterFromUIDL(uidl);
+ public VideoState getState() {
+ return (VideoState) super.getState();
}
- private void setPosterFromUIDL(UIDL uidl) {
- if (uidl.hasAttribute(ATTR_POSTER)) {
- getWidget().setPoster(
- getConnection().translateVaadinUri(
- uidl.getStringAttribute(ATTR_POSTER)));
+ @Override
+ public void onStateChanged(StateChangeEvent stateChangeEvent) {
+ super.onStateChanged(stateChangeEvent);
+ URLReference poster = getState().getPoster();
+ if (poster != null) {
+ getWidget().setPoster(poster.getURL());
+ } else {
+ getWidget().setPoster(null);
}
}
return GWT.create(VVideo.class);
}
+ @Override
+ protected String getDefaultAltHtml() {
+ return "Your browser does not support the <code>video</code> element.";
+ }
+
}
--- /dev/null
+package com.vaadin.terminal.gwt.client.ui.video;
+
+import com.vaadin.terminal.gwt.client.communication.URLReference;
+import com.vaadin.terminal.gwt.client.ui.AbstractMediaState;
+
+public class VideoState extends AbstractMediaState {
+ private URLReference poster;
+
+ public URLReference getPoster() {
+ return poster;
+ }
+
+ public void setPoster(URLReference poster) {
+ this.poster = poster;
+ }
+
+}
package com.vaadin.ui;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
-import java.util.Map;
-import com.vaadin.terminal.PaintException;
-import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.Resource;
-import com.vaadin.terminal.Vaadin6Component;
-import com.vaadin.terminal.gwt.client.ui.MediaBaseConnector;
+import com.vaadin.terminal.gwt.client.communication.URLReference;
+import com.vaadin.terminal.gwt.client.ui.AbstractMediaState;
import com.vaadin.terminal.gwt.client.ui.MediaBaseConnector.MediaControl;
+import com.vaadin.terminal.gwt.server.ResourceReference;
/**
* Abstract base class for the HTML5 media components.
*
* @author Vaadin Ltd
*/
-public class AbstractMedia extends AbstractComponent implements
- Vaadin6Component {
+public class AbstractMedia extends AbstractComponent {
- private List<Resource> sources = new ArrayList<Resource>();
-
- private boolean showControls;
-
- private String altText;
-
- private boolean htmlContentAllowed;
-
- private boolean autoplay;
-
- private boolean muted;
+ @Override
+ public AbstractMediaState getState() {
+ return (AbstractMediaState) super.getState();
+ }
/**
* Sets a single media file as the source of the media component.
* @param source
*/
public void setSource(Resource source) {
- sources.clear();
+ clearSources();
+
addSource(source);
}
+ private void clearSources() {
+ getState().getSources().clear();
+ getState().getSourceTypes().clear();
+ }
+
/**
* Adds an alternative media file to the sources list. Which of the sources
* is used is selected by the browser depending on which file formats it
*/
public void addSource(Resource source) {
if (source != null) {
- sources.add(source);
+ getState().getSources().add(new ResourceReference(source));
+ getState().getSourceTypes().add(source.getMIMEType());
requestRepaint();
}
}
* @param sources
*/
public void setSources(Resource... sources) {
- this.sources.addAll(Arrays.asList(sources));
- requestRepaint();
+ clearSources();
+ for (Resource source : sources) {
+ addSource(source);
+ }
}
/**
* @return The sources pointed to in this media.
*/
public List<Resource> getSources() {
- return Collections.unmodifiableList(sources);
+ ArrayList<Resource> sources = new ArrayList<Resource>();
+ for (URLReference ref : getState().getSources()) {
+ sources.add(((ResourceReference) ref).getResource());
+ }
+ return sources;
}
/**
* @param showControls
*/
public void setShowControls(boolean showControls) {
- this.showControls = showControls;
+ getState().setShowControls(showControls);
requestRepaint();
}
* @return true if the browser is to show native media controls.
*/
public boolean isShowControls() {
- return showControls;
+ return getState().isShowControls();
}
/**
* "https://developer.mozilla.org/En/Using_audio_and_video_in_Firefox#Using_Flash"
* >Mozilla Developer Network</a> for details.
*
- * @param text
+ * @param altText
*/
- public void setAltText(String text) {
- altText = text;
+ public void setAltText(String altText) {
+ getState().setAltText(altText);
requestRepaint();
}
* HTML5.
*/
public String getAltText() {
- return altText;
+ return getState().getAltText();
}
/**
* @param htmlContentAllowed
*/
public void setHtmlContentAllowed(boolean htmlContentAllowed) {
- this.htmlContentAllowed = htmlContentAllowed;
+ getState().setHtmlContentAllowed(htmlContentAllowed);
requestRepaint();
}
* be rendered as HTML.
*/
public boolean isHtmlContentAllowed() {
- return htmlContentAllowed;
+ return getState().isHtmlContentAllowed();
}
/**
* @param autoplay
*/
public void setAutoplay(boolean autoplay) {
- this.autoplay = autoplay;
+ getState().setAutoplay(autoplay);
requestRepaint();
}
* @return true if the media is set to automatically start playback.
*/
public boolean isAutoplay() {
- return autoplay;
+ return getState().isAutoplay();
}
/**
* @param muted
*/
public void setMuted(boolean muted) {
- this.muted = muted;
+ getState().setMuted(muted);
requestRepaint();
}
* @return true if the audio is muted.
*/
public boolean isMuted() {
- return muted;
+ return getState().isMuted();
}
/**
getRpcProxy(MediaControl.class).play();
}
- public void paintContent(PaintTarget target) throws PaintException {
- target.addAttribute(MediaBaseConnector.ATTR_CONTROLS, isShowControls());
- if (getAltText() != null) {
- target.addAttribute(MediaBaseConnector.ATTR_ALT_TEXT, getAltText());
- }
- target.addAttribute(MediaBaseConnector.ATTR_HTML,
- isHtmlContentAllowed());
- target.addAttribute(MediaBaseConnector.ATTR_AUTOPLAY, isAutoplay());
- for (Resource r : getSources()) {
- target.startTag(MediaBaseConnector.TAG_SOURCE);
- target.addAttribute(MediaBaseConnector.ATTR_RESOURCE, r);
- target.addAttribute(MediaBaseConnector.ATTR_RESOURCE_TYPE,
- r.getMIMEType());
- target.endTag(MediaBaseConnector.TAG_SOURCE);
- }
- target.addAttribute(MediaBaseConnector.ATTR_MUTED, isMuted());
- }
-
- public void changeVariables(Object source, Map<String, Object> variables) {
- // TODO Remove once Vaadin6Component is no longer implemented
- }
}
package com.vaadin.ui;
-import com.vaadin.terminal.PaintException;
-import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.Resource;
-import com.vaadin.terminal.gwt.client.ui.video.VideoConnector;
+import com.vaadin.terminal.gwt.client.ui.video.VideoState;
+import com.vaadin.terminal.gwt.server.ResourceReference;
/**
* The Video component translates into an HTML5 <video> element and as
*/
public class Video extends AbstractMedia {
- private Resource poster;
+ @Override
+ public VideoState getState() {
+ return (VideoState) super.getState();
+ }
public Video() {
this("", null);
* @param poster
*/
public void setPoster(Resource poster) {
- this.poster = poster;
+ getState().setPoster(new ResourceReference(poster));
+ requestRepaint();
}
/**
* @return The poster image.
*/
public Resource getPoster() {
- return poster;
+ return ((ResourceReference) getState().getPoster()).getResource();
}
- @Override
- public void paintContent(PaintTarget target) throws PaintException {
- super.paintContent(target);
- if (getPoster() != null) {
- target.addAttribute(VideoConnector.ATTR_POSTER, getPoster());
- }
- }
}