Search in sources :

Example 16 with Shape

use of javafx.scene.shape.Shape in project TestFX by TestFX.

the class BoundsQueryUtilsTest method setupShape.

private static void setupShape() {
    // nodeBounds()
    shape = new Rectangle(0, 0, SHAPE_WIDTH, 0);
    // nodeBoundsInLocal()
    shape.setClip(new Rectangle(0, 0, CLIP_WIDTH, 0));
    // nodeBoundsInParent()
    shape.getTransforms().add(new Translate(TRANSLATE_X, 0));
    // nodeBounds()
    Shape altShape = new Rectangle(0, 0, SHAPE_WIDTH, 0);
    altShape.setFill(Color.GREEN);
    altShape.setStroke(Color.BLACK);
    altShape.setStrokeType(StrokeType.OUTSIDE);
    // nodeBounds(), nodeBoundsInParent()
    altShape.setStrokeWidth(5);
    // nodeBoundsInLocal()
    altShape.setEffect(new BoxBlur(10, 10, 1));
}
Also used : Shape(javafx.scene.shape.Shape) Rectangle(javafx.scene.shape.Rectangle) Translate(javafx.scene.transform.Translate) BoxBlur(javafx.scene.effect.BoxBlur)

Example 17 with Shape

use of javafx.scene.shape.Shape in project JFoenix by jfoenixadmin.

the class JFXRippler method getMask.

// methods that can be changed by extending the rippler class
/**
 * generate the clipping mask
 *
 * @return the mask node
 */
protected Node getMask() {
    double borderWidth = ripplerPane.getBorder() != null ? ripplerPane.getBorder().getInsets().getTop() : 0;
    Bounds bounds = control.getBoundsInParent();
    double width = control.getLayoutBounds().getWidth();
    double height = control.getLayoutBounds().getHeight();
    double diffMinX = Math.abs(control.getBoundsInLocal().getMinX() - control.getLayoutBounds().getMinX());
    double diffMinY = Math.abs(control.getBoundsInLocal().getMinY() - control.getLayoutBounds().getMinY());
    double diffMaxX = Math.abs(control.getBoundsInLocal().getMaxX() - control.getLayoutBounds().getMaxX());
    double diffMaxY = Math.abs(control.getBoundsInLocal().getMaxY() - control.getLayoutBounds().getMaxY());
    Node mask;
    switch(getMaskType()) {
        case RECT:
            mask = new Rectangle(bounds.getMinX() + diffMinX - snappedLeftInset(), bounds.getMinY() + diffMinY - snappedTopInset(), width - 2 * borderWidth, // -0.1 to prevent resizing the anchor pane
            height - 2 * borderWidth);
            break;
        case CIRCLE:
            double radius = Math.min((width / 2) - 2 * borderWidth, (height / 2) - 2 * borderWidth);
            mask = new Circle((bounds.getMinX() + diffMinX + bounds.getMaxX() - diffMaxX) / 2 - snappedLeftInset(), (bounds.getMinY() + diffMinY + bounds.getMaxY() - diffMaxY) / 2 - snappedTopInset(), radius, Color.BLUE);
            break;
        case FIT:
            mask = new Region();
            if (control instanceof Shape) {
                ((Region) mask).setShape((Shape) control);
            } else if (control instanceof Region) {
                ((Region) mask).setShape(((Region) control).getShape());
                JFXNodeUtils.updateBackground(((Region) control).getBackground(), (Region) mask);
            }
            mask.resize(width, height);
            mask.relocate(bounds.getMinX() + diffMinX, bounds.getMinY() + diffMinY);
            break;
        default:
            mask = new Rectangle(bounds.getMinX() + diffMinX - snappedLeftInset(), bounds.getMinY() + diffMinY - snappedTopInset(), width - 2 * borderWidth, // -0.1 to prevent resizing the anchor pane
            height - 2 * borderWidth);
            break;
    }
    return mask;
}
Also used : Circle(javafx.scene.shape.Circle) Shape(javafx.scene.shape.Shape) Bounds(javafx.geometry.Bounds) Node(javafx.scene.Node) Rectangle(javafx.scene.shape.Rectangle) Region(javafx.scene.layout.Region)

Example 18 with Shape

use of javafx.scene.shape.Shape in project Malai by arnobl.

the class Pencil method configureBindings.

@Override
protected void configureBindings() {
    // A DnD interaction with the left button of the mouse will produce an AddShape command while interacting on the canvas.
    // A temporary view of the created shape is created and displayed by the canvas.
    // This view is removed at the end of the interaction.
    nodeBinder(new DnD(), i -> new AddShape(drawing, new MyRect(i.getSrcLocalPoint().getX(), i.getSrcLocalPoint().getY()))).on(canvas).first((i, c) -> canvas.setTmpShape(ViewFactory.INSTANCE.createViewShape(c.getShape()))).then((i, c) -> {
        final MyRect sh = (MyRect) c.getShape();
        sh.setWidth(i.getTgtLocalPoint().getX() - sh.getX());
        sh.setHeight(i.getTgtLocalPoint().getY() - sh.getY());
    }).when(i -> i.getButton() == MouseButton.PRIMARY).end((i, c) -> canvas.setTmpShape(null)).log(LogLevel.INTERACTION).strictStart().help(new AddRectHelpAnimation(learningPane, canvas)).bind();
    // A DnD interaction with the right button of the mouse moves the targeted shape.
    // To incrementally moves the shape, the DnD interaction has its parameter 'updateSrcOnUpdate' set to true:
    // At each interaction updates, the source point and object take the latest target point and object.
    // The DnD interaction can be stopped (aborted) by pressing the key 'ESC'. This cancels the ongoing command (that thus needs to be undoable).
    nodeBinder(new DnD(true, true), // In the command these binding are @autoUnbind to be unbound on their command termination.
    i -> {
        final MyShape sh = i.getSrcObject().map(o -> (MyShape) o.getUserData()).get();
        return new MoveShape(sh, Bindings.createDoubleBinding(() -> sh.getX() + (i.getTgtScenePoint().getX() - i.getSrcScenePoint().getX()), i.tgtScenePointProperty(), i.srcScenePointProperty()), Bindings.createDoubleBinding(() -> sh.getY() + (i.getTgtScenePoint().getY() - i.getSrcScenePoint().getY()), i.tgtScenePointProperty(), i.srcScenePointProperty()));
    }).on(canvas.getShapesPane().getChildren()).when(i -> i.getButton() == MouseButton.SECONDARY).exec().first((i, c) -> {
        // Required to grab the focus to get key events
        Platform.runLater(() -> i.getSrcObject().get().requestFocus());
        i.getSrcObject().get().setEffect(new DropShadow(20d, Color.BLACK));
    }).endOrCancel((i, c) -> i.getSrcObject().get().setEffect(null)).strictStart().help(new MoveRectHelpAnimation(learningPane, canvas)).throttle(40L).bind();
    // nodeBinder(new DnD(true, true), i -> new MoveShape(i.getSrcObject().map(o ->(MyShape) o.getUserData()).orElse(null))).
    // // The binding dynamically registers elements of the given observable list.
    // // When nodes are added to this list, these nodes register the binding.
    // // When nodes are removed from this list, their binding is cancelled.
    // // This permits to interact on nodes (here, shapes) that are dynamically added to/removed from the canvas.
    // on(canvas.getShapesPane().getChildren()).
    // then((i, c) -> c.setCoord(c.getShape().getX() + (i.getTgtScenePoint().getX() - i.getSrcScenePoint().getX()),
    // c.getShape().getY() + (i.getTgtScenePoint().getY() - i.getSrcScenePoint().getY()))).
    // when(i -> i.getButton() == MouseButton.SECONDARY).
    // // exec(true): this allows to execute the command each time the interaction updates (and 'when' is true).
    // exec(true).
    // first((i, c) -> {
    // // Required to grab the focus to get key events
    // Platform.runLater(() -> i.getSrcObject().get().requestFocus());
    // i.getSrcObject().get().setEffect(new DropShadow(20d, Color.BLACK));
    // }).
    // end((i, c) -> i.getSrcObject().get().setEffect(null)).
    // strictStart().
    // bind();
    /*
		 * A DnD on the colour picker produces ChangeCol commands when the target of the DnD is a shape
		 * (the shape we want to change the colour). The interim feedback changes the cursor during the DnD to show the dragged colour.
		 * Note that the feedback callback is not optimised here as the colour does not change during the DnD. The cursor
		 * should be changed in 'first'
		 */
    nodeBinder(new DnD(), i -> new ChangeColour(lineCol.getValue(), null)).on(lineCol).then((i, c) -> i.getTgtObject().map(view -> (MyShape) view.getUserData()).ifPresent(sh -> c.setShape(sh))).when(i -> i.getTgtObject().orElse(null) instanceof Shape).feedback(() -> lineCol.getScene().setCursor(new ColorCursor(lineCol.getValue()))).endOrCancel((a, i) -> lineCol.getScene().setCursor(Cursor.DEFAULT)).bind();
    /*
		 * A mouse pressure creates an anonymous command that simply shows a message in the console.
		 */
    anonCmdBinder(new Press(), () -> System.out.println("An example of the anonymous command.")).on(canvas).bind();
    /*
		 * A widget binding that execute a command asynchronously.
		 * Widgets and properties are provided to the binding to:
		 * show/hide the cancel button, provide widgets with information regarding the progress of the command execution.
		 */
    buttonBinder(Save::new).on(save).async(cancel, progressbar.progressProperty(), textProgress.textProperty()).bind();
}
Also used : Button(javafx.scene.control.Button) AddShape(org.malai.ex.draw.command.AddShape) Initializable(javafx.fxml.Initializable) MouseButton(javafx.scene.input.MouseButton) MyCanvas(org.malai.ex.draw.view.MyCanvas) MyDrawing(org.malai.ex.draw.model.MyDrawing) URL(java.net.URL) Bindings(javafx.beans.binding.Bindings) AddRectHelpAnimation(org.malai.ex.draw.learning.AddRectHelpAnimation) ProgressBar(javafx.scene.control.ProgressBar) MyRect(org.malai.ex.draw.model.MyRect) ResourceBundle(java.util.ResourceBundle) ListChangeListener(javafx.collections.ListChangeListener) MyShape(org.malai.ex.draw.model.MyShape) DnD(org.malai.javafx.interaction.library.DnD) Pane(javafx.scene.layout.Pane) Save(org.malai.ex.draw.command.Save) MoveRectHelpAnimation(org.malai.ex.draw.learning.MoveRectHelpAnimation) ColorPicker(javafx.scene.control.ColorPicker) LogLevel(org.malai.logging.LogLevel) Color(javafx.scene.paint.Color) Label(javafx.scene.control.Label) MoveShape(org.malai.ex.draw.command.MoveShape) ViewFactory(org.malai.ex.draw.view.ViewFactory) ChangeColour(org.malai.ex.draw.command.ChangeColour) JfxInstrument(org.malai.javafx.instrument.JfxInstrument) Group(javafx.scene.Group) Collectors(java.util.stream.Collectors) DropShadow(javafx.scene.effect.DropShadow) Objects(java.util.Objects) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) Cursor(javafx.scene.Cursor) Press(org.malai.javafx.interaction.library.Press) ColorCursor(org.malai.ex.util.ColorCursor) Shape(javafx.scene.shape.Shape) AddShape(org.malai.ex.draw.command.AddShape) MoveShape(org.malai.ex.draw.command.MoveShape) AddShape(org.malai.ex.draw.command.AddShape) MyShape(org.malai.ex.draw.model.MyShape) MoveShape(org.malai.ex.draw.command.MoveShape) Shape(javafx.scene.shape.Shape) MyRect(org.malai.ex.draw.model.MyRect) AddRectHelpAnimation(org.malai.ex.draw.learning.AddRectHelpAnimation) ChangeColour(org.malai.ex.draw.command.ChangeColour) MyShape(org.malai.ex.draw.model.MyShape) ColorCursor(org.malai.ex.util.ColorCursor) DropShadow(javafx.scene.effect.DropShadow) MoveRectHelpAnimation(org.malai.ex.draw.learning.MoveRectHelpAnimation) DnD(org.malai.javafx.interaction.library.DnD) Press(org.malai.javafx.interaction.library.Press)

Example 19 with Shape

use of javafx.scene.shape.Shape in project FXGL by AlmasB.

the class ParticleDigitsSample method initParticles.

private void initParticles() {
    // blur particle pane to smooth out edges
    var particlePane = new Pane();
    particlePane.setEffect(new BoxBlur(2, 2, 3));
    addUINode(particlePane);
    int max = 0;
    for (char c : DIGITS_STRING.toCharArray()) {
        // shape of each digit
        var text = getUIFactoryService().newText(c + "", Color.WHITE, 256);
        var digitPixels = toPixels(toImage(text)).stream().filter(p -> !p.getColor().equals(Color.TRANSPARENT)).collect(Collectors.toList());
        max = Math.max(max, digitPixels.size());
        digits.add(new ParticleDigit(digitPixels));
    }
    for (int i = 0; i < max; i++) {
        // shape of each particle
        var particle = new Circle(3, 3, 3, Color.WHITE);
        particles.add(particle);
        particlePane.getChildren().add(particle);
    }
}
Also used : Color(javafx.scene.paint.Color) CubicCurve(javafx.scene.shape.CubicCurve) Pixel(com.almasb.fxgl.texture.Pixel) IntegerProperty(javafx.beans.property.IntegerProperty) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ImagesKt.toPixels(com.almasb.fxgl.texture.ImagesKt.toPixels) Duration(javafx.util.Duration) List(java.util.List) BoxBlur(javafx.scene.effect.BoxBlur) Interpolators(com.almasb.fxgl.animation.Interpolators) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) GameSettings(com.almasb.fxgl.app.GameSettings) Point2D(javafx.geometry.Point2D) ImagesKt.toImage(com.almasb.fxgl.texture.ImagesKt.toImage) Circle(javafx.scene.shape.Circle) Comparator(java.util.Comparator) GameApplication(com.almasb.fxgl.app.GameApplication) Shape(javafx.scene.shape.Shape) FXGL(com.almasb.fxgl.dsl.FXGL) Pane(javafx.scene.layout.Pane) Circle(javafx.scene.shape.Circle) Pane(javafx.scene.layout.Pane) BoxBlur(javafx.scene.effect.BoxBlur)

Example 20 with Shape

use of javafx.scene.shape.Shape in project Gargoyle by callakrsos.

the class CheckBoxFxControlsTreeItem method createNode.

/**
	 * 파일 트리를 생성하기 위한 노드를 반환한다.
	 *
	 * @Date 2015. 10. 14.
	 * @param f
	 * @return
	 * @User KYJ
	 */
public TreeItem<Node> createNode(final Node f) {
    TreeItem<Node> treeItem = new CheckBoxTreeItem<Node>(f) {

        private boolean isLeaf;

        private boolean isFirstTimeChildren = true;

        private boolean isFirstTimeLeaf = true;

        @Override
        public ObservableList<TreeItem<Node>> getChildren() {
            if (isFirstTimeChildren) {
                isFirstTimeChildren = false;
                super.getChildren().setAll(buildChildren(this));
            }
            return super.getChildren();
        }

        @Override
        public boolean isLeaf() {
            if (isFirstTimeLeaf) {
                isFirstTimeLeaf = false;
                Node f = getValue();
                if (f == null) {
                    isLeaf = true;
                } else if (f instanceof Control) {
                    isLeaf = ((Control) f).getChildrenUnmodifiable().isEmpty();
                } else if (f instanceof Parent) {
                    isLeaf = ((Parent) f).getChildrenUnmodifiable().isEmpty();
                } else if (f instanceof Shape)
                    isLeaf = true;
                else
                    isLeaf = false;
            }
            return isLeaf;
        }

        private ObservableList<TreeItem<Node>> buildChildren(TreeItem<Node> treeItem) {
            Node f = treeItem.getValue();
            if (f == null) {
                return FXCollections.emptyObservableList();
            }
            treeItem.setGraphic(getImage(getName(f)));
            List<Node> childrens = getChildrens(f);
            if (childrens == null || childrens.isEmpty()) {
                return FXCollections.emptyObservableList();
            } else {
                ObservableList<TreeItem<Node>> children = FXCollections.observableArrayList();
                for (Node child : childrens) {
                    children.add(createNode(child));
                }
                return children;
            }
        }
    };
    treeItem.setGraphic(getImage(getName(f)));
    return treeItem;
}
Also used : Control(javafx.scene.control.Control) Shape(javafx.scene.shape.Shape) TreeItem(javafx.scene.control.TreeItem) CheckBoxTreeItem(javafx.scene.control.CheckBoxTreeItem) Parent(javafx.scene.Parent) CheckBoxTreeItem(javafx.scene.control.CheckBoxTreeItem) Node(javafx.scene.Node)

Aggregations

Shape (javafx.scene.shape.Shape)35 Rectangle (javafx.scene.shape.Rectangle)9 Node (javafx.scene.Node)8 Test (org.junit.Test)7 TimeGraphDrawnEventProvider (com.efficios.jabberwocky.views.timegraph.model.provider.drawnevents.TimeGraphDrawnEventProvider)6 Color (javafx.scene.paint.Color)6 Circle (javafx.scene.shape.Circle)6 StubDrawnEventProvider1 (org.lttng.scope.views.timeline.widgets.timegraph.StubDrawnEventProviders.StubDrawnEventProvider1)6 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Platform (javafx.application.Platform)4 Text (javafx.scene.text.Text)4 Bounds (javafx.geometry.Bounds)3 Parent (javafx.scene.Parent)3 URL (java.net.URL)2 ResourceBundle (java.util.ResourceBundle)2 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)2 FXML (javafx.fxml.FXML)2 Initializable (javafx.fxml.Initializable)2