001/*
002 * #%L
003 * GwtMaterial
004 * %%
005 * Copyright (C) 2015 - 2017 GwtMaterialDesign
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 * 
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 * 
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020package gwt.material.design.client.ui;
021
022import com.google.gwt.dom.client.Document;
023import com.google.gwt.user.client.ui.Frame;
024import gwt.material.design.client.base.AbstractValueWidget;
025import gwt.material.design.client.base.MaterialWidget;
026import gwt.material.design.client.constants.CssName;
027
028//@formatter:off
029
030/**
031 * Material Video get any youtube url that will inherit responsive design
032 *
033 * <p>
034 * <p>
035 * <h3>UiBinder Usage:</h3>
036 * <pre>
037 * {@code
038 *     <m:MaterialVideo url="someurl" />
039 * }
040 * </pre>
041 * </p>
042 *
043 * @author kevzlou7979
044 * @author Ben Dol
045 *
046 * @see <a href="http://gwtmaterialdesign.github.io/gwt-material-demo/#media">Material Video</a>
047 */
048//@formatter:on
049public class MaterialVideo extends AbstractValueWidget<String> {
050
051    private Frame frame = new Frame();
052
053    public MaterialVideo() {
054        super(Document.get().createDivElement(), CssName.VIDEO_CONTAINER);
055    }
056
057    public MaterialVideo(String url) {
058        this();
059        setUrl(url);
060    }
061
062    @Override
063    protected void onLoad() {
064        super.onLoad();
065
066        add(frame);
067    }
068
069    public String getUrl() {
070        return getValue();
071    }
072
073    public void setUrl(String url) {
074        setValue(url, true);
075    }
076
077    /**
078     * @param fullscreen the fullscreen to set.
079     */
080    public void setFullscreen(boolean fullscreen) {
081        frame.getElement().setAttribute("allowfullscreen", String.valueOf(fullscreen));
082    }
083
084    @Override
085    public void setValue(String value, boolean fireEvents) {
086        frame.setUrl(value);
087        super.setValue(value, fireEvents);
088    }
089
090    @Override
091    public String getValue() {
092        return frame.getUrl();
093    }
094}