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; }
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())); } }
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); }
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(); }
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(); }
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 }; }
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); }
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; }
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; } }); }
/** * 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); }
/** * 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); } }); }
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); } } }
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; }
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; }
@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)); }
@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); }
@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); }
@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); }
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; }
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; }
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())); } }
@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; } } }
@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)); }
@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)); }
@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)); }
@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)); }
@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)); }
@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)); }
@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)); }
@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)); }
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); }
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); }
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; }
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); }
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; }
public static Point findPopOverArrowPosition(Node node, double screenY, double arrowSize, ArrowLocation arrowLocation) { Point point = new Point(); point.setY(screenY); Bounds entryBounds = node.localToScreen(node.getBoundsInLocal()); if (arrowLocation == ArrowLocation.LEFT_TOP || arrowLocation == ArrowLocation.LEFT_BOTTOM) { point.setX(entryBounds.getMaxX()); } else { point.setX(entryBounds.getMinX() - arrowSize); } return point; }