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

The following examples show how to use javafx.scene.shape.Rectangle#setWidth() . 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: PolygonLayoutBoundsBug.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
	final Polygon p = new Polygon(10, 30, 20, 20, 20, 40);
	p.setFill(Color.RED);
	p.setStroke(Color.BLACK);

	final Rectangle r = new Rectangle();
	r.setFill(new Color(0, 0, 1, 0.5));
	r.setX(p.getLayoutBounds().getMinX());
	r.setY(p.getLayoutBounds().getMinY());
	r.setWidth(p.getLayoutBounds().getWidth());
	r.setHeight(p.getLayoutBounds().getHeight());

	Group g = new Group(r, p);
	g.getTransforms().add(new Scale(10, 10));
	Scene scene = new Scene(g, 500, 500);
	primaryStage.setScene(scene);
	primaryStage.sizeToScene();
	primaryStage.show();
}
 
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: PackMan.java    From games_oop_javafx with Apache License 2.0 6 votes vote down vote up
private Rectangle buildFigure(int x, int y, int size, String image) {
    Rectangle rect = new Rectangle();
    rect.setX(x);
    rect.setY(y);
    rect.setHeight(size);
    rect.setWidth(size);
    Image img = new Image(this.getClass().getClassLoader().getResource(image).toString());
    rect.setFill(new ImagePattern(img));
    return rect;
}
 
Example 4
Source File: SeaBattle.java    From games_oop_javafx with Apache License 2.0 6 votes vote down vote up
private void buildShip(Group board, int desk, int startX, int startY) {
    Rectangle rect = new Rectangle();
    rect.setX(startX);
    rect.setY(startY);
    rect.setHeight(25);
    rect.setWidth(desk * 25);
    rect.setFill(Color.BLACK);
    rect.setOnMouseDragged(
            event -> {
                rect.setX(event.getX());
                rect.setY(event.getY());
            }
    );
    rect.setOnMouseReleased(
            event -> {
                rect.setX((((int) event.getX() / 25) * 25));
                rect.setY(((int) event.getY() / 25) * 25);
            }
    );
    rect.setOnMouseClicked(
            event -> {
                if (event.getButton() != MouseButton.PRIMARY) {
                    Rectangle momento = new Rectangle(rect.getX(),
                            rect.getY(), rect.getWidth(), rect.getHeight());
                    rect.setWidth(momento.getHeight());
                    rect.setHeight(momento.getWidth());
                }
            }
    );
    board.getChildren().add(rect);
}
 
Example 5
Source File: ImageItem.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public Node makeNode(int size) {
    try {
        if (isColor()) {
            Rectangle rect = new Rectangle();
            rect.setFill(Color.web(address.substring(6)));
            rect.setWidth(size);
            rect.setHeight(size);
            rect.setStyle("-fx-padding: 10 10 10 10;-fx-background-radius: 10;");
            rect.setUserData(index);
            return rect;
        } else {
            if (image == null) {
                readImage();
            }
            ImageView view = new ImageView(image);
            view.setPreserveRatio(false);
            view.setFitWidth(size);
            view.setFitHeight(size);
            view.setUserData(index);
            return view;
        }
    } catch (Exception e) {
        return null;
    }
}
 
Example 6
Source File: ListImageCheckBoxCell.java    From MyBox with Apache License 2.0 5 votes vote down vote up
private void init() {
    view = new ImageView();
    view.setPreserveRatio(true);
    view.setFitHeight(imageSize);
    rect = new Rectangle();
    rect.setWidth(40);
    rect.setHeight(40);
    Callback<ImageItem, ObservableValue<Boolean>> itemToBoolean
            = (ImageItem item) -> item.getSelected();
    setSelectedStateCallback(itemToBoolean);
}
 
Example 7
Source File: SeaBattle.java    From games_oop_javafx with Apache License 2.0 5 votes vote down vote up
private Rectangle buildRectangle(int x, int y, int size) {
    Rectangle rect = new Rectangle();
    rect.setX(x * size);
    rect.setY(y * size);
    rect.setHeight(size);
    rect.setWidth(size);
    rect.setFill(Color.WHITE);
    rect.setStroke(Color.BLACK);
    return rect;
}
 
Example 8
Source File: Piece.java    From DevToolBox with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Rectangle createPieceRectangle() {
    Rectangle rec = new Rectangle();
    rec.setX(-50);
    rec.setY(-50);
    rec.setWidth(SIZE);
    rec.setHeight(SIZE);
    return rec;
}
 
Example 9
Source File: SCUtils.java    From scenic-view with GNU General Public License v3.0 5 votes vote down vote up
static void updateRect(final Parent overlayParent, final Node node, final Bounds bounds, final double tx, final double ty, final Rectangle rect) {
    final Bounds b = toSceneBounds(overlayParent, node, bounds, tx, ty);
    rect.setX(b.getMinX());
    rect.setY(b.getMinY());
    rect.setWidth(b.getMaxX() - b.getMinX());
    rect.setHeight(b.getMaxY() - b.getMinY());
}
 
Example 10
Source File: Puzzle.java    From games_oop_javafx with Apache License 2.0 5 votes vote down vote up
private Rectangle buildFigure(int x, int y, int size, String image) {
    Rectangle rect = new Rectangle();
    rect.setX(x);
    rect.setY(y);
    rect.setHeight(size);
    rect.setWidth(size);
    Image img = new Image(this.getClass().getClassLoader().getResource(image).toString());
    rect.setFill(new ImagePattern(img));
    final Rectangle momento = new Rectangle(x, y);
    rect.setOnDragDetected(
            event -> {
                momento.setX(event.getX());
                momento.setY(event.getY());
            }
    );
    rect.setOnMouseDragged(
            event -> {
                rect.setX(event.getX() - size / 2);
                rect.setY(event.getY() - size / 2);
            }
    );
    rect.setOnMouseReleased(
            event -> {
                if (logic.move(this.extract(momento.getX(), momento.getY()),
                        this.extract(event.getX(), event.getY()))) {
                    rect.setX(((int) event.getX() / 40) * 40 + 5);
                    rect.setY(((int) event.getY() / 40) * 40 + 5);
                    checkWinner();
                } else {
                    rect.setX(((int) momento.getX() / 40) * 40 + 5);
                    rect.setY(((int) momento.getY() / 40) * 40 + 5);
                }
            }
    );
    return rect;
}
 
Example 11
Source File: BendConnectionPolicyTests.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void doRefreshVisual(final Rectangle visual) {
	final org.eclipse.gef.geometry.planar.Rectangle rect = ((org.eclipse.gef.geometry.planar.IShape) getContent())
			.getBounds();
	visual.setX(rect.getX());
	visual.setY(rect.getY());
	visual.setWidth(rect.getWidth());
	visual.setHeight(rect.getHeight());
}
 
Example 12
Source File: Chess.java    From games_oop_javafx with Apache License 2.0 5 votes vote down vote up
private Rectangle buildFigure(int x, int y, int size, String image) {
    Rectangle rect = new Rectangle();
    rect.setX(x);
    rect.setY(y);
    rect.setHeight(size);
    rect.setWidth(size);
    Image img = new Image(this.getClass().getClassLoader().getResource(image).toString());
    rect.setFill(new ImagePattern(img));
    final Rectangle momento = new Rectangle(x, y);
    rect.setOnDragDetected(
            event -> {
                momento.setX(event.getX());
                momento.setY(event.getY());
            }
    );
    rect.setOnMouseDragged(
            event -> {
                rect.setX(event.getX() - size / 2);
                rect.setY(event.getY() - size / 2);
            }
    );
    rect.setOnMouseReleased(
            event -> {
                try {
                    logic.move(
                            this.findBy(momento.getX(), momento.getY()),
                            this.findBy(event.getX(), event.getY()));
                    rect.setX(((int) event.getX() / 40) * 40 + 5);
                    rect.setY(((int) event.getY() / 40) * 40 + 5);
                } catch (Exception e) {
                    Alert info = new Alert(Alert.AlertType.ERROR);
                    info.setContentText(e.getClass().getName() +  " "  + e.getMessage());
                    info.show();
                    rect.setX(((int) momento.getX() / 40) * 40 + 5);
                    rect.setY(((int) momento.getY() / 40) * 40 + 5);
                }
            }
    );
    return rect;
}
 
Example 13
Source File: EpidemicReportsSettingsController.java    From MyBox with Apache License 2.0 4 votes vote down vote up
protected void makeLocationsColors() {
    try {
        colorRects.clear();
        locationColorsBox.getChildren().clear();
        List<GeographyCode> locations = chartController.chartLocations;
        if (locations == null || locationColors == null) {
            return;
        }
        Collections.sort(locations, (GeographyCode p1, GeographyCode p2)
                -> p1.getFullName().compareTo(p2.getFullName()));
        for (int i = 0; i < locations.size(); i++) {
            GeographyCode location = locations.get(i);
            String name = location.getFullName();
            String color = locationColors.get(name);
            Label label = new Label(name);
            Rectangle rect = new Rectangle();
            rect.setWidth(15);
            rect.setHeight(15);
            Color c = Color.web(color);
            rect.setFill(c);
            FxmlControl.setTooltip(rect, new Tooltip(FxmlColor.colorNameDisplay(c)));
            rect.setUserData(name);
            colorRects.add(rect);

            Button button = new Button();
            ImageView image = new ImageView(ControlStyle.getIcon("iconPalette.png"));
            image.setFitWidth(AppVariables.iconSize);
            image.setFitHeight(AppVariables.iconSize);
            button.setGraphic(image);
            button.setOnAction((ActionEvent event) -> {
                showPalette(button, message("Settings") + " - " + name);
            });
            button.setUserData(i);
            VBox.setMargin(button, new Insets(0, 0, 0, 15));
            FxmlControl.setTooltip(button, message("Palette"));

            HBox line = new HBox();
            line.setAlignment(Pos.CENTER_LEFT);
            line.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
            line.setSpacing(5);
            VBox.setVgrow(line, Priority.ALWAYS);
            HBox.setHgrow(line, Priority.ALWAYS);
            line.getChildren().addAll(label, rect, button);

            locationColorsBox.getChildren().add(line);
        }
    } catch (Exception e) {
        logger.debug(e.toString());
    }
}
 
Example 14
Source File: Exercise_16_03.java    From Intro-to-Java-Programming with MIT License 4 votes vote down vote up
@Override // Override the start method in the Application calss
public void start(Stage primaryStage) {
	// Create a vbox
	VBox paneForCircles = new VBox(5);
	paneForCircles.setAlignment(Pos.CENTER);

	// Create three circles
	Circle c1 = getCircle();
	Circle c2 = getCircle();
	Circle c3 = getCircle();
	c1.setFill(Color.RED);

	// Place circles in vbox
	paneForCircles.getChildren().addAll(c1, c2, c3);

	// Create a rectangle
	Rectangle rectangle = new Rectangle();
	rectangle.setFill(Color.WHITE);
	rectangle.setWidth(30);
	rectangle.setHeight(100);
	rectangle.setStroke(Color.BLACK);
	rectangle.setStrokeWidth(2);
	StackPane stopSign = new StackPane(rectangle, paneForCircles);

	// Create a hbox
	HBox paneForRadioButtons = new HBox(5);
	paneForRadioButtons.setAlignment(Pos.CENTER);

	// Create radio buttons
	RadioButton rbRed = new RadioButton("Red");
	RadioButton rbYellow = new RadioButton("Yellow");
	RadioButton rbGreen = new RadioButton("Green");

	// Create a toggle group
	ToggleGroup group = new ToggleGroup();
	rbRed.setToggleGroup(group);
	rbYellow.setToggleGroup(group);
	rbGreen.setToggleGroup(group);
	rbRed.setSelected(true);
	paneForRadioButtons.getChildren().addAll(rbRed, rbYellow, rbGreen);

	// Create a border pane
	BorderPane pane = new BorderPane();
	pane.setCenter(stopSign);
	pane.setBottom(paneForRadioButtons);

	// Create and register handlers
	rbRed.setOnAction(e -> {
		if (rbRed.isSelected()) {
			c1.setFill(Color.RED);
			c2.setFill(Color.WHITE);
			c3.setFill(Color.WHITE);
		}
	});

	rbYellow.setOnAction(e -> {
		if (rbYellow.isSelected()) {
			c1.setFill(Color.WHITE);
			c2.setFill(Color.YELLOW);
			c3.setFill(Color.WHITE);
		}
	});

	rbGreen.setOnAction(e -> {
		if (rbGreen.isSelected()) {
			c1.setFill(Color.WHITE);
			c2.setFill(Color.WHITE);
			c3.setFill(Color.GREEN);
		}
	});

	// Create a scene and place it in the stage
	Scene scene = new Scene(pane, 200, 150);
	primaryStage.setTitle("Exercise_16_03"); // Set the stage title
	primaryStage.setScene(scene); // Place the scene in the stage
	primaryStage.show(); // Display the stage
}
 
Example 15
Source File: Level.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void initInfoPanel() {
    infoPanel = new Group();
    roundCaption = new Text();
    roundCaption.setText("ROUND");
    roundCaption.setTextOrigin(VPos.TOP);
    roundCaption.setFill(Color.rgb(51, 102, 51));
    Font f = new Font("Impact", 18);
    roundCaption.setFont(f);
    roundCaption.setTranslateX(30);
    roundCaption.setTranslateY(128);
    round = new Text();
    round.setTranslateX(roundCaption.getTranslateX() +
        roundCaption.getBoundsInLocal().getWidth() + Config.INFO_TEXT_SPACE);
    round.setTranslateY(roundCaption.getTranslateY());
    round.setText(levelNumber + "");
    round.setTextOrigin(VPos.TOP);
    round.setFont(f);
    round.setFill(Color.rgb(0, 204, 102));
    scoreCaption = new Text();
    scoreCaption.setText("SCORE");
    scoreCaption.setFill(Color.rgb(51, 102, 51));
    scoreCaption.setTranslateX(30);
    scoreCaption.setTranslateY(164);
    scoreCaption.setTextOrigin(VPos.TOP);
    scoreCaption.setFont(f);
    score = new Text();
    score.setTranslateX(scoreCaption.getTranslateX() +
        scoreCaption.getBoundsInLocal().getWidth() + Config.INFO_TEXT_SPACE);
    score.setTranslateY(scoreCaption.getTranslateY());
    score.setFill(Color.rgb(0, 204, 102));
    score.setTextOrigin(VPos.TOP);
    score.setFont(f);
    score.setText("");
    livesCaption = new Text();
    livesCaption.setText("LIFE");
    livesCaption.setTranslateX(30);
    livesCaption.setTranslateY(200);
    livesCaption.setFill(Color.rgb(51, 102, 51));
    livesCaption.setTextOrigin(VPos.TOP);
    livesCaption.setFont(f);
    Color INFO_LEGEND_COLOR = Color.rgb(0, 114, 188);
    int infoWidth = Config.SCREEN_WIDTH - Config.FIELD_WIDTH;
    Rectangle black = new Rectangle();
    black.setWidth(infoWidth);
    black.setHeight(Config.SCREEN_HEIGHT);
    black.setFill(Color.BLACK);
    ImageView verLine = new ImageView();
    verLine.setImage(new Image(Level.class.getResourceAsStream(Config.IMAGE_DIR+"vline.png")));
    verLine.setTranslateX(3);
    ImageView logo = new ImageView();
    logo.setImage(Config.getImages().get(Config.IMAGE_LOGO));
    logo.setTranslateX(30);
    logo.setTranslateY(30);
    Text legend = new Text();
    legend.setTranslateX(30);
    legend.setTranslateY(310);
    legend.setText("LEGEND");
    legend.setFill(INFO_LEGEND_COLOR);
    legend.setTextOrigin(VPos.TOP);
    legend.setFont(new Font("Impact", 18));
    infoPanel.getChildren().addAll(black, verLine, logo, roundCaption,
            round, scoreCaption, score, livesCaption, legend);
    for (int i = 0; i < Bonus.COUNT; i++) {
        Bonus bonus = new Bonus(i);
        Text text = new Text();
        text.setTranslateX(100);
        text.setTranslateY(350 + i * 40);
        text.setText(Bonus.NAMES[i]);
        text.setFill(INFO_LEGEND_COLOR);
        text.setTextOrigin(VPos.TOP);
        text.setFont(new Font("Arial", 12));
        bonus.setTranslateX(30 + (820 - 750 - bonus.getWidth()) / 2);
        bonus.setTranslateY(text.getTranslateY() -
            (bonus.getHeight() - text.getBoundsInLocal().getHeight()) / 2);
        // Workaround JFXC-2379
        infoPanel.getChildren().addAll(bonus, text);
    }
    infoPanel.setTranslateX(Config.FIELD_WIDTH);
}
 
Example 16
Source File: JFXRippler.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
protected void setOverLayBounds(Rectangle overlay) {
    overlay.setWidth(control.getLayoutBounds().getWidth());
    overlay.setHeight(control.getLayoutBounds().getHeight());
}
 
Example 17
Source File: Level.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private void initInfoPanel() {
    infoPanel = new Group();
    roundCaption = new Text();
    roundCaption.setText("ROUND");
    roundCaption.setTextOrigin(VPos.TOP);
    roundCaption.setFill(Color.rgb(51, 102, 51));
    Font f = new Font("Impact", 18);
    roundCaption.setFont(f);
    roundCaption.setTranslateX(30);
    roundCaption.setTranslateY(128);
    round = new Text();
    round.setTranslateX(roundCaption.getTranslateX() +
        roundCaption.getBoundsInLocal().getWidth() + Config.INFO_TEXT_SPACE);
    round.setTranslateY(roundCaption.getTranslateY());
    round.setText(levelNumber + "");
    round.setTextOrigin(VPos.TOP);
    round.setFont(f);
    round.setFill(Color.rgb(0, 204, 102));
    scoreCaption = new Text();
    scoreCaption.setText("SCORE");
    scoreCaption.setFill(Color.rgb(51, 102, 51));
    scoreCaption.setTranslateX(30);
    scoreCaption.setTranslateY(164);
    scoreCaption.setTextOrigin(VPos.TOP);
    scoreCaption.setFont(f);
    score = new Text();
    score.setTranslateX(scoreCaption.getTranslateX() +
        scoreCaption.getBoundsInLocal().getWidth() + Config.INFO_TEXT_SPACE);
    score.setTranslateY(scoreCaption.getTranslateY());
    score.setFill(Color.rgb(0, 204, 102));
    score.setTextOrigin(VPos.TOP);
    score.setFont(f);
    score.setText("");
    livesCaption = new Text();
    livesCaption.setText("LIFE");
    livesCaption.setTranslateX(30);
    livesCaption.setTranslateY(200);
    livesCaption.setFill(Color.rgb(51, 102, 51));
    livesCaption.setTextOrigin(VPos.TOP);
    livesCaption.setFont(f);
    Color INFO_LEGEND_COLOR = Color.rgb(0, 114, 188);
    int infoWidth = Config.SCREEN_WIDTH - Config.FIELD_WIDTH;
    Rectangle black = new Rectangle();
    black.setWidth(infoWidth);
    black.setHeight(Config.SCREEN_HEIGHT);
    black.setFill(Color.BLACK);
    ImageView verLine = new ImageView();
    verLine.setImage(new Image(Level.class.getResourceAsStream(Config.IMAGE_DIR+"vline.png")));
    verLine.setTranslateX(3);
    ImageView logo = new ImageView();
    logo.setImage(Config.getImages().get(Config.IMAGE_LOGO));
    logo.setTranslateX(30);
    logo.setTranslateY(30);
    Text legend = new Text();
    legend.setTranslateX(30);
    legend.setTranslateY(310);
    legend.setText("LEGEND");
    legend.setFill(INFO_LEGEND_COLOR);
    legend.setTextOrigin(VPos.TOP);
    legend.setFont(new Font("Impact", 18));
    infoPanel.getChildren().addAll(black, verLine, logo, roundCaption,
            round, scoreCaption, score, livesCaption, legend);
    for (int i = 0; i < Bonus.COUNT; i++) {
        Bonus bonus = new Bonus(i);
        Text text = new Text();
        text.setTranslateX(100);
        text.setTranslateY(350 + i * 40);
        text.setText(Bonus.NAMES[i]);
        text.setFill(INFO_LEGEND_COLOR);
        text.setTextOrigin(VPos.TOP);
        text.setFont(new Font("Arial", 12));
        bonus.setTranslateX(30 + (820 - 750 - bonus.getWidth()) / 2);
        bonus.setTranslateY(text.getTranslateY() -
            (bonus.getHeight() - text.getBoundsInLocal().getHeight()) / 2);
        // Workaround JFXC-2379
        infoPanel.getChildren().addAll(bonus, text);
    }
    infoPanel.setTranslateX(Config.FIELD_WIDTH);
}
 
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: Level.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private void initInfoPanel() {
    infoPanel = new Group();
    roundCaption = new Text();
    roundCaption.setText("ROUND");
    roundCaption.setTextOrigin(VPos.TOP);
    roundCaption.setFill(Color.rgb(51, 102, 51));
    Font f = new Font("Impact", 18);
    roundCaption.setFont(f);
    roundCaption.setTranslateX(30);
    roundCaption.setTranslateY(128);
    round = new Text();
    round.setTranslateX(roundCaption.getTranslateX() +
        roundCaption.getBoundsInLocal().getWidth() + Config.INFO_TEXT_SPACE);
    round.setTranslateY(roundCaption.getTranslateY());
    round.setText(levelNumber + "");
    round.setTextOrigin(VPos.TOP);
    round.setFont(f);
    round.setFill(Color.rgb(0, 204, 102));
    scoreCaption = new Text();
    scoreCaption.setText("SCORE");
    scoreCaption.setFill(Color.rgb(51, 102, 51));
    scoreCaption.setTranslateX(30);
    scoreCaption.setTranslateY(164);
    scoreCaption.setTextOrigin(VPos.TOP);
    scoreCaption.setFont(f);
    score = new Text();
    score.setTranslateX(scoreCaption.getTranslateX() +
        scoreCaption.getBoundsInLocal().getWidth() + Config.INFO_TEXT_SPACE);
    score.setTranslateY(scoreCaption.getTranslateY());
    score.setFill(Color.rgb(0, 204, 102));
    score.setTextOrigin(VPos.TOP);
    score.setFont(f);
    score.setText("");
    livesCaption = new Text();
    livesCaption.setText("LIFE");
    livesCaption.setTranslateX(30);
    livesCaption.setTranslateY(200);
    livesCaption.setFill(Color.rgb(51, 102, 51));
    livesCaption.setTextOrigin(VPos.TOP);
    livesCaption.setFont(f);
    Color INFO_LEGEND_COLOR = Color.rgb(0, 114, 188);
    int infoWidth = Config.SCREEN_WIDTH - Config.FIELD_WIDTH;
    Rectangle black = new Rectangle();
    black.setWidth(infoWidth);
    black.setHeight(Config.SCREEN_HEIGHT);
    black.setFill(Color.BLACK);
    ImageView verLine = new ImageView();
    verLine.setImage(new Image(Level.class.getResourceAsStream(Config.IMAGE_DIR+"vline.png")));
    verLine.setTranslateX(3);
    ImageView logo = new ImageView();
    logo.setImage(Config.getImages().get(Config.IMAGE_LOGO));
    logo.setTranslateX(30);
    logo.setTranslateY(30);
    Text legend = new Text();
    legend.setTranslateX(30);
    legend.setTranslateY(310);
    legend.setText("LEGEND");
    legend.setFill(INFO_LEGEND_COLOR);
    legend.setTextOrigin(VPos.TOP);
    legend.setFont(new Font("Impact", 18));
    infoPanel.getChildren().addAll(black, verLine, logo, roundCaption,
            round, scoreCaption, score, livesCaption, legend);
    for (int i = 0; i < Bonus.COUNT; i++) {
        Bonus bonus = new Bonus(i);
        Text text = new Text();
        text.setTranslateX(100);
        text.setTranslateY(350 + i * 40);
        text.setText(Bonus.NAMES[i]);
        text.setFill(INFO_LEGEND_COLOR);
        text.setTextOrigin(VPos.TOP);
        text.setFont(new Font("Arial", 12));
        bonus.setTranslateX(30 + (820 - 750 - bonus.getWidth()) / 2);
        bonus.setTranslateY(text.getTranslateY() -
            (bonus.getHeight() - text.getBoundsInLocal().getHeight()) / 2);
        // Workaround JFXC-2379
        infoPanel.getChildren().addAll(bonus, text);
    }
    infoPanel.setTranslateX(Config.FIELD_WIDTH);
}
 
Example 20
Source File: MessageItemRight.java    From oim-fx with MIT License 4 votes vote down vote up
private void initComponent() {
	this.getChildren().add(rootPane);
	rootPane.setTop(timePane);
	rootPane.setLeft(leftBox);
	rootPane.setCenter(centerPane);
	rootPane.setRight(heahBox);
	
	leftBox.setPrefWidth(40);
	
	heahBox.setPrefHeight(20);
	timeLabel.setStyle("-fx-text-fill:#fff;"
			+ "-fx-background-color:#dadada;\r\n" + 
			"   -fx-background-radius:2;-fx-padding: 0 6px;");
	nameLabel.setStyle("-fx-text-fill:rgba(120, 120, 120, 1)");
	double value=38;
	Rectangle clip = new Rectangle();
	clip.setWidth(value);
	clip.setHeight(value);

	clip.setArcHeight(value);
	clip.setArcWidth(value);
	
	StackPane heahPane = new StackPane();
	heahPane.setClip(clip);
	heahPane.getChildren().add(headImageView);
	
	timePane.getChildren().add(timeLabel);
	heahBox.getChildren().add(heahPane);

	headImageView.setFitWidth(40);
	headImageView.setFitHeight(40);

	Polygon polygon = new Polygon(new double[] {

			0, 0,

			10, 10,

			0, 20,

	});

	polygon.setFill(Color.web("rgba(44, 217, 44, 1)"));
	//polygon.setStroke(Color.BLUE);
	//polygon.setStyle("-fx-background-color:rgba(245, 245, 245, 1);");
	VBox arrowBox = new VBox();
	arrowBox.setPadding(new Insets(3, 0, 0, 0));
	arrowBox.setAlignment(Pos.TOP_RIGHT);
	arrowBox.getChildren().add(polygon);
	
	contentBox.setStyle("-fx-background-color:rgba(44, 217, 44, 1);-fx-background-radius:3;");

	centerBox.setAlignment(Pos.CENTER_RIGHT);
	
	centerBox.getChildren().add(contentBox);
	centerBox.getChildren().add(arrowBox);
	
	HBox nameBox=new HBox();
	nameBox.setAlignment(Pos.TOP_RIGHT);
	nameBox.setPadding(new Insets(0, 10, 0, 10));
	nameBox.getChildren().add(nameLabel);
	
	centerPane.setTop(nameBox);
	centerPane.setCenter(centerBox);
}