|
| 1 | +package edu.wpi.axon.ui.component |
| 2 | + |
| 3 | +import com.github.mvysny.karibudsl.v10.VaadinDsl |
| 4 | +import com.github.mvysny.karibudsl.v10.init |
| 5 | +import com.vaadin.flow.component.Component |
| 6 | +import com.vaadin.flow.component.HasComponents |
| 7 | +import com.vaadin.flow.component.HasSize |
| 8 | +import com.vaadin.flow.component.HasStyle |
| 9 | +import com.vaadin.flow.component.Tag |
| 10 | +import com.vaadin.flow.dom.Element |
| 11 | +import com.vaadin.flow.server.InputStreamFactory |
| 12 | +import com.vaadin.flow.server.StreamResource |
| 13 | +import java.io.File |
| 14 | +import java.io.FileInputStream |
| 15 | + |
| 16 | +@Tag("video") |
| 17 | +class Video(file: File) : Component(), HasSize, HasStyle { |
| 18 | + private class Source(file: File) : Element("source") { |
| 19 | + init { |
| 20 | + setAttribute("src", StreamResource(file.name, InputStreamFactory { FileInputStream(file) })) |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + var controls: Boolean |
| 25 | + get() = element.hasAttribute("controls") |
| 26 | + set(value) { |
| 27 | + if (value) { |
| 28 | + element.setAttribute("controls", "") |
| 29 | + } else { |
| 30 | + element.removeAttribute("controls") |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + var volume: Double |
| 35 | + get() = element.getProperty("volume", 0.0) |
| 36 | + set(value) { element.setProperty("volume", value) } |
| 37 | + |
| 38 | + init { |
| 39 | + controls = true |
| 40 | + |
| 41 | + element.appendChild(Source(file)) |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +@VaadinDsl |
| 46 | +fun (@VaadinDsl HasComponents).video(file: File, block: (@VaadinDsl Video).() -> Unit = {}) = init(Video(file), block) |
0 commit comments