videocapture.gui-util - Videocapture

Table of Contents

1 Namespace videocapture.gui-util

This namespace provides GUI helper functions to provide information to the user.

2 Messages

These functions show messages to the user to make him aware of background processes, progress and errors.

(s/def ::type #{:information :warning :error})

(def types {:information (Alert$AlertType/INFORMATION)
	    :warning (Alert$AlertType/WARNING)
	    :error (Alert$AlertType/ERROR)})

2.1 Notifications

Notifications are popups shown at the bottom center of the screen. They show shorter messages that do not need intervention by the user and disappear after a few seconds.

(defn notification
  "Shows a self-closing notification popup at the bottom center of the screen."
  [type title text]
  {:pre [(s/valid? ::type type) (string? title) (string? text)]}
  (debug title text)
  (fx/run-later (let [note (.. Notifications
			       create
			       (title title)
			       (text text)
			       hideCloseButton
			       (position Pos/BOTTOM_CENTER))]
		  (case type
		    :information (.showInformation note)
		    :error (.showError note)))))

2.2 Alerts

Alerts are classic dialog boxes that block progress until the user intervenes.

(defn alert [type title text]
  {:pre [(s/valid? ::type type) (string? title) (string? text)]}
  (debug text)
  (fx/run-now (let [alertbox (new Alert (type types))]
		(.setTitle alertbox title)
		(.setResizable alertbox true)
		(.setContentText alertbox text)
		(.setMinHeight (.getDialogPane alertbox) Region/USE_PREF_SIZE)
		(.setMinWidth (.getDialogPane alertbox) Region/USE_PREF_SIZE)
		(.. alertbox getDialogPane getScene getWindow sizeToScene)
		(.showAndWait alertbox))))

3 Masking Pane

(defn unmask [instance]
  (fx/run-now (.setMouseTransparent (.-maskerPane instance) true)
	      (.setOpacity (.-maskerPane instance) 0)))

(defn mask [instance & [text]] 
  (fx/run-now (.setMouseTransparent (.-maskerPane instance) false)
	      (.setText (.-maskerPane instance) (or text "Bitte warten..."))
	      (.setOpacity (.-maskerPane instance) 1)))

4 Complete namespace definition

(ns videocapture.gui-util
  (:require [clojurefx.clojurefx :as fx]
	    [clojure.core.async :as async :refer [go chan >! <!]]
	    [taoensso.timbre :as timbre
	     :refer [log trace debug info warn error fatal report
		     logf tracef debugf infof warnf errorf fatalf reportf
		     spy get-env]]
	    [clojure.spec.alpha :as s])
  (:import (javafx.scene.control Alert$AlertType Alert)
	   (javafx.geometry Pos)
	   (org.controlsfx.control Notifications)
	   (javafx.scene.layout Region)))

<<types>>

<<notifications>>

<<alerts>>

<<masking-pane>>

Author: Daniel Ziltener

Created: 2019-06-21 Fr 16:22

Validate