Search in sources :

Example 96 with Node

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));
            }
        }
    }
}
Also used : Parent(javafx.scene.Parent) Node(javafx.scene.Node) SplitPane(javafx.scene.control.SplitPane) Stack(java.util.Stack)

Example 97 with Node

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)));
            }
        }
    }
}
Also used : Parent(javafx.scene.Parent) Node(javafx.scene.Node) SplitPane(javafx.scene.control.SplitPane) Orientation(javafx.geometry.Orientation) Stack(java.util.Stack)

Example 98 with Node

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);
        }
    }
}
Also used : Parent(javafx.scene.Parent) Node(javafx.scene.Node) Stage(javafx.stage.Stage) Stack(java.util.Stack)

Example 99 with Node

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);
    });
}
Also used : MouseButton(javafx.scene.input.MouseButton) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) MouseEvent(javafx.scene.input.MouseEvent) IGargoyleChartAdapter(com.kyj.fx.voeditor.visual.framework.adapter.IGargoyleChartAdapter) FXCollections(javafx.collections.FXCollections) StackPane(javafx.scene.layout.StackPane) VBox(javafx.scene.layout.VBox) LineChart(javafx.scene.chart.LineChart) Line(javafx.scene.shape.Line) Insets(javafx.geometry.Insets) BorderWidths(javafx.scene.layout.BorderWidths) BackgroundFill(javafx.scene.layout.BackgroundFill) Color(javafx.scene.paint.Color) ObjectProperty(javafx.beans.property.ObjectProperty) Node(javafx.scene.Node) Border(javafx.scene.layout.Border) Event(javafx.event.Event) Rectangle(javafx.scene.shape.Rectangle) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) CategoryAxis(javafx.scene.chart.CategoryAxis) Collectors(java.util.stream.Collectors) Background(javafx.scene.layout.Background) BorderStrokeStyle(javafx.scene.layout.BorderStrokeStyle) BorderStroke(javafx.scene.layout.BorderStroke) Platform(javafx.application.Platform) Text(javafx.scene.text.Text) List(java.util.List) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Optional(java.util.Optional) ObservableList(javafx.collections.ObservableList) NumberAxis(javafx.scene.chart.NumberAxis) StringProperty(javafx.beans.property.StringProperty) CornerRadii(javafx.scene.layout.CornerRadii) Insets(javafx.geometry.Insets) Background(javafx.scene.layout.Background) BackgroundFill(javafx.scene.layout.BackgroundFill) Node(javafx.scene.Node) Text(javafx.scene.text.Text) Line(javafx.scene.shape.Line) BorderWidths(javafx.scene.layout.BorderWidths) BorderStroke(javafx.scene.layout.BorderStroke) VBox(javafx.scene.layout.VBox) Border(javafx.scene.layout.Border) StackPane(javafx.scene.layout.StackPane)

Example 100 with Node

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);
}
Also used : Text(javafx.scene.text.Text) FxUtil(com.kyj.fx.voeditor.visual.util.FxUtil) PieChart(javafx.scene.chart.PieChart) Legend(com.sun.javafx.charts.Legend) Node(javafx.scene.Node) BiConsumer(java.util.function.BiConsumer) Optional(java.util.Optional) StringConverter(javafx.util.StringConverter) Node(javafx.scene.Node) Text(javafx.scene.text.Text)

Aggregations

Node (javafx.scene.Node)118 Label (javafx.scene.control.Label)18 Stage (javafx.stage.Stage)17 Parent (javafx.scene.Parent)16 Button (javafx.scene.control.Button)16 ArrayList (java.util.ArrayList)15 ObservableList (javafx.collections.ObservableList)14 FXML (javafx.fxml.FXML)14 List (java.util.List)12 BorderPane (javafx.scene.layout.BorderPane)12 HBox (javafx.scene.layout.HBox)11 IOException (java.io.IOException)10 Platform (javafx.application.Platform)10 Insets (javafx.geometry.Insets)10 Color (javafx.scene.paint.Color)10 FXCollections (javafx.collections.FXCollections)9 MouseEvent (javafx.scene.input.MouseEvent)9 VBox (javafx.scene.layout.VBox)9 FadeTransition (javafx.animation.FadeTransition)8 MenuItem (javafx.scene.control.MenuItem)8