private static Bounds computeUnclippedBounds(Node node) {
    final Bounds layoutBounds;
    double minX, minY, maxX, maxY, minZ, maxZ;

    assert node != null;
    assert node.getLayoutBounds().isEmpty() == false;

    layoutBounds = node.getLayoutBounds();
    minX = layoutBounds.getMinX();
    minY = layoutBounds.getMinY();
    maxX = layoutBounds.getMaxX();
    maxY = layoutBounds.getMaxY();
    minZ = layoutBounds.getMinZ();
    maxZ = layoutBounds.getMaxZ();

    if (node instanceof Parent) {
      final Parent parent = (Parent) node;

      for (Node child : parent.getChildrenUnmodifiable()) {
        final Bounds childBounds = child.getBoundsInParent();
        minX = Math.min(minX, childBounds.getMinX());
        minY = Math.min(minY, childBounds.getMinY());
        maxX = Math.max(maxX, childBounds.getMaxX());
        maxY = Math.max(maxY, childBounds.getMaxY());
        minZ = Math.min(minZ, childBounds.getMinZ());
        maxZ = Math.max(maxZ, childBounds.getMaxZ());
      }
    }

    assert minX <= maxX;
    assert minY <= maxY;
    assert minZ <= maxZ;

    return new BoundingBox(minX, minY, minZ, maxX - minX, maxY - minY, maxZ - minZ);
  }
예제 #2
0
 private void removeEmptyGroups() {
   for (Parent p : emptyParents) {
     Parent parent = p.getParent();
     Group g = (Group) parent;
     g.getChildren().addAll(p.getChildrenUnmodifiable());
     g.getChildren().remove(p);
   }
 }
예제 #3
0
  /**
   * Traverse the scene graph for all open stages and pick an event target for a dock event based on
   * the location. Once the event target is chosen run the event task with the target and the
   * previous target of the last dock event if one is cached. If an event target is not found fire
   * the explicit dock event on the stage root if one is provided.
   *
   * @param location The location of the dock event in screen coordinates.
   * @param eventTask The event task to be run when the event target is found.
   * @param explicit The explicit event to be fired on the stage root when no event target is found.
   */
  private void pickEventTarget(Point2D location, EventTask eventTask, Event explicit) {
    // RFE for public scene graph traversal API filed but closed:
    // https://bugs.openjdk.java.net/browse/JDK-8133331

    ObservableList<Stage> stages =
        FXCollections.unmodifiableObservableList(StageHelper.getStages());
    // fire the dock over event for the active stages
    for (Stage targetStage : stages) {
      // obviously this title bar does not need to receive its own events
      // though users of this library may want to know when their
      // dock node is being dragged by subclassing it or attaching
      // an event listener in which case a new event can be defined or
      // this continue behavior can be removed
      if (targetStage == this.dockNode.getStage()) continue;

      eventTask.reset();

      Node dragNode = dragNodes.get(targetStage);

      Parent root = targetStage.getScene().getRoot();
      Stack<Parent> stack = new Stack<Parent>();
      if (root.contains(root.screenToLocal(location.getX(), location.getY()))
          && !root.isMouseTransparent()) {
        stack.push(root);
      }
      // depth first traversal to find the deepest node or parent with no children
      // that intersects the point of interest
      while (!stack.isEmpty()) {
        Parent parent = stack.pop();
        // if this parent contains the mouse click in screen coordinates in its local bounds
        // then traverse its children
        boolean notFired = true;
        for (Node node : parent.getChildrenUnmodifiable()) {
          if (node.contains(node.screenToLocal(location.getX(), location.getY()))
              && !node.isMouseTransparent()) {
            if (node instanceof Parent) {
              stack.push((Parent) node);
            } else {
              eventTask.run(node, dragNode);
            }
            notFired = false;
            break;
          }
        }
        // if none of the children fired the event or there were no children
        // fire it with the parent as the target to receive the event
        if (notFired) {
          eventTask.run(parent, dragNode);
        }
      }

      if (explicit != null && dragNode != null && eventTask.getExecutions() < 1) {
        Event.fireEvent(dragNode, explicit.copyFor(this, dragNode));
        dragNodes.put(targetStage, null);
      }
    }
  }
 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;
 }
예제 #5
0
파일: Utils2.java 프로젝트: sunecz/SSP
 /* This code has been taken from:
  * https://community.oracle.com/thread/2534556?tstart=0
  * AND WAS MODIFIED!*/
 public static final Node getCaretNode(Parent parent) {
   for (Node n : parent.getChildrenUnmodifiable()) {
     if (n instanceof Path) return n;
     else if (n instanceof Parent) {
       Node k = getCaretNode((Parent) n);
       if (k != null) return k;
     }
   }
   return null;
 }
예제 #6
0
 public static void addListenerDeeply(final Node node, final EventHandler<MouseEvent> listener) {
   node.addEventHandler(MouseEvent.MOUSE_MOVED, listener);
   node.addEventHandler(MouseEvent.MOUSE_PRESSED, listener);
   node.addEventHandler(MouseEvent.MOUSE_DRAGGED, listener);
   if (node instanceof Parent) {
     final Parent parent = (Parent) node;
     final ObservableList<Node> children = parent.getChildrenUnmodifiable();
     for (final Node child : children) {
       ResizeAndMoveHelper.addListenerDeeply(child, listener);
     }
   }
 }
예제 #7
0
 private void optimize(Node node) {
   ObservableList<Transform> transforms = node.getTransforms();
   Iterator<Transform> iterator = transforms.iterator();
   boolean prevIsStatic = false;
   while (iterator.hasNext()) {
     Transform transform = iterator.next();
     trTotal++;
     if (transform.isIdentity()) {
       if (timeline == null || !bound.contains(transform)) {
         iterator.remove();
         trRemoved++;
       }
     } else {
       if (timeline == null || !bound.contains(transform)) {
         if (prevIsStatic) {
           trCandidate++;
         }
         prevIsStatic = true;
       } else {
         prevIsStatic = false;
       }
     }
   }
   if (node instanceof Parent) {
     groupsTotal++;
     Parent p = (Parent) node;
     for (Node n : p.getChildrenUnmodifiable()) {
       optimize(n);
     }
     if (transforms.isEmpty()) {
       Parent parent = p.getParent();
       if (parent instanceof Group) {
         trEmpty++;
         //                    System.out.println("Empty group = " + node.getId());
         emptyParents.add(p);
       } else {
         //                    System.err.println("parent is not group = " + parent);
       }
     }
   }
   if (node instanceof MeshView) {
     meshViews.add((MeshView) node);
   }
 }
 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;
 }