use of javafx.scene.Node 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.Node 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.Node in project Gargoyle by callakrsos.
the class DockTitleBar method pickEventTarget.
/**
* Traverse the scene graph for all open stages and pick an event target for
* a dock event based on the location. Once the event target is chosen run
* the event task with the target and the previous target of the last dock
* event if one is cached. If an event target is not found fire the explicit
* dock event on the stage root if one is provided.
*
* @param location
* The location of the dock event in screen coordinates.
* @param eventTask
* The event task to be run when the event target is found.
* @param explicit
* The explicit event to be fired on the stage root when no event
* target is found.
*/
private void pickEventTarget(Point2D location, EventTask eventTask, Event explicit) {
// 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());
// fire the dock over event for the active stages
for (Stage targetStage : stages) {
// this continue behavior can be removed
if (targetStage == this.dockNode.getStage())
continue;
eventTask.reset();
Node dragNode = dragNodes.get(targetStage);
Parent root = targetStage.getScene().getRoot();
Stack<Parent> stack = new Stack<Parent>();
if (root.contains(root.screenToLocal(location.getX(), location.getY())) && !root.isMouseTransparent()) {
stack.push(root);
}
// that intersects the point of interest
while (!stack.isEmpty()) {
Parent parent = stack.pop();
// if this parent contains the mouse click in screen coordinates
// in its local bounds
// then traverse its children
boolean notFired = true;
for (Node node : parent.getChildrenUnmodifiable()) {
if (node.contains(node.screenToLocal(location.getX(), location.getY())) && !node.isMouseTransparent()) {
if (node instanceof Parent) {
stack.push((Parent) node);
} else {
eventTask.run(node, dragNode);
}
notFired = false;
break;
}
}
// fire it with the parent as the target to receive the event
if (notFired) {
eventTask.run(parent, dragNode);
}
}
if (explicit != null && dragNode != null && eventTask.getExecutions() < 1) {
Event.fireEvent(dragNode, explicit.copyFor(this, dragNode));
dragNodes.put(targetStage, null);
}
}
}
use of javafx.scene.Node in project Gargoyle by callakrsos.
the class AbstractGoogleTrendChart method action.
/**
* @작성자 : KYJ
* @작성일 : 2016. 11. 4.
*/
private void action() {
Line e = new Line();
e.getStyleClass().add("google-chart-flow-line");
e.setStyle("-fx-fill:gray");
e.setOpacity(0.3d);
// getChildren().add(e);
getPlotChildren().add(e);
Text label = new Text(" \n\n\n\n\n\n\n\n\n\n ");
// label.setStyle("-fx-fill:red");
// StackPane s = new StackPane(label);
VBox s = new VBox(label);
// s.getStyleClass().add("google-chart-guide-box");
// s.setStyle("-fx-background-color : green;");
s.setPrefSize(VBox.USE_COMPUTED_SIZE, VBox.USE_COMPUTED_SIZE);
s.setPadding(new Insets(10));
s.setBorder(new Border(new BorderStroke(Color.GREEN, BorderStrokeStyle.DASHED, CornerRadii.EMPTY, new BorderWidths(3d))));
s.setBackground(new Background(new BackgroundFill(Color.GREEN, CornerRadii.EMPTY, new Insets(5))));
getPlotChildren().add(s);
this.addEventHandler(MouseEvent.MOUSE_CLICKED, ev -> {
if (ev.getButton() == MouseButton.PRIMARY) {
List<Node> collect = lookupAll(".chart-line-symbol").stream().filter(v -> v != null).filter(n -> {
if (n instanceof StackPane) {
StackPane sp = (StackPane) n;
sp.setStyle(null);
if (e.intersects(n.getBoundsInParent())) {
sp.setStyle("-fx-background-color:green");
return true;
}
}
return false;
}).filter(v -> v.getUserData() != null).collect(Collectors.toList());
if (!collect.isEmpty()) {
GoogleTrendChartEvent intersectNodeClickEvent = new GoogleTrendChartEvent(this, GoogleTrendChartEvent.NULL_SOURCE_TARGET, GoogleTrendChartEvent.GOOGLE_CHART_INTERSECT_NODE_CLICK, ev.getX(), ev.getY(), ev.getScreenX(), ev.getScreenY(), null, ev.getClickCount(), collect);
Event.fireEvent(this, intersectNodeClickEvent);
}
}
});
this.addEventHandler(MouseEvent.MOUSE_MOVED, ev -> {
double sceneX = Math.abs(getYAxis().getLayoutX() + getYAxis().getWidth() - ev.getX() - getYAxis().getPadding().getLeft() - getYAxis().getPadding().getRight() - getYAxis().getInsets().getLeft() - getYAxis().getInsets().getRight());
e.setStartX(sceneX);
e.setStartY(0d);
e.setEndX(sceneX);
e.setEndY(this.getHeight());
Optional<String> reduce = lookupAll(".chart-line-symbol").stream().filter(v -> v != null).filter(n -> {
if (n instanceof StackPane) {
StackPane sp = (StackPane) n;
sp.setStyle(null);
if (e.intersects(n.getBoundsInParent())) {
sp.setStyle("-fx-background-color:green");
return true;
}
}
return false;
}).filter(v -> v.getUserData() != null).map(v -> v.getUserData().toString()).reduce((a, b) -> {
return a + "\n" + b;
});
if (reduce.isPresent()) {
label.setText(reduce.get());
s.setOpacity(1d);
if ((label.getBoundsInParent().getWidth() + label.getBoundsInParent().getMaxX() + sceneX) > this.getWidth()) {
s.setLayoutX(sceneX - label.getBoundsInParent().getWidth() - label.getBoundsInParent().getMinX());
} else {
s.setLayoutX(sceneX);
}
if ((label.getBoundsInParent().getMaxY() + label.getBoundsInLocal().getHeight() + ev.getSceneY()) > getYAxis().getBoundsInParent().getMaxY()) {
s.setLayoutY(getYAxis().getBoundsInParent().getMaxY() - label.getBoundsInLocal().getHeight() - label.getBoundsInParent().getMaxY());
} else {
s.setLayoutY(ev.getY());
}
} else
s.setOpacity(0.3d);
});
}
use of javafx.scene.Node in project Gargoyle by callakrsos.
the class AttachedTextValuePieChart method layoutChartChildren.
/* (non-Javadoc)
* @see javafx.scene.chart.PieChart#layoutChartChildren(double, double, double, double)
*/
@Override
protected void layoutChartChildren(double top, double left, double contentWidth, double contentHeight) {
if (getLabelsVisible()) {
getData().forEach(d -> {
if (tooltipConverter != null || customAction != null) {
d.getNode().lookupAll(".chart-pie").stream().forEach(v -> {
if (tooltipConverter != null)
FxUtil.installTooltip(v, tooltipConverter.toString(d));
if (customAction != null) {
customAction.accept(d, v);
}
});
}
if (labelConverter != null) {
Optional<Node> opTextNode = this.lookupAll(".chart-pie-label").stream().filter(n -> n instanceof Text && ((Text) n).getText().contains(d.getName())).findAny();
if (opTextNode.isPresent()) {
Text text = (Text) opTextNode.get();
text.setText(labelConverter.toString(d));
}
}
});
// Legend legend = (Legend) getLegend();
// legend.getItems().forEach(item->{
//
// item.
//
// });
// if (isLegendVisible() && seriesLegendLabelCustomAction != null) {
// this.lookupAll(".chart-legend-item").stream().forEach(v -> {
// System.out.println(v);
// });
// }
}
super.layoutChartChildren(top, left, contentWidth, contentHeight);
}
Aggregations