Skip to content

Commit

Permalink
Java 9 StageHelper Replacement
Browse files Browse the repository at this point in the history
The ability to grab all stages was made private in Java 9 so I have to
improvise. My workaround for now is to just maintain a non-threadsafe
package-private statically-initialized list of all DockPanes to use for
scene graph traversal. This works because every Node, which DockPane is
a descendant of, knows its scene which in turn is aware of its stage.
  • Loading branch information
RobertBColton committed Feb 25, 2018
1 parent ce0cb6e commit 8d44134
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/dockfx/DockEvent.java
Expand Up @@ -30,7 +30,7 @@
import javafx.scene.input.PickResult;

/**
* Base class for DockFX events. Each DockFX event has associated an event source, event target and
* Base class for DockFX events. Each DockFX event has an associated event source, event target and
* an event type. The event source specifies for an event handler the object on which that handler
* has been registered and which sent the event to it. The event target defines the path through
* which the event will travel when posted. The event type provides additional classification to
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/dockfx/DockPane.java
Expand Up @@ -20,6 +20,8 @@

package org.dockfx;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

import com.sun.javafx.css.StyleManager;
Expand Down Expand Up @@ -53,6 +55,11 @@
* @since DockFX 0.1
*/
public class DockPane extends StackPane implements EventHandler<DockEvent> {
/**
* Package-private internal list of all DockPanes for event mouse picking.
*/
static List<DockPane> dockPanes = new ArrayList<DockPane>();

/**
* The current root node of this dock pane's layout.
*/
Expand Down Expand Up @@ -184,6 +191,7 @@ public final boolean isDockRoot() {
*/
public DockPane() {
super();
DockPane.dockPanes.add(this);

this.addEventHandler(DockEvent.ANY, this);
this.addEventFilter(DockEvent.ANY, new EventHandler<DockEvent>() {
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/org/dockfx/DockTitleBar.java
Expand Up @@ -21,6 +21,7 @@
package org.dockfx;

import java.util.HashMap;
import java.util.List;
import java.util.Stack;

import com.sun.javafx.stage.StageHelper;
Expand Down Expand Up @@ -230,10 +231,14 @@ private void pickEventTarget(Point2D location, EventTask eventTask, Event explic
// RFE for public scene graph traversal API filed but closed:
// https://bugs.openjdk.java.net/browse/JDK-8133331

ObservableList<Stage> stages =
FXCollections.unmodifiableObservableList(StageHelper.getStages());
List<DockPane> dockPanes = DockPane.dockPanes;

// fire the dock over event for the active stages
for (Stage targetStage : stages) {
for (DockPane dockPane : dockPanes) {
Window window = dockPane.getScene().getWindow();
if (!(window instanceof Stage)) continue;
Stage targetStage = (Stage) window;

// obviously this title bar does not need to receive its own events
// though users of this library may want to know when their
// dock node is being dragged by subclassing it or attaching
Expand Down

0 comments on commit 8d44134

Please sign in to comment.