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.

MediaBaseConnector.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.client.ui;
  5. import com.vaadin.shared.communication.URLReference;
  6. import com.vaadin.shared.ui.AbstractMediaState;
  7. import com.vaadin.shared.ui.MediaControl;
  8. import com.vaadin.terminal.gwt.client.Util;
  9. import com.vaadin.terminal.gwt.client.communication.StateChangeEvent;
  10. public abstract class MediaBaseConnector extends AbstractComponentConnector {
  11. @Override
  12. protected void init() {
  13. super.init();
  14. registerRpc(MediaControl.class, new MediaControl() {
  15. @Override
  16. public void play() {
  17. getWidget().play();
  18. }
  19. @Override
  20. public void pause() {
  21. getWidget().pause();
  22. }
  23. });
  24. }
  25. @Override
  26. public AbstractMediaState getState() {
  27. return (AbstractMediaState) super.getState();
  28. }
  29. @Override
  30. public void onStateChanged(StateChangeEvent stateChangeEvent) {
  31. super.onStateChanged(stateChangeEvent);
  32. getWidget().setControls(getState().isShowControls());
  33. getWidget().setAutoplay(getState().isAutoplay());
  34. getWidget().setMuted(getState().isMuted());
  35. for (int i = 0; i < getState().getSources().size(); i++) {
  36. URLReference source = getState().getSources().get(i);
  37. String sourceType = getState().getSourceTypes().get(i);
  38. getWidget().addSource(source.getURL(), sourceType);
  39. }
  40. setAltText(getState().getAltText());
  41. }
  42. @Override
  43. public VMediaBase getWidget() {
  44. return (VMediaBase) super.getWidget();
  45. }
  46. private void setAltText(String altText) {
  47. if (altText == null || "".equals(altText)) {
  48. altText = getDefaultAltHtml();
  49. } else if (!getState().isHtmlContentAllowed()) {
  50. altText = Util.escapeHTML(altText);
  51. }
  52. getWidget().setAltText(altText);
  53. }
  54. /**
  55. * @return the default HTML to show users with browsers that do not support
  56. * HTML5 media markup.
  57. */
  58. protected abstract String getDefaultAltHtml();
  59. }