@Override public void drag(MouseEvent e, Dimension delta) { if (invalidGesture) { return; } if (selectionBounds == null) { return; } Rectangle sel = updateSelectionBounds(e); for (IContentPart<Node, ? extends Node> targetPart : targetParts) { // compute initial and new bounds for this target Bounds initialBounds = getBounds(selectionBounds, targetPart); Bounds newBounds = getBounds(sel, targetPart); // compute translation in scene coordinates double dx = newBounds.getMinX() - initialBounds.getMinX(); double dy = newBounds.getMinY() - initialBounds.getMinY(); // transform translation to parent coordinates Node visual = targetPart.getVisual(); Point2D originInParent = visual.getParent().sceneToLocal(0, 0); Point2D deltaInParent = visual.getParent().sceneToLocal(dx, dy); dx = deltaInParent.getX() - originInParent.getX(); dy = deltaInParent.getY() - originInParent.getY(); // apply translation getTransformPolicy(targetPart).setPostTranslate(translateIndices.get(targetPart), dx, dy); // check if we can resize the part AffineTransform affineTransform = getTransformPolicy(targetPart).getCurrentNodeTransform(); if (affineTransform.getRotation().equals(Angle.fromDeg(0))) { // no rotation => resize possible // TODO: special case 90 degree rotations double dw = newBounds.getWidth() - initialBounds.getWidth(); double dh = newBounds.getHeight() - initialBounds.getHeight(); Point2D originInLocal = visual.sceneToLocal(newBounds.getMinX(), newBounds.getMinY()); Point2D dstInLocal = visual.sceneToLocal(newBounds.getMinX() + dw, newBounds.getMinY() + dh); dw = dstInLocal.getX() - originInLocal.getX(); dh = dstInLocal.getY() - originInLocal.getY(); getResizePolicy(targetPart).resize(dw, dh); } else { // compute scaling based on bounds change double sx = newBounds.getWidth() / initialBounds.getWidth(); double sy = newBounds.getHeight() / initialBounds.getHeight(); // apply scaling getTransformPolicy(targetPart).setPostScale(scaleIndices.get(targetPart), sx, sy); } } }
/** * Finds the ancestor of the node which is the type of the classToFind and before it reaches a * node that is of type classToStop. * * @param node the node that we will look for the ancestor. * @param classToFind the ancestor type we will try to look for * @param classToStop the ancestor type which will stop looking for further if seeing a node of * this type. * @return the ancestor node if any. */ @SuppressWarnings("unchecked") public static Node findAncestor(Node node, Class classToFind, Class classToStop) { node = node.getParent(); while (node != null) { if (classToStop != null && classToStop.isAssignableFrom(node.getClass())) { return null; } if (classToFind.isAssignableFrom(node.getClass())) { return node; } node = node.getParent(); } return null; }
/* This code has been taken from: * https://community.oracle.com/thread/2534556?tstart=0 * AND WAS MODIFIED!*/ public static final Point2D getNodeLocation(Node node) { double x = 0, y = 0; for (Node n = node; n != null; n = n.getParent()) { Bounds parentBounds = n.getBoundsInParent(); x += parentBounds.getMinX(); y += parentBounds.getMinY(); } return new Point2D(x, y); }
private int getIndexOfComponentInParent(Node component) { Parent parent = component.getParent(); if (parent == null) return -1; ObservableList<Node> components = parent.getChildrenUnmodifiable(); for (int i = 0; i < components.size(); i++) { if (components.get(i) == component) return i; } return -1; }
@Override public boolean isViewerVisual(Node node) { while (node != null) { if (node == infiniteCanvas) { return true; } node = node.getParent(); } return false; }
/** * determine if the {@code Node} is the ancestorNode of another {@code Node} or the same. * * @param node the node * @param ancestorNode the possible ancestorNode node * @return true of the ancestorNode is an ancestor of the node, or the same. */ public static boolean isAncestor(Node node, Node ancestorNode) { if (node != null && ancestorNode != null) { Node parent = ancestorNode; while (parent != null) { if (parent == node) { return true; } parent = parent.getParent(); } } return false; }
protected void refreshHandleLocation(Node hostVisual) { // position vbox top-right next to the host Bounds hostBounds = hostVisual.getBoundsInParent(); Parent parent = hostVisual.getParent(); if (parent != null) { hostBounds = parent.localToScene(hostBounds); } Point2D location = getVisual().getParent().sceneToLocal(hostBounds.getMaxX(), hostBounds.getMinY()); getVisual().setLayoutX(location.getX()); getVisual().setLayoutY(location.getY()); }
/** * Finds the ancestor of the node which its type class name ends with String classNameEndWith and * before it reaches a node that is of type classToStop. * * @param node the node that we will look for the ancestor. * @param classNameEndWith the ancestor class name that ends with this String * @param classToStop the ancestor type which will stop looking for further if seeing a node of * this type. * @return the ancestor node if any. */ @SuppressWarnings("unchecked") public static Node findAncestor(Node node, String classNameEndWith, Class classToStop) { while (node != null) { if (classToStop != null && classToStop.isAssignableFrom(node.getClass())) { return null; } if (node.getClass().getName().endsWith(classNameEndWith)) { return node; } node = node.getParent(); } return null; }
private void removeConnector(Connector connector) { connectorList.remove(connector); Node connectorNode = connectors.remove(connector.getId()); if (connectorNode != null && connectorNode.getParent() != null) { // TODO: remove connectors&connections? if (connector.isInput()) { inputList.remove(connectorNode); } else if (connector.isOutput()) { outputList.remove(connectorNode); } NodeUtil.removeFromParent(connectorNode); } }
private void updateContentGroup() { /* * fxomRoot */ final String statusMessageText, statusStyleClass; contentGroup.getChildren().clear(); if (fxomDocument == null) { statusMessageText = "FXOMDocument is null"; // NOI18N statusStyleClass = "stage-prompt"; // NOI18N } else if (fxomDocument.getFxomRoot() == null) { statusMessageText = I18N.getString("content.label.status.invitation"); statusStyleClass = "stage-prompt"; // NOI18N } else { final Object userSceneGraph = fxomDocument.getSceneGraphRoot(); if (userSceneGraph instanceof Node) { final Node rootNode = (Node) userSceneGraph; assert rootNode.getParent() == null; contentGroup.getChildren().add(rootNode); layoutContent(true /* applyCSS */); if (layoutException == null) { statusMessageText = ""; // NOI18N statusStyleClass = "stage-prompt-default"; // NOI18N } else { contentGroup.getChildren().clear(); statusMessageText = I18N.getString("content.label.status.cannot.display"); statusStyleClass = "stage-prompt"; // NOI18N } } else { statusMessageText = I18N.getString("content.label.status.cannot.display"); statusStyleClass = "stage-prompt"; // NOI18N } } backgroundPane.setText(statusMessageText); backgroundPane.getStyleClass().clear(); backgroundPane.getStyleClass().add(statusStyleClass); // If layoutException != null, then this layout call is required // so that backgroundPane updates its message... Strange... backgroundPane.layout(); adjustWorkspace(); }
protected List<IJavaFXElement> found(List<IJavaFXElement> pElements, IJavaFXAgent driver) { List<IJavaFXElement> r = new ArrayList<IJavaFXElement>(); for (IJavaFXElement je : pElements) { Node component = je.getComponent(); if (!(component instanceof Parent)) continue; int index = getIndexOfComponentInParent(component); if (index < 0) continue; Parent parent = component.getParent(); JFXWindow topContainer = driver.switchTo().getTopContainer(); ObservableList<Node> children = parent.getChildrenUnmodifiable(); for (int i = index + 1; i < children.size(); i++) { Node c = children.get(i); IJavaFXElement je2 = JavaFXElementFactory.createElement(c, driver, driver.switchTo().getTopContainer()); if (sibling.matchesSelector(je2).size() > 0) { IJavaFXElement e = topContainer.addElement(JavaFXElementFactory.createElement(c, driver, topContainer)); if (!r.contains(e)) r.add(e); } } } return r; }
public TargetView() { setId("targetview"); setCellFactory( e -> { return new PageItemListCell(); }); getSelectionModel() .selectedIndexProperty() .addListener( (a, b, c) -> { ToolbarEvent ev = new ToolbarEvent( this, c.intValue() != -1 ? ToolbarEvent.ENABLE : ToolbarEvent.DISABLE); getScene().lookup("#targettoolbar").fireEvent(ev); }); getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); setOnDragDetected( de -> { Dragboard dragBoard = startDragAndDrop(TransferMode.COPY_OR_MOVE); ClipboardContent content = new ClipboardContent(); ObservableList<PageItem> pi = getSelectionModel().getSelectedItems(); content.put(PAGE_ITEM_FORMAT, new PageItems(pi)); // getItems().removeAll(pi); dragBoard.setContent(content); getSelectionModel().clearSelection(); }); setOnDragOver( dragEvent -> { dragEvent.acceptTransferModes(TransferMode.COPY_OR_MOVE); }); setOnDragDropped( dragEvent -> { PageItems item = (PageItems) dragEvent.getDragboard().getContent(PAGE_ITEM_FORMAT); EventTarget target = dragEvent.getTarget(); Node p = null; if (target instanceof Node) { p = (Node) target; } while (!(p instanceof PageItemListCell) && p != null) { p = p.getParent(); } int index = -1; if (dragEvent.getTransferMode() == TransferMode.MOVE) { getItems().removeAll(item); } else { ArrayList<PageItem> itemsx = new ArrayList<>(getItems()); itemsx.addAll(item); // copy should change name #1 item.forEach( e -> { e.countUp(itemsx); }); } if (p instanceof PageItemListCell) { index = getItems().indexOf(((PageItemListCell) p).getItem()); } if (index != -1) { getItems().addAll(index, item); } else { getItems().addAll(item); } dragEvent.setDropCompleted(true); }); addEventHandler( ToolbarEvent.ROTATE, e -> { System.out.println("R event"); }); addEventHandler( ToolbarEvent.SAVE, e -> { System.out.println("SAVE!!"); }); }
private void adjustWorkspace() { final Bounds backgroundBounds, extensionBounds; final Object userSceneGraph; if (fxomDocument == null) { userSceneGraph = null; } else { userSceneGraph = fxomDocument.getSceneGraphRoot(); } if ((userSceneGraph instanceof Node) && (layoutException == null)) { final Node rootNode = (Node) userSceneGraph; final Bounds rootBounds = rootNode.getLayoutBounds(); if (rootBounds.isEmpty() || (rootBounds.getWidth() == 0.0) || (rootBounds.getHeight() == 0.0)) { backgroundBounds = new BoundingBox(0.0, 0.0, 0.0, 0.0); extensionBounds = new BoundingBox(0.0, 0.0, 0.0, 0.0); } else { final double scale; if ((rootBounds.getDepth() > 0) && autoResize3DContent) { // Content is 3D final double scaleX = AUTORESIZE_SIZE / rootBounds.getWidth(); final double scaleY = AUTORESIZE_SIZE / rootBounds.getHeight(); final double scaleZ = AUTORESIZE_SIZE / rootBounds.getDepth(); scale = Math.min(scaleX, Math.min(scaleY, scaleZ)); } else { scale = 1.0; } contentGroup.setScaleX(scale); contentGroup.setScaleY(scale); contentGroup.setScaleZ(scale); final Bounds contentBounds = rootNode.localToParent(rootBounds); backgroundBounds = new BoundingBox( 0.0, 0.0, contentBounds.getMinX() + contentBounds.getWidth(), contentBounds.getMinY() + contentBounds.getHeight()); final Bounds unclippedRootBounds = computeUnclippedBounds(rootNode); assert unclippedRootBounds.getHeight() != 0.0; assert unclippedRootBounds.getWidth() != 0.0; assert rootNode.getParent() == contentGroup; final Bounds unclippedContentBounds = rootNode.localToParent(unclippedRootBounds); extensionBounds = computeExtensionBounds(backgroundBounds, unclippedContentBounds); } } else { backgroundBounds = new BoundingBox(0.0, 0.0, 320.0, 150.0); extensionBounds = new BoundingBox(0.0, 0.0, 0.0, 0.0); } backgroundPane.setPrefWidth(backgroundBounds.getWidth()); backgroundPane.setPrefHeight(backgroundBounds.getHeight()); extensionRect.setX(extensionBounds.getMinX()); extensionRect.setY(extensionBounds.getMinY()); extensionRect.setWidth(extensionBounds.getWidth()); extensionRect.setHeight(extensionBounds.getHeight()); contentSubScene.setWidth(contentGroup.getLayoutBounds().getWidth()); contentSubScene.setHeight(contentGroup.getLayoutBounds().getHeight()); }