SnapFX coordinates the logical model (DockGraph), rendering layer,
drag-and-drop integration, floating windows, sidebars, and layout persistence.
Typical usage:
SnapFX snapFX = new SnapFX();
snapFX.dock(new TextArea("Editor"), "Editor");
snapFX.dock(new TextArea("Console"), "Console");
Scene scene = new Scene(snapFX.buildLayout(), 1200, 800);
stage.setScene(scene);
snapFX.initialize(stage);
stage.show();
-
Constructor Summary
ConstructorsConstructorDescriptionSnapFX()Creates a new SnapFX instance with default services, callbacks, and shortcut/theme configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoidattachFloatingWindow(DockFloatingWindow floatingWindow) Attaches a floating window back into the main layout.javafx.scene.ParentBuilds the visual representation of the current dock layout.voidclearShortcut(DockShortcutAction action) Removes the key binding for a shortcut action.voidProgrammatically requests a close action for a DockNode.voidcloseFloatingWindows(boolean attachBack) Closes all currently open floating windows.voidcollapsePinnedSideBar(javafx.geometry.Side side) Collapses the sidebar panel for the given side back to icon-strip mode.Simple API to dock a node with a title.dock(javafx.scene.Node content, String title, DockElement target, DockPosition position) Docks a node at a specific position relative to a target.voiddock(DockNode node, DockElement target, DockPosition position) Docks an existing DockNode at a specific position.Moves an existing DockNode into an external floating window.Moves an existing DockNode into an external floating window at a screen position.Returns all built-in theme names in deterministic order.Returns all built-in themes as an ordered map ofthemeName -> stylesheetResourcePath.Returns the close-button mode used by layout views.Returns the configured default close behavior.static StringReturns the built-in default theme name.static StringReturns the default classpath stylesheet used by SnapFX.Returns the underlying dock graph model.intReturns the number of dock nodes with the given logical dock-node ID.Returns the drag service used by this SnapFX instance.Returns the current drop-zone visualization mode.Returns the current global pin-button mode.Returns lock-mode behavior for floating pin controls.javafx.collections.ObservableList<DockFloatingWindow> Returns all currently open floating windows.doubleReturns the configured floating-window snap distance in pixels.Returns the configured floating-window snap targets.javafx.collections.ObservableList<DockNode> Returns the observable list of currently hidden nodes.Returns the layout engine used by this SnapFX instance.javafx.geometry.SidegetPinnedSide(DockNode node) Returns the sidebar side of the node, ornullif the node is not pinned.javafx.stage.StageReturns the primary stage last passed toinitialize(Stage).javafx.scene.input.KeyCombinationgetShortcut(DockShortcutAction action) Returns the configured key binding for a shortcut action.Map<DockShortcutAction, javafx.scene.input.KeyCombination> Returns a snapshot of all currently configured shortcut bindings.Returns the current framework sidebar rendering mode.javafx.collections.ObservableList<DockNode> getSideBarNodes(javafx.geometry.Side side) Returns the read-only list of pinned sidebar nodes for the given side.doublegetSideBarPanelWidth(javafx.geometry.Side side) Returns the preferred sidebar panel width for the given side.Returns the currently configured stylesheet resource path or absolute URL.Returns the title-bar mode used by layout views.voidHides a DockNode (removes from layout but keeps in memory for restore).voidinitialize(javafx.stage.Stage stage) Initializes SnapFX with the primary stage.booleanReturns whether user pin toggling is enabled in floating title bars.booleanReturns whether clicking the active side-bar icon collapses a pinned-open side panel.booleanReturns the default always-on-top state for newly created floating windows.booleanReturns whether floating-window snapping is enabled.booleanisLocked()Returns whether layout mutations are currently locked.booleanisPinnedToSideBar(DockNode node) Returns whether the node is currently pinned to any sidebar.booleanisSideBarPinnedOpen(javafx.geometry.Side side) Returns whether the sidebar panel for the given side is currently pinned-open (layout-consuming).voidloadLayout(String json) Loads a layout from JSON.voidpinOpenSideBar(javafx.geometry.Side side) Opens the sidebar panel for the given side in pinned (layout-consuming) mode.voidpinToSideBar(DockNode node, javafx.geometry.Side side) Pins a dock node into a sidebar on the given side.voidRemoves a DockNode from layout/floating windows without adding it to the hidden list.voidRestores the default framework shortcut mapping.voidRestores a hidden DockNode back to the layout.voidrestoreFromSideBar(DockNode node) Restores a pinned sidebar node back to the main layout.Saves the current layout as JSON.voidsetAllowFloatingPinToggle(boolean allowPinToggle) Enables or disables user pin toggling in floating title bars.voidSets the close-button mode used by layout views.voidsetCollapsePinnedSideBarOnActiveIconClick(boolean collapsePinnedSideBarOnActiveIconClick) Controls whether clicking the active side-bar icon collapses a pinned-open side panel.voidsetDefaultCloseBehavior(DockCloseBehavior defaultCloseBehavior) Sets the default close behavior for close requests.voidsetDefaultFloatingAlwaysOnTop(boolean defaultAlwaysOnTop) Sets the default always-on-top state for newly created floating windows.voidSets the drop-zone visualization mode during drag operations.voidControls pin-button visibility behavior for all floating windows.voidSets lock-mode behavior for pin controls in floating windows.voidsetFloatingWindowAlwaysOnTop(DockFloatingWindow floatingWindow, boolean alwaysOnTop) Sets always-on-top for an open floating window.voidsetFloatingWindowSnapDistance(double pixels) Sets the snap distance in pixels used for floating-window drag snapping.voidsetFloatingWindowSnappingEnabled(boolean enabled) Enables or disables floating-window snapping while title bars are dragged.voidConfigures which targets are used for floating-window snapping.voidsetLocked(boolean locked) Locks or unlocks the layout (disables drag & drop when locked).voidsetNodeFactory(DockNodeFactory factory) Sets the factory used to create DockNodes when loading layouts.voidsetOnCloseHandled(Consumer<DockCloseResult> handler) Sets the callback invoked after close handling is resolved.voidSets the close-request decision callback.voidSets callback for floating pin-state changes.booleansetRootSplitRatios(double... paneRatios) Sets the pane ratios of the root split pane.voidsetShortcut(DockShortcutAction action, javafx.scene.input.KeyCombination keyCombination) Assigns or removes a key binding for a built-in shortcut action.voidControls framework sidebar rendering and sidebar move action availability.voidsetSideBarPanelWidth(javafx.geometry.Side side, double width) Sets the preferred sidebar panel width for the given side.booleansetSplitRatios(DockSplitPane splitPane, double... paneRatios) Sets the pane ratios of a specific split pane.voidsetThemeStylesheet(String stylesheetResourcePath) Sets the stylesheet used by SnapFX and applies it immediately to the primary and floating window scenes.voidSets the title-bar mode used by layout views.voidRemoves a DockNode from the graph.
-
Constructor Details
-
SnapFX
public SnapFX()Creates a new SnapFX instance with default services, callbacks, and shortcut/theme configuration.
-
-
Method Details
-
initialize
public void initialize(javafx.stage.Stage stage) Initializes SnapFX with the primary stage. Also applies the currently configured framework stylesheet to the primary and floating scenes.- Parameters:
stage- primary application stage
-
getDefaultThemeName
Returns the built-in default theme name.- Returns:
- default theme name
-
getDefaultThemeStylesheetResourcePath
Returns the default classpath stylesheet used by SnapFX.- Returns:
- default stylesheet resource path
-
getAvailableThemeStylesheets
Returns all built-in themes as an ordered map ofthemeName -> stylesheetResourcePath.- Returns:
- ordered theme name to stylesheet path map
-
getAvailableThemeNames
Returns all built-in theme names in deterministic order.- Returns:
- ordered theme names
-
getThemeStylesheetResourcePath
Returns the currently configured stylesheet resource path or absolute URL.Classpath resources use paths like
/snapfx.css; external stylesheets keep their original URL.- Returns:
- configured stylesheet resource path or absolute URL
-
setThemeStylesheet
Sets the stylesheet used by SnapFX and applies it immediately to the primary and floating window scenes.Passing
nullor blank restores the default stylesheet (/snapfx.css).- Parameters:
stylesheetResourcePath- classpath resource path (for example/snapfx-dark.css) or an absolute stylesheet URL- Throws:
IllegalArgumentException- when the classpath resource cannot be resolved
-
dock
Simple API to dock a node with a title. Creates a DockNode and adds it to the root.- Parameters:
content- JavaFX node contenttitle- dock-node title- Returns:
- created and docked node
-
dock
public DockNode dock(javafx.scene.Node content, String title, DockElement target, DockPosition position) Docks a node at a specific position relative to a target.- Parameters:
content- JavaFX node contenttitle- dock-node titletarget- docking target elementposition- docking position relative to target- Returns:
- created and docked node
-
dock
Docks an existing DockNode at a specific position.- Parameters:
node- node to docktarget- docking target elementposition- docking position relative to target
-
undock
Removes a DockNode from the graph.- Parameters:
node- node to remove
-
buildLayout
public javafx.scene.Parent buildLayout()Builds the visual representation of the current dock layout. The returned Parent will automatically update when the model changes.- Returns:
- root layout container node
-
resetShortcutsToDefaults
public void resetShortcutsToDefaults()Restores the default framework shortcut mapping.Default bindings:
Ctrl+W:DockShortcutAction.CLOSE_ACTIVE_NODECtrl+Tab:DockShortcutAction.NEXT_TABCtrl+Shift+Tab:DockShortcutAction.PREVIOUS_TABEscape:DockShortcutAction.CANCEL_DRAGCtrl+Shift+P:DockShortcutAction.TOGGLE_ACTIVE_FLOATING_ALWAYS_ON_TOP
-
setShortcut
public void setShortcut(DockShortcutAction action, javafx.scene.input.KeyCombination keyCombination) Assigns or removes a key binding for a built-in shortcut action.- Parameters:
action- Shortcut action to configurekeyCombination- Key combination to assign, ornullto remove the binding
-
clearShortcut
Removes the key binding for a shortcut action.- Parameters:
action- shortcut action to clear
-
getShortcut
Returns the configured key binding for a shortcut action.- Parameters:
action- shortcut action to query- Returns:
- configured key combination, or
null
-
getShortcuts
Returns a snapshot of all currently configured shortcut bindings.- Returns:
- immutable snapshot of shortcut bindings
-
setLocked
public void setLocked(boolean locked) Locks or unlocks the layout (disables drag & drop when locked).- Parameters:
locked-trueto lock layout interactions
-
isLocked
public boolean isLocked()Returns whether layout mutations are currently locked.- Returns:
truewhen layout is locked
-
setNodeFactory
Sets the factory used to create DockNodes when loading layouts. This is required for proper persistence across application sessions.Example usage:
snapFX.setNodeFactory(nodeId -> switch(nodeId) { case "projectExplorer" -> createProjectExplorer(); case "mainEditor" -> createMainEditor(); default -> null; });- Parameters:
factory- Factory that creates nodes from their IDs
-
saveLayout
Saves the current layout as JSON.- Returns:
- serialized layout snapshot JSON
-
loadLayout
Loads a layout from JSON.- Parameters:
json- serialized layout snapshot JSON- Throws:
DockLayoutLoadException- if layout JSON is invalid or cannot be deserialized
-
hide
Hides a DockNode (removes from layout but keeps in memory for restore).- Parameters:
node- node to hide
-
remove
Removes a DockNode from layout/floating windows without adding it to the hidden list.- Parameters:
node- node to remove
-
close
Programmatically requests a close action for a DockNode. The request is processed using the configured close behavior and callbacks.- Parameters:
node- node to close
-
restore
Restores a hidden DockNode back to the layout.- Parameters:
node- node to restore
-
pinToSideBar
Pins a dock node into a sidebar on the given side.If the node is currently hidden, it is removed from the hidden list first. If it is inside a floating window, it is detached from that floating host before pinning.
Pinning keeps the target sidebar in its current pinned-open/collapsed state. New pinned entries are therefore collapsed by default unless the sidebar is explicitly opened with
pinOpenSideBar(Side).- Parameters:
node- node to pinside- target sidebar side
-
restoreFromSideBar
Restores a pinned sidebar node back to the main layout.Restore reuses the same remembered placement strategy used for floating-window attach operations: preferred anchor, neighbor anchors, then fallback docking.
- Parameters:
node- node to restore from sidebar
-
pinOpenSideBar
public void pinOpenSideBar(javafx.geometry.Side side) Opens the sidebar panel for the given side in pinned (layout-consuming) mode.- Parameters:
side- sidebar side
-
collapsePinnedSideBar
public void collapsePinnedSideBar(javafx.geometry.Side side) Collapses the sidebar panel for the given side back to icon-strip mode.- Parameters:
side- sidebar side
-
isSideBarPinnedOpen
public boolean isSideBarPinnedOpen(javafx.geometry.Side side) Returns whether the sidebar panel for the given side is currently pinned-open (layout-consuming).When
isCollapsePinnedSideBarOnActiveIconClick()is enabled, a pinned side panel can be temporarily collapsed via active-icon click while this method still returnstrue(pin mode preserved). The temporary collapsed/expanded state is managed as transient view state in SnapFX.- Parameters:
side- sidebar side- Returns:
truewhen sidebar is pinned-open
-
isCollapsePinnedSideBarOnActiveIconClick
public boolean isCollapsePinnedSideBarOnActiveIconClick()Returns whether clicking the active side-bar icon collapses a pinned-open side panel.When enabled (default), clicking the icon of the currently open pinned panel collapses the panel back to icon-strip mode. When disabled, the click keeps the pinned panel open.
- Returns:
truewhen active-icon click collapses pinned sidebars
-
setCollapsePinnedSideBarOnActiveIconClick
public void setCollapsePinnedSideBarOnActiveIconClick(boolean collapsePinnedSideBarOnActiveIconClick) Controls whether clicking the active side-bar icon collapses a pinned-open side panel.Default is
true.- Parameters:
collapsePinnedSideBarOnActiveIconClick- collapse policy flag
-
setSideBarMode
Controls framework sidebar rendering and sidebar move action availability.DockSideBarMode.AUTOis the default and renders sidebars only when they contain pinned nodes.DockSideBarMode.ALWAYSkeeps empty left/right strips visible, whileDockSideBarMode.NEVERdisables framework sidebar UI and built-in sidebar move context-menu actions.- Parameters:
mode- sidebar mode, defaults toDockSideBarMode.AUTOwhennull
-
getSideBarMode
Returns the current framework sidebar rendering mode.- Returns:
- current sidebar rendering mode
-
getSideBarPanelWidth
public double getSideBarPanelWidth(javafx.geometry.Side side) Returns the preferred sidebar panel width for the given side.The returned value is the persisted preference. Rendering may clamp the effective width depending on the current layout size.
- Parameters:
side- sidebar side- Returns:
- preferred panel width
-
setSideBarPanelWidth
public void setSideBarPanelWidth(javafx.geometry.Side side, double width) Sets the preferred sidebar panel width for the given side.The value is validated and clamped to the current SnapFX sidebar width policy. The effective rendered width may still be smaller on narrow scenes due to runtime clamping.
- Parameters:
side- sidebar sidewidth- preferred panel width
-
getSideBarNodes
Returns the read-only list of pinned sidebar nodes for the given side.- Parameters:
side- sidebar side- Returns:
- read-only pinned nodes for the side
-
isPinnedToSideBar
Returns whether the node is currently pinned to any sidebar.- Parameters:
node- node to check- Returns:
truewhen node is pinned in any sidebar
-
getPinnedSide
Returns the sidebar side of the node, ornullif the node is not pinned.- Parameters:
node- node to check- Returns:
- pinned side, or
null
-
floatNode
Moves an existing DockNode into an external floating window.- Parameters:
node- node to float- Returns:
- created or reused floating window, or
nullwhen node isnull
-
floatNode
Moves an existing DockNode into an external floating window at a screen position. The screen coordinates can be on any monitor.Before detaching a node from its current host (main layout or another floating window), SnapFX captures placement anchors so
attachFloatingWindow(DockFloatingWindow)can restore the node as close as possible to its previous location later.- Parameters:
node- node to floatscreenX- optional preferred floating x-positionscreenY- optional preferred floating y-position- Returns:
- created or reused floating window, or
nullwhen node isnull
-
attachFloatingWindow
Attaches a floating window back into the main layout.Attach uses a best-effort placement restore strategy per node:
- Try remembered exact target/position/tab-index in the original host.
- Try remembered previous/next-neighbor anchors from the original host.
- If anchors are missing but the original floating host is still active, dock into that host.
- If the original floating host no longer exists, skip it and continue with main-layout fallback.
- If nothing is restorable, dock into the main layout without interruption.
No dialogs are shown for restore failures; attach is always resolved via fallback.
- Parameters:
floatingWindow- floating window to attach back
-
getFloatingWindows
Returns all currently open floating windows. (read-only)- Returns:
- read-only list of floating windows
-
closeFloatingWindows
public void closeFloatingWindows(boolean attachBack) Closes all currently open floating windows.- Parameters:
attachBack- whether floating nodes should be attached back to the main layout
-
getHiddenNodes
Returns the observable list of currently hidden nodes.- Returns:
- hidden-node list
-
getDockGraph
Returns the underlying dock graph model.- Returns:
- dock graph
-
getLayoutEngine
Returns the layout engine used by this SnapFX instance.- Returns:
- layout engine
-
getDragService
Returns the drag service used by this SnapFX instance.- Returns:
- drag service
-
setDropVisualizationMode
Sets the drop-zone visualization mode during drag operations.- Parameters:
mode- visualization mode
-
getDropVisualizationMode
Returns the current drop-zone visualization mode.- Returns:
- current drop visualization mode
-
setCloseButtonMode
Sets the close-button mode used by layout views.- Parameters:
mode- close-button mode
-
getCloseButtonMode
Returns the close-button mode used by layout views.- Returns:
- close-button mode
-
setTitleBarMode
Sets the title-bar mode used by layout views.- Parameters:
mode- title-bar mode
-
getTitleBarMode
Returns the title-bar mode used by layout views.- Returns:
- title-bar mode
-
getPrimaryStage
public javafx.stage.Stage getPrimaryStage()Returns the primary stage last passed toinitialize(Stage).- Returns:
- primary stage, or
null
-
setDefaultCloseBehavior
Sets the default close behavior for close requests.- Parameters:
defaultCloseBehavior- default close behavior
-
getDefaultCloseBehavior
Returns the configured default close behavior.- Returns:
- default close behavior
-
setOnCloseRequest
Sets the close-request decision callback.- Parameters:
handler- callback that decides close handling, ornull
-
setOnCloseHandled
Sets the callback invoked after close handling is resolved.- Parameters:
handler- close-handled callback, ornull
-
setFloatingPinButtonMode
Controls pin-button visibility behavior for all floating windows.- Parameters:
mode- global pin-button mode, defaults toDockFloatingPinButtonMode.AUTOwhennull
-
getFloatingPinButtonMode
Returns the current global pin-button mode.- Returns:
- current global pin-button mode
-
setDefaultFloatingAlwaysOnTop
public void setDefaultFloatingAlwaysOnTop(boolean defaultAlwaysOnTop) Sets the default always-on-top state for newly created floating windows.- Parameters:
defaultAlwaysOnTop- default always-on-top state for newly created floating windows
-
isDefaultFloatingAlwaysOnTop
public boolean isDefaultFloatingAlwaysOnTop()Returns the default always-on-top state for newly created floating windows.- Returns:
- default always-on-top state for new floating windows
-
setAllowFloatingPinToggle
public void setAllowFloatingPinToggle(boolean allowPinToggle) Enables or disables user pin toggling in floating title bars.- Parameters:
allowPinToggle-trueto allow user pin toggling
-
isAllowFloatingPinToggle
public boolean isAllowFloatingPinToggle()Returns whether user pin toggling is enabled in floating title bars.- Returns:
truewhen user pin toggling is enabled
-
setFloatingPinLockedBehavior
Sets lock-mode behavior for pin controls in floating windows.- Parameters:
behavior- pin behavior while layout is locked
-
getFloatingPinLockedBehavior
Returns lock-mode behavior for floating pin controls.- Returns:
- lock-mode behavior for floating pin controls
-
setFloatingWindowSnappingEnabled
public void setFloatingWindowSnappingEnabled(boolean enabled) Enables or disables floating-window snapping while title bars are dragged.- Parameters:
enabled-trueto enable snapping
-
isFloatingWindowSnappingEnabled
public boolean isFloatingWindowSnappingEnabled()Returns whether floating-window snapping is enabled.- Returns:
truewhen floating-window snapping is enabled
-
setFloatingWindowSnapDistance
public void setFloatingWindowSnapDistance(double pixels) Sets the snap distance in pixels used for floating-window drag snapping.- Parameters:
pixels- snap tolerance in pixels
-
getFloatingWindowSnapDistance
public double getFloatingWindowSnapDistance()Returns the configured floating-window snap distance in pixels.- Returns:
- floating-window snap distance in pixels
-
setFloatingWindowSnapTargets
Configures which targets are used for floating-window snapping.- Parameters:
targets- snapping targets,nullclears all targets
-
getFloatingWindowSnapTargets
Returns the configured floating-window snap targets.- Returns:
- immutable snapshot of configured snapping targets
-
setOnFloatingPinChanged
Sets callback for floating pin-state changes.- Parameters:
handler- callback for floating pin-state changes, ornull
-
setFloatingWindowAlwaysOnTop
Sets always-on-top for an open floating window.- Parameters:
floatingWindow- floating window to updatealwaysOnTop- target always-on-top state
-
getDockNodeCount
Returns the number of dock nodes with the given logical dock-node ID.- Parameters:
id- logical dock-node ID- Returns:
- number of matching nodes across layout and sidebars
-
setRootSplitRatios
public boolean setRootSplitRatios(double... paneRatios) Sets the pane ratios of the root split pane.Ratios are normalized automatically, so both
(0.25, 0.5, 0.25)and(25, 50, 25)are valid inputs.- Parameters:
paneRatios- Ratios for each pane of the root split pane- Returns:
trueif ratios were applied;falseif the root is not a split pane or if input validation failed
-
setSplitRatios
Sets the pane ratios of a specific split pane.The number of ratios must match the number of split children.
- Parameters:
splitPane- Split pane to configurepaneRatios- Ratios for each pane in the split pane- Returns:
trueif ratios were applied;falseif validation failed
-