Java Code Examples for javafx.scene.shape.Line#setEndY()

The following examples show how to use javafx.scene.shape.Line#setEndY() . 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: TicTacToeApp.java    From FXGLGames with MIT License 6 votes vote down vote up
private void playWinAnimation(TileCombo combo) {
    Line line = new Line();
    line.setStartX(combo.getTile1().getCenter().getX());
    line.setStartY(combo.getTile1().getCenter().getY());
    line.setEndX(combo.getTile1().getCenter().getX());
    line.setEndY(combo.getTile1().getCenter().getY());
    line.setStroke(Color.YELLOW);
    line.setStrokeWidth(3);

    getGameScene().addUINode(line);

    Timeline timeline = new Timeline();
    timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(1),
            new KeyValue(line.endXProperty(), combo.getTile3().getCenter().getX()),
            new KeyValue(line.endYProperty(), combo.getTile3().getCenter().getY())));
    timeline.setOnFinished(e -> gameOver(combo.getWinSymbol()));
    timeline.play();
}
 
Example 2
Source File: TicTacToeApp.java    From FXGLGames with MIT License 6 votes vote down vote up
private void playWinAnimation(TileCombo combo) {
    Line line = new Line();
    line.setStartX(combo.getTile1().getCenter().getX());
    line.setStartY(combo.getTile1().getCenter().getY());
    line.setEndX(combo.getTile1().getCenter().getX());
    line.setEndY(combo.getTile1().getCenter().getY());
    line.setStroke(Color.YELLOW);
    line.setStrokeWidth(3);

    getGameScene().addUINode(line);

    Timeline timeline = new Timeline();
    timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(1),
            new KeyValue(line.endXProperty(), combo.getTile3().getCenter().getX()),
            new KeyValue(line.endYProperty(), combo.getTile3().getCenter().getY())));
    timeline.setOnFinished(e -> gameOver(combo.getWinSymbol()));
    timeline.play();
}
 
Example 3
Source File: HangmanMain.java    From FXTutorials with MIT License 6 votes vote down vote up
public HangmanImage() {
    Circle head = new Circle(20);
    head.setTranslateX(SPINE_START_X);

    Line spine = new Line();
    spine.setStartX(SPINE_START_X);
    spine.setStartY(SPINE_START_Y);
    spine.setEndX(SPINE_END_X);
    spine.setEndY(SPINE_END_Y);

    Line leftArm = new Line();
    leftArm.setStartX(SPINE_START_X);
    leftArm.setStartY(SPINE_START_Y);
    leftArm.setEndX(SPINE_START_X + 40);
    leftArm.setEndY(SPINE_START_Y + 10);

    Line rightArm = new Line();
    rightArm.setStartX(SPINE_START_X);
    rightArm.setStartY(SPINE_START_Y);
    rightArm.setEndX(SPINE_START_X - 40);
    rightArm.setEndY(SPINE_START_Y + 10);

    Line leftLeg = new Line();
    leftLeg.setStartX(SPINE_END_X);
    leftLeg.setStartY(SPINE_END_Y);
    leftLeg.setEndX(SPINE_END_X + 25);
    leftLeg.setEndY(SPINE_END_Y + 50);

    Line rightLeg = new Line();
    rightLeg.setStartX(SPINE_END_X);
    rightLeg.setStartY(SPINE_END_Y);
    rightLeg.setEndX(SPINE_END_X - 25);
    rightLeg.setEndY(SPINE_END_Y + 50);

    getChildren().addAll(head, spine, leftArm, rightArm, leftLeg, rightLeg);
    lives.set(getChildren().size());
}
 
Example 4
Source File: TicTacToeApp.java    From FXTutorials with MIT License 5 votes vote down vote up
private void playWinAnimation(Combo combo) {
    Line line = new Line();
    line.setStartX(combo.tiles[0].getCenterX());
    line.setStartY(combo.tiles[0].getCenterY());
    line.setEndX(combo.tiles[0].getCenterX());
    line.setEndY(combo.tiles[0].getCenterY());

    root.getChildren().add(line);

    Timeline timeline = new Timeline();
    timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(1),
            new KeyValue(line.endXProperty(), combo.tiles[2].getCenterX()),
            new KeyValue(line.endYProperty(), combo.tiles[2].getCenterY())));
    timeline.play();
}
 
Example 5
Source File: PopOverSkin.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
private Node createCloseIcon() {
    Group group = new Group();
    group.getStyleClass().add("graphics"); //$NON-NLS-1$

    Circle circle = new Circle();
    circle.getStyleClass().add("circle"); //$NON-NLS-1$
    circle.setRadius(6);
    circle.setCenterX(6);
    circle.setCenterY(6);
    group.getChildren().add(circle);

    Line line1 = new Line();
    line1.getStyleClass().add("line"); //$NON-NLS-1$
    line1.setStartX(4);
    line1.setStartY(4);
    line1.setEndX(8);
    line1.setEndY(8);
    group.getChildren().add(line1);

    Line line2 = new Line();
    line2.getStyleClass().add("line"); //$NON-NLS-1$
    line2.setStartX(8);
    line2.setStartY(4);
    line2.setEndX(4);
    line2.setEndY(8);
    group.getChildren().add(line2);

    return group;
}
 
Example 6
Source File: GraphEditorGrid.java    From graph-editor with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Draws the grid for the given width and height.
 *
 * @param width the width of the editor region
 * @param height the height of the editor region
 */
public void draw(final double width, final double height) {

    final double spacing = editorProperties.getGridSpacing();

    getChildren().clear();

    final int hLineCount = (int) Math.floor((height + 1) / spacing);
    final int vLineCount = (int) Math.floor((width + 1) / spacing);

    for (int i = 0; i < hLineCount; i++) {

        final Line hLine = new Line();

        hLine.setStartX(0);
        hLine.setEndX(width);
        hLine.setStartY((i + 1) * spacing + HALF_PIXEL_OFFSET);
        hLine.setEndY((i + 1) * spacing + HALF_PIXEL_OFFSET);
        hLine.strokeProperty().bind(gridColor);

        getChildren().add(hLine);
    }

    for (int i = 0; i < vLineCount; i++) {

        final Line vLine = new Line();

        vLine.setStartX((i + 1) * spacing + HALF_PIXEL_OFFSET);
        vLine.setEndX((i + 1) * spacing + HALF_PIXEL_OFFSET);
        vLine.setStartY(0);
        vLine.setEndY(height);
        vLine.strokeProperty().bind(gridColor);

        getChildren().add(vLine);
    }
}
 
Example 7
Source File: Arrow.java    From fxgraph with Do What The F*ck You Want To Public License 4 votes vote down vote up
public Arrow(Line line, Line arrow1, Line arrow2, double arrowLength, double arrowWidth) {
    super(line, arrow1, arrow2);
    this.line = line;
    InvalidationListener updater = o -> {
        double ex = getEndX();
        double ey = getEndY();
        double sx = getStartX();
        double sy = getStartY();

        arrow1.setEndX(ex);
        arrow1.setEndY(ey);
        arrow2.setEndX(ex);
        arrow2.setEndY(ey);

        if (ex == sx && ey == sy) {
            // arrow parts of length 0
            arrow1.setStartX(ex);
            arrow1.setStartY(ey);
            arrow2.setStartX(ex);
            arrow2.setStartY(ey);
        } else {
            double factor = arrowLength / Math.hypot(sx-ex, sy-ey);
            double factorO = arrowWidth / Math.hypot(sx-ex, sy-ey);

            // part in direction of main line
            double dx = (sx - ex) * factor;
            double dy = (sy - ey) * factor;

            // part ortogonal to main line
            double ox = (sx - ex) * factorO;
            double oy = (sy - ey) * factorO;

            arrow1.setStartX(ex + dx - oy);
            arrow1.setStartY(ey + dy + ox);
            arrow2.setStartX(ex + dx + oy);
            arrow2.setStartY(ey + dy - ox);
        }
    };

    // add updater to properties
    startXProperty().addListener(updater);
    startYProperty().addListener(updater);
    endXProperty().addListener(updater);
    endYProperty().addListener(updater);
    updater.invalidated(null);
}
 
Example 8
Source File: DynamicAnchorSnippet.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Scene createScene() {
	BorderPane root = new BorderPane();
	Scene scene = new Scene(root, 400, 400);

	r1 = new Rectangle(50, 50);
	r1.setFill(Color.RED);
	r1.relocate(100, 100);
	r2 = new Rectangle(50, 50);
	r2.setFill(Color.BLUE);
	r2.relocate(200, 200);
	final Line l = new Line();
	l.setStroke(Color.BLACK);

	DynamicAnchor startAnchor = new DynamicAnchor(r1);
	DynamicAnchor endAnchor = new DynamicAnchor(r2);
	final AnchorKey startKey = new AnchorKey(l, "start");
	final AnchorKey endKey = new AnchorKey(l, "end");

	// update start and end point in case provided position values change
	MapChangeListener<AnchorKey, Point> changeListener = new MapChangeListener<AnchorKey, Point>() {

		@Override
		public void onChanged(
				MapChangeListener.Change<? extends AnchorKey, ? extends Point> change) {
			if (change.getKey().equals(startKey)) {
				l.setStartX(change.getMap().get(startKey).x);
				l.setStartY(change.getMap().get(startKey).y);
			}
			if (change.getKey().equals(endKey)) {
				l.setEndX(change.getMap().get(endKey).x);
				l.setEndY(change.getMap().get(endKey).y);
			}
		}
	};

	startAnchor.positionsUnmodifiableProperty().addListener(changeListener);
	endAnchor.positionsUnmodifiableProperty().addListener(changeListener);

	Point r1Center = new Point(
			r1.getLayoutBounds().getMinX() + r1.getLayoutX()
					+ r1.getWidth() / 2,
			r1.getLayoutBounds().getMinY() + r1.getLayoutY()
					+ r1.getHeight() / 2);
	Point r2Center = new Point(
			r2.getLayoutBounds().getMinX() + r2.getLayoutX()
					+ r2.getWidth() / 2,
			r2.getLayoutBounds().getMinY() + r2.getLayoutY()
					+ r2.getHeight() / 2);

	// use static values for dynamic anchor reference points
	startAnchor.getComputationParameter(startKey,
			AnchoredReferencePoint.class).set(r2Center);
	startAnchor.attach(startKey);
	endAnchor.getComputationParameter(endKey,
			AnchoredReferencePoint.class).set(r1Center);
	endAnchor.attach(endKey);

	Group g = new Group(r1, r2, l);
	root.getChildren().add(g);

	return scene;
}