Beispiel #1
0
  private void setJointPoint() {
    rightElbowPoint.centerXProperty().bind(speaker.rightElbowXProperty());
    rightElbowPoint.centerYProperty().bind(speaker.rightElbowYProperty());

    leftElbowPoint.centerXProperty().bind(speaker.leftElbowXProperty());
    leftElbowPoint.centerYProperty().bind(speaker.leftElbowYProperty());

    rightKneePoint.centerXProperty().bind(speaker.rightKneeXProperty());
    rightKneePoint.centerYProperty().bind(speaker.rightKneeYProperty());

    leftKneePoint.centerXProperty().bind(speaker.leftKneeXProperty());
    leftKneePoint.centerYProperty().bind(speaker.leftKneeYProperty());

    getChildren().addAll(rightElbowPoint, leftElbowPoint, rightKneePoint, leftKneePoint);
  }
  @Override
  public void start(Stage primaryStage) {

    Circle circle = new Circle();

    StackPane root = new StackPane();
    root.getChildren().add(circle);

    Scene scene = new Scene(root, 100, 100);

    circle.centerXProperty().bind(scene.widthProperty().divide(2));
    circle.centerYProperty().bind(scene.heightProperty().divide(2));
    circle
        .radiusProperty()
        .bind(Bindings.min(scene.widthProperty(), scene.heightProperty()).divide(2));

    primaryStage.setTitle("Bindings in java fx");
    primaryStage.setScene(scene);
    primaryStage.show();
  }
  public ColorPickerPopover() {

    getStyleClass().add("color-picker-popover");
    popup.setAutoHide(true);

    // add this to popup
    popup.getContent().add(this);

    // load stylesheet
    getStylesheets().add(ColorPicker.class.getResource("ColorPicker.css").toString());

    // create popover path for main shape
    final Path p = new Path();
    p.getElements()
        .addAll(
            new MoveTo(PICKER_PADDING, PICKER_PADDING + ARROW_SIZE + RADIUS),
            new ArcTo(
                RADIUS,
                RADIUS,
                90,
                PICKER_PADDING + RADIUS,
                PICKER_PADDING + ARROW_SIZE,
                false,
                true),
            new LineTo(PICKER_PADDING + ARROW_X - (ARROW_SIZE * 0.8), PICKER_PADDING + ARROW_SIZE),
            new LineTo(PICKER_PADDING + ARROW_X, PICKER_PADDING),
            new LineTo(PICKER_PADDING + ARROW_X + (ARROW_SIZE * 0.8), PICKER_PADDING + ARROW_SIZE),
            new LineTo(PICKER_PADDING + PICKER_WIDTH - RADIUS, PICKER_PADDING + ARROW_SIZE),
            new ArcTo(
                RADIUS,
                RADIUS,
                90,
                PICKER_PADDING + PICKER_WIDTH,
                PICKER_PADDING + ARROW_SIZE + RADIUS,
                false,
                true),
            new LineTo(
                PICKER_PADDING + PICKER_WIDTH,
                PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT - RADIUS),
            new ArcTo(
                RADIUS,
                RADIUS,
                90,
                PICKER_PADDING + PICKER_WIDTH - RADIUS,
                PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT,
                false,
                true),
            new LineTo(PICKER_PADDING + RADIUS, PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT),
            new ArcTo(
                RADIUS,
                RADIUS,
                90,
                PICKER_PADDING,
                PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT - RADIUS,
                false,
                true),
            new ClosePath());
    p.setFill(
        new LinearGradient(
            0,
            0,
            0,
            1,
            true,
            CycleMethod.NO_CYCLE,
            new Stop(0, Color.web("#313131")),
            new Stop(0.5, Color.web("#5f5f5f")),
            new Stop(1, Color.web("#313131"))));
    p.setStroke(null);
    p.setEffect(new DropShadow(15, 0, 1, Color.gray(0, 0.6)));
    p.setCache(true);

    // create rectangle to capture mouse events to hide
    Rectangle windowClickRect =
        RectangleBuilder.create()
            .width(PICKER_PADDING + PICKER_WIDTH + PICKER_PADDING)
            .height(PICKER_PADDING + PICKER_HEIGHT + PICKER_PADDING)
            .fill(Color.TRANSPARENT)
            .onMouseClicked(
                new EventHandler<MouseEvent>() {

                  @Override
                  public void handle(MouseEvent event) {

                    System.out.println("x= " + event.getX());
                    System.out.println(
                        "p.contains(event.getX(), event.getY()) = "
                            + p.contains(event.getX(), event.getY()));
                    if (!p.contains(event.getX(), event.getY())) {
                      hide();
                    }
                  }
                })
            .build();

    final Circle colorRectIndicator =
        CircleBuilder.create()
            .centerX(60)
            .centerY(60)
            .radius(5)
            .stroke(Color.WHITE)
            .fill(null)
            .effect(new DropShadow(2, 0, 1, Color.BLACK))
            .build();

    colorRectIndicator
        .centerXProperty()
        .bind(
            new DoubleBinding() {

              {
                bind(sat);
              }

              @Override
              protected double computeValue() {

                return (PICKER_PADDING + 10) + (RECT_SIZE * (sat.get() / 100));
              }
            });

    colorRectIndicator
        .centerYProperty()
        .bind(
            new DoubleBinding() {

              {
                bind(bright);
              }

              @Override
              protected double computeValue() {

                return (PICKER_PADDING + ARROW_SIZE + 10)
                    + (RECT_SIZE * (1 - (bright.get() / 100)));
              }
            });

    final Rectangle colorRect =
        RectangleBuilder.create()
            .x(PICKER_PADDING + 10)
            .y(PICKER_PADDING + ARROW_SIZE + 10)
            .width(RECT_SIZE)
            .height(RECT_SIZE)
            .build();
    colorRect
        .fillProperty()
        .bind(
            new ObjectBinding<Paint>() {

              {
                bind(color);
              }

              @Override
              protected Paint computeValue() {

                return Color.hsb(hue.getValue(), 1, 1);
              }
            });

    Rectangle colorRectOverlayOne =
        RectangleBuilder.create()
            .x(PICKER_PADDING + 10)
            .y(PICKER_PADDING + ARROW_SIZE + 10)
            .width(RECT_SIZE)
            .height(RECT_SIZE)
            .fill(
                new LinearGradient(
                    0,
                    0,
                    1,
                    0,
                    true,
                    CycleMethod.NO_CYCLE,
                    new Stop(0, Color.rgb(255, 255, 255, 1)),
                    new Stop(1, Color.rgb(255, 255, 255, 0))))
            .build();

    EventHandler<MouseEvent> rectMouseHandler =
        new EventHandler<MouseEvent>() {

          @Override
          public void handle(MouseEvent event) {

            final double x = event.getX() - colorRect.getX();
            final double y = event.getY() - colorRect.getY();
            sat.set(clamp(x / RECT_SIZE) * 100);
            bright.set(100 - (clamp(y / RECT_SIZE) * 100));
          }
        };

    Rectangle colorRectOverlayTwo =
        RectangleBuilder.create()
            .x(PICKER_PADDING + 10)
            .y(PICKER_PADDING + ARROW_SIZE + 10)
            .width(RECT_SIZE)
            .height(RECT_SIZE)
            .fill(
                new LinearGradient(
                    0,
                    0,
                    0,
                    1,
                    true,
                    CycleMethod.NO_CYCLE,
                    new Stop(0, Color.rgb(0, 0, 0, 0)),
                    new Stop(1, Color.rgb(0, 0, 0, 1))))
            .onMouseDragged(rectMouseHandler)
            .onMouseClicked(rectMouseHandler)
            .build();
    final Rectangle colorBar =
        RectangleBuilder.create()
            .x(PICKER_PADDING + PICKER_WIDTH - 30)
            .y(PICKER_PADDING + ARROW_SIZE + 10)
            .width(20)
            .height(RECT_SIZE)
            .fill(createHueGradient())
            .build();
    final Rectangle colorBarIndicator =
        RectangleBuilder.create()
            .x(PICKER_PADDING + PICKER_WIDTH - 32)
            .y(PICKER_PADDING + ARROW_SIZE + 15)
            .width(24)
            .height(10)
            .arcWidth(4)
            .arcHeight(4)
            .stroke(Color.WHITE)
            .fill(null)
            .effect(new DropShadow(2, 0, 1, Color.BLACK))
            .build();

    colorBarIndicator
        .yProperty()
        .bind(
            new DoubleBinding() {

              {
                bind(hue);
              }

              @Override
              protected double computeValue() {

                return (PICKER_PADDING + ARROW_SIZE + 5) + (RECT_SIZE * (hue.get() / 360));
              }
            });
    EventHandler<MouseEvent> barMouseHandler =
        new EventHandler<MouseEvent>() {

          @Override
          public void handle(MouseEvent event) {

            final double y = event.getY() - colorBar.getY();
            hue.set(clamp(y / RECT_SIZE) * 360);
          }
        };
    colorBar.setOnMouseDragged(barMouseHandler);
    colorBar.setOnMouseClicked(barMouseHandler);

    Label brightnessLabel = new Label("Brightness:");
    brightnessLabel.setMinWidth(Control.USE_PREF_SIZE);
    GridPane.setConstraints(brightnessLabel, 0, 0);

    Slider brightnessSlider = SliderBuilder.create().min(0).max(100).id("BrightnessSlider").build();
    brightnessSlider.valueProperty().bindBidirectional(bright);
    GridPane.setConstraints(brightnessSlider, 1, 0);

    IntegerField brightnessField = new IntegerField();
    brightnessField.valueProperty().bindBidirectional(bright);
    brightnessField.setPrefColumnCount(7);
    GridPane.setConstraints(brightnessField, 2, 0);

    Label saturationLabel = new Label("Saturation:");
    saturationLabel.setMinWidth(Control.USE_PREF_SIZE);
    GridPane.setConstraints(saturationLabel, 0, 1);

    Slider saturationSlider = SliderBuilder.create().min(0).max(100).id("SaturationSlider").build();
    saturationSlider.valueProperty().bindBidirectional(sat);
    GridPane.setConstraints(saturationSlider, 1, 1);

    saturationSlider
        .styleProperty()
        .bind(
            new StringBinding() {

              {
                bind(color);
              }

              @Override
              protected String computeValue() {

                return "picker-color: hsb(" + hue.get() + ",100%,100%);";
              }
            });

    IntegerField saturationField = new IntegerField();
    saturationField.valueProperty().bindBidirectional(sat);
    saturationField.setPrefColumnCount(7);
    GridPane.setConstraints(saturationField, 2, 1);

    Label webLabel = new Label("Web:");
    webLabel.setMinWidth(Control.USE_PREF_SIZE);
    GridPane.setConstraints(webLabel, 0, 2);

    WebColorField webField = new WebColorField();
    webField.valueProperty().bindBidirectional(color);
    GridPane.setConstraints(webField, 1, 2, 2, 1);

    GridPane controls = new GridPane();
    controls.setVgap(5);
    controls.setHgap(5);
    controls
        .getChildren()
        .addAll(
            brightnessLabel,
            brightnessSlider,
            brightnessField,
            saturationLabel,
            saturationSlider,
            saturationField,
            webLabel,
            webField);
    controls.setManaged(false);
    controls.resizeRelocate(
        PICKER_PADDING + 10,
        PICKER_PADDING + ARROW_SIZE + 10 + 170 + 10,
        PICKER_WIDTH - 20,
        controls.getPrefHeight());

    getChildren()
        .addAll(
            windowClickRect,
            p,
            colorRect,
            colorRectOverlayOne,
            colorRectOverlayTwo,
            colorBar,
            colorRectIndicator,
            colorBarIndicator,
            controls);
  }
Beispiel #4
0
  /**
   * Drawing function for Circles and Lines
   *
   * @param drawPane
   * @param coords Circle Coordinates
   * @param edges array of edges
   * @param startIndex NumberOfNodes
   */
  private void drawShapes(Pane drawPane, double[][] coords, int[][] edges, int startIndex) {

    // clear previous pane
    drawPane.getChildren().clear();
    circleList = new ArrayList<>();

    // generate Circles
    for (int i = 0; i < coords.length; i++) {
      Circle currentCircle = new Circle(coords[i][0], coords[i][1], nodeSize, Color.BLACK);
      String toolTipText = "Node " + Integer.toString(i + 1);
      // expand toolTip text with nucleotide and Circle color, if possible
      if (sequenceField.getText().length() > i) {
        toolTipText += ": " + sequenceField.getText().charAt(i);
        currentCircle.setFill(getNodeColor(sequenceField.getText().charAt(i)));
      }
      Tooltip.install(currentCircle, new Tooltip(toolTipText));
      if (isAnimated) {
        currentCircle.setOnMousePressed(circleOnMousePressedEventHandler);
        currentCircle.setOnMouseDragged(circleOnMouseDraggedEventHandler);
        currentCircle.setOnMouseReleased(circleOnMouseReleasedEventHandler);
      }

      circleList.add(currentCircle);
    }

    // generate  basic Lines
    ArrayList<Line> lineList = new ArrayList<>();
    for (int i = 0; i < circleList.size() - 1; i++) {
      Line line = new Line();
      line.setStroke(Color.BLACK);
      line.setFill(Color.BLACK);
      Circle circle1 = circleList.get(i);
      Circle circle2 = circleList.get(i + 1);

      // bind ends of line:
      line.startXProperty().bind(circle1.centerXProperty().add(circle1.translateXProperty()));
      line.startYProperty().bind(circle1.centerYProperty().add(circle1.translateYProperty()));
      line.endXProperty().bind(circle2.centerXProperty().add(circle2.translateXProperty()));
      line.endYProperty().bind(circle2.centerYProperty().add(circle2.translateYProperty()));

      lineList.add(line);
    }

    // generate edges
    for (int i = startIndex - 1; i < edges.length; i++) {
      Line line = new Line();
      line.setStroke(Color.ORANGE);
      Circle circle1 = circleList.get(edges[i][0]);
      Circle circle2 = circleList.get(edges[i][1]);

      line.startXProperty().bind(circle1.centerXProperty().add(circle1.translateXProperty()));
      line.startYProperty().bind(circle1.centerYProperty().add(circle1.translateYProperty()));
      line.endXProperty().bind(circle2.centerXProperty().add(circle2.translateXProperty()));
      line.endYProperty().bind(circle2.centerYProperty().add(circle2.translateYProperty()));

      lineList.add(line);
    }

    drawPane.getChildren().addAll(lineList);
    drawPane.getChildren().addAll(circleList);
  }
  // drawing
  public void drawGraph() {

    Timeline timeline = new Timeline();

    if (graph != null && finalCoordinates != null) {

      // reset pane
      drawing.getChildren().clear();
      SpringEmbedder.centerCoordinates(finalCoordinates, 20, 380, 20, 380);
      SpringEmbedder.centerCoordinates(startingCoordinates, 20, 380, 20, 380);

      // draw nucleotides
      circles = new Circle[finalCoordinates.length];
      for (int i = 0; i < finalCoordinates.length; i++) {
        // create nodes
        Circle circle = new Circle(5);
        circle.setCenterX(finalCoordinates[i][0]);
        circle.setCenterY(finalCoordinates[i][1]);
        switch (graph.getSequence().charAt(i)) {
          case 'A':
            circle.setFill(Color.YELLOW);
            break;
          case 'a':
            circle.setFill(Color.YELLOW);
            break;
          case 'U':
            circle.setFill(Color.GREEN);
            break;
          case 'u':
            circle.setFill(Color.GREEN);
            break;
          case 'C':
            circle.setFill(Color.BLUE);
            break;
          case 'c':
            circle.setFill(Color.BLUE);
            break;
          case 'G':
            circle.setFill(Color.RED);
            break;
          case 'g':
            circle.setFill(Color.RED);
            break;
        }
        circle.setStroke(Color.BLACK);
        // add tooltip
        Tooltip t =
            new Tooltip("Nucleotide: " + graph.getSequence().charAt(i) + "\nPosition: " + i);
        Tooltip.install(circle, t);

        // add drag-and-drop behaviour
        circle.setOnMousePressed(
            event -> {
              if (isAnimationActivated) {
                dragStartX = circle.getCenterX();
                dragStartY = circle.getCenterY();
              }
            });

        circle.setOnMouseDragged(
            event -> {
              if (isAnimationActivated) {
                circle.setCenterX(event.getX());
                circle.setCenterY(event.getY());
              }
            });

        circle.setOnMouseReleased(
            event -> {
              if (isAnimationActivated) {
                Timeline dragTimeline = new Timeline();
                KeyValue circlePositionXKey = new KeyValue(circle.centerXProperty(), dragStartX);
                KeyValue circlePositionYKey = new KeyValue(circle.centerYProperty(), dragStartY);
                dragTimeline
                    .getKeyFrames()
                    .add(new KeyFrame(Duration.millis(animationTime), circlePositionXKey));
                dragTimeline
                    .getKeyFrames()
                    .add(new KeyFrame(Duration.millis(animationTime), circlePositionYKey));
                dragTimeline.play();
              }
            });

        // save circle locally
        circles[i] = circle;

        // animate circles
        KeyValue startingXKey = new KeyValue(circle.centerXProperty(), startingCoordinates[i][0]);
        KeyValue finalXKey = new KeyValue(circle.centerXProperty(), circle.getCenterX());
        KeyValue startingYKey = new KeyValue(circle.centerYProperty(), startingCoordinates[i][1]);
        KeyValue finalYKey = new KeyValue(circle.centerYProperty(), circle.getCenterY());
        timeline.getKeyFrames().add(new KeyFrame(Duration.millis(0), startingXKey));
        timeline.getKeyFrames().add(new KeyFrame(Duration.millis(0), startingYKey));
        timeline.getKeyFrames().add(new KeyFrame(Duration.millis(animationTime), finalXKey));
        timeline.getKeyFrames().add(new KeyFrame(Duration.millis(animationTime), finalYKey));
      }

      // create edges
      int[][] edges = graph.getEdges();
      for (int i = 0; i < edges.length; i++) {
        // bind edges to nodes
        Line line =
            new Line(
                finalCoordinates[edges[i][0]][0],
                finalCoordinates[edges[i][0]][1],
                finalCoordinates[edges[i][1]][0],
                finalCoordinates[edges[i][1]][1]);
        line.startYProperty().bind(circles[edges[i][0]].centerYProperty());
        line.startXProperty().bind(circles[edges[i][0]].centerXProperty());
        line.endYProperty().bind(circles[edges[i][1]].centerYProperty());
        line.endXProperty().bind(circles[edges[i][1]].centerXProperty());

        // draw edges
        if (edges[i][1] - edges[i][0] != 1) {
          line.setStroke(Color.CADETBLUE);
        } else {
          line.setFill(Color.DARKGRAY);
        }
        drawing.getChildren().add(line);
      }

      // draw all circles in order to overlap the edges
      drawing.getChildren().addAll(circles);

      if (isAnimationActivated) {
        timeline.play();
      }

    } else {
      throw new IllegalArgumentException(
          "graph is null: "
              + graph.equals(null)
              + "\ncoordinates is null: "
              + finalCoordinates.equals(null));
    }
  }