use of javafx.scene.control.ScrollPane in project org.csstudio.display.builder by kasemir.
the class JFXRepresentation method createModelRoot.
/**
* Create scrollpane etc. for hosting the model
*
* @return ScrollPane
* @throws IllegalStateException if had already been called
*/
public final ScrollPane createModelRoot() {
if (model_root != null)
throw new IllegalStateException("Already created model root");
widget_parent = new Pane();
scroll_body = new Group(widget_parent);
if (isEditMode()) {
horiz_bound = new Line();
horiz_bound.getStyleClass().add("display_model_bounds");
horiz_bound.setStartX(0);
vert_bound = new Line();
vert_bound.getStyleClass().add("display_model_bounds");
vert_bound.setStartY(0);
scroll_body.getChildren().addAll(vert_bound, horiz_bound);
}
model_root = new ScrollPane(scroll_body);
final InvalidationListener resized = prop -> handleViewportChanges();
model_root.widthProperty().addListener(resized);
model_root.heightProperty().addListener(resized);
// Middle Button (Wheel press) drag panning started
final EventHandler<MouseEvent> onMousePressedHandler = evt -> {
if (evt.isMiddleButtonDown()) {
lastMouseCoordinates.set(new Point2D(evt.getX(), evt.getY()));
scroll_body.setCursor(Cursor.CLOSED_HAND);
evt.consume();
}
};
if (isEditMode())
scroll_body.addEventFilter(MouseEvent.MOUSE_PRESSED, onMousePressedHandler);
else
scroll_body.setOnMousePressed(onMousePressedHandler);
// Middle Button (Wheel press) drag panning function
final EventHandler<MouseEvent> onMouseDraggedHandler = evt -> {
if (evt.isMiddleButtonDown()) {
double deltaX = evt.getX() - lastMouseCoordinates.get().getX();
double extraWidth = scroll_body.getLayoutBounds().getWidth() - model_root.getViewportBounds().getWidth();
double deltaH = deltaX * (model_root.getHmax() - model_root.getHmin()) / extraWidth;
double desiredH = model_root.getHvalue() - deltaH;
model_root.setHvalue(Math.max(0, Math.min(model_root.getHmax(), desiredH)));
double deltaY = evt.getY() - lastMouseCoordinates.get().getY();
double extraHeight = scroll_body.getLayoutBounds().getHeight() - model_root.getViewportBounds().getHeight();
double deltaV = deltaY * (model_root.getHmax() - model_root.getHmin()) / extraHeight;
double desiredV = model_root.getVvalue() - deltaV;
model_root.setVvalue(Math.max(0, Math.min(model_root.getVmax(), desiredV)));
evt.consume();
}
};
if (isEditMode())
scroll_body.addEventFilter(MouseEvent.MOUSE_DRAGGED, onMouseDraggedHandler);
else
scroll_body.setOnMouseDragged(onMouseDraggedHandler);
// Middle Button (Wheel press) drag panning finished
final EventHandler<MouseEvent> onMouseReleasedHandler = evt -> {
if (scroll_body.getCursor() == Cursor.CLOSED_HAND) {
scroll_body.setCursor(Cursor.DEFAULT);
evt.consume();
}
};
if (isEditMode())
scroll_body.addEventFilter(MouseEvent.MOUSE_RELEASED, onMouseReleasedHandler);
else
scroll_body.setOnMouseReleased(onMouseReleasedHandler);
// also handle the wheel
if (isEditMode())
model_root.addEventFilter(ScrollEvent.ANY, evt -> {
if (evt.isControlDown()) {
evt.consume();
doWheelZoom(evt.getDeltaY(), evt.getX(), evt.getY());
}
});
else
widget_parent.addEventHandler(ScrollEvent.ANY, evt -> {
if (evt.isControlDown()) {
evt.consume();
ScrollEvent gevt = evt.copyFor(model_root, scroll_body);
doWheelZoom(evt.getDeltaY(), gevt.getX(), gevt.getY());
}
});
return model_root;
}
use of javafx.scene.control.ScrollPane in project org.csstudio.display.builder by kasemir.
the class ZoomPan method createScene.
public static Scene createScene() {
// Stuff to show as 'widgets'
final Node[] stuff = new Node[3];
for (int i = 0; i < stuff.length; ++i) {
final Rectangle rect = new Rectangle(50 + i * 100, 100, 10 + i * 50, 20 + i * 40);
rect.setFill(Color.BLUE);
stuff[i] = rect;
}
// With 'Group', stuff would start in top-left (0, 0) corner,
// not at (50, 100) based on its coordinates
final Pane widgets = new Pane(stuff);
widgets.setStyle("-fx-background-color: coral;");
final ScrollPane scroll;
if (true) {
// Additional Group to help ScrollPane get correct bounds
final Group scroll_content = new Group(widgets);
scroll = new ScrollPane(scroll_content);
} else
scroll = new ScrollPane(widgets);
final InvalidationListener resized = prop -> handleViewportChanges(scroll);
scroll.widthProperty().addListener(resized);
scroll.heightProperty().addListener(resized);
System.out.println("Press 'space' to change zoom");
final Scene scene = new Scene(scroll);
scene.addEventFilter(KeyEvent.KEY_PRESSED, (KeyEvent event) -> {
if (event.getCode() == KeyCode.SPACE) {
zoom_in = !zoom_in;
if (zoom_in)
widgets.getTransforms().setAll(new Scale(2.5, 2.5));
else
widgets.getTransforms().setAll(new Scale(0.5, 0.5));
}
});
return scene;
}
use of javafx.scene.control.ScrollPane in project narchy by automenta.
the class RDPCV method createScrollPane.
/**
* @return a ScrollPane which scrolls the layout.
*/
private ScrollPane createScrollPane(Pane layout) {
ScrollPane scroll = new ScrollPane();
scroll.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scroll.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scroll.setPannable(true);
scroll.setPrefSize(800, 600);
scroll.setContent(layout);
return scroll;
}
use of javafx.scene.control.ScrollPane in project S4T1TM2 by CSUS-CSC-131-Spring2018.
the class YaamDemo method constructInnerContent.
private void constructInnerContent() {
innerContent = new ScrollPane();
innerContent.setId("innerContent");
innerContent.layoutXProperty().bind(sidebar.widthProperty());
innerContent.layoutYProperty().bind(brandName.heightProperty());
innerContent.prefWidthProperty().bind(content.widthProperty().subtract(brandName.widthProperty()));
innerContent.prefHeightProperty().bind(content.heightProperty().subtract(brandName.heightProperty()));
content.getChildren().add(innerContent);
}
use of javafx.scene.control.ScrollPane in project bisq-desktop by bisq-network.
the class TakeOfferView method addScrollPane.
// /////////////////////////////////////////////////////////////////////////////////////////
// Build UI elements
// /////////////////////////////////////////////////////////////////////////////////////////
private void addScrollPane() {
scrollPane = new ScrollPane();
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
scrollPane.setFitToWidth(true);
scrollPane.setFitToHeight(true);
scrollPane.setOnScroll(e -> InputTextField.hideErrorMessageDisplay());
AnchorPane.setLeftAnchor(scrollPane, 0d);
AnchorPane.setTopAnchor(scrollPane, 0d);
AnchorPane.setRightAnchor(scrollPane, 0d);
AnchorPane.setBottomAnchor(scrollPane, 0d);
root.getChildren().add(scrollPane);
}
Aggregations