use of javafx.scene.control.SplitPane in project Gargoyle by callakrsos.
the class DockPane method undock.
/**
* Detach the node from this dock pane removing it from the layout.
*
* @param node The node that is to be removed from this dock pane.
*/
public void undock(DockNode node) {
DockNodeEventHandler dockNodeEventHandler = dockNodeEventFilters.get(node);
node.removeEventFilter(DockEvent.DOCK_OVER, dockNodeEventHandler);
dockNodeEventFilters.remove(node);
// depth first search to find the parent of the node
Stack<Parent> findStack = new Stack<Parent>();
findStack.push((Parent) root);
while (!findStack.isEmpty()) {
Parent parent = findStack.pop();
ObservableList<Node> children = parent.getChildrenUnmodifiable();
if (parent instanceof SplitPane) {
SplitPane split = (SplitPane) parent;
children = split.getItems();
}
for (int i = 0; i < children.size(); i++) {
if (children.get(i) == node) {
children.remove(i);
// start from the root again and remove any SplitPane's with no children in them
Stack<Parent> clearStack = new Stack<Parent>();
clearStack.push((Parent) root);
while (!clearStack.isEmpty()) {
parent = clearStack.pop();
children = parent.getChildrenUnmodifiable();
if (parent instanceof SplitPane) {
SplitPane split = (SplitPane) parent;
children = split.getItems();
}
for (i = 0; i < children.size(); i++) {
if (children.get(i) instanceof SplitPane) {
SplitPane split = (SplitPane) children.get(i);
if (split.getItems().size() < 1) {
children.remove(i);
continue;
} else {
clearStack.push(split);
}
}
}
}
return;
} else if (children.get(i) instanceof Parent) {
findStack.push((Parent) children.get(i));
}
}
}
}
use of javafx.scene.control.SplitPane in project Gargoyle by callakrsos.
the class DockPane method dock.
/**
* Dock the node into this dock pane at the given docking position relative to the sibling in the
* layout. This is used to relatively position the dock nodes to other nodes given their preferred
* size.
*
* @param node The node that is to be docked into this dock pane.
* @param dockPos The docking position of the node relative to the sibling.
* @param sibling The sibling of this node in the layout.
*/
public void dock(Node node, DockPos dockPos, Node sibling) {
DockNodeEventHandler dockNodeEventHandler = new DockNodeEventHandler(node);
dockNodeEventFilters.put(node, dockNodeEventHandler);
node.addEventFilter(DockEvent.DOCK_OVER, dockNodeEventHandler);
SplitPane split = (SplitPane) root;
if (split == null) {
split = new SplitPane();
split.getItems().add(node);
root = split;
this.getChildren().add(root);
return;
}
// find the parent of the sibling
if (sibling != null && sibling != root) {
Stack<Parent> stack = new Stack<Parent>();
stack.push((Parent) root);
while (!stack.isEmpty()) {
Parent parent = stack.pop();
ObservableList<Node> children = parent.getChildrenUnmodifiable();
if (parent instanceof SplitPane) {
SplitPane splitPane = (SplitPane) parent;
children = splitPane.getItems();
}
for (int i = 0; i < children.size(); i++) {
if (children.get(i) == sibling) {
split = (SplitPane) parent;
} else if (children.get(i) instanceof Parent) {
stack.push((Parent) children.get(i));
}
}
}
}
Orientation requestedOrientation = (dockPos == DockPos.LEFT || dockPos == DockPos.RIGHT) ? Orientation.HORIZONTAL : Orientation.VERTICAL;
// if the orientation is different then reparent the split pane
if (split.getOrientation() != requestedOrientation) {
if (split.getItems().size() > 1) {
SplitPane splitPane = new SplitPane();
if (split == root && sibling == root) {
this.getChildren().set(this.getChildren().indexOf(root), splitPane);
splitPane.getItems().add(split);
root = splitPane;
} else {
split.getItems().set(split.getItems().indexOf(sibling), splitPane);
splitPane.getItems().add(sibling);
}
split = splitPane;
}
split.setOrientation(requestedOrientation);
}
// finally dock the node to the correct split pane
ObservableList<Node> splitItems = split.getItems();
double magnitude = 0;
if (splitItems.size() > 0) {
if (split.getOrientation() == Orientation.HORIZONTAL) {
for (Node splitItem : splitItems) {
magnitude += splitItem.prefWidth(0);
}
} else {
for (Node splitItem : splitItems) {
magnitude += splitItem.prefHeight(0);
}
}
}
if (dockPos == DockPos.LEFT || dockPos == DockPos.TOP) {
int relativeIndex = 0;
if (sibling != null && sibling != root) {
relativeIndex = splitItems.indexOf(sibling);
}
splitItems.add(relativeIndex, node);
if (splitItems.size() > 1) {
if (split.getOrientation() == Orientation.HORIZONTAL) {
split.setDividerPosition(relativeIndex, node.prefWidth(0) / (magnitude + node.prefWidth(0)));
} else {
split.setDividerPosition(relativeIndex, node.prefHeight(0) / (magnitude + node.prefHeight(0)));
}
}
} else if (dockPos == DockPos.RIGHT || dockPos == DockPos.BOTTOM) {
int relativeIndex = splitItems.size();
if (sibling != null && sibling != root) {
relativeIndex = splitItems.indexOf(sibling) + 1;
}
splitItems.add(relativeIndex, node);
if (splitItems.size() > 1) {
if (split.getOrientation() == Orientation.HORIZONTAL) {
split.setDividerPosition(relativeIndex - 1, 1 - node.prefWidth(0) / (magnitude + node.prefWidth(0)));
} else {
split.setDividerPosition(relativeIndex - 1, 1 - node.prefHeight(0) / (magnitude + node.prefHeight(0)));
}
}
}
}
use of javafx.scene.control.SplitPane in project Gargoyle by callakrsos.
the class WebViewConsole method init.
private void init() {
txtCommand = new TextArea();
txtResult = new TextArea();
btnExec = new Button(" Apply ");
SplitPane value = new SplitPane(txtResult, txtCommand);
value.setOrientation(Orientation.VERTICAL);
setCenter(value);
setBottom(btnExec);
btnExec.setOnMouseClicked(this::btnExecOnMouseClick);
txtCommand.setOnKeyPressed(this::txtCommandOnKeyClick);
}
Aggregations