Package limn.testing
Class HeadlessBackend
java.lang.Object
limn.testing.HeadlessBackend
- All Implemented Interfaces:
AutoCloseable,Backend,BackendPeer
A backend that mints
HeadlessWindows and remembers them, so that a dialog, a menu or a
popup which opens as a window of its own opens somewhere a test can read. Install it with a
HeadlessUi's runtime: new HeadlessBackend(ui.runtime()).
Modality is the two bits the toolkit asks a window about and nothing more: the modal's own bit and its owner's blocked bit, set and cleared exactly as a platform would.
-
Nested Class Summary
Nested classes/interfaces inherited from interface limn.backend.spi.BackendPeer
BackendPeer.SceneModalHandle -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Destroys all windows and releases native resources.booleanWhether the system's compositor casts a shadow around an undecorated window of this backend's (a menu, the list of a combo box, a dialog with no frame).createWindow(WindowConfig config) Creates (but does not necessarily show) a native window, as its peer.@Nullable LoopEndended()Opens the application's own window, the one a demo scene binds to.voidpopModal(NativeWindow modal) Removesmodalfrom the modal stack, releasing what it locked.voidpushModal(NativeWindow modal, @Nullable NativeWindow parent) Registersmodalas an active modal window and pushes it on the modal stack.pushSceneModal(NativeWindow owner, boolean toolkitScope) Registers an in-scene (overlay) modal hosted byowner.voidAsks the quit handler and then each window, front to back, as a desktop backend does.Runs the event/render loop on the calling (UI) thread.voidsetCompositorShadowsPopups(boolean casts) Says whether this backend's system casts a shadow around an undecorated window, which it does by default.voidsetLoopLifetime(LoopLifetime newLifetime) Sets how longBackend.runEventLoop()runs: until the last window closes (the default) or until the application ends it, which lets an application live with no window open.voidsetQuitHandler(@Nullable QuitHandler handler) Sets the handlerBackend.requestQuit()asks before any window, for what belongs to no window.voidsetSystemMenuBar(@Nullable SystemMenuBar bar) Gives this backend a menu bar outside its windows, which it has none of, for a test of what aMenuBardoes where the system keeps the bar: it is asked for the bar as a real backend is on such a system.voidGives the modal-blocked feedback (the alert sound plus a re-raise of the top modal) for an interaction the active modal ignores.voidstop()Asks the loop to exit.@Nullable SystemMenuBarThe menu bar the system keeps outside the windows, where it keeps one and the application may have it.windows()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface limn.backend.Backend
displays, graphicsInfo, primaryDisplay, render3DStats, renderStats, setApplicationNameMethods inherited from interface limn.backend.spi.BackendPeer
createTray
-
Constructor Details
-
HeadlessBackend
- Parameters:
runtime- the runtime the test installed, which is whatuiRuntime()answers
-
-
Method Details
-
setCompositorShadowsPopups
public void setCompositorShadowsPopups(boolean casts) Says whether this backend's system casts a shadow around an undecorated window, which it does by default. Told it does not, the toolkit makes such a window larger than its panel and draws the shadow in the margin, as on a desktop whose compositor casts none: what a test of a frameless dialog or popup on such a desktop sets first.- Parameters:
casts- whether the compositor casts the shadow
-
compositorShadowsPopups
public boolean compositorShadowsPopups()Description copied from interface:BackendWhether the system's compositor casts a shadow around an undecorated window of this backend's (a menu, the list of a combo box, a dialog with no frame). Where it does the toolkit draws none of its own, or there would be two; where it does not, the toolkit makes such a window larger than its panel and draws the shadow in the margin.- Specified by:
compositorShadowsPopupsin interfaceBackend- Returns:
true(the default) where the compositor casts it, and for a backend with no desktop under it, which then draws nothing extra
-
open
Opens the application's own window, the one a demo scene binds to.- Parameters:
title- what the window is called, which is the tree's root namewidth- logical widthheight- logical height- Returns:
- the window
-
windows
- Returns:
- every window this backend created that has not closed, in the order it created
them; a live view, whose iteration walks the windows there were when it began. A
window leaves it as it closes, so that a test is not what keeps a closed window, its
scene and what that scene held alive (a native popup's page looked leaked); a test
that needs a window after it closed keeps its own reference, which still answers
HeadlessWindow.isClosed()
-
uiRuntime
-
createWindow
Description copied from interface:BackendPeerCreates (but does not necessarily show) a native window, as its peer. UI thread only.- Specified by:
createWindowin interfaceBackend- Specified by:
createWindowin interfaceBackendPeer
-
ended
- Returns:
- why the application ended:
LoopEnd.QUITonce arequestQuit()was agreed to and every window closed, andnulluntil then. WhatrunEventLoop()would have returned, for a backend that has no loop.
-
runEventLoop
Description copied from interface:BackendRuns the event/render loop on the calling (UI) thread. Returns when the last window closes (underLoopLifetime.UNTIL_LAST_WINDOW), when aBackend.requestQuit()was agreed to and every window has closed, or whenBackend.stop()is invoked.- Specified by:
runEventLoopin interfaceBackend- Returns:
- why it returned
-
setLoopLifetime
Description copied from interface:BackendSets how longBackend.runEventLoop()runs: until the last window closes (the default) or until the application ends it, which lets an application live with no window open. UI thread only.- Specified by:
setLoopLifetimein interfaceBackend- Parameters:
newLifetime- the lifetime; nevernull
-
loopLifetime
- Specified by:
loopLifetimein interfaceBackend- Returns:
- how long
Backend.runEventLoop()runs;LoopLifetime.UNTIL_LAST_WINDOWunless set
-
requestQuit
public void requestQuit()Asks the quit handler and then each window, front to back, as a desktop backend does.- Specified by:
requestQuitin interfaceBackend
-
setQuitHandler
Description copied from interface:BackendSets the handlerBackend.requestQuit()asks before any window, for what belongs to no window.nullclears. UI thread only.- Specified by:
setQuitHandlerin interfaceBackend- Parameters:
handler- the handler, ornullfor none
-
setSystemMenuBar
Gives this backend a menu bar outside its windows, which it has none of, for a test of what aMenuBardoes where the system keeps the bar: it is asked for the bar as a real backend is on such a system.- Parameters:
bar- what answers for the system's bar, ornullfor none again
-
systemMenuBar
Description copied from interface:BackendPeerThe menu bar the system keeps outside the windows, where it keeps one and the application may have it.The default is the answer of every system but one:
null, and a menu bar is drawn in its window.- Specified by:
systemMenuBarin interfaceBackendPeer
-
pushModal
Description copied from interface:BackendPeerRegistersmodalas an active modal window and pushes it on the modal stack. Only the topmost modal receives input; every window it locks ignores input until it closes.Modality scope: a non-null
parentmakes it window-modal, so it locks onlyparent(andparent's owned popups), leaving unrelated windows interactive. Anullparent makes it toolkit-modal, so it locks every other window. Modals stack: with several open, only the top one is usable and the non-modal windows are released only after the whole modal stack closes. UI thread only.- Specified by:
pushModalin interfaceBackendPeer
-
popModal
Description copied from interface:BackendPeerRemovesmodalfrom the modal stack, releasing what it locked. UI thread only.- Specified by:
popModalin interfaceBackendPeer
-
pushSceneModal
Description copied from interface:BackendPeerRegisters an in-scene (overlay) modal hosted byowner. UnlikeBackendPeer.pushModal(limn.backend.NativeWindow, limn.backend.NativeWindow), there is no separate modal window: the overlay blocksowner's own content, soownerstays interactive, while this call blocks the same sibling windows a native modal would.toolkitScopetruelocks every other window;falselocks onlyowner's owned popups. Release the returned handle when the overlay closes. UI thread only.- Specified by:
pushSceneModalin interfaceBackendPeer
-
signalModalBlocked
public void signalModalBlocked()Description copied from interface:BackendPeerGives the modal-blocked feedback (the alert sound plus a re-raise of the top modal) for an interaction the active modal ignores. The backend already does this for clicks on blocked native windows; call it for an in-scene modal's scrim so internal and native modals feel identical. UI thread only.- Specified by:
signalModalBlockedin interfaceBackendPeer
-
stop
public void stop()Description copied from interface:BackendAsks the loop to exit. Safe to call from any thread. -
close
public void close()Description copied from interface:BackendDestroys all windows and releases native resources. UI thread only.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceBackend
-