Ah i missed you passing them to the constructor.

Still i don't see this as much an improvement because we still create a vast 
amount of anon inner classes.

Tom

Von meinem iPhone gesendet

> Am 22.03.2014 um 16:23 schrieb Tom Schindl <tom.schi...@bestsolution.at>:
> 
> Why not i expect the property to be fully initialize so this would be a 
> breaking change in behavior.
> 
> Tom
> 
> Von meinem iPhone gesendet
> 
>> Am 22.03.2014 um 14:54 schrieb Tomas Mikula <tomas.mik...@gmail.com>:
>> 
>> On Fri, Mar 21, 2014 at 8:53 PM, Tom Schindl
>> <tom.schi...@bestsolution.at> wrote:
>>> Hi Richard,
>>> 
>>> Coming back to this old thread and now that we are using lamdas all over
>>> I guess we could take one more look into that.
>>> 
>>> I've prototyped an initial version by introducing a new internal type
>>> named InvalidatedSimpleObjectProperty (not the best name ever!) - see
>>> code pasted below.
>>> 
>>> And now one can write code like this:
>>> 
>>>>   public final ObjectProperty<Rectangle2D> viewportProperty() {
>>>>       if (viewport == null) {
>>>>           viewport = new InvalidatedSimpleObjectProperty<>(this, 
>>>> "viewport", (o) -> {
>>>>             invalidateWidthHeight();
>>>>               impl_markDirty(DirtyBits.NODE_VIEWPORT);
>>>>               impl_geomChanged();
>>>>           } );
>>>>       }
>>>>       return viewport;
>>>>   }
>>> 
>>> instead of
>>> 
>>>>   public final ObjectProperty<Rectangle2D> viewportProperty() {
>>>>       if (viewport == null) {
>>>>           viewport = new ObjectPropertyBase<Rectangle2D>() {
>>>> 
>>>>               @Override
>>>>               protected void invalidated() {
>>>>                   invalidateWidthHeight();
>>>>                   impl_markDirty(DirtyBits.NODE_VIEWPORT);
>>>>                   impl_geomChanged();
>>>>               }
>>>> 
>>>>               @Override
>>>>               public Object getBean() {
>>>>                   return ImageView.this;
>>>>               }
>>>> 
>>>>               @Override
>>>>               public String getName() {
>>>>                   return "viewport";
>>>>               }
>>>>           };
>>>>       }
>>>>       return viewport;
>>>>   }
>> 
>> Nice idea. Just to get the comparison to status quo more fair, you
>> don't need to override getBean() and getName() methods:
>> 
>> public final ObjectProperty<Rectangle2D> viewportProperty() {
>>   if (viewport == null) {
>>       viewport = new SimpleObjectProperty<Rectangle2D>(this, "viewport") {
>> 
>>           @Override
>>           protected void invalidated() {
>>               invalidateWidthHeight();
>>               impl_markDirty(DirtyBits.NODE_VIEWPORT);
>>               impl_geomChanged();
>>           }
>>       };
>>   }
>>   return viewport;
>> }
>> 
>> Regards,
>> Tomas
>> 
>>> 
>>> Which allows us to get rid of most of the ObjectPropertyBase sublcasses.
>>> 
>>> Tom
>>> 
>>> 
>>>> package com.sun.javafx.property;
>>>> 
>>>> import java.util.function.Consumer;
>>>> 
>>>> import javafx.beans.property.SimpleObjectProperty;
>>>> 
>>>> public final class InvalidatedSimpleObjectProperty<T> extends 
>>>> SimpleObjectProperty<T> {
>>>>     private final Consumer<InvalidatedSimpleObjectProperty<T>> 
>>>> invalidationConsumer;
>>>> 
>>>>   /**
>>>>    * The constructor of {@code ObjectProperty}
>>>>    *
>>>>    * @param initialValue
>>>>    *            the initial value of the wrapped value
>>>>    * @param invalidationConsumer
>>>>    *                          the consumer to be called when the bean is 
>>>> invalidated
>>>>    */
>>>>   public InvalidatedSimpleObjectProperty(T initialValue, final 
>>>> Consumer<InvalidatedSimpleObjectProperty<T>> invalidationConsumer) {
>>>>       super(initialValue);
>>>>       if( invalidationConsumer == null ) {
>>>>             throw new IllegalArgumentException("Consumer can not be null");
>>>>       }
>>>>       this.invalidationConsumer = invalidationConsumer;
>>>>   }
>>>> 
>>>>   /**
>>>>    * The constructor of {@code ObjectProperty}
>>>>    *
>>>>    * @param bean
>>>>    *            the bean of this {@code ObjectProperty}
>>>>    * @param name
>>>>    *            the name of this {@code ObjectProperty}
>>>>    * @param invalidationConsumer
>>>>    *                          the consumer to be called when the bean is 
>>>> invalidated
>>>>    */
>>>>   public InvalidatedSimpleObjectProperty(Object bean, String name, final 
>>>> Consumer<InvalidatedSimpleObjectProperty<T>> invalidationConsumer) {
>>>>      super(bean, name);
>>>>      if( invalidationConsumer == null ) {
>>>>             throw new IllegalArgumentException("Consumer can not be null");
>>>>      }
>>>>      this.invalidationConsumer = invalidationConsumer;
>>>>   }
>>>> 
>>>>   /**
>>>>    * The constructor of {@code ObjectProperty}
>>>>    *
>>>>    * @param bean
>>>>    *            the bean of this {@code ObjectProperty}
>>>>    * @param name
>>>>    *            the name of this {@code ObjectProperty}
>>>>    * @param initialValue
>>>>    *            the initial value of the wrapped value
>>>>    * @param invalidationConsumer
>>>>    *                          the consumer to be called when the bean is 
>>>> invalidated
>>>>    */
>>>>   public InvalidatedSimpleObjectProperty(Object bean, String name, T 
>>>> initialValue, final Consumer<InvalidatedSimpleObjectProperty<T>> 
>>>> invalidationConsumer) {
>>>>       super(bean,name,initialValue);
>>>>       if( invalidationConsumer == null ) {
>>>>             throw new IllegalArgumentException("Consumer can not be null");
>>>>       }
>>>>       this.invalidationConsumer = invalidationConsumer;
>>>>   }
>>>> 
>>>>   @Override
>>>>   protected void invalidated() {
>>>>     invalidationConsumer.accept(this);
>>>>   }
>>>> }
>>> 
>>> 
>>> On 22.01.13 10:30, Richard Bair wrote:
>>>>> Is the Java8 plan still there if not should the current Simple*Property
>>>>> subclasses who overload invalidated be changed to PropertyBase?
>>>> 
>>>> It is unlikely that we'll be able to do anything major here in Java 8 just 
>>>> because we don't really have Lambda yet that we can play with, and 
>>>> changing over every property is a big job. Unless we knew it would be a 
>>>> major win. I would say, if you encounter a Simple* property that has been 
>>>> subclassed, then we should fix it up as we go to be a PropertyBase* guy 
>>>> instead.
>>> 

Reply via email to