Java Code Examples for javafx.scene.shape.Rectangle#setTranslateY()

The following examples show how to use javafx.scene.shape.Rectangle#setTranslateY() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MenuBox.java    From FXTutorials with MIT License 14 votes vote down vote up
public MenuBox(int width, int height) {

        Rectangle bg = new Rectangle(width, height);
        bg.setFill(Colors.MENU_BG);

        Rectangle lineTop = new Rectangle(width, 2);
        lineTop.setFill(Colors.MENU_BORDER);
        lineTop.setStroke(Color.BLACK);

        Rectangle lineBot = new Rectangle(width, 2);
        lineBot.setTranslateY(height - 2);
        lineBot.setFill(Colors.MENU_BORDER);
        lineBot.setStroke(Color.BLACK);

        box = new VBox(5);
        box.setTranslateX(25);
        box.setTranslateY(25);

        getChildren().addAll(bg, lineTop, lineBot, box);
    }
 
Example 2
Source File: StarsComponent.java    From FXGLGames with MIT License 6 votes vote down vote up
private void respawn(Rectangle star) {
    star.setWidth(random(0.5f, 2.5f));
    star.setHeight(random(0.5f, 2.5f));
    star.setArcWidth(random(0.5f, 2.5f));
    star.setArcHeight(random(0.5f, 2.5f));

    star.setFill(Color.color(
            random(0.75, 1.0),
            random(0.75, 1.0),
            random(0.75, 1.0),
            random(0.5f, 1.0f)
    ));

    star.setTranslateX(random(0, FXGL.getAppWidth()));
    star.setTranslateY(-random(10, FXGL.getAppHeight()));
}
 
Example 3
Source File: ShearSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public ShearSample() {
    super(125,160);

    //create rectangle
    Rectangle rect = new Rectangle(75, 75, Color.web("#ed4b00", 0.5));
    rect.setTranslateY(50);
    
    Shear shear = new Shear(0.7, 0);
    rect.getTransforms().add(shear);

    //show the rectangles
    getChildren().addAll(rect);

    // REMOVE ME
    setControls(
            new SimplePropertySheet.PropDesc("Shear X", shear.xProperty(), 0d, 1d),
            new SimplePropertySheet.PropDesc("Shear Y", shear.yProperty(), 0d, 1d),
            new SimplePropertySheet.PropDesc("Shear Pivot X", shear.pivotXProperty(), 0d, 50d),
            new SimplePropertySheet.PropDesc("Shear Pivot Y", shear.pivotYProperty(), 0d, 50d)
    );
    // END REMOVE ME

}
 
Example 4
Source File: StarsComponent.java    From FXGLGames with MIT License 6 votes vote down vote up
private void respawn(Rectangle star) {
    star.setWidth(random(0.5f, 2.5f));
    star.setHeight(random(0.5f, 2.5f));
    star.setArcWidth(random(0.5f, 2.5f));
    star.setArcHeight(random(0.5f, 2.5f));

    star.setFill(Color.color(
            random(0.75, 1.0),
            random(0.75, 1.0),
            random(0.75, 1.0),
            random(0.5f, 1.0f)
    ));

    star.setTranslateX(random(0, FXGL.getAppWidth()));
    star.setTranslateY(-random(10, FXGL.getAppHeight()));
}
 
Example 5
Source File: TowerDefenseApp.java    From FXGLGames with MIT License 6 votes vote down vote up
@Override
protected void initUI() {
    Rectangle uiBG = new Rectangle(getAppWidth(), 100);
    uiBG.setTranslateY(500);

    getGameScene().addUINode(uiBG);

    for (int i = 0; i < 4; i++) {
        int index = i + 1;

        Color color = FXGLMath.randomColor();
        TowerIcon icon = new TowerIcon(color);
        icon.setTranslateX(10 + i * 100);
        icon.setTranslateY(500);
        icon.setOnMouseClicked(e -> {
            selectedColor = color;
            selectedIndex = index;
        });

        getGameScene().addUINode(icon);
    }
}
 
Example 6
Source File: ShearSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public ShearSample() {
    super(125,160);

    //create rectangle
    Rectangle rect = new Rectangle(75, 75, Color.web("#ed4b00", 0.5));
    rect.setTranslateY(50);
    
    Shear shear = new Shear(0.7, 0);
    rect.getTransforms().add(shear);

    //show the rectangles
    getChildren().addAll(rect);

    // REMOVE ME
    setControls(
            new SimplePropertySheet.PropDesc("Shear X", shear.xProperty(), 0d, 1d),
            new SimplePropertySheet.PropDesc("Shear Y", shear.yProperty(), 0d, 1d),
            new SimplePropertySheet.PropDesc("Shear Pivot X", shear.pivotXProperty(), 0d, 50d),
            new SimplePropertySheet.PropDesc("Shear Pivot Y", shear.pivotYProperty(), 0d, 50d)
    );
    // END REMOVE ME

}
 
Example 7
Source File: PauseTransitionSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public PauseTransitionSample() {
    super(400,150);
    // create rectangle
    Rectangle rect = new Rectangle(-25,-25,50, 50);
    rect.setArcHeight(15);
    rect.setArcWidth(15);
    rect.setFill(Color.CRIMSON);
    rect.setTranslateX(50);
    rect.setTranslateY(75);
    getChildren().add(rect);
    
    animation = SequentialTransitionBuilder.create()
        .node(rect)
        .children(
            TranslateTransitionBuilder.create()
                .duration(Duration.seconds(2))
                .fromX(50)
                .toX(200)
                .build(),
            PauseTransitionBuilder.create()
                .duration(Duration.seconds(2))
                .build(),
            TranslateTransitionBuilder.create()
                .duration(Duration.seconds(2))
                .fromX(200)
                .toX(350)
                .build()
        )
        .cycleCount(Timeline.INDEFINITE)
        .autoReverse(true)
        .build();                
}
 
Example 8
Source File: StarsComponent.java    From FXGLGames with MIT License 5 votes vote down vote up
@Override
public void onUpdate(double tpf) {
    for (int i = 0; i < starParticles.size(); i++) {
        Rectangle star = starParticles.get(i);
        star.setTranslateY(star.getTranslateY() + tpf * Config.STARS_MOVE_SPEED);

        if (star.getTranslateY() > FXGL.getAppHeight())
            respawn(star);
    }
}
 
Example 9
Source File: EventDetectionUI.java    From SONDY with GNU General Public License v3.0 5 votes vote down vote up
public final void detectedEventsUI(){
    // Detected events
    HBox detectedEventsBOTH = new HBox(0);
    initializeEventTable();
    initializeFrequencyChart();
    VBox detectedEventsRIGHT = new VBox(3);
    filterEventsField = new TextField();
    filterEventsField.setPromptText("Filter events");
    UIUtils.setSize(filterEventsField, Main.columnWidthRIGHT, 24);
    final EventHandler<KeyEvent> enterPressed =
        new EventHandler<KeyEvent>() {
            @Override
            public void handle(final KeyEvent keyEvent) {
                if(keyEvent.getCode()==KeyCode.ENTER){
                    eventTable.getItems().clear();
                    selectedMethod.events.filterList(filterEventsField.getText());
                    eventTable.setItems(selectedMethod.events.observableList);
                }
            }
        };
    filterEventsField.setOnKeyReleased(enterPressed);
    detectedEventsRIGHT.getChildren().addAll(filterEventsField,eventTable,createTimelineButton());
    detectedEventsBOTH.getChildren().addAll(frequencyChart,detectedEventsRIGHT);
    grid.add(detectedEventsBOTH,0,5);
    rectangleSelection = new Rectangle(0,240);
    rectangleSelection.setOpacity(0.22);
    rectangleSelection.setTranslateY(-28);
    grid.add(rectangleSelection,0,5);
}
 
Example 10
Source File: StarsComponent.java    From FXGLGames with MIT License 5 votes vote down vote up
@Override
public void onUpdate(double tpf) {
    for (int i = 0; i < starParticles.size(); i++) {
        Rectangle star = starParticles.get(i);
        star.setTranslateY(star.getTranslateY() + tpf * Config.STARS_MOVE_SPEED);

        if (star.getTranslateY() > FXGL.getAppHeight())
            respawn(star);
    }
}
 
Example 11
Source File: Main.java    From FXTutorials with MIT License 5 votes vote down vote up
private Node createEntity(int x, int y, int w, int h, Color color) {
    Rectangle entity = new Rectangle(w, h);
    entity.setTranslateX(x);
    entity.setTranslateY(y);
    entity.setFill(color);
    entity.getProperties().put("alive", true);

    gameRoot.getChildren().add(entity);
    return entity;
}
 
Example 12
Source File: TranslateSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public TranslateSample() {
    super(230, 220);

    //create 2 rectangles with different color
    Rectangle rect1 = new Rectangle(90, 90, Color.web("#ed4b00", 0.75));
    Rectangle rect2 = new Rectangle(90, 90, Color.web("#ed4b00", 0.5));

    //translate second one
    rect2.setTranslateX(140);

    // rectangle with adjustable translate
    Rectangle rect3 = new Rectangle(40, 130, 60, 60);
    rect3.setFill(Color.DODGERBLUE);
    rect3.setTranslateX(20);
    rect3.setTranslateY(10);

    //show the rectangles
    getChildren().addAll(rect2, rect1, rect3);

    // REMOVE ME
    setControls(
            new SimplePropertySheet.PropDesc("Translate X", rect3.translateXProperty(), 0d, 50d),
            new SimplePropertySheet.PropDesc("Translate Y", rect3.translateYProperty(), 0d, 50d)
    );
    // END REMOVE ME
    
    //create arrow
    Polygon polygon = createArrow();
    polygon.setLayoutX(110);
    polygon.setLayoutY(30);
    polygon.setRotate(90);

    getChildren().addAll(polygon);

}
 
Example 13
Source File: CubeViewer.java    From FXyzLib with GNU General Public License v3.0 5 votes vote down vote up
private void buildPanels(double size) {
    //@SMP TODO might be easier to just replace the Rectangle side panels with really flat Box 3D objects
    x1AxisRectangle = new Rectangle(size, size, x1AxisRectangleColor);
    x2AxisRectangle = new Rectangle(size, size, x2AxisRectangleColor);
    y1AxisRectangle = new Rectangle(size, size, y1AxisRectangleColor);
    y2AxisRectangle = new Rectangle(size, size, y2AxisRectangleColor);
    z1AxisRectangle = new Rectangle(size, size, z1AxisRectangleColor);
    z2AxisRectangle = new Rectangle(size, size, z2AxisRectangleColor);
    
    x1AxisRectangle.setTranslateX(-size / 2);
    x1AxisRectangle.setTranslateY(-size / 2);
    x1AxisRectangle.setTranslateZ(-size / 2);
    x2AxisRectangle.setTranslateX(-size / 2);
    x2AxisRectangle.setTranslateY(-size / 2);
    x2AxisRectangle.setTranslateZ(size / 2);
    getChildren().addAll(x1AxisRectangle, x2AxisRectangle);

    y2AxisRectangle.setTranslateY(-size / 2);
    y2AxisRectangle.setRotationAxis(Rotate.Y_AXIS);
    y2AxisRectangle.setRotate(89.9);
    y1AxisRectangle.setTranslateX(-size);
    y1AxisRectangle.setTranslateY(-size / 2);
    y1AxisRectangle.setRotationAxis(Rotate.Y_AXIS);
    y1AxisRectangle.setRotate(89.9);
    getChildren().addAll(y1AxisRectangle, y2AxisRectangle);

    z1AxisRectangle.setTranslateX(-size / 2);
    z1AxisRectangle.setRotationAxis(Rotate.X_AXIS);
    z1AxisRectangle.setRotate(89.9);
    z2AxisRectangle.setTranslateX(-size / 2);
    z2AxisRectangle.setTranslateY(-size);
    z2AxisRectangle.setRotationAxis(Rotate.X_AXIS);
    z2AxisRectangle.setRotate(89.9);
    getChildren().addAll(z1AxisRectangle, z2AxisRectangle);
}
 
Example 14
Source File: FroggerApp.java    From FXTutorials with MIT License 5 votes vote down vote up
private Node spawnCar() {
    Rectangle rect = new Rectangle(40, 40, Color.RED);
    rect.setTranslateY((int)(Math.random() * 14) * 40);

    root.getChildren().add(rect);
    return rect;
}
 
Example 15
Source File: TranslateSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public TranslateSample() {
    super(230, 220);

    //create 2 rectangles with different color
    Rectangle rect1 = new Rectangle(90, 90, Color.web("#ed4b00", 0.75));
    Rectangle rect2 = new Rectangle(90, 90, Color.web("#ed4b00", 0.5));

    //translate second one
    rect2.setTranslateX(140);

    // rectangle with adjustable translate
    Rectangle rect3 = new Rectangle(40, 130, 60, 60);
    rect3.setFill(Color.DODGERBLUE);
    rect3.setTranslateX(20);
    rect3.setTranslateY(10);

    //show the rectangles
    getChildren().addAll(rect2, rect1, rect3);

    // REMOVE ME
    setControls(
            new SimplePropertySheet.PropDesc("Translate X", rect3.translateXProperty(), 0d, 50d),
            new SimplePropertySheet.PropDesc("Translate Y", rect3.translateYProperty(), 0d, 50d)
    );
    // END REMOVE ME
    
    //create arrow
    Polygon polygon = createArrow();
    polygon.setLayoutX(110);
    polygon.setLayoutY(30);
    polygon.setRotate(90);

    getChildren().addAll(polygon);

}
 
Example 16
Source File: CubeWorld.java    From FXyzLib with GNU General Public License v3.0 5 votes vote down vote up
private void buildPanels(double size) {
    //@SMP TODO might be easier to just replace the Rectangle side panels with really flat Box 3D objects
    x1AxisRectangle = new Rectangle(size, size, panelWallColor);
    x2AxisRectangle = new Rectangle(size, size, panelWallColor);
    y1AxisRectangle = new Rectangle(size, size, panelWallColor);
    y2AxisRectangle = new Rectangle(size, size, panelWallColor);
    z1AxisRectangle = new Rectangle(size, size, panelFloorColor);
    z2AxisRectangle = new Rectangle(size, size, panelCeilingColor);

    x1AxisRectangle.setTranslateX(-size / 2);
    x1AxisRectangle.setTranslateY(-size / 2);
    x1AxisRectangle.setTranslateZ(-size / 2);
    x2AxisRectangle.setTranslateX(-size / 2);
    x2AxisRectangle.setTranslateY(-size / 2);
    x2AxisRectangle.setTranslateZ(size / 2);
    getChildren().addAll(x1AxisRectangle, x2AxisRectangle);

    y2AxisRectangle.setTranslateY(-size / 2);
    y2AxisRectangle.setRotationAxis(Rotate.Y_AXIS);
    y2AxisRectangle.setRotate(89.9);
    y1AxisRectangle.setTranslateX(-size);
    y1AxisRectangle.setTranslateY(-size / 2);
    y1AxisRectangle.setRotationAxis(Rotate.Y_AXIS);
    y1AxisRectangle.setRotate(89.9);
    getChildren().addAll(y1AxisRectangle, y2AxisRectangle);

    z1AxisRectangle.setTranslateX(-size / 2);
    z1AxisRectangle.setRotationAxis(Rotate.X_AXIS);
    z1AxisRectangle.setRotate(89.9);
    z2AxisRectangle.setTranslateX(-size / 2);
    z2AxisRectangle.setTranslateY(-size);
    z2AxisRectangle.setRotationAxis(Rotate.X_AXIS);
    z2AxisRectangle.setRotate(89.9);
    getChildren().addAll(z1AxisRectangle, z2AxisRectangle);
}
 
Example 17
Source File: ParallelTransitionSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public ParallelTransitionSample() {
    super(400,150);
    // create rectangle
    Rectangle rect = new Rectangle(-25,-25,50, 50);
    rect.setArcHeight(15);
    rect.setArcWidth(15);
    rect.setFill(Color.CRIMSON);
    rect.setTranslateX(50);
    rect.setTranslateY(75);
    getChildren().add(rect); 
    // create parallel transition to do all 4 transitions at the same time        
    parallelTransition = ParallelTransitionBuilder.create()
        .node(rect)
        .children(
            FadeTransitionBuilder.create()
                .duration(Duration.seconds(3))
                .node(rect)
                .fromValue(1)
                .toValue(0.3)
                .autoReverse(true)
                .build(),
            TranslateTransitionBuilder.create()
                .duration(Duration.seconds(2))
                .fromX(50)
                .toX(350)
                .cycleCount(2)
                .autoReverse(true)
                .build(),
            RotateTransitionBuilder.create()
                .duration(Duration.seconds(3))
                .byAngle(180)
                .cycleCount(4)
                .autoReverse(true)
                .build(),
            ScaleTransitionBuilder.create()
                .duration(Duration.seconds(2))
                .toX(2)
                .toY(2)
                .cycleCount(2)
                .autoReverse(true)
                .build()
        )
        .cycleCount(Timeline.INDEFINITE)
        .autoReverse(true)
        .build();
    
}
 
Example 18
Source File: RectangleSegmentHandlePart.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Updates the color of this part's visualization. If this handle part
 * represents a way or end point of an {@link Connection}, it's color will
 * be set to indicate whether the handle is connected to another part or
 * not.
 */
protected void updateColor() {
	// only update when bound to anchorage
	SetMultimap<IVisualPart<? extends Node>, String> anchorages = getAnchoragesUnmodifiable();
	if (getRoot() == null || anchorages.keySet().size() != 1) {
		return;
	}

	Rectangle visual = getVisual();
	// no need to update the color if we are invisible
	if (!visual.isVisible()) {
		return;
	}

	if (getSegmentParameter() == 0.5) {
		// move handle in the middle of a segment
		visual.setFill(getMoveFill());
	} else if (getSegmentParameter() != 0.0
			&& getSegmentParameter() != 1.0) {
		// quarter handles (creation)
		visual.setFill(getInsertFill());
		visual.setWidth(DEFAULT_LENGTH * 4d / 5d);
		visual.setHeight(DEFAULT_WIDTH * 4d / 5d);
		visual.setTranslateX(-DEFAULT_LENGTH / 2d + DEFAULT_LENGTH / 10d);
		visual.setTranslateY(-DEFAULT_WIDTH / 2d + DEFAULT_WIDTH / 10d);
	} else {
		visual.setTranslateX(-DEFAULT_LENGTH / 2);
		visual.setTranslateY(-DEFAULT_WIDTH / 2);
		visual.setWidth(DEFAULT_LENGTH);
		visual.setHeight(DEFAULT_WIDTH);
		// end point handles
		boolean connected = false;
		IVisualPart<? extends Node> targetPart = anchorages.keySet()
				.iterator().next();
		if (targetPart.getVisual() instanceof Connection) {
			Connection connection = (Connection) targetPart.getVisual();
			if (getSegmentIndex() + getSegmentParameter() == 0.0) {
				// handle at start point
				connected = connection.isStartConnected();
			} else if (getSegmentParameter()
					+ getSegmentIndex() == getSegmentsInScene().length) {
				// handle at end point
				connected = connection.isEndConnected();
			}
		}
		// update color according to connected state
		if (connected) {
			visual.setFill(getConnectedFill());
		} else {
			visual.setFill(getMoveFill());
		}
	}
}
 
Example 19
Source File: SequentialTransitionSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public SequentialTransitionSample() {
    super(400,100);
    // create rectangle
    Rectangle rect = new Rectangle(-25,-25,50, 50);
    rect.setArcHeight(15);
    rect.setArcWidth(15);
    rect.setFill(Color.CRIMSON);
    rect.setTranslateX(50);
    rect.setTranslateY(50);
    getChildren().add(rect);
    // create 4 transitions
    FadeTransition fadeTransition =
            FadeTransitionBuilder.create()
            .duration(Duration.seconds(1))
            .fromValue(1)
            .toValue(0.3)
            .cycleCount(2)
            .autoReverse(true)
            .build();
    TranslateTransition translateTransition =
            TranslateTransitionBuilder.create()
            .duration(Duration.seconds(2))
            .fromX(50)
            .toX(375)
            .cycleCount(2)
            .autoReverse(true)
            .build();       
    RotateTransition rotateTransition = 
            RotateTransitionBuilder.create()
            .duration(Duration.seconds(2))
            .byAngle(180)
            .cycleCount(4)
            .autoReverse(true)
            .build();
    ScaleTransition scaleTransition =
            ScaleTransitionBuilder.create()
            .duration(Duration.seconds(2))
            .toX(2)
            .toY(2)
            .cycleCount(2)
            .autoReverse(true)
            .build();
    // create sequential transition to do 4 transitions one after another       
    sequentialTransition = SequentialTransitionBuilder.create()
            .node(rect)
            .children(fadeTransition, translateTransition, rotateTransition,
                       scaleTransition)
            .cycleCount(Timeline.INDEFINITE)
            .autoReverse(true)
            .build();
}
 
Example 20
Source File: FroggerApp.java    From FXTutorials with MIT License 4 votes vote down vote up
private Node initFrog() {
    Rectangle rect = new Rectangle(38, 38, Color.GREEN);
    rect.setTranslateY(600 - 39);

    return rect;
}