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);
}
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();
}
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);
}
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();
}
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();
}
Aggregations