public static void main(String[] args) {
    System.out.println("Constructing x with initial value of 2.0.");
    final DoubleProperty x = new SimpleDoubleProperty(null, "x", 2.0);
    System.out.println("Constructing y with initial value of 3.0.");
    final DoubleProperty y = new SimpleDoubleProperty(null, "y", 3.0);
    System.out.println("Creating binding area with dependencies x and y.");
    DoubleBinding area =
        new DoubleBinding() {
          private double value;

          {
            super.bind(x, y);
          }

          @Override
          protected double computeValue() {
            System.out.println("computeValue() is called.");
            return x.get() * y.get();
          }
        };
    System.out.println("area.get() = " + area.get());
    System.out.println("area.get() = " + area.get());
    System.out.println("Setting x to 5");
    x.set(5);
    System.out.println("Setting y to 7");
    y.set(7);
    System.out.println("area.get() = " + area.get());
  }
예제 #2
0
 public BlockingExecutor() {
   overallProgressBinding =
       Bindings.createDoubleBinding(
           () -> {
             if (scheduledTasks.isEmpty()) return 1d;
             double progress = 0d;
             for (TimeTask<?> task : scheduledTasks) {
               if (task.isDone()) progress += 1d;
               else if (task.getProgress() > 0) progress += task.getProgress();
             }
             return progress / (double) scheduledTasks.size();
           },
           scheduledTasks,
           currentTaskProperty);
   isIdleBinding =
       Bindings.createBooleanBinding(
           () -> overallProgressBinding.get() == 1d, overallProgressBinding);
   currentTaskProperty.addListener(
       (__, ___, task) -> {
         if (task.isDone()) next();
         else {
           task.exceptionProperty()
               .addListener(
                   (____, _____, exception) ->
                       new ErrorDialog(ConExpFX.instance.primaryStage, exception).showAndWait());
           task.setOnCancelled(____ -> next());
           task.setOnFailed(____ -> next());
           task.setOnSucceeded(____ -> next());
           tpe.submit(task);
         }
       });
 }
예제 #3
0
 public CartesianCase(Node a, Node b) {
   super.bind(
       a.layoutXProperty(), a.layoutYProperty(), b.layoutXProperty(), b.layoutYProperty());
   mXa = a.layoutXProperty();
   mYa = a.layoutYProperty();
   mXb = b.layoutXProperty();
   mYb = b.layoutYProperty();
 }
예제 #4
0
  public static void main(String[] args) {

    DoubleProperty radius = new SimpleDoubleProperty(7.0);

    // Create a binding for computing arae of the circle
    DoubleBinding area = radius.multiply(radius).multiply(Math.PI);

    System.out.println("Radius = " + radius.get() + ", Area = " + area.get());

    // Change the radius
    radius.set(14.0);
    System.out.println("Radius = " + radius.get() + ", Area = " + area.get());

    // Create a DoubleProperty and bind it to an expression that computes the area of the circle
    DoubleProperty area2 = new SimpleDoubleProperty();
    area2.bind(radius.multiply(radius).multiply(Math.PI));
    System.out.println("Radius = " + radius.get() + ", Area2 = " + area2.get());
  }
예제 #5
0
 public final void execute(final TimeTask<?> task) {
   Platform2.runOnFXThread(
       () -> {
         synchronized (scheduledTasks) {
           if (isIdleBinding.get()) currentTaskProperty.setValue(task);
           scheduledTasks.add(task);
           task.progressProperty()
               .addListener(
                   (__, ___, ____) -> {
                     overallProgressBinding.invalidate();
                     datasetProgressBindings.values().forEach(DoubleBinding::invalidate);
                   });
           task.stateProperty()
               .addListener(
                   (__, ___, ____) -> {
                     overallProgressBinding.invalidate();
                     datasetProgressBindings.values().forEach(DoubleBinding::invalidate);
                   });
         }
       });
 }
예제 #6
0
    @Override
    protected double computeValue() {
      boolean primeiroQuadrante =
          mXa.getValue() <= mXb.getValue() && mYa.getValue() >= mYb.getValue();
      boolean segundoQuadrante =
          mXa.getValue() >= mXb.getValue() && mYa.getValue() >= mYb.getValue();
      boolean terceiroQuadrante =
          mXa.getValue() >= mXb.getValue() && mYa.getValue() <= mYb.getValue();
      boolean quartoQuadrante =
          mXa.getValue() <= mXb.getValue() && mYa.getValue() <= mYb.getValue();

      //        System.out.printf("%s, %s, %s, %s\n", primeiroQuadrante, segundoQuadrante,
      // terceiroQuadrante, quartoQuadrante);
      if (segundoQuadrante && terceiroQuadrante) {
        return mSecondAndThirthBinding != null
            ? mSecondAndThirthBinding.get()
            : mSecondAndThirthValue;
      } else if (primeiroQuadrante && segundoQuadrante) {
        return mFirstAndSecondBinding != null ? mFirstAndSecondBinding.get() : mFirstAndSecondValue;
      } else if (terceiroQuadrante && quartoQuadrante) {
        return mTerceiroAndQuartoBinding != null
            ? mTerceiroAndQuartoBinding.get()
            : mTerceiroAndQuartoValue;
      } else if (primeiroQuadrante && !segundoQuadrante && !terceiroQuadrante && !quartoQuadrante) {
        //            System.out.println("1 " + (mFirstBinding != null ? mFirstBinding.get() :
        // mFirstValue));
        return mFirstBinding != null ? mFirstBinding.get() : mFirstValue;
      } else if (!primeiroQuadrante && segundoQuadrante && !terceiroQuadrante && !quartoQuadrante) {
        //            System.out.println("2 " + (mSecondBinding != null ? mSecondBinding.get() :
        // mSecondValue));
        return mSecondBinding != null ? mSecondBinding.get() : mSecondValue;
      } else if (!primeiroQuadrante && !segundoQuadrante && terceiroQuadrante && !quartoQuadrante) {
        //            System.out.println("3 " + (mSecondBinding != null ? mSecondBinding.get() :
        // mSecondValue));
        return mThirthBinding != null ? mThirthBinding.get() : mThirthValue;
      } else if (!primeiroQuadrante && !segundoQuadrante && !terceiroQuadrante && quartoQuadrante) {
        //            System.out.println("4 " + (mSecondBinding != null ? mSecondBinding.get() :
        // mSecondValue));
        return mFourthBinding != null ? mFourthBinding.get() : mFourthValue;
      } else {
        //            System.out.println("zero!");
        return 0;
      }
    }