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 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 blue by kunstmusik.
the class BSBObjectViewHolder method setupResizeHandles.
private void setupResizeHandles(Rectangle rect, BSBEditSelection selection) {
if (!(bsbObjectView instanceof ResizeableView)) {
return;
}
BooleanBinding visibleBinding = Bindings.createBooleanBinding(() -> rect.isVisible() && selection.selection.size() == 1, rect.visibleProperty(), selection.selection);
rView = (ResizeableView) bsbObjectView;
if (rView.canResizeWidgetWidth()) {
Rectangle resizeLeftHandle = new Rectangle(5, 5);
resizeLeftHandle.setManaged(false);
resizeLeftHandle.setFill(Color.rgb(0, 255, 0));
resizeLeftHandle.setLayoutX(-2);
resizeLeftHandle.yProperty().bind(rect.heightProperty().divide(2).subtract(2));
resizeLeftHandle.visibleProperty().bind(visibleBinding);
resizeLeftHandle.setCursor(Cursor.W_RESIZE);
resizeLeftHandle.setOnMousePressed(evt -> recordMouseOrigin(evt));
resizeLeftHandle.setOnMouseDragged(evt -> resizeLeft(evt));
Rectangle resizeRightHandle = new Rectangle(5, 5);
resizeRightHandle.setManaged(false);
resizeRightHandle.setFill(Color.rgb(0, 255, 0));
resizeRightHandle.xProperty().bind(rect.widthProperty().subtract(2));
resizeRightHandle.yProperty().bind(rect.heightProperty().divide(2).subtract(2));
resizeRightHandle.visibleProperty().bind(visibleBinding);
resizeRightHandle.setCursor(Cursor.E_RESIZE);
resizeRightHandle.setOnMousePressed(evt -> recordMouseOrigin(evt));
resizeRightHandle.setOnMouseDragged(evt -> resizeRight(evt));
getChildren().addAll(resizeLeftHandle, resizeRightHandle);
}
if (rView.canResizeWidgetHeight()) {
Rectangle resizeTopHandle = new Rectangle(5, 5);
resizeTopHandle.setManaged(false);
resizeTopHandle.setFill(Color.rgb(0, 255, 0));
resizeTopHandle.setLayoutY(-2);
resizeTopHandle.xProperty().bind(rect.widthProperty().divide(2).subtract(2));
resizeTopHandle.visibleProperty().bind(visibleBinding);
resizeTopHandle.setCursor(Cursor.N_RESIZE);
resizeTopHandle.setOnMousePressed(evt -> recordMouseOrigin(evt));
resizeTopHandle.setOnMouseDragged(evt -> resizeUp(evt));
Rectangle resizeBottomHandle = new Rectangle(5, 5);
resizeBottomHandle.setManaged(false);
resizeBottomHandle.setFill(Color.rgb(0, 255, 0));
resizeBottomHandle.yProperty().bind(rect.heightProperty().subtract(2));
resizeBottomHandle.xProperty().bind(rect.widthProperty().divide(2).subtract(2));
resizeBottomHandle.visibleProperty().bind(visibleBinding);
resizeBottomHandle.setCursor(Cursor.S_RESIZE);
resizeBottomHandle.setOnMousePressed(evt -> recordMouseOrigin(evt));
resizeBottomHandle.setOnMouseDragged(evt -> resizeDown(evt));
getChildren().addAll(resizeTopHandle, resizeBottomHandle);
}
}
use of javafx.scene.shape.Rectangle in project blue by kunstmusik.
the class BSBObjectViewHolder method resizeDown.
protected void resizeDown(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.getY() - mouseOrigin.getY());
int newHeight = (int) originBounds.getHeight() + diff;
if (grid.isSnapEnabled()) {
double top = getLayoutY();
double bottom = top + newHeight;
int h = grid.getHeight();
newHeight = (int) ((Math.round(bottom / h) * h) - top);
}
newHeight = Math.max(newHeight, rView.getWidgetMinimumHeight());
if (newHeight != rView.getWidgetHeight()) {
rView.setWidgetHeight(newHeight);
}
evt.consume();
}
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