Builders proposal

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Duplicate
    • Priority: P4
    • 8
    • Affects Version/s: fx2.0
    • Component/s: javafx
    • None

      I like having builders for javafx classes, by using them the code becomes similar to javafx script and hence more readable.
      However when wanting to bind variables of the class that is being built to other observableValues one cannot use the builder. As such I propose that the builders also accept propertys as well as the primitive value.

      -- javafx script
      var innerRectangle = Rectangle{
              width: bind _outerRectangle.width - OUTER_RECTANGLE_STROKE_WIDTH * 2
              height: bind _outerRectangle.height - OUTER_RECTANGLE_STROKE_WIDTH * 2
              x: bind OUTER_RECTANGLE_STROKE_WIDTH + _outerRectangle.x
              y: bind OUTER_RECTANGLE_STROKE_WIDTH + _outerRectangle.y
              fill: Color.WHITE
              stroke: Color.BLACK
          };

      Example (Now):
      -- java
      Rectangle innerRectangle = new Rectangle();
      innerRectangle.widthProperty().bind(outerRectangle.widthProperty().subtract(OUTER_RECTANGLE_STROKE_WIDTH * 2));
      innerRectangle.heightProperty().bind(outerRectangle.heightProperty().subtract(OUTER_RECTANGLE_STROKE_WIDTH * 2));
      innerRectangle.xProperty().bind(outerRectangle.xProperty().add(OUTER_RECTANGLE_STROKE_WIDTH));
      innerRectangle.yProperty().bind(outerRectangle.yProperty().add(OUTER_RECTANGLE_STROKE_WIDTH));
      innerRectangle.setFill(Color.WHITE);
      innerRectangle.setStroke(Color.BLACK);

      Example (with proposal):
      --java
      Rectangle innerRectagle = RectangleBuilder.create()
                                               .width( outerRectangle.widthProperty().subtract(OUTER_RECTANGLE_STROKE_WIDTH * 2) )
                                               .height( outerRectangle.heightProperty().subtract(OUTER_RECTANGLE_STROKE_WIDTH * 2) )
                                               .x( outerRectangle.xProperty().add(OUTER_RECTANGLE_STROKE_WIDTH) )
                                               .y( outerRectangle.yProperty().add(OUTER_RECTANGLE_STROKE_WIDTH) )
                                               .fill( Color.WHITE )
                                              .stroke( Color.BLACK )
                                            .build();

            Assignee:
            Michael Heinrichs (Inactive)
            Reporter:
            Pedro Vieira
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: