@Override
 public void doActivate() {
   super.doActivate();
   final Procedure1<Text> _function =
       (Text it) -> {
         String _name = this.getName();
         it.setText(_name);
         TooltipExtensions.setTooltip(it, "Zoom to reveal content");
       };
   ObjectExtensions.<Text>operator_doubleArrow(this.label, _function);
   boolean _equals = Objects.equal(this.innerDiagram, null);
   if (_equals) {
     String _name = this.getName();
     String _plus = ("No inner diagram set on node " + _name);
     String _plus_1 = (_plus + ". LOD behavior deactivated");
     LevelOfDetailDiagramNode.LOG.severe(_plus_1);
   } else {
     XDiagram _diagram = CoreExtensions.getDiagram(this);
     ViewportTransform _viewportTransform = _diagram.getViewportTransform();
     ReadOnlyDoubleProperty _scaleProperty = _viewportTransform.scaleProperty();
     final ChangeListener<Number> _function_1 =
         (ObservableValue<? extends Number> prop, Number oldVal, Number newVal) -> {
           Bounds _boundsInLocal = this.getBoundsInLocal();
           final Bounds bounds = this.localToScene(_boundsInLocal);
           double _width = bounds.getWidth();
           double _height = bounds.getHeight();
           final double area = (_width * _height);
           if ((area <= 100000)) {
             this.label.setVisible(true);
             this.innerDiagramGroup.setVisible(false);
             this.pane.setBackgroundPaint(RectangleBorderPane.DEFAULT_BACKGROUND);
           } else {
             this.label.setVisible(false);
             this.innerDiagramGroup.setVisible(true);
             this.innerDiagram.activate();
             final Procedure1<DiagramScaler> _function_2 =
                 (DiagramScaler it) -> {
                   Bounds _layoutBounds = this.label.getLayoutBounds();
                   double _width_1 = _layoutBounds.getWidth();
                   double _plus_2 = (_width_1 + 40);
                   it.setWidth(_plus_2);
                   Bounds _layoutBounds_1 = this.label.getLayoutBounds();
                   double _height_1 = _layoutBounds_1.getHeight();
                   double _plus_3 = (_height_1 + 20);
                   it.setHeight(_plus_3);
                   it.activate();
                 };
             ObjectExtensions.<DiagramScaler>operator_doubleArrow(this.diagramScaler, _function_2);
             Paint _backgroundPaint = this.innerDiagram.getBackgroundPaint();
             this.pane.setBackgroundPaint(_backgroundPaint);
           }
         };
     _scaleProperty.addListener(_function_1);
   }
 }
  @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);
      }
    }
  }
Esempio n. 3
0
 private static Bounds translateBounds(Bounds bounds, Point2D offset) {
   return new BoundingBox(
       bounds.getMinX() + offset.getX(),
       bounds.getMinY() + offset.getY(),
       bounds.getWidth(),
       bounds.getHeight());
 }
 @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 void setLayoutBounds(Bounds layoutBounds) {

    // Setup layoutX/layoutY on the image view and the region (1)
    region.setLayoutX(layoutBounds.getMinX());
    region.setLayoutY(layoutBounds.getMinY());
    region.setPrefWidth(layoutBounds.getWidth());
    region.setPrefHeight(layoutBounds.getHeight());
  }
 @Override
 protected void anchorBoundsDidChange() {
   final Bounds lb = getAnchor().getLayoutBounds();
   messagePanelController.setPanelWidth(lb.getWidth());
   // This callback should not be needed for auto hiding popups
   // See RT-31292 : Popup does not auto hide when resizing the window
   updatePopupLocation();
 }
Esempio n. 7
0
  private void handlePlatform() {

    switch (currentDirection) {
      case NONE:
        break;

      case LEFT:
        {
          double newPos = rect.getTranslateX() - SPEED;
          if (newPos < areaBounds.getMinX()) {
            newPos = areaBounds.getMinX();
          }
          rect.setTranslateX(newPos);
        }
        break;

      case RIGHT:
        {
          double newPos = rect.getTranslateX() + SPEED;
          if (newPos > areaBounds.getMaxX() - rectBounds.getWidth()) {
            newPos = areaBounds.getMaxX() - rectBounds.getWidth();
          }
          rect.setTranslateX(newPos);
        }
        break;

      case UP:
        sceneSpeed += 0.1;
        if (sceneSpeed > 10) {
          sceneSpeed = 10;
        }
        break;

      case DOWN:
        sceneSpeed -= 0.1;
        if (sceneSpeed < 0) {
          sceneSpeed = 0;
        }
        break;

      default:
        break;
    }
  }
  private void animateTransitionToLabel(Label newLabel) {
    final Bounds newLabelBounds = newLabel.getBoundsInParent();

    final double newX = newLabelBounds.getMinX();
    final double newWidth = newLabelBounds.getWidth();

    animation.getKeyFrames().clear();
    animation
        .getKeyFrames()
        .add(
            new KeyFrame(
                TRANSITION_DURATION,
                new KeyValue(selectedBackground.xProperty(), newX),
                new KeyValue(selectedBackground.widthProperty(), newWidth)));

    animation.play();
  }
Esempio n. 9
0
  @Override
  public Object eval(Environment env) {

    Sprite sprite = env.getSprite();
    Bounds spriteBounds = sprite.getBoundsInLocal();
    Pane parent = (AnchorPane) sprite.getParent();

    // x軸への動きしか想定しない
    double rCollision =
        parent.getWidth() - sprite.getTranslateX() - env.getX() - spriteBounds.getWidth();
    double lCollision = sprite.getTranslateX() + env.getX();

    if (rCollision < 0 || lCollision < 0) {
      return TRUE;
    }

    return FALSE;
  }
Esempio n. 10
0
 protected void animateComputeBox(double frac, Context context) {
   bounds = label.getBoundsInParent();
   bounds =
       new BoundingBox(
           bounds.getMinX() - HMARGIN,
           bounds.getMinY() - VMARGIN,
           bounds.getWidth() + 2 * HMARGIN,
           bounds.getHeight() + 2 * VMARGIN);
   rectangle.setFill(Color.TRANSPARENT);
   context.styles.get(StyleId.LineColor).apply(rectangle);
   context.styles.get(StyleId.PenWidth).apply(rectangle);
   context.styles.get(StyleId.Dash).apply(rectangle);
   context.styles.get(StyleId.Opacity).apply(rectangle);
   rectangle.setX(bounds.getMinX());
   rectangle.setY(bounds.getMinY());
   rectangle.setWidth(0d);
   rectangle.setHeight(0d);
   rectangle.setVisible(false);
 }
Esempio n. 11
0
 private void handleEvents(final String EVENT_TYPE) {
   if ("RESIZE".equals(EVENT_TYPE)) {
     resize();
     redraw();
   } else if ("REDRAW".equals(EVENT_TYPE)) {
     redraw();
   } else if ("RECALC".equals(EVENT_TYPE)) {
     angleRange = Helper.clamp(90.0, 180.0, getSkinnable().getAngleRange());
     startAngle = getStartAngle();
     minValue = getSkinnable().getMinValue();
     range = getSkinnable().getRange();
     sections = getSkinnable().getSections();
     angleStep = angleRange / range;
     redraw();
   } else if ("FINISHED".equals(EVENT_TYPE)) {
     needleTooltip.setText(String.format(locale, formatString, getSkinnable().getValue()));
     double value = getSkinnable().getValue();
     if (getSkinnable().isValueVisible()) {
       Bounds bounds = pane.localToScreen(pane.getBoundsInLocal());
       double xFactor = value > getSkinnable().getRange() * 0.8 ? 0.0 : 0.25;
       double tooltipAngle = value * angleStep;
       double sinValue = Math.sin(Math.toRadians(180 + angleRange * 0.5 - tooltipAngle));
       double cosValue = Math.cos(Math.toRadians(180 + angleRange * 0.5 - tooltipAngle));
       double needleTipX =
           bounds.getMinX() + bounds.getWidth() * 0.5 + bounds.getHeight() * sinValue;
       double needleTipY =
           bounds.getMinY() + bounds.getHeight() * 0.72 + bounds.getHeight() * cosValue;
       needleTooltip.show(needle, needleTipX, needleTipY);
       needleTooltip.setAnchorX(needleTooltip.getX() - needleTooltip.getWidth() * xFactor);
     }
     if (sections.isEmpty() || sectionsAlwaysVisible) return;
     for (Section section : sections) {
       if (section.contains(value)) {
         barTooltip.setText(section.getText());
         break;
       }
     }
   } else if ("VISIBILITY".equals(EVENT_TYPE)) {
     Helper.enableNode(titleText, !getSkinnable().getTitle().isEmpty());
   }
 }
Esempio n. 12
0
  @Override
  protected void layoutChildren() {
    super.layoutChildren();

    if (_nodeByPosition.isEmpty()) {
      adjustLineCount(0);

      setPrefWidth(0);
      setPrefHeight(0);

      return;
    }

    // Calculate width per position based on layout bounds
    Map<NodePosition, Double> widthByPosition = new HashMap<>();
    Map<Integer, Double> levelHeight = new HashMap<>();

    Map<Integer, Set<NodePosition>> positionsByLevel = new HashMap<>();
    Map<NodePosition, Set<NodePosition>> positionsByParentPosition = new HashMap<>();

    int maxLevel = Collections.max(_nodeByLevel.keySet());

    for (int curLevel = maxLevel; curLevel >= 0; --curLevel) {
      levelHeight.put(curLevel, 0.0);

      positionsByLevel.put(curLevel, new HashSet<NodePosition>());
    }

    for (int curLevel = maxLevel; curLevel >= 0; --curLevel) {
      // Get bounds of nodes on current level
      Set<Node> curLevelNodes = _nodeByLevel.get(curLevel);

      if (curLevelNodes != null) {
        // Get node bounds
        for (Node node : curLevelNodes) {
          // Node data
          NodePosition nodePosition = _positionByNode.get(node);
          Bounds nodeBounds = node.getLayoutBounds();

          // Get bounds
          widthByPosition.put(nodePosition, nodeBounds.getWidth() + this.getXAxisSpacing());
          levelHeight.put(
              curLevel,
              Math.max(levelHeight.get(curLevel), nodeBounds.getHeight() + this.getYAxisSpacing()));

          // Register positions
          positionsByLevel.get(curLevel).add(nodePosition);

          if (curLevel > 0) {
            positionsByLevel.get(curLevel - 1).add(nodePosition.getParent());
          }
        }
      }

      // Calculate position widths of current level
      for (NodePosition position : positionsByLevel.get(curLevel)) {
        // Register positions
        if (position.getLevel() > 0) {
          NodePosition parentPosition = position.getParent();

          positionsByLevel.get(position.getLevel() - 1).add(parentPosition);

          if (positionsByParentPosition.containsKey(parentPosition) == false) {
            positionsByParentPosition.put(parentPosition, new HashSet<NodePosition>());
          }

          positionsByParentPosition.get(parentPosition).add(position);
        }

        // Get width of children
        double widthOfChildren = 0;

        Set<NodePosition> parentPositions = positionsByParentPosition.get(position);

        if (parentPositions != null) {
          for (NodePosition childPosition : parentPositions) {
            if (widthByPosition.containsKey(childPosition) == true) {
              widthOfChildren += widthByPosition.get(childPosition);
            }
          }
        }

        // Get maximum of node bound and sum of child node bounds
        if (widthByPosition.containsKey(position) == false) {
          widthByPosition.put(position, widthOfChildren);
        } else {
          widthByPosition.put(position, Math.max(widthByPosition.get(position), widthOfChildren));
        }
      }
    }

    // Calculate position boxes
    Map<NodePosition, Rectangle2D> boxesByPosition = new HashMap<>();

    if (positionsByLevel.containsKey(0) == false || positionsByLevel.get(0).size() != 1) {
      throw new IllegalStateException();
    }

    boxesByPosition.put(
        NodePosition.ROOT,
        new Rectangle2D(0, 0, widthByPosition.get(NodePosition.ROOT), levelHeight.get(0)));

    for (int curLevel = 0; curLevel <= maxLevel; ++curLevel) {
      for (NodePosition position : positionsByLevel.get(curLevel)) {
        Rectangle2D positionBox = boxesByPosition.get(position);

        List<NodePosition> childPositions = new ArrayList<>();

        if (positionsByParentPosition.containsKey(position)) {
          childPositions.addAll(positionsByParentPosition.get(position));
        }

        Collections.sort(childPositions);

        double childX = positionBox.getMinX();

        for (NodePosition childPosition : childPositions) {
          double childWidth = widthByPosition.get(childPosition);

          boxesByPosition.put(
              childPosition,
              new Rectangle2D(
                  childX,
                  positionBox.getMaxY(),
                  childWidth,
                  levelHeight.get(childPosition.getLevel())));

          childX += childWidth;
        }
      }
    }

    // Position nodes
    Map<NodePosition, Double> xCenterHintByPosition = new HashMap<>();
    Map<NodePosition, Double> yCenterHintByPosition = new HashMap<>();

    for (int curLevel = maxLevel; curLevel >= 0; --curLevel) {
      for (NodePosition position : positionsByLevel.get(curLevel)) {
        // Calculate center hints
        Rectangle2D positionBox = boxesByPosition.get(position);

        double xCenterHint = (positionBox.getMinX() + positionBox.getMaxX()) / 2;

        if (xCenterHintByPosition.containsKey(position) == true) {
          xCenterHint = xCenterHintByPosition.get(position);
        }

        double yCenterHint = (positionBox.getMinY() + positionBox.getMaxY()) / 2;

        xCenterHintByPosition.put(position, xCenterHint);
        yCenterHintByPosition.put(position, yCenterHint);

        // Position node
        if (_nodeByPosition.containsKey(position)) {
          Node node = _nodeByPosition.get(position);
          Bounds nodeBounds = node.getLayoutBounds();

          node.relocate(
              xCenterHint - nodeBounds.getWidth() / 2, yCenterHint - nodeBounds.getHeight() / 2);
        }

        // Update parent node position hint
        NodePosition parentPosition = position.getParent();

        if (xCenterHintByPosition.containsKey(parentPosition)) {
          xCenterHintByPosition.put(
              parentPosition, (xCenterHintByPosition.get(parentPosition) + xCenterHint) / 2);
        } else {
          xCenterHintByPosition.put(parentPosition, xCenterHint);
        }
      }
    }

    // Update lines
    if (this.getShowLines() == true) {
      adjustLineCount(boxesByPosition.size() - 1);

      int currentLine = 0;

      for (NodePosition position : boxesByPosition.keySet()) {
        if (positionsByParentPosition.containsKey(position) == false) {
          continue;
        }

        for (NodePosition childPosition : positionsByParentPosition.get(position)) {
          Bounds fromBounds =
              _nodeByPosition.containsKey(position)
                  ? _nodeByPosition.get(position).getLayoutBounds()
                  : null;
          Bounds toBounds =
              _nodeByPosition.containsKey(childPosition)
                  ? _nodeByPosition.get(childPosition).getLayoutBounds()
                  : null;

          Point2D lineFrom =
              new Point2D(
                  xCenterHintByPosition.get(position),
                  yCenterHintByPosition.get(position)
                      + (fromBounds != null ? (fromBounds.getHeight() / 2) : 0)
                      + this.getLineSpacing());

          Point2D lineTo =
              new Point2D(
                  xCenterHintByPosition.get(childPosition),
                  yCenterHintByPosition.get(childPosition)
                      - (toBounds != null ? (toBounds.getHeight() / 2) : 0)
                      - this.getLineSpacing());

          Line l = _lines.get(currentLine);

          l.setStartX(lineFrom.getX());
          l.setStartY(lineFrom.getY());

          l.setEndX(lineTo.getX());
          l.setEndY(lineTo.getY());

          ++currentLine;
        }
      }
    } else {
      adjustLineCount(0);
    }

    // Update preferred size
    double totalHeight = 0;
    for (Double h : levelHeight.values()) {
      totalHeight += h;
    }

    setPrefWidth(widthByPosition.get(NodePosition.ROOT));
    setPrefHeight(totalHeight);
  }
Esempio n. 13
0
 protected void animateDrawBox(double frac, Context context) {
   rectangle.setWidth(bounds.getWidth() * frac);
   rectangle.setHeight(bounds.getHeight() * frac);
   if (frac != 0d) rectangle.setVisible(true);
 }
  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());
  }