Search in sources :

Example 91 with Rectangle

use of javafx.scene.shape.Rectangle in project jphp by jphp-compiler.

the class GamePane method scrollTo.

public void scrollTo(double x, double y) {
    if (x < 0) {
        x = 0;
    }
    if (y < 0) {
        y = 0;
    }
    if (y > area.getPrefHeight() - getPrefHeight()) {
        y = area.getPrefHeight() - getPrefHeight();
    }
    if (x > area.getPrefWidth() - getPrefWidth()) {
        x = area.getWidth() - getPrefWidth();
    }
    area.setClip(new Rectangle(x, y, getPrefWidth(), getPrefHeight()));
    area.setLayoutX(-x);
    area.setLayoutY(-y);
    if (getOnScrollScene() != null) {
        getOnScrollScene().handle(new ActionEvent(this, this));
    }
}
Also used : ActionEvent(javafx.event.ActionEvent) Rectangle(javafx.scene.shape.Rectangle)

Example 92 with Rectangle

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

the class JFXListCell method layoutChildren.

@Override
protected void layoutChildren() {
    super.layoutChildren();
    cellRippler.resizeRelocate(0, 0, getWidth(), getHeight());
    double gap = getGap();
    if (clip == null) {
        clip = new Rectangle(0, gap / 2, getWidth(), getHeight() - gap);
        setClip(clip);
    } else {
        if (gap != 0) {
            if (playExpandAnimation || selectionChanged) {
                // fake list collapse state
                if (playExpandAnimation) {
                    this.setTranslateY(-gap / 2 + (-gap * (getIndex())));
                    clip.setY(gap / 2);
                    clip.setHeight(getHeight() - gap);
                    gapAnimation = new Timeline(new KeyFrame(Duration.millis(240), new KeyValue(this.translateYProperty(), 0, Interpolator.EASE_BOTH)));
                    playExpandAnimation = false;
                } else if (selectionChanged) {
                    clip.setY(0);
                    clip.setHeight(getHeight());
                    gapAnimation = new Timeline(new KeyFrame(Duration.millis(240), new KeyValue(clip.yProperty(), gap / 2, Interpolator.EASE_BOTH), new KeyValue(clip.heightProperty(), getHeight() - gap, Interpolator.EASE_BOTH)));
                }
                playExpandAnimation = false;
                selectionChanged = false;
                gapAnimation.play();
            } else {
                if (gapAnimation != null) {
                    gapAnimation.stop();
                }
                this.setTranslateY(0);
                clip.setY(gap / 2);
                clip.setHeight(getHeight() - gap);
            }
        } else {
            this.setTranslateY(0);
            clip.setY(0);
            clip.setHeight(getHeight());
        }
        clip.setX(0);
        clip.setWidth(getWidth());
    }
    if (!getChildren().contains(cellRippler)) {
        makeChildrenTransparent();
        getChildren().add(0, cellRippler);
        cellRippler.rippler.clear();
    }
    // refresh sublist style class
    if (this.getGraphic() != null && this.getGraphic().getStyleClass().contains("sublist-container")) {
        this.getStyleClass().add("sublist-item");
    } else {
        this.getStyleClass().remove("sublist-item");
    }
}
Also used : Timeline(javafx.animation.Timeline) KeyValue(javafx.animation.KeyValue) Rectangle(javafx.scene.shape.Rectangle) KeyFrame(javafx.animation.KeyFrame)

Example 93 with Rectangle

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

the class JFXDecorator method initializeContainers.

private void initializeContainers(Node node, boolean fullScreen, boolean max, boolean min) {
    buttonsContainer = new HBox();
    buttonsContainer.getStyleClass().add("jfx-decorator-buttons-container");
    buttonsContainer.setBackground(new Background(new BackgroundFill(Color.BLACK, CornerRadii.EMPTY, Insets.EMPTY)));
    // BINDING
    buttonsContainer.setPadding(new Insets(4));
    buttonsContainer.setAlignment(Pos.CENTER_RIGHT);
    // customize decorator buttons
    List<JFXButton> btns = new ArrayList<>();
    if (fullScreen) {
        btns.add(btnFull);
    }
    if (min) {
        btns.add(btnMin);
    }
    if (max) {
        btns.add(btnMax);
        // maximize/restore the window on header double click
        buttonsContainer.addEventHandler(MouseEvent.MOUSE_CLICKED, (mouseEvent) -> {
            if (mouseEvent.getClickCount() == 2) {
                btnMax.fire();
            }
        });
    }
    btns.add(btnClose);
    text = new Text();
    text.getStyleClass().addAll("jfx-decorator-text", "title", "jfx-decorator-title");
    text.setFill(Color.WHITE);
    // binds the Text's text to title
    text.textProperty().bind(title);
    // binds title to the primaryStage's title
    title.bind(primaryStage.titleProperty());
    graphicContainer = new HBox();
    graphicContainer.setPickOnBounds(false);
    graphicContainer.setAlignment(Pos.CENTER_LEFT);
    graphicContainer.getChildren().setAll(text);
    HBox graphicTextContainer = new HBox(graphicContainer, text);
    graphicTextContainer.getStyleClass().add("jfx-decorator-title-container");
    graphicTextContainer.setAlignment(Pos.CENTER_LEFT);
    graphicTextContainer.setPickOnBounds(false);
    HBox.setHgrow(graphicTextContainer, Priority.ALWAYS);
    HBox.setMargin(graphicContainer, new Insets(0, 8, 0, 8));
    buttonsContainer.getChildren().setAll(graphicTextContainer);
    buttonsContainer.getChildren().addAll(btns);
    buttonsContainer.addEventHandler(MouseEvent.MOUSE_ENTERED, (enter) -> allowMove = true);
    buttonsContainer.addEventHandler(MouseEvent.MOUSE_EXITED, (enter) -> {
        if (!isDragging) {
            allowMove = false;
        }
    });
    buttonsContainer.setMinWidth(180);
    contentPlaceHolder.getStyleClass().add("jfx-decorator-content-container");
    contentPlaceHolder.setMinSize(0, 0);
    StackPane clippedContainer = new StackPane(node);
    contentPlaceHolder.getChildren().add(clippedContainer);
    ((Region) node).setMinSize(0, 0);
    VBox.setVgrow(contentPlaceHolder, Priority.ALWAYS);
    contentPlaceHolder.getStyleClass().add("resize-border");
    contentPlaceHolder.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(0, 4, 4, 4))));
    // BINDING
    Rectangle clip = new Rectangle();
    clip.widthProperty().bind(clippedContainer.widthProperty());
    clip.heightProperty().bind(clippedContainer.heightProperty());
    clippedContainer.setClip(clip);
    this.getChildren().addAll(buttonsContainer, contentPlaceHolder);
}
Also used : HBox(javafx.scene.layout.HBox) Insets(javafx.geometry.Insets) Background(javafx.scene.layout.Background) BackgroundFill(javafx.scene.layout.BackgroundFill) ArrayList(java.util.ArrayList) Rectangle(javafx.scene.shape.Rectangle) Text(javafx.scene.text.Text) BorderWidths(javafx.scene.layout.BorderWidths) Region(javafx.scene.layout.Region) BorderStroke(javafx.scene.layout.BorderStroke) Border(javafx.scene.layout.Border) StackPane(javafx.scene.layout.StackPane)

Example 94 with Rectangle

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

the class JFXHighlighter method highlight.

/**
 * highlights the matching text in the specified pane
 * @param pane node to search into its text
 * @param query search text
 */
public synchronized void highlight(Parent pane, String query) {
    if (this.parent != null && !boxes.isEmpty()) {
        clear();
    }
    if (query == null || query.isEmpty())
        return;
    this.parent = pane;
    Set<Node> nodes = getTextNodes(pane);
    ArrayList<Rectangle> allRectangles = new ArrayList<>();
    for (Node node : nodes) {
        Text text = ((Text) node);
        final int beginIndex = text.getText().toLowerCase().indexOf(query.toLowerCase());
        if (beginIndex > -1 && node.impl_isTreeVisible()) {
            ArrayList<Bounds> boundingBoxes = getMatchingBounds(query, text);
            ArrayList<Rectangle> rectangles = new ArrayList<>();
            for (Bounds boundingBox : boundingBoxes) {
                HighLightRectangle rect = new HighLightRectangle(text);
                rect.setCacheHint(CacheHint.SPEED);
                rect.setCache(true);
                rect.setMouseTransparent(true);
                rect.setBlendMode(BlendMode.MULTIPLY);
                rect.fillProperty().bind(paintProperty());
                rect.setManaged(false);
                rect.setX(boundingBox.getMinX());
                rect.setY(boundingBox.getMinY());
                rect.setWidth(boundingBox.getWidth());
                rect.setHeight(boundingBox.getHeight());
                rectangles.add(rect);
                allRectangles.add(rect);
            }
            boxes.put(node, rectangles);
        }
    }
    JFXUtilities.runInFXAndWait(() -> getParentChildren(pane).addAll(allRectangles));
}
Also used : Node(javafx.scene.Node) RectBounds(com.sun.javafx.geom.RectBounds) Bounds(javafx.geometry.Bounds) Rectangle(javafx.scene.shape.Rectangle) Text(javafx.scene.text.Text) CacheHint(javafx.scene.CacheHint) Paint(javafx.scene.paint.Paint)

Example 95 with Rectangle

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

the class MoveShape method testCanCancelDnDWithObsList.

@Test
public void testCanCancelDnDWithObsList(final FxRobot robot) {
    new NodeBinder<>(new DnD(true, true), i -> new MoveShape((Rectangle) i.getSrcObject().get()), instrument).on(widget1.getChildren()).first((i, c) -> Platform.runLater(() -> i.getSrcObject().get().requestFocus())).then((i, c) -> c.setCoord(((Rectangle) i.getSrcObject().get()).getX() + (i.getTgtScenePoint().getX() - i.getSrcScenePoint().getX()), ((Rectangle) i.getSrcObject().get()).getY() + (i.getTgtScenePoint().getY() - i.getSrcScenePoint().getY()))).end((i, c) -> fail("")).exec().bind();
    final Rectangle rec2 = new Rectangle(200d, 200d, 70d, 50d);
    Platform.runLater(() -> widget1.getChildren().addAll(rec2));
    WaitForAsyncUtils.waitForFxEvents();
    robot.drag(rec2).moveBy(100, 100).type(KeyCode.ESCAPE).sleep(50L);
    assertEquals(0, instrument.exec.get());
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) KeyCode(javafx.scene.input.KeyCode) NodeBinder(org.malai.javafx.binding.NodeBinder) Undoable(org.malai.undo.Undoable) Rectangle(javafx.scene.shape.Rectangle) DoubleProperty(javafx.beans.property.DoubleProperty) CommandImpl(org.malai.command.CommandImpl) WaitForAsyncUtils(org.testfx.util.WaitForAsyncUtils) Platform(javafx.application.Platform) Test(org.junit.jupiter.api.Test) ResourceBundle(java.util.ResourceBundle) Stage(javafx.stage.Stage) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) FxRobot(org.testfx.api.FxRobot) Start(org.testfx.framework.junit5.Start) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DnD(org.malai.javafx.interaction.library.DnD) ApplicationExtension(org.testfx.framework.junit5.ApplicationExtension) Pane(javafx.scene.layout.Pane) Rectangle(javafx.scene.shape.Rectangle) DnD(org.malai.javafx.interaction.library.DnD) NodeBinder(org.malai.javafx.binding.NodeBinder) Test(org.junit.jupiter.api.Test)

Aggregations

Rectangle (javafx.scene.shape.Rectangle)190 Point2D (javafx.geometry.Point2D)33 Text (javafx.scene.text.Text)28 Entity (com.almasb.fxgl.entity.Entity)27 Circle (javafx.scene.shape.Circle)20 Color (javafx.scene.paint.Color)18 HitBox (com.almasb.fxgl.physics.HitBox)16 Pane (javafx.scene.layout.Pane)16 Group (javafx.scene.Group)15 Node (javafx.scene.Node)14 PhysicsComponent (com.almasb.fxgl.physics.PhysicsComponent)12 Scene (javafx.scene.Scene)12 EntityView (com.almasb.fxgl.entity.view.EntityView)10 Label (javafx.scene.control.Label)10 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 TextFlow (javafx.scene.text.TextFlow)8 CollidableComponent (com.almasb.fxgl.entity.component.CollidableComponent)7 Bounds (javafx.geometry.Bounds)7 KeyCode (javafx.scene.input.KeyCode)7