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

The following examples show how to use javafx.scene.shape.Rectangle#setHeight() . 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: 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 2
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 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: RadialGlobalMenu.java    From RadialFx with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void computeBack() {
final Rectangle rect = new Rectangle();
rect.setWidth(widthProp.get());
rect.setHeight(heightProp.get());
rect.setTranslateX(widthProp.get() / -2.0);
rect.setTranslateY(heightProp.get() / -2.0);

final RadialGradient radialGradient = new RadialGradient(0, 0,
	widthProp.get() / 2.0, heightProp.get() / 2.0,
	widthProp.get() / 2.0, false, CycleMethod.NO_CYCLE, new Stop(0,
		Color.TRANSPARENT), new Stop(1, BACK_GRADIENT_COLOR));

rect.setFill(radialGradient);
backContainer.getChildren().setAll(rect);
   }
 
Example 6
Source File: Exercise_15_02.java    From Intro-to-Java-Programming with MIT License 5 votes vote down vote up
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
	// Create a rectangle
	Rectangle rectangle = new Rectangle();
	rectangle.setWidth(90);
	rectangle.setHeight(40);
	rectangle.setFill(Color.RED);
	rectangle.setStroke(Color.BLACK);

	// Create a button
	Button btRotate = new Button("Rotate");

	// Process events
	btRotate.setOnAction(e -> 
		rectangle.setRotate(rectangle.getRotate() + 15));

	// Create a border pane and set its properties
	BorderPane pane = new BorderPane();
	pane.setCenter(rectangle);
	pane.setBottom(btRotate);
	BorderPane.setAlignment(rectangle, Pos.CENTER);
	BorderPane.setAlignment(btRotate, Pos.CENTER);
	pane.setPadding(new Insets(5, 5, 5, 5));

	// Create a scene and place it in the stage
	Scene scene = new Scene(pane, 170, 170);
	primaryStage.setTitle("Exercise_15_02"); // Set the stage title
	primaryStage.setScene(scene); // Place the scene in the stage
	primaryStage.show(); // Display the stage; 
}
 
Example 7
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 8
Source File: BlendEffect.java    From Learn-Java-12-Programming with MIT License 5 votes vote down vote up
private static Rectangle createSquare(){
    Rectangle r = new Rectangle();
    r.setFill(Color.rgb(0, 0, 255, 1.0));
    r.setWidth(50);
    r.setHeight(50);
    return r;
}
 
Example 9
Source File: Puzzle.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 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: 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 12
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 13
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 14
Source File: MessageItemLeft.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(heahBox);
	rootPane.setCenter(centerPane);
	rootPane.setRight(rightBox);

	rightBox.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, 10,

			10, 0,

			10, 20,

	});

	polygon.setFill(Color.web("rgba(220, 220, 220, 1.0)"));
	//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_LEFT);
	arrowBox.getChildren().add(polygon);
	
	contentBox.setStyle("-fx-background-color:rgba(220, 220, 220, 1);-fx-background-radius:3;");

	centerBox.getChildren().add(arrowBox);
	centerBox.getChildren().add(contentBox);
	
	HBox nameBox=new HBox();
	nameBox.setAlignment(Pos.TOP_LEFT);
	nameBox.setPadding(new Insets(0, 10, 0, 10));
	nameBox.getChildren().add(nameLabel);
	
	centerPane.setTop(nameBox);
	centerPane.setCenter(centerBox);
}
 
Example 15
Source File: Callout.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
protected Animation buildSubTitleAnim(HBox mainTitle, HBox subTitle) {

        // Small rectangle (prompt)
        // Calculate main title width and height upfront
        Rectangle2D mainTitleBounds = getBoundsUpfront(mainTitle);

        double mainTitleWidth = mainTitleBounds.getWidth();
        double mainTitleHeight = mainTitleBounds.getHeight();

        Pos textPos = (LEFT == getEndLeaderLineDirection()) ? Pos.CENTER_LEFT : Pos.CENTER_RIGHT;
        subTitle.setAlignment(textPos);

        Rectangle2D subTitleBounds = getBoundsUpfront(subTitle);

        double subTitleTextWidth = subTitleBounds.getWidth();
        double subTitleTextHeight = subTitleBounds.getHeight();

        Point2D endPointLL = calcEndPointOfLeaderLine();
        int direction = getEndLeaderLineDirection();
        double x = endPointLL.getX() + (5 * direction);
        double y = endPointLL.getY();
        subTitle.setLayoutX( x );
        subTitle.setLayoutY( y + (mainTitleHeight/2) + 4);

        Rectangle subTitleViewPort = new Rectangle();
        subTitleViewPort.setWidth(0);
        subTitleViewPort.setHeight(subTitleTextHeight);
        subTitle.setClip(subTitleViewPort);

        // Animate subtitle from end point to the left.
        if (LEFT == getEndLeaderLineDirection()) {
            return new Timeline(
                    new KeyFrame(Duration.millis(1),
                            new KeyValue(subTitle.visibleProperty(), true),
                            new KeyValue(subTitle.layoutXProperty(), x)), // show
                    new KeyFrame(Duration.millis(200),

                            new KeyValue(subTitle.layoutXProperty(), x - subTitleTextWidth),
                            new KeyValue(subTitleViewPort.widthProperty(), subTitleTextWidth))
            );
        }

        // Animate subtitle from end point to the right.
        return new Timeline(
                new KeyFrame(Duration.millis(1),
                        new KeyValue(subTitle.visibleProperty(), true)), // show
                new KeyFrame(Duration.millis(200),
                        new KeyValue(subTitleViewPort.widthProperty(), subTitleTextWidth))
        );
    }
 
Example 16
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 17
Source File: Callout.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
protected Animation buildMainTitleAnim(HBox mainTitleBackground) {

        // main title box
        // Calculate main title width and height upfront
        Rectangle2D mainTitleBounds = getBoundsUpfront(mainTitleBackground);

        double mainTitleWidth = mainTitleBounds.getWidth();
        double mainTitleHeight = mainTitleBounds.getHeight();

        // Position mainTitleText background beside the end part of the leader line.
        Point2D endPointLLine = calcEndPointOfLeaderLine();
        double x = endPointLLine.getX();
        double y = endPointLLine.getY();

        // Viewport to make main title appear to scroll
        Rectangle mainTitleViewPort = new Rectangle();
        mainTitleViewPort.setWidth(0);
        mainTitleViewPort.setHeight(mainTitleHeight);

        mainTitleBackground.setClip(mainTitleViewPort);
        mainTitleBackground.setLayoutX(x);
        mainTitleBackground.setLayoutY(y - (mainTitleHeight/2));

        // Animate main title from end point to the left.
        if (LEFT == getEndLeaderLineDirection()) {
            // animate layout x and width
            return new Timeline(
                    new KeyFrame(Duration.millis(1),
                            new KeyValue(mainTitleBackground.visibleProperty(), true),
                            new KeyValue(mainTitleBackground.layoutXProperty(), x)
                    ), // show
                    new KeyFrame(Duration.millis(200),
                            new KeyValue(mainTitleBackground.layoutXProperty(), x - mainTitleWidth),
                            new KeyValue(mainTitleViewPort.widthProperty(), mainTitleWidth)
                    )
            );
        }

        // Animate main title from end point to the right
        return new Timeline(
                new KeyFrame(Duration.millis(1),
                        new KeyValue(mainTitleBackground.visibleProperty(), true)), // show
                new KeyFrame(Duration.millis(200),
                        new KeyValue(mainTitleViewPort.widthProperty(), mainTitleWidth)
                )
        );
    }
 
Example 18
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 19
Source File: ToggleButtonSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Stage stage) {
    stage.setTitle("Toggle Button Sample");
    stage.setWidth(250);
    stage.setHeight(180);

    HBox hbox = new HBox();
    VBox vbox = new VBox();

    Scene scene = new Scene(new Group(vbox));
    stage.setScene(scene);
    scene.getStylesheets().add("togglebuttonsample/ControlStyle.css");

    Rectangle rect = new Rectangle();
    rect.setHeight(50);
    rect.setFill(Color.WHITE);
    rect.setStroke(Color.DARKGRAY);
    rect.setStrokeWidth(2);
    rect.setArcHeight(10);
    rect.setArcWidth(10);

    final ToggleGroup group = new ToggleGroup();

    group.selectedToggleProperty().addListener((ObservableValue<? extends Toggle> ov, Toggle toggle, Toggle new_toggle) -> {
        if (new_toggle == null)
            rect.setFill(Color.WHITE);
        else
            rect.setFill((Color) group.getSelectedToggle().getUserData());
    });

    ToggleButton tb1 = new ToggleButton("Minor");
    tb1.setToggleGroup(group);
    tb1.setUserData(Color.LIGHTGREEN);
    tb1.setSelected(true);
    tb1.getStyleClass().add("toggle-button1");

    ToggleButton tb2 = new ToggleButton("Major");
    tb2.setToggleGroup(group);
    tb2.setUserData(Color.LIGHTBLUE);
    tb2.getStyleClass().add("toggle-button2");

    ToggleButton tb3 = new ToggleButton("Critical");
    tb3.setToggleGroup(group);
    tb3.setUserData(Color.SALMON);
    tb3.getStyleClass().add("toggle-button3");

    hbox.getChildren().addAll(tb1, tb2, tb3);

    vbox.getChildren().add(new Label("Priority:"));
    vbox.getChildren().add(hbox);
    vbox.getChildren().add(rect);
    vbox.setPadding(new Insets(20, 10, 10, 20));

    stage.show();
    rect.setWidth(hbox.getWidth());
}
 
Example 20
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);
}