Skip to content

Instantly share code, notes, and snippets.

@dkandalov
Last active July 19, 2019 09:49
Show Gist options
  • Select an option

  • Save dkandalov/26db075b5d17977d4d02e4cc9ecf38be to your computer and use it in GitHub Desktop.

Select an option

Save dkandalov/26db075b5d17977d4d02e4cc9ecf38be to your computer and use it in GitHub Desktop.
Popup box with placeholder for video (to be used in IJ presentation mode when recording videos)
import com.intellij.concurrency.JobScheduler
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.Application
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.ui.popup.Balloon
import com.intellij.openapi.ui.popup.JBPopupFactory
import com.intellij.openapi.util.Disposer
import com.intellij.ui.Gray
import com.intellij.ui.LightColors
import com.intellij.ui.awt.RelativePoint
import com.intellij.ui.components.JBLabel
import com.intellij.util.ui.JBUI
import javax.swing.JLabel
import javax.swing.JPanel
import javax.swing.SwingUtilities
import javax.swing.text.Position
import java.awt.Color
import java.awt.Dimension
import java.awt.GridBagLayout
import java.awt.Point
import java.util.concurrent.ScheduledFuture
import java.util.concurrent.TimeUnit
import static liveplugin.PluginUtil.*
class PlaceholderBalloon implements Disposable {
private Balloon balloon
private ScheduledFuture schedule
def init() {
def label = new JBLabel("<html>Video placeholder<br/>Time: 00:00</html>")
def panel = new JPanel().with {
layout = new GridBagLayout()
def scale = 38 // Looks ok in full HD resolution.
it.setPreferredSize(new Dimension((16 * scale).toInteger(), (9 * scale).toInteger()))
it.background = LightColors.SLIGHTLY_GRAY
it.add(label)
it
}
balloon = JBPopupFactory.getInstance().createBalloonBuilder(panel)
.setFadeoutTime(0)
.setFillColor(Gray.TRANSPARENT)
.setShowCallout(false)
.setBorderColor(Gray.TRANSPARENT)
.setBorderInsets(JBUI.emptyInsets())
.setAnimationCycle(0)
.setCloseButtonEnabled(false)
.setHideOnClickOutside(false)
// .setDisposable(pluginDisposable)
.setHideOnFrameResize(false)
.setHideOnKeyOutside(false)
.setBlockClicksThroughBalloon(true)
.setHideOnAction(false)
.setShadow(false)
.createBalloon()
balloon.show(new RelativePoint(new Point(10_000, 0)), Balloon.Position.below)
def seconds = 0
schedule = JobScheduler.scheduler.scheduleWithFixedDelay({
invokeLaterOnEDT {
seconds++
def secondsString = (seconds % 60).toString()
if (secondsString.length() == 1) secondsString = "0" + secondsString
def minutesString = (seconds / 60).toInteger().toString()
if (minutesString.length() == 1) minutesString = "0" + minutesString
label.text = "<html>Video placeholder<br/>Time: $minutesString:$secondsString</html>"
}
}, 1000, 1000, TimeUnit.MILLISECONDS)
this
}
@Override void dispose() {
schedule.cancel(true)
Disposer.dispose(balloon)
}
}
registerAction("ShowBoxBalloon", "alt meta shift B", "Tools", "ShowBoxBalloon", pluginDisposable) {
changeGlobalVar("boxBalloon") { PlaceholderBalloon oldBalloon ->
if (oldBalloon == null) {
new PlaceholderBalloon().init()
} else {
Disposer.dispose(oldBalloon)
null
}
}
}
registerAction("ShowAndHideBoxBalloon", "alt meta shift PERIOD", "Tools", "ShowAndHideBoxBalloon", pluginDisposable) {
def panel = new JPanel()
panel.setPreferredSize(new Dimension(1, 1))
Balloon balloon = JBPopupFactory.getInstance().createBalloonBuilder(panel)
.setFadeoutTime(0)
.setFillColor(Gray.TRANSPARENT)
.setShowCallout(false)
.setBorderColor(Gray.TRANSPARENT)
.setBorderInsets(JBUI.emptyInsets())
.setAnimationCycle(0)
.setCloseButtonEnabled(false)
.setHideOnClickOutside(false)
.setDisposable(pluginDisposable)
.setHideOnFrameResize(false)
.setHideOnKeyOutside(false)
.setBlockClicksThroughBalloon(true)
.setHideOnAction(false)
.setShadow(false)
.createBalloon()
balloon.show(new RelativePoint(new Point(0, 0)), Balloon.Position.below)
SwingUtilities.invokeLater {
Disposer.dispose(balloon)
}
}
if (!isIdeStartup) show("reloaded ShowBoxBalloon")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment