Java Code Examples for javafx.geometry.Bounds

The following are top voted examples for showing how to use javafx.geometry.Bounds. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: marathonv5   File: JavaFXElementPropertyAccessor.java   Source Code and License 8 votes vote down vote up
public Point2D getPoint(TableView<?> tableView, int columnIndex, int rowIndex) {
    Set<Node> tableRowCell = tableView.lookupAll(".table-row-cell");
    TableRow<?> row = null;
    for (Node tableRow : tableRowCell) {
        TableRow<?> r = (TableRow<?>) tableRow;
        if (r.getIndex() == rowIndex) {
            row = r;
            break;
        }
    }
    Set<Node> cells = row.lookupAll(".table-cell");
    for (Node node : cells) {
        TableCell<?, ?> cell = (TableCell<?, ?>) node;
        if (tableView.getColumns().indexOf(cell.getTableColumn()) == columnIndex) {
            Bounds bounds = cell.getBoundsInParent();
            Point2D localToParent = cell.localToParent(bounds.getWidth() / 2, bounds.getHeight() / 2);
            Point2D rowLocal = row.localToScene(localToParent, true);
            return rowLocal;
        }
    }
    return null;
}
 
Example 2
Project: marathonv5   File: JavaFXTableViewElementScrollTest.java   Source Code and License 7 votes vote down vote up
public Point2D getPoint(TableView<?> tableView, int columnIndex, int rowIndex) {
    Set<Node> tableRowCell = tableView.lookupAll(".table-row-cell");
    TableRow<?> row = null;
    for (Node tableRow : tableRowCell) {
        TableRow<?> r = (TableRow<?>) tableRow;
        if (r.getIndex() == rowIndex) {
            row = r;
            break;
        }
    }
    Set<Node> cells = row.lookupAll(".table-cell");
    for (Node node : cells) {
        TableCell<?, ?> cell = (TableCell<?, ?>) node;
        if (tableView.getColumns().indexOf(cell.getTableColumn()) == columnIndex) {
            Bounds bounds = cell.getBoundsInParent();
            Point2D localToParent = cell.localToParent(bounds.getWidth() / 2, bounds.getHeight() / 2);
            Point2D rowLocal = row.localToScene(localToParent, true);
            return rowLocal;
        }
    }
    return null;
}
 
Example 3
Project: marathonv5   File: ImagePanel.java   Source Code and License 6 votes vote down vote up
private static void ensureVisible(ScrollPane pane, Node node) {
    Bounds viewport = pane.getViewportBounds();
    double contentHeight = pane.getContent().getBoundsInLocal().getHeight();
    double contentWidth = pane.getContent().getBoundsInLocal().getWidth();
    double nodeMinY = node.getBoundsInParent().getMinY();
    double nodeMaxY = node.getBoundsInParent().getMaxY();
    double nodeMinX = node.getBoundsInParent().getMinX();
    double nodeMaxX = node.getBoundsInParent().getMaxX();
    double viewportMinY = (contentHeight - viewport.getHeight()) * pane.getVvalue();
    double viewportMaxY = viewportMinY + viewport.getHeight();
    double viewportMinX = (contentWidth - viewport.getWidth()) * pane.getHvalue();
    double viewportMaxX = viewportMinX + viewport.getWidth();
    if (nodeMinY < viewportMinY) {
        pane.setVvalue(nodeMinY / (contentHeight - viewport.getHeight()));
    } else if (nodeMaxY > viewportMaxY) {
        pane.setVvalue((nodeMaxY - viewport.getHeight()) / (contentHeight - viewport.getHeight()));
    }
    if (nodeMinX < viewportMinX) {
        pane.setHvalue(nodeMinX / (contentWidth - viewport.getWidth()));
    } else if (nodeMaxX > viewportMaxX) {
        pane.setHvalue((nodeMaxX - viewport.getWidth()) / (contentWidth - viewport.getWidth()));
    }

}
 
Example 4
Project: marathonv5   File: FXEventQueueDevice.java   Source Code and License 6 votes vote down vote up
protected void ensureVisible(Node target) {
    ScrollPane scrollPane = getParentScrollPane(target);
    if (scrollPane == null) {
        return;
    }
    Node content = scrollPane.getContent();
    Bounds contentBounds = content.localToScene(content.getBoundsInLocal());
    Bounds viewportBounds = scrollPane.getViewportBounds();
    Bounds nodeBounds = target.localToScene(target.getBoundsInLocal());
    if (scrollPane.contains(nodeBounds.getMinX() - contentBounds.getMinX(), nodeBounds.getMinY() - contentBounds.getMinY())) {
        return;
    }
    double toVScroll = (nodeBounds.getMinY() - contentBounds.getMinY())
            * ((scrollPane.getVmax() - scrollPane.getVmin()) / (contentBounds.getHeight() - viewportBounds.getHeight()));
    scrollPane.setVvalue(toVScroll);
    double toHScroll = (nodeBounds.getMinX() - contentBounds.getMinX())
            * ((scrollPane.getHmax() - scrollPane.getHmin()) / (contentBounds.getWidth() - viewportBounds.getWidth()));
    scrollPane.setHvalue(toHScroll);
}
 
Example 5
Project: marathonv5   File: JavaFXElementPropertyAccessor.java   Source Code and License 6 votes vote down vote up
protected int getIndexAt(ListView<?> listView, Point2D point) {
    if (point == null) {
        return listView.getSelectionModel().getSelectedIndex();
    }
    point = listView.localToScene(point);
    Set<Node> lookupAll = getListCells(listView);
    ListCell<?> selected = null;
    for (Node cellNode : lookupAll) {
        Bounds boundsInScene = cellNode.localToScene(cellNode.getBoundsInLocal(), true);
        if (boundsInScene.contains(point)) {
            selected = (ListCell<?>) cellNode;
            break;
        }
    }
    if (selected == null) {
        return -1;
    }
    return selected.getIndex();
}
 
Example 6
Project: marathonv5   File: JavaFXElementPropertyAccessor.java   Source Code and License 6 votes vote down vote up
public int getRowAt(TreeView<?> treeView, Point2D point) {
    if (point == null) {
        return treeView.getSelectionModel().getSelectedIndex();
    }
    point = treeView.localToScene(point);
    int itemCount = treeView.getExpandedItemCount();
    @SuppressWarnings("rawtypes")
    List<TreeCell> cells = new ArrayList<>();
    for (int i = 0; i < itemCount; i++) {
        cells.add(getCellAt(treeView, i));
    }
    TreeCell<?> selected = null;
    for (Node cellNode : cells) {
        Bounds boundsInScene = cellNode.localToScene(cellNode.getBoundsInLocal(), true);
        if (boundsInScene.contains(point)) {
            selected = (TreeCell<?>) cellNode;
            break;
        }
    }
    if (selected == null) {
        return -1;
    }
    return selected.getIndex();
}
 
Example 7
Project: charts   File: World.java   Source Code and License 6 votes vote down vote up
private double[] getBounds(final List<Country> COUNTRIES) {
    double upperLeftX  = PREFERRED_WIDTH;
    double upperLeftY  = PREFERRED_HEIGHT;
    double lowerRightX = 0;
    double lowerRightY = 0;
    for (Country country : COUNTRIES) {
        List<CountryPath> paths = countryPaths.get(country.getName());
        for (int i = 0; i < paths.size(); i++) {
            CountryPath path   = paths.get(i);
            Bounds      bounds = path.getLayoutBounds();
            upperLeftX  = Math.min(bounds.getMinX(), upperLeftX);
            upperLeftY  = Math.min(bounds.getMinY(), upperLeftY);
            lowerRightX = Math.max(bounds.getMaxX(), lowerRightX);
            lowerRightY = Math.max(bounds.getMaxY(), lowerRightY);
        }
    }
    return new double[]{ upperLeftX, upperLeftY, lowerRightX, lowerRightY };
}
 
Example 8
Project: marathonv5   File: ScrollPaneSample2.java   Source Code and License 6 votes vote down vote up
private void scrollTo(Node target) {
	ScrollPane scrollPane = getParentScrollPane(target);
	if (scrollPane == null)
		return;
	Node content = scrollPane.getContent();
	Bounds contentBounds = content.localToScene(content.getBoundsInLocal());
	Bounds viewportBounds = scrollPane.getViewportBounds();
	Bounds nodeBounds = target.localToScene(target.getBoundsInLocal());
	double toVScroll = (nodeBounds.getMinY() - contentBounds.getMinY())
			* ((scrollPane.getVmax() - scrollPane.getVmin())
					/ (contentBounds.getHeight() - viewportBounds.getHeight()));
	if (toVScroll >= scrollPane.getVmin() && toVScroll < scrollPane.getVmax())
		scrollPane.setVvalue(toVScroll);
	double toHScroll = (nodeBounds.getMinX() - contentBounds.getMinX())
			* ((scrollPane.getHmax() - scrollPane.getHmin())
					/ (contentBounds.getWidth() - viewportBounds.getWidth()));
	if (toHScroll >= scrollPane.getHmin() && toHScroll < scrollPane.getHmax())
		scrollPane.setHvalue(toHScroll);
}
 
Example 9
Project: marathonv5   File: RFXComponentTest.java   Source Code and License 6 votes vote down vote up
public Point2D getPoint(TableView<?> tableView, int columnIndex, int rowIndex) {
    Set<Node> tableRowCell = tableView.lookupAll(".table-row-cell");
    TableRow<?> row = null;
    for (Node tableRow : tableRowCell) {
        TableRow<?> r = (TableRow<?>) tableRow;
        if (r.getIndex() == rowIndex) {
            row = r;
            break;
        }
    }
    Set<Node> cells = row.lookupAll(".table-cell");
    for (Node node : cells) {
        TableCell<?, ?> cell = (TableCell<?, ?>) node;
        if (tableView.getColumns().indexOf(cell.getTableColumn()) == columnIndex) {
            Bounds bounds = cell.getBoundsInParent();
            Point2D localToParent = cell.localToParent(bounds.getWidth() / 2, bounds.getHeight() / 2);
            Point2D rowLocal = row.localToScene(localToParent, true);
            return rowLocal;
        }
    }
    return null;
}
 
Example 10
Project: marathonv5   File: RFXComponentTest.java   Source Code and License 6 votes vote down vote up
protected Point2D getPoint(TreeTableView<?> treeTableView, int rowIndex, int columnIndex) {
    Set<Node> treeTableRowCell = treeTableView.lookupAll(".tree-table-row-cell");
    TreeTableRow<?> row = null;
    for (Node tableRow : treeTableRowCell) {
        TreeTableRow<?> r = (TreeTableRow<?>) tableRow;
        if (r.getIndex() == rowIndex) {
            row = r;
            break;
        }
    }
    Set<Node> cells = row.lookupAll(".tree-table-cell");
    for (Node node : cells) {
        TreeTableCell<?, ?> cell = (TreeTableCell<?, ?>) node;
        if (treeTableView.getColumns().indexOf(cell.getTableColumn()) == columnIndex) {
            Bounds bounds = cell.getBoundsInParent();
            Point2D localToParent = cell.localToParent(bounds.getWidth() / 2, bounds.getHeight() / 2);
            Point2D rowLocal = row.localToScene(localToParent, true);
            return rowLocal;
        }
    }
    return null;
}
 
Example 11
Project: worldheatmap   File: World.java   Source Code and License 6 votes vote down vote up
private double[] getBounds(final List<Country> COUNTRIES) {
    double upperLeftX  = PREFERRED_WIDTH;
    double upperLeftY  = PREFERRED_HEIGHT;
    double lowerRightX = 0;
    double lowerRightY = 0;
    for (Country country : COUNTRIES) {
        List<CountryPath> paths = countryPaths.get(country.getName());
        for (int i = 0; i < paths.size(); i++) {
            CountryPath path   = paths.get(i);
            Bounds      bounds = path.getLayoutBounds();
            upperLeftX  = Math.min(bounds.getMinX(), upperLeftX);
            upperLeftY  = Math.min(bounds.getMinY(), upperLeftY);
            lowerRightX = Math.max(bounds.getMaxX(), lowerRightX);
            lowerRightY = Math.max(bounds.getMaxY(), lowerRightY);
        }
    }
    return new double[]{ upperLeftX, upperLeftY, lowerRightX, lowerRightY };
}
 
Example 12
Project: campingsimulator2017   File: MapCreatorView.java   Source Code and License 6 votes vote down vote up
private void handleDropItem() {
    addEventFilter(MouseEvent.MOUSE_RELEASED, mouseEvent -> {
        if(selectedItem != null) {
            Bounds boundsInScene = draggingIcon.localToScene(draggingIcon.getBoundsInLocal());
            Bounds mapViewPort_coords = mapViewPort.sceneToLocal(boundsInScene);
            Bounds map_coords = mapPane.sceneToLocal(boundsInScene);

            //Si l'item est dans le viewport
            if(mapViewPort_coords.getMinX() > 0 && mapViewPort_coords.getMaxX() < mapViewPort.getWidth() && mapViewPort_coords.getMinY() > 0 && mapViewPort_coords.getMaxY() < mapViewPort.getHeight()) {
                createItem(map_coords.getMinX(), map_coords.getMinY());
            }

            stackPaneRoot.getChildren().remove(draggingIcon);
            draggingIcon = null;
            selectedItem = null;
        }
    });
}
 
Example 13
Project: GazePlay   File: StatsDisplay.java   Source Code and License 6 votes vote down vote up
private static void zoomInAndCenter(Node node, double initialWidth, double initialHeight, boolean preserveRatio) {
    Parent parent = node.getParent();

    node.toFront();

    Bounds parentBoundsInParent = parent.getBoundsInLocal();

    double xScaleRatio = parentBoundsInParent.getMaxX() / initialWidth;
    double yScaleRatio = parentBoundsInParent.getMaxY() / initialHeight;

    if (preserveRatio) {
        double bestScaleRatio = Math.min(xScaleRatio, yScaleRatio);
        node.setScaleX(bestScaleRatio);
        node.setScaleY(bestScaleRatio);
    } else {
        node.setScaleX(xScaleRatio);
        node.setScaleY(yScaleRatio);
    }

    Bounds boundsInParent = node.getBoundsInParent();

    double translateX = -1 * Math.abs(boundsInParent.getMinY());
    double translateY = -1 * Math.abs(boundsInParent.getMinY());

    node.setTranslateX(translateX);
    node.setTranslateY(translateY);
}
 
Example 14
Project: graphing-loan-analyzer   File: DatePickerSkin.java   Source Code and License 6 votes vote down vote up
/**
 * Shows the popup.
 */
private void showPopup() {

    if (popup.isShowing())
        return;

    calendarView.setVisible(true);
    //calendarView.setManaged(true);

    Bounds calendarBounds = calendarView.getBoundsInLocal();
    Bounds bounds = getSkinnable().localToScene(getSkinnable().getBoundsInLocal());

    double posX = calendarBounds.getMinX() + bounds.getMinX() + getSkinnable().getScene().getX() + getSkinnable().getScene().getWindow().getX();
    double posY = calendarBounds.getMinY() + bounds.getHeight() + bounds.getMinY() + getSkinnable().getScene().getY() + getSkinnable().getScene().getWindow().getY();

    popup.show(getSkinnable(), posX, posY);
}
 
Example 15
Project: Dr-Assistant   File: PatientsController.java   Source Code and License 6 votes vote down vote up
/**
 * Initializes the controller class.
 *
 * @param url
 * @param rb
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    scrollPan.viewportBoundsProperty().addListener((ObservableValue<? extends Bounds> observable, Bounds oldValue, Bounds newValue) -> {
        flowPane.setPrefWidth(newValue.getWidth());
    });

    lblTotalPatient.setText("Loading..........");

    Platform.runLater(() -> {
        totalPatient = patientGetway.totalPatient();
        loadPatients();
        lblTotalPatient.setText("Total :" + totalPatient);
        lblShowingPatient.setText("Showing " + paginate.getStart() + " To " + paginate.getEnd());
        if (totalPatient == 0) {
            lblTotalPatient.setText("No patient found");
            lblShowingPatient.setVisible(false);
        }
    });

}
 
Example 16
Project: marathonv5   File: FXEventQueueDevice.java   Source Code and License 5 votes vote down vote up
private void checkHit(Node child, double x, double y, List<Node> hits, String indent) {
    Bounds boundsInParent = child.getBoundsInParent();
    if (boundsInParent.contains(x, y)) {
        hits.add(child);
        if (!(child instanceof Parent)) {
            return;
        }
        ObservableList<Node> childrenUnmodifiable = ((Parent) child).getChildrenUnmodifiable();
        for (Node node : childrenUnmodifiable) {
            checkHit(node, x, y, hits, "    " + indent);
        }
    }
}
 
Example 17
Project: marathonv5   File: JavaFXElementPropertyAccessor.java   Source Code and License 5 votes vote down vote up
private TableCell<?, ?> getTableCellAt(TableView<?> tableView, Point2D point) {
    point = tableView.localToScene(point);
    Set<Node> lookupAll = getTableCells(tableView);
    TableCell<?, ?> selected = null;
    for (Node cellNode : lookupAll) {
        Bounds boundsInScene = cellNode.localToScene(cellNode.getBoundsInLocal(), true);
        if (boundsInScene.contains(point)) {
            selected = (TableCell<?, ?>) cellNode;
            break;
        }
    }
    return selected;
}
 
Example 18
Project: marathonv5   File: JavaFXElementPropertyAccessor.java   Source Code and License 5 votes vote down vote up
public TreeTableCell<?, ?> getTreeTableCellAt(TreeTableView<?> treeTableView, Point2D point) {
    point = treeTableView.localToScene(point);
    Set<Node> lookupAll = getTreeTableCells(treeTableView);
    TreeTableCell<?, ?> selected = null;
    for (Node cellNode : lookupAll) {
        Bounds boundsInScene = cellNode.localToScene(cellNode.getBoundsInLocal(), true);
        if (boundsInScene.contains(point)) {
            selected = (TreeTableCell<?, ?>) cellNode;
            break;
        }
    }
    return selected;
}
 
Example 19
Project: marathonv5   File: JavaFXTableCellElement.java   Source Code and License 5 votes vote down vote up
@Override public Point2D _getMidpoint() {
    Node cell = getPseudoComponent();
    Bounds boundsInParent = cell.getBoundsInParent();
    double x = boundsInParent.getWidth() / 2;
    double y = boundsInParent.getHeight() / 2;
    return cell.getParent().localToParent(cell.localToParent(x, y));
}
 
Example 20
Project: marathonv5   File: JavaFXTreeViewNodeElement.java   Source Code and License 5 votes vote down vote up
@Override public Point2D _getMidpoint() {
    TreeView<?> treeView = (TreeView<?>) getComponent();
    Node cell = getCellAt(treeView, getPath(treeView, path));
    Bounds boundsInParent = cell.getBoundsInParent();
    double x = boundsInParent.getWidth() / 2;
    double y = boundsInParent.getHeight() / 2;
    return cell.localToParent(x, y);
}
 
Example 21
Project: marathonv5   File: JavaFXListViewItemElement.java   Source Code and License 5 votes vote down vote up
@Override public Point2D _getMidpoint() {
    Node cell = getPseudoComponent();
    Bounds boundsInParent = cell.getBoundsInParent();
    double x = boundsInParent.getWidth() / 2;
    double y = boundsInParent.getHeight() / 2;
    return cell.localToParent(x, y);
}
 
Example 22
Project: marathonv5   File: JavaFXTabPaneTabJavaElement.java   Source Code and License 5 votes vote down vote up
@Override public Point2D _getMidpoint() {
    StackPane tabRegion = getTabRegion();
    Bounds boundsInParent = tabRegion.getBoundsInParent();
    double x = boundsInParent.getWidth() / 2;
    double y = boundsInParent.getHeight() / 2;
    return tabRegion.localToParent(x, y);
}
 
Example 23
Project: marathonv5   File: JavaFXListViewElementScrollTest.java   Source Code and License 5 votes vote down vote up
public Point2D getPoint(ListView<?> listView, int index) {
    Set<Node> cells = listView.lookupAll(".list-cell");
    for (Node node : cells) {
        ListCell<?> cell = (ListCell<?>) node;
        if (cell.getIndex() == index) {
            Bounds bounds = cell.getBoundsInParent();
            return cell.localToParent(bounds.getWidth() / 2, bounds.getHeight() / 2);
        }
    }
    return null;
}
 
Example 24
Project: marathonv5   File: RFXComponentTest.java   Source Code and License 5 votes vote down vote up
public Point2D getPoint(ListView<?> listView, int index) {
    Set<Node> cells = listView.lookupAll(".list-cell");
    for (Node node : cells) {
        ListCell<?> cell = (ListCell<?>) node;
        if (cell.getIndex() == index) {
            Bounds bounds = cell.getBoundsInParent();
            return cell.localToParent(bounds.getWidth() / 2, bounds.getHeight() / 2);
        }
    }
    return null;
}
 
Example 25
Project: marathonv5   File: RFXComponentTest.java   Source Code and License 5 votes vote down vote up
public Point2D getPoint(TreeView<?> treeView, int index) {
    Set<Node> cells = treeView.lookupAll(".tree-cell");
    for (Node node : cells) {
        TreeCell<?> cell = (TreeCell<?>) node;
        if (cell.getIndex() == index) {
            Bounds bounds = cell.getBoundsInParent();
            return cell.localToParent(bounds.getWidth() / 2, bounds.getHeight() / 2);
        }
    }
    return null;
}
 
Example 26
Project: Dayflower-Path-Tracer   File: AbstractApplication.java   Source Code and License 5 votes vote down vote up
private void doOnMouseMoved(final MouseEvent e) {
	final int mouseMovedDeltaX = this.mouseMovedDeltaX.get();
	final int mouseMovedDeltaY = this.mouseMovedDeltaY.get();
	
	this.mouseMovementTime.set(System.currentTimeMillis());
	
	if(mouseMovedDeltaX != 0 || mouseMovedDeltaY != 0) {
		this.mouseMovedX.addAndGet(this.mouseMovedDeltaX.get() - (int)(e.getScreenX()));
		this.mouseMovedY.addAndGet(this.mouseMovedDeltaY.get() - (int)(e.getScreenY()));
	}
	
	this.mouseX.set((int)(e.getX()));
	this.mouseY.set((int)(e.getY()));
	
	onMouseMoved(this.mouseMovedX.getAndSet(0), this.mouseMovedY.getAndSet(0));
	
	if(isMouseRecentering()) {
		final Bounds bounds = this.canvas.localToScreen(this.canvas.getBoundsInLocal());
		
		final int minX = (int)(bounds.getMinX());
		final int minY = (int)(bounds.getMinY());
		final int width = (int)(bounds.getWidth());
		final int height = (int)(bounds.getHeight());
		final int x = minX + width / 2;
		final int y = minY + height / 2;
		
		this.robot.mouseMove(x, y);
		
		this.mouseMovedDeltaX.set(x);
		this.mouseMovedDeltaY.set(y);
	} else {
		this.mouseMovedDeltaX.set((int)(e.getScreenX()));
		this.mouseMovedDeltaY.set((int)(e.getScreenY()));
	}
}
 
Example 27
Project: JavaFX-EX   File: DragSupport.java   Source Code and License 5 votes vote down vote up
@Override
public void press(MouseEvent e) {
  Node node = get();
  if (isEnable() && e.isConsumed() == false && node != null) {
    Bounds boundsInLocal = node.getBoundsInLocal();
    if (canDrag(node.screenToLocal(e.getScreenX(), e.getScreenY()), boundsInLocal.getMaxX(), boundsInLocal.getMaxY())) {
      startX = e.getScreenX() - node.getLayoutX();
      startY = e.getScreenY() - node.getLayoutY();
      e.consume();
      pressed = true;
    }
  }
}
 
Example 28
Project: JavaFX-EX   File: DragSupportTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testBoard() throws Exception {
  config.borderWidthProperty().set(10.0);
  assertThat(rectangle, atParent(0, 0));
  Bounds screen = rectangle.localToScreen(rectangle.getBoundsInLocal());
  moveTo(screen.getMinX(), screen.getMinY());
  drag(100, 100);
  assertThat(rectangle, atParent(0, 0));
  moveTo(rectangle);
  drag(100, 100);
  assertThat(rectangle, atParent(100, 100));
}
 
Example 29
Project: JavaFX-EX   File: ResizeSupportTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testRightLarge() throws Exception {
  assertThat(rectangle, sizeOf(100, 100));
  Bounds screen = rectangle.localToScreen(rectangle.getBoundsInLocal());
  moveTo(screen.getMaxX() - 1, screen.getMaxY() - 1);
  drag(50, 50);
  assertThat(rectangle, sizeOf(150, 150));
}
 
Example 30
Project: JavaFX-EX   File: ResizeSupportTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testRightSmall() throws Exception {
  assertThat(rectangle, sizeOf(100, 100));
  Bounds screen = rectangle.localToScreen(rectangle.getBoundsInLocal());
  moveTo(screen.getMaxX() - 1, screen.getMaxY() - 1);
  drag(-50, -50);
  assertThat(rectangle, sizeOf(50, 50));
}
 
Example 31
Project: JavaFX-EX   File: ResizeSupportTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testLeftLarge() throws Exception {
  assertThat(rectangle, sizeOf(100, 100));
  Bounds screen = rectangle.localToScreen(rectangle.getBoundsInLocal());
  moveTo(screen.getMinX() + 1, screen.getMinY() + 1);
  drag(50, 50);
  assertThat(rectangle, sizeOf(50, 50));
}
 
Example 32
Project: JavaFX-EX   File: ResizeSupportTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testLeftSmall() throws Exception {
  assertThat(rectangle, sizeOf(100, 100));
  Bounds screen = rectangle.localToScreen(rectangle.getBoundsInLocal());
  moveTo(screen.getMinX() + 1, screen.getMinY() + 1);
  drag(-50, -50);
  assertThat(rectangle, sizeOf(150, 150));
}
 
Example 33
Project: JavaFX-EX   File: ResizeSupportTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testBorder() throws Exception {
  config.borderWidthProperty().set(10);
  assertThat(rectangle, sizeOf(100, 100));
  Bounds screen = rectangle.localToScreen(rectangle.getBoundsInLocal());
  moveTo(screen.getMaxX() - 8, screen.getMaxY() - 8);
  drag(50, 50);
  assertThat(rectangle, sizeOf(150, 150));
}
 
Example 34
Project: JavaFX-EX   File: ResizeSupportTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testEnable() throws Exception {
  assertThat(rectangle, sizeOf(100, 100));
  Bounds screen = rectangle.localToScreen(rectangle.getBoundsInLocal());
  moveTo(screen.getMaxX() - 1, screen.getMaxY() - 1);
  drag(50, 50);
  assertThat(rectangle, sizeOf(150, 150));
  config.enableProperty().set(false);
  drag(-50, -50);
  assertThat(rectangle, sizeOf(150, 150));
  config.enableProperty().set(true);
  drag(50, 50);
  drag(50, 50);
  assertThat(rectangle, sizeOf(200, 200));
}
 
Example 35
Project: JavaFX-EX   File: ResizeSupportTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testUnbind() throws Exception {
  assertThat(rectangle, sizeOf(100, 100));
  Bounds screen = rectangle.localToScreen(rectangle.getBoundsInLocal());
  moveTo(screen.getMaxX() - 1, screen.getMaxY() - 1);
  drag(50, 50);
  assertThat(rectangle, sizeOf(150, 150));
  config.unbind();
  drag(-50, -50);
  assertThat(rectangle, sizeOf(150, 150));
}
 
Example 36
Project: fx-animation-editor   File: MathFunctions.java   Source Code and License 5 votes vote down vote up
public static Bounds union(Bounds first, Bounds second) {
    if (first == null) {
        return second;
    } else if (second == null) {
        return first;
    }
    double minX = Math.min(first.getMinX(), second.getMinX());
    double minY = Math.min(first.getMinY(), second.getMinY());
    double maxX = Math.max(first.getMaxX(), second.getMaxX());
    double maxY = Math.max(first.getMaxY(), second.getMaxY());
    return new BoundingBox(minX, minY, maxX - minX, maxY - minY);
}
 
Example 37
Project: CalendarFX   File: IntroPaneSkin.java   Source Code and License 5 votes vote down vote up
private void snapshotNode(Scene scene, Node node) {
    SnapshotParameters params = new SnapshotParameters();
    Bounds layoutBounds = node.getLayoutBounds();
    Bounds bounds = node.localToScene(layoutBounds);

    if (!(bounds.getWidth() > 0 && bounds.getHeight() > 0)) {
        return;
    }

    params.setViewport(new Rectangle2D(bounds.getMinX(), bounds.getMinY(), bounds.getWidth(), bounds.getHeight()));
    WritableImage writable = new WritableImage((int) bounds.getWidth(), (int) bounds.getHeight());
    writable = scene.getRoot().snapshot(params, writable);

    ImageView imageView = new ImageView(writable);
    imageView.getStyleClass().add("snapshot-image");
    imageView.setManaged(false);
    imageView.setLayoutX(bounds.getMinX());
    imageView.setLayoutY(bounds.getMinY());
    imageView.setFitWidth(bounds.getWidth());
    imageView.setFitHeight(bounds.getHeight());

    Region rect = new Region();
    rect.getStyleClass().add("snapshot-background");
    rect.setLayoutX(bounds.getMinX() - 5);
    rect.setLayoutY(bounds.getMinY() - 5);
    rect.resize(bounds.getWidth() + 10, bounds.getHeight() + 10);
    rect.setManaged(false);

    Line line = new Line();
    line.setStartX(bounds.getMaxX() + 4);
    line.setStartY(bounds.getMaxY() + 4);
    line.setEndX(bounds.getMaxX() + 200);
    line.setEndY(bounds.getMaxY() + 200);
    line.setStroke(imagePattern);
    line.setStrokeWidth(5);
    line.setManaged(false);

    getChildren().addAll(rect, imageView); //, line);
}
 
Example 38
Project: CalendarFX   File: WeekView.java   Source Code and License 5 votes vote down vote up
private WeekDayView getWeekDayViewAt(double x) {
    for (WeekDayView view : getWeekDayViews()) {
        final Bounds bounds = view.getBoundsInParent();
        if (bounds.getMinX() <= x && bounds.getMaxX() >= x) {
            return view;
        }
    }

    return null;
}
 
Example 39
Project: CalendarFX   File: MonthSheetViewSkin.java   Source Code and License 5 votes vote down vote up
private void showDateDetails(LocalDate date) {
    DateCell cell = cellMap.get(date);
    Bounds bounds = cell.localToScreen(cell.getLayoutBounds());
    Callback<DateControl.DateDetailsParameter, Boolean> callback = getSkinnable().getDateDetailsCallback();
    DateControl.DateDetailsParameter param = new DateControl.DateDetailsParameter(null, getSkinnable(), cell, date, bounds.getMinX(), bounds.getMinY());
    callback.call(param);
}
 
Example 40
Project: CalendarFX   File: ViewHelper.java   Source Code and License 5 votes vote down vote up
public static ArrowLocation findPopOverArrowLocation(Node view) {
    Bounds localBounds = view.getBoundsInLocal();
    Bounds entryBounds = view.localToScreen(localBounds);

    ObservableList<Screen> screens = Screen.getScreensForRectangle(
            entryBounds.getMinX(), entryBounds.getMinY(),
            entryBounds.getWidth(), entryBounds.getHeight());
    Rectangle2D screenBounds = screens.get(0).getVisualBounds();

    double spaceLeft = entryBounds.getMinX();
    double spaceRight = screenBounds.getWidth() - entryBounds.getMaxX();
    double spaceTop = entryBounds.getMinY();
    double spaceBottom = screenBounds.getHeight() - entryBounds.getMaxY();

    if (spaceLeft > spaceRight) {
        if (spaceTop > spaceBottom) {
            return ArrowLocation.RIGHT_BOTTOM;
        }
        return ArrowLocation.RIGHT_TOP;
    }

    if (spaceTop > spaceBottom) {
        return ArrowLocation.LEFT_BOTTOM;
    }

    return ArrowLocation.LEFT_TOP;
}