public Curbstone(final double size, final Color color, final double shade) { getTransforms().addAll(rz, ry, rx); getChildren().addAll( RectangleBuilder.create() // back face .width(2 * size).height(size).fill(color.deriveColor(0.0, 1.0, 1 - 0.5 * shade, 1.0)) .translateX(-0.5 * size).translateY(-0.5 * size).translateZ(0.5 * size).build(), RectangleBuilder.create() // bottom face .width(2 * size).height(size).fill(color.deriveColor(0.0, 1.0, 1 - 0.4 * shade, 1.0)) .translateX(-0.5 * size).translateY(0).rotationAxis(Rotate.X_AXIS).rotate(90).build(), RectangleBuilder.create() // right face .width(size).height(size).fill(Color.GRAY.deriveColor(0.0, 1.0, 1 - 0.3 * shade, 1.0)) .translateX(-1 * size).translateY(-0.5 * size).rotationAxis(Rotate.Y_AXIS).rotate(90) .build(), RectangleBuilder.create() // left face .width(size).height(size).fill(Color.GRAY.deriveColor(0.0, 1.0, 1 - 0.2 * shade, 1.0)) .translateX(size).translateY(-0.5 * size).rotationAxis(Rotate.Y_AXIS).rotate(90).build(), RectangleBuilder.create() // top face .width(2 * size).height(size).fill(color.deriveColor(0.0, 1.0, 1 - 0.1 * shade, 1.0)) .translateX(-0.5 * size).translateY(-1 * size).rotationAxis(Rotate.X_AXIS).rotate(90) .build(), RectangleBuilder.create() // top face .width(2 * size).height(size).fill(color).translateX(-0.5 * size).translateY(-0.5 * size) .translateZ(-0.5 * size).build()); }
public Banner(String message) { Rectangle rectangle = RectangleBuilder .create() .x(0) .y(0) .width(W) .height(H) .fill(LinearGradientBuilder .create() .startX(0.0) .startY(0.0) .endX(10.0) .endY(0.0) .proportional(false) .cycleMethod(CycleMethod.REFLECT) .stops(StopBuilder.create().offset(0.0).color(Color.BLUE).build(), StopBuilder.create().offset(1.0).color(Color.LIGHTBLUE).build()).build()).build(); Text text = TextBuilder.create().x(25).y(H / 16).text(message).fill(Color.YELLOW).font(Font.font(null, FontWeight.BOLD, 36)) .build(); getChildren().addAll(rectangle, text); }
private Rectangle getBox(String effectStr){ /*Text sp3 = TextBuilder.create() .text("Inner Shadow") .fill(Color.YELLOW) .font(Font.font(null, FontWeight.BOLD, 40)) .style(effectStr).build();*/ Rectangle sp3 = RectangleBuilder.create() .width(200) .height(200) .fill(Color.YELLOW) .arcWidth(25) .arcHeight(25) .style(effectStr).build(); return sp3; }
public Help() { Rectangle background = RectangleBuilder.create() .width(460) .height(300) .arcWidth(20) .arcHeight(20) .fill(Color.rgb(0, 0, 0, 0.5)) .build(); Text text = TextBuilder.create() .text("Welcome to Jumpman !\n" + "Avoid the fireballs and make it to the goal as fast as possible.\n" + "You can afford getting hit once, but not twice !\n\n" + "Jumpman has the following skills:\n\n" + " * Walk: by pressing the left or right arrow keys.\n" + " * Run: by holding the F key while walking.\n" + " * Brake: by pressing the opposite arrow key while moving.\n" + " * Duck: by pressing the down arrow key.\n" + " * Jump: by pressing the space key.\n\n" + "Holding space longer will make Jumpman jump higher.\n" + "Pressing more than one arrow key at the same time will not work.\n\n" + "Press the escape key to close this window and start playing.") .font(Font.font("Arial", FontWeight.NORMAL, 14)) .fill(Color.WHITE) .build(); getChildren().addAll(background, text); setOpacity(0); AnchorPane root = View.getInstance().getRoot(); translateXProperty().bind(root.widthProperty().divide(2).subtract(widthProperty().divide(2))); translateYProperty().bind(root.heightProperty().divide(2).subtract(heightProperty().divide(2))); }
public ClippedNode(Node content, double width, double height) { this.width = width; this.height = height; this.content = content; this.clip = RectangleBuilder.create().width(width).height(height).build(); this.content.setClip(this.clip); this.content.translateXProperty().bind(transX.multiply(-1)); this.content.translateYProperty().bind(transY.multiply(-1)); this.clip.translateXProperty().bind(transX); this.clip.translateYProperty().bind(transY); getChildren().setAll(content); }
private void configureBox(VBox root) { StackPane container = new StackPane(); container.setPrefHeight(250); container.setPrefSize(boxBounds.getWidth(), boxBounds.getHeight()); container.setStyle("-fx-border-width:1px;-fx-border-style:solid;-fx-border-color:#999999;"); /* BOTTOM PANE */ Stop[] stops = new Stop[] { new Stop(0, Color.web("#F89C8C")), new Stop(1, Color.web("#BE250A"))}; LinearGradient lg = new LinearGradient(0, 0, 0, 1, true, CycleMethod.NO_CYCLE, stops); bottomPane = new StackPane(); bottomPane.getChildren().addAll(RectangleBuilder.create().width(boxBounds.getWidth()).height(boxBounds.getHeight()).fill(lg).build(), TextBuilder.create().text("Click the above \"Slide Down\" button to see the top pane content...").wrappingWidth(200).font(Font.font("Arial", 22)).build()); /* TOP PANE */ Stop[] stops2 = new Stop[] { new Stop(0, Color.web("#FFFFFF")), new Stop(1, Color.web("#50AABC"))}; LinearGradient lg2 = new LinearGradient(0, 0, 0, 1, true, CycleMethod.NO_CYCLE, stops2); StackPane sp1 = new StackPane(); sp1.getChildren().add(TextBuilder.create().text("Click the below \"Slide Up\" button to see the bottom pane content...").wrappingWidth(200).font(Font.font("Arial", 22)).build()); topPane = new StackPane(); topPane.getChildren().addAll(RectangleBuilder.create().width(boxBounds.getWidth()).height(boxBounds.getHeight()).fill(lg2).build(), sp1); container.getChildren().addAll(bottomPane,topPane); setAnimation(); Group gp = new Group(); gp.getChildren().add(container); root.getChildren().addAll(getActionPane(),gp); }
@Override public void start(Stage stage) throws Exception { // Create a vbox to position all nodes in a vertical stack VBox root = new VBox(); // Create a toolbar ToolBar toolbar = new ToolBar(); toolbar.getItems().add(new Button("Do something!")); // position a rectangle absolutely Rectangle r = RectangleBuilder.create() .x(-100) // absolute position in container .y(100) // absolute position in container .fill(Color.AQUA) .width(50) .height(50) .build(); Group canvas = new Group(r); // put the toolbar and the canvas group in the vbox. // Add the toolbar first so it is on top root.getChildren().addAll(toolbar, canvas); Scene scene = new Scene(root, 400, 400); stage.setScene(scene); stage.setTitle("Group Bounds Example"); stage.show(); ScenicView.show(scene); /* Notice how the entire rectangle is on screen? * This is because the bounds of the Group expand to fit the entire * rectangle effectively pushing the origin of the Group over. */ }
@Override public void start(Stage stage) throws Exception { // Create a vbox to position all nodes in a vertical stack VBox root = new VBox(); // Create a toolbar ToolBar toolbar = new ToolBar(); toolbar.getItems().add(new Button("Do something!")); // position a rectangle absolutely Rectangle r = RectangleBuilder.create() .x(-100) // absolute position in container .y(100) // absolute position in container .fill(Color.AQUA) .width(50) .height(50) .build(); Pane canvas = new Pane(); canvas.getChildren().add(r); // put the toolbar and the canvas group in the vbox. // Add the toolbar first so it is on top root.getChildren().addAll(toolbar, canvas); Scene scene = new Scene(root, 400, 400); stage.setScene(scene); stage.setTitle("Pane As Canvas Example"); stage.show(); ScenicView.show(scene); /* Now the Rectangle will be completely off screen as we might expect * A Pane does not expand to include all its children, so if there is an * object with a negative position, the it will not be shown. */ }
@Override public void start(Stage stage) throws Exception { // Create a pane as the scene root Pane root = new Pane(); // position a rectangle absolutely // NOTE: A rectangle is drawn from the upper left hand corner Rectangle r = RectangleBuilder.create() .x(100) // absolute position in container .y(100) // absolute position in container .fill(Color.AQUA) .width(50) .height(50) .build(); // NOTE: A circle is drawn from the center Circle c = CircleBuilder.create() .centerX(200) .centerY(200) .radius(50) .fill(Color.ORANGERED) .build(); root.getChildren().addAll(r,c); Scene scene = new Scene(root, 400, 400); stage.setScene(scene); stage.setTitle("Position Nodes Aboslutely"); stage.show(); ScenicView.show(scene); /* * If you inspect the rectangle and circle with SceniceView, you'll * that they don't have a layoutX/Y. When you position nodes absolutely * layoutX/Y is never set. This isn't a problem, just be aware that it * happens. It can effect the way you do custom layouts. */ }
public Cube(double size, Color color, double shade) { getTransforms().addAll(rz, ry, rx); getChildren().addAll( RectangleBuilder.create() // back face .width(size).height(size) .fill(color.deriveColor(0.0, 1.0, (1 - 0.5*shade), 1.0)) .translateX(-0.5*size) .translateY(-0.5*size) .translateZ(0.5*size) .build(), RectangleBuilder.create() // bottom face .width(size).height(size) .fill(color.deriveColor(0.0, 1.0, (1 - 0.4*shade), 1.0)) .translateX(-0.5*size) .translateY(0) .rotationAxis(Rotate.X_AXIS) .rotate(90) .build(), RectangleBuilder.create() // right face .width(size).height(size) .fill(color.deriveColor(0.0, 1.0, (1 - 0.3*shade), 1.0)) .translateX(-1*size) .translateY(-0.5*size) .rotationAxis(Rotate.Y_AXIS) .rotate(90) .build(), RectangleBuilder.create() // left face .width(size).height(size) .fill(color.deriveColor(0.0, 1.0, (1 - 0.2*shade), 1.0)) .translateX(0) .translateY(-0.5*size) .rotationAxis(Rotate.Y_AXIS) .rotate(90) .build(), RectangleBuilder.create() // top face .width(size).height(size) .fill(color.deriveColor(0.0, 1.0, (1 - 0.1*shade), 1.0)) .translateX(-0.5*size) .translateY(-1*size) .rotationAxis(Rotate.X_AXIS) .rotate(90) .build(), RectangleBuilder.create() // top face .width(size).height(size) .fill(color) .translateX(-0.5*size) .translateY(-0.5*size) .translateZ(-0.5*size) .build() ); }
public Cube(double size, Color color, double shade) { getTransforms().addAll(rz, ry, rx, s); getChildren().addAll( RectangleBuilder.create() // back face .width(size).height(size) .fill(color.deriveColor(0.0, 1.0, (1 - 0.5*shade), 1.0)) .translateX(-0.5*size) .translateY(-0.5*size) .translateZ(0.5*size) .build(), RectangleBuilder.create() // bottom face .width(size).height(size) .fill(color.deriveColor(0.0, 1.0, (1 - 0.4*shade), 1.0)) .translateX(-0.5*size) .translateY(0) .rotationAxis(Rotate.X_AXIS) .rotate(90) .build(), RectangleBuilder.create() // right face .width(size).height(size) .fill(color.deriveColor(0.0, 1.0, (1 - 0.3*shade), 1.0)) .translateX(-1*size) .translateY(-0.5*size) .rotationAxis(Rotate.Y_AXIS) .rotate(90) .build(), RectangleBuilder.create() // left face .width(size).height(size) .fill(color.deriveColor(0.0, 1.0, (1 - 0.2*shade), 1.0)) .translateX(0) .translateY(-0.5*size) .rotationAxis(Rotate.Y_AXIS) .rotate(90) .build(), RectangleBuilder.create() // top face .width(size).height(size) .fill(color.deriveColor(0.0, 1.0, (1 - 0.1*shade), 1.0)) .translateX(-0.5*size) .translateY(-1*size) .rotationAxis(Rotate.X_AXIS) .rotate(90) .build(), RectangleBuilder.create() // top face .width(size).height(size) .fill(color) .translateX(-0.5*size) .translateY(-0.5*size) .translateZ(-0.5*size) .build() ); }
@Override public void start(Stage stage) { final Group root; Scene scene = SceneBuilder.create() .width(500).height(500) .fill(Color.WHITE) .root(root = GroupBuilder.create() .children(RectangleBuilder.create() .layoutX(5).layoutY(5) .width(490).height(490) .fill(Color.LIGHTSKYBLUE) .onMouseClicked(new EventHandler<MouseEvent>() { // Eventhandler for mouse click event @Override public void handle(MouseEvent e) { if (clickcount > 2) { initialize(); } for (int j = clickcount; j < 3; j++) { org_x[j].set(e.getSceneX()); org_y[j].set(e.getSceneY()); } clickcount++; } }).build(), // line for x-axis through the Origin LineBuilder.create() .startX(5).startY(490) .endX(495).endY(490) .build(), // Line for y-axis through the Origin LineBuilder.create() .startX(10).startY(5) .endX(10).endY(495) .build(), // grid horizontal lines which interval is of 1cm a_x_l[0], a_x_l[1], a_x_l[2], a_x_l[3], a_x_l[4], a_x_l[5], a_x_l[6], a_x_l[7], a_x_l[8], a_x_l[9], a_x_l[10], a_x_l[11], // grid vertical lines which interval is of 1cm a_y_l[0], a_y_l[1], a_y_l[2], a_y_l[3], a_y_l[4], a_y_l[5], a_y_l[6], a_y_l[7], a_y_l[8], a_y_l[9], a_y_l[10], a_y_l[11], // Sides l[0], l[1], l[2], // Vertices c[0], c[1], c[2], // the printing space of the coordinates and // the area of triangle HBoxBuilder.create() .layoutX(10) .padding(new Insets(10, 10, 10, 10)).spacing(3) .alignment(Pos.BOTTOM_CENTER) .children( LabelBuilder.create().text("A(").build(), tx[0], LabelBuilder.create().text(",").build(), ty[0], LabelBuilder.create().text("),").build(), LabelBuilder.create().text("B(").build(), tx[1], LabelBuilder.create().text(",").build(), ty[1], LabelBuilder.create().text("),").build(), LabelBuilder.create().text("C(").build(), tx[2], LabelBuilder.create().text(",").build(), ty[2], LabelBuilder.create().text(") ⇒ ").build(), area_Label ).build() ).build() ).build(); stage.setTitle("Triangle Area"); stage.setScene(scene); stage.show(); }
public void addGraphicControl(final String title, final ObjectProperty<Node> graphicProperty) { final Node circle = CircleBuilder.create().radius(4).fill(Color.ORANGE).build(); final Node square = RectangleBuilder.create().width(8).height(8).build(); final Node text = TextBuilder.create().text("test").build(); final ComboBox<Node> choices = new ComboBox<Node>(FXCollections.observableArrayList(circle, square, text)); choices.setCellFactory(new Callback<ListView<Node>, ListCell<Node>>() { @Override public ListCell<Node> call(final ListView<Node> param) { final ListCell<Node> cell = new ListCell<Node>() { @Override public void updateItem(final Node item, final boolean empty) { super.updateItem(item, empty); if (item != null) { setText(item.getClass().getSimpleName()); } else { setText(null); } } }; return cell; } }); choices.getSelectionModel().select(0); graphicProperty.bind(choices.valueProperty()); final VBox box = new VBox(); final Text titleText = new Text(title); titleText.textProperty().bind(new StringBinding() { { super.bind(choices.selectionModelProperty()); } @Override protected String computeValue() { return title + " : " + String.valueOf(choices.selectionModelProperty().get().getSelectedItem().getClass().getSimpleName()); } }); box.getChildren().addAll(titleText, choices); getChildren().add(box); }
@Override public void start(Stage stage) throws Exception { // Create a pane as the scene root Pane root = new Pane(); // position a rectangle absolutely // NOTE: A rectangle is drawn from the upper left hand corner Rectangle r = RectangleBuilder.create() .x(0) // absolute position in container .y(0) // absolute position in container .fill(Color.AQUA) .width(50) .height(50) .build(); r.relocate(100, 100); // NOTE: A circle is drawn from the center Circle c = CircleBuilder.create() .centerX(0) .centerY(0) .radius(50) .fill(Color.ORANGERED) .build(); c.relocate(200, 200); root.getChildren().addAll(r,c); Scene scene = new Scene(root, 400, 400); stage.setScene(scene); stage.setTitle("Position Nodes With Relocate"); stage.show(); ScenicView.show(scene); /* * This approach treats the shape as its own coordinate system and uses * layoutX/Y to position the nodes. * * Check layoutX/Y for the circle. Notice anything strange? It's position * says it is 250, 250. What?! Remember that when you use relocate(x, y) * it does the calculation finalX - getLayoutBounds().getMinX(). * Because a circle is drawn from the center it's layout bounds are * [-50, -50, 100, 100]. 200 - -50 is 250. If you want to know the * position of the circle in the parent container, use * boundsInParent.getMinX/Y(). This also works for rectangles. */ }
@Override public void start(Stage stage) throws Exception { // Create a pane as the scene root Pane root = new Pane(); // position a rectangle absolutely // NOTE: A rectangle is drawn from the upper left hand corner Rectangle r = RectangleBuilder.create() .x(0) // absolute position in container .y(0) // absolute position in container .fill(Color.AQUA) .width(50) .height(50) .build(); r.relocate(100, 100); // NOTE: A circle is drawn from the center Circle c = CircleBuilder.create() .centerX(0) .centerY(0) .radius(50) .fill(Color.ORANGERED) .build(); c.relocate(200, 200); Group g = new Group(r, c); g.relocate(0, 0); // add/remove this line to see the effect of relocate root.getChildren().add(g); Scene scene = new Scene(root, 400, 400); stage.setScene(scene); stage.setTitle("Position Nodes With Relocate"); stage.show(); ScenicView.show(scene); /* *By default the bounds of the Group will be the sum of it's children's *bounds. If we don't set it's position with relocate, we'll need to use *BoundsInParent.getMinX/Y() to get it's position. * *Notice also that if we don't call g.relocate() the circles and rectangles *positions appear to be with respect to the Pane's coordinate system. That is *the Group is just wrapping the rectangle and circle. The only way we *can treat a Group like a coordinate system is use relocate to position *it. Then it behaves as we might expect. */ }
public VerticalTab(String name, int selectIndex, VerticalTabPane parent) { this.name = name; this.parent = parent; this.selectIndex = selectIndex; setId(name); // build tab Shape tabRect = RectangleBuilder.create() .x(0) .y(selectIndex * TAB_HEIGHT + (3 * (selectIndex + 1))) .arcWidth(6) .arcHeight(6) .width(TAB_WIDTH + 3) // allow overlap for union of tab and content rectangle .height(TAB_HEIGHT) //.fill(Color.rgb(0, 0, 0, .50)) //.stroke(Color.WHITE) .build(); Rectangle contentRect = RectangleBuilder.create() .x(TAB_WIDTH) .y(0) .arcWidth(10) .arcHeight(10) .width(parent.getPrefWidth() - TAB_WIDTH) .height(parent.getPrefHeight()) .build(); Shape tabShape = Shape.union(tabRect, contentRect); tabContentShape = tabShape; tabShape.setStroke(Color.WHITE); tabShape.setFill(Color.rgb(0, 0, 0, .70)); group.getChildren().add(tabShape); // IMPORTANT now you add the tab region with white stroke after union operation // when using shape operations don't mess with colors until after. tabRect = Shape.subtract(tabRect, contentRect); tabRect.setFill(Color.rgb(0, 0, 0, .70)); tabRect.setStroke(Color.WHITE); tabRectangle = tabRect; group.getChildren().add(tabRectangle); // build content region getChildren().add(group); group.setOnMousePressed((me) -> { logger.info("Tab pressed " + selectIndex); }); // add the text of the tab last double topTabY = selectIndex * TAB_HEIGHT + (3 * (selectIndex + 1)); double bottomTextY = topTabY + TAB_HEIGHT - (3 * (selectIndex + 1)); Text text = new Text(TAB_WIDTH - 6,bottomTextY, name); text.setFont(Font.font("SanSerif", 13)); text.setStroke(Color.WHITE); text.setFill(Color.WHITE); text.getTransforms().add(Transform.rotate(-90, TAB_WIDTH - 6, bottomTextY)); getChildren().add(text); }