Search in sources :

Example 81 with Rectangle

use of javafx.scene.shape.Rectangle in project org.csstudio.display.builder by kasemir.

the class BaseLEDRepresentation method createLED.

private void createLED() {
    jfx_node.getChildren().clear();
    if (model_widget.propSquare().getValue())
        led = new Rectangle();
    else
        led = new Ellipse();
    led.getStyleClass().add("led");
    led.setManaged(false);
    label = new Label();
    label.getStyleClass().add("led_label");
    label.setAlignment(Pos.CENTER);
    label.setManaged(false);
    jfx_node.getChildren().addAll(led, label);
}
Also used : Ellipse(javafx.scene.shape.Ellipse) Rectangle(javafx.scene.shape.Rectangle) Label(javafx.scene.control.Label)

Example 82 with Rectangle

use of javafx.scene.shape.Rectangle in project org.csstudio.display.builder by kasemir.

the class PopupDemo method start.

@Override
public void start(final Stage stage) {
    final Popup popup = new Popup();
    final BorderPane content = new BorderPane(new Label("Center"), new Label("Top"), new Label("Right"), new Label("Bottom"), new Label("Left"));
    final Rectangle background = new Rectangle(100, 100, Color.LIGHTGRAY);
    final InvalidationListener resize_background = p -> {
        background.setWidth(content.getWidth());
        background.setHeight(content.getHeight());
    };
    content.widthProperty().addListener(resize_background);
    content.heightProperty().addListener(resize_background);
    final StackPane stack = new StackPane(background, content);
    popup.getContent().addAll(stack);
    final Button toggle_popup = new Button("Popup");
    final ChangeListener<Number> track_moves = (p, old, current) -> {
        // Position popup just below button
        final Bounds bounds = toggle_popup.localToScreen(toggle_popup.getBoundsInLocal());
        popup.setX(bounds.getMinX());
        popup.setY(bounds.getMaxY());
    };
    toggle_popup.setOnAction(event -> {
        if (popup.isShowing()) {
            popup.hide();
            toggle_popup.getScene().getWindow().xProperty().removeListener(track_moves);
            toggle_popup.getScene().getWindow().yProperty().removeListener(track_moves);
        } else {
            toggle_popup.getScene().getWindow().xProperty().addListener(track_moves);
            toggle_popup.getScene().getWindow().yProperty().addListener(track_moves);
            track_moves.changed(null, null, null);
            popup.show(stage);
        }
    });
    final BorderPane layout = new BorderPane(toggle_popup);
    stage.setScene(new Scene(layout));
    stage.show();
}
Also used : Button(javafx.scene.control.Button) Scene(javafx.scene.Scene) Color(javafx.scene.paint.Color) Label(javafx.scene.control.Label) Rectangle(javafx.scene.shape.Rectangle) StackPane(javafx.scene.layout.StackPane) InvalidationListener(javafx.beans.InvalidationListener) Application(javafx.application.Application) Popup(javafx.stage.Popup) Stage(javafx.stage.Stage) BorderPane(javafx.scene.layout.BorderPane) ChangeListener(javafx.beans.value.ChangeListener) Bounds(javafx.geometry.Bounds) BorderPane(javafx.scene.layout.BorderPane) Button(javafx.scene.control.Button) Popup(javafx.stage.Popup) Bounds(javafx.geometry.Bounds) Label(javafx.scene.control.Label) Rectangle(javafx.scene.shape.Rectangle) InvalidationListener(javafx.beans.InvalidationListener) Scene(javafx.scene.Scene) StackPane(javafx.scene.layout.StackPane)

Example 83 with Rectangle

use of javafx.scene.shape.Rectangle in project org.csstudio.display.builder by kasemir.

the class ByteMonitorRepresentation method addLEDs.

private void addLEDs(final Pane pane, final double w, final double h, final boolean horizontal) {
    final Color text_color = JFXUtil.convert(model_widget.propForegroundColor().getValue());
    final Font text_font = JFXUtil.convert(model_widget.propFont().getValue());
    final int save_bits = numBits;
    final boolean save_sq = square_led;
    final Color[] save_colorVals = value_colors;
    final Shape[] leds = new Shape[save_bits];
    final Label[] labels = new Label[save_bits];
    final double gap = 4;
    double led_w, led_h, dx, dy, rad;
    if (horizontal) {
        dx = w / save_bits;
        dy = 0;
        led_w = dx;
        led_h = h;
        rad = led_w / 2;
    } else {
        dx = 0;
        dy = h / save_bits;
        led_w = w;
        led_h = dy;
        rad = led_h / 2;
    }
    double x = 0.0, y = 0.0;
    for (int i = 0; i < save_bits; i++) {
        final Label label;
        final int lbl_index = bitReverse ? i : save_bits - i - 1;
        if (lbl_index < model_widget.propLabels().size()) {
            label = new Label(model_widget.propLabels().getElement(lbl_index).getValue());
            label.getStyleClass().add("led_label");
            label.setFont(text_font);
            label.setTextFill(text_color);
            label.setManaged(false);
        } else
            label = null;
        final Shape led;
        if (save_sq) {
            final Rectangle rect = new Rectangle();
            rect.setX(x);
            rect.setY(y);
            rect.setWidth(led_w);
            rect.setHeight(led_h);
            led = rect;
            if (label != null) {
                label.relocate(x, y);
                label.resize(led_w, led_h);
                label.setAlignment(Pos.CENTER);
                if (horizontal)
                    label.setRotate(-90);
            }
        } else {
            final Ellipse ell = new Ellipse();
            ell.setCenterX(x + rad);
            ell.setCenterY(y + rad);
            ell.setRadiusX(rad);
            ell.setRadiusY(rad);
            led = ell;
            if (label != null) {
                if (horizontal) {
                    label.getTransforms().setAll(new Rotate(-90.0));
                    // label.setBackground(new Background(new BackgroundFill(Color.BISQUE, CornerRadii.EMPTY, Insets.EMPTY)));
                    label.relocate(x, y + led_h);
                    label.resize(led_h - 2 * rad - gap, led_w);
                    label.setAlignment(Pos.CENTER_RIGHT);
                } else {
                    label.relocate(x + 2 * rad + gap, y);
                    label.resize(led_w - 2 * rad - gap, led_h);
                }
            }
        }
        led.getStyleClass().add("led");
        led.setManaged(false);
        if (save_colorVals != null && i < save_colorVals.length)
            led.setFill(toolkit.isEditMode() ? editColor() : save_colorVals[i]);
        leds[i] = led;
        labels[i] = label;
        if (label != null)
            label.layout();
        x += dx;
        y += dy;
    }
    this.leds = leds;
    pane.getChildren().setAll(leds);
    for (Label label : labels) if (label != null)
        pane.getChildren().add(label);
}
Also used : Ellipse(javafx.scene.shape.Ellipse) Shape(javafx.scene.shape.Shape) Rotate(javafx.scene.transform.Rotate) Color(javafx.scene.paint.Color) Label(javafx.scene.control.Label) Rectangle(javafx.scene.shape.Rectangle) Font(javafx.scene.text.Font) Paint(javafx.scene.paint.Paint)

Example 84 with Rectangle

use of javafx.scene.shape.Rectangle in project org.csstudio.display.builder by kasemir.

the class GroupVsPaneDemo method start.

@Override
public void start(Stage primaryStage) {
    Pane pane = new Pane();
    Group group = new Group();
    VBox.setVgrow(group, Priority.NEVER);
    VBox.setVgrow(pane, Priority.NEVER);
    VBox vbox = new VBox(group, pane);
    Rectangle rect1 = new Rectangle(100, 100, 100, 100);
    Rectangle rect2 = new Rectangle(100, 100, 100, 100);
    Rectangle rect3 = new Rectangle(200, 200, 100, 100);
    Rectangle rect4 = new Rectangle(200, 200, 100, 100);
    rect1.setFill(Color.BLUE);
    rect2.setFill(Color.BLUE);
    rect3.setFill(Color.GREEN);
    rect4.setFill(Color.GREEN);
    group.getChildren().addAll(rect1, rect3);
    pane.getChildren().addAll(rect2, rect4);
    Scene scene = new Scene(vbox, 800, 800);
    scene.addEventHandler(KeyEvent.KEY_PRESSED, e -> {
        double deltaX;
        switch(e.getCode()) {
            case LEFT:
                deltaX = -10;
                break;
            case RIGHT:
                deltaX = 10;
                break;
            default:
                deltaX = 0;
        }
        rect3.setX(rect3.getX() + deltaX);
        rect4.setX(rect4.getX() + deltaX);
    });
    primaryStage.setScene(scene);
    primaryStage.show();
}
Also used : Group(javafx.scene.Group) Rectangle(javafx.scene.shape.Rectangle) Scene(javafx.scene.Scene) Pane(javafx.scene.layout.Pane) VBox(javafx.scene.layout.VBox)

Example 85 with Rectangle

use of javafx.scene.shape.Rectangle in project blue by kunstmusik.

the class BSBObjectViewHolder method resizeRight.

protected void resizeRight(MouseEvent evt) {
    Rectangle r = (Rectangle) evt.getSource();
    Point2D curPoint = r.localToParent(evt.getX(), evt.getY());
    curPoint = localToParent(curPoint);
    GridSettings grid = selection.getGridSettings();
    int diff = (int) (curPoint.getX() - mouseOrigin.getX());
    int newWidth = (int) originBounds.getWidth() + diff;
    if (grid.isSnapEnabled()) {
        double left = getLayoutX();
        double right = left + newWidth;
        int w = grid.getWidth();
        newWidth = (int) ((Math.round(right / w) * w) - left);
    }
    newWidth = Math.max(newWidth, rView.getWidgetMinimumWidth());
    if (newWidth != rView.getWidgetWidth()) {
        rView.setWidgetWidth(newWidth);
    }
    evt.consume();
}
Also used : Point2D(javafx.geometry.Point2D) Rectangle(javafx.scene.shape.Rectangle) GridSettings(blue.orchestra.blueSynthBuilder.GridSettings)

Aggregations

Rectangle (javafx.scene.shape.Rectangle)190 Point2D (javafx.geometry.Point2D)33 Text (javafx.scene.text.Text)28 Entity (com.almasb.fxgl.entity.Entity)27 Circle (javafx.scene.shape.Circle)20 Color (javafx.scene.paint.Color)18 HitBox (com.almasb.fxgl.physics.HitBox)16 Pane (javafx.scene.layout.Pane)16 Group (javafx.scene.Group)15 Node (javafx.scene.Node)14 PhysicsComponent (com.almasb.fxgl.physics.PhysicsComponent)12 Scene (javafx.scene.Scene)12 EntityView (com.almasb.fxgl.entity.view.EntityView)10 Label (javafx.scene.control.Label)10 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 TextFlow (javafx.scene.text.TextFlow)8 CollidableComponent (com.almasb.fxgl.entity.component.CollidableComponent)7 Bounds (javafx.geometry.Bounds)7 KeyCode (javafx.scene.input.KeyCode)7