Re: Formatted text field API (RT-14000, RT-30881)

2014-07-02 Thread Martin Sladecek

There's a new proposal here: https://javafx-jira.kenai.com/browse/RT-14000

I merged FormattedTextField and content filter to a single Formatter 
class, that's now part of the TextInputControl.


-Martin

On 06/11/2014 10:50 AM, Martin Sladecek wrote:

Hello,
I would like to start some discussion about formatted text field API. 
The related JIRA issues are RT-14000 (formatted text field) and 
RT-30881 (content filter).


The RT-30881 defines a content filter for all text input controls (in 
TextInputControl class), like TextField and TextArea. This was 
originally implemented by Richard Bair and briefly discussed here: 
http://mail.openjdk.java.net/pipermail/openjfx-dev/2012-December/004687.html. 
I've tried to build formatted text field on top of that (and made some 
changes to the API) since content filtering is something most 
formatted text fields will use.


First, the TextInputControl additions:

* contentFilter property of type ObjectProperty

So let's look at the content filter and content change (both nested 
classes of TextInputControl):


  /**
 * Content Filter specifies the filter to be used with {@link 
TextInputControl#contentFilterProperty()}.
 * It allow user to intercept and modify any change done to the 
text content.
 * To avoid content that's not valid for the filter, it's possible 
to assign a default value supplier for the filter.

 * 
 * The filter itself is an {@code UnaryOperator} that accepts 
{@link javafx.scene.control.TextInputControl.ContentChange} object.
 * It should return a {@link 
javafx.scene.control.TextInputControl.ContentChange} object that 
contains the actual (filtered)

 * change. Returning null rejects the change.
 * 
 * If default value supplier is provided, it is used when the 
{@code ContentFilter} is assigned to a {@code TextInputControl}
 * and it's current text is invalid. It is expected that the 
provided default value is accepted by the filtering operator.

 */
public static class ContentFilter {

/**
 * Creates a new filter with the providing filtering operator.
 * @param filter the filtering operator
 *
 * @throws java.lang.NullPointerException if filter is null
 */
public ContentFilter(UnaryOperator filter) {}

/**
 * Creates a new filter with the providing filtering operator 
and default value supplier.

 * @param filter the filtering operator
 * @param defaultValue the default value or null
 *
 * @throws java.lang.NullPointerException if filter is null
 */
public ContentFilter(UnaryOperator filter, 
Supplier defaultValue) {}


/**
 * The filtering operator of this filter.
 * @return the operator
 */
public UnaryOperator getFilter() {}

/**
 * The default value provider of this filter
 * @return the default value provider or null
 */
public Supplier getDefaultValue() {}

/**
 * Chains this filter with a filtering operator. The other 
filtering operator is used only if this
 * filter's operator rejects the operation. The default value 
of the new {@code ContentFilter} is the same

 * as of this filter.
 * @param other the filtering operator to chain
 * @return a new ContentFilter as described above
 */
public ContentFilter orApply(UnaryOperator 
other) {}


/**
 * Chains this filter with a filtering operator of another 
{@code ContentFilter}. The other filtering operator is used only if this
 * filter's operator rejects the operation. The default value 
of the new {@code ContentFilter} is the same

 * as of this filter.
 * @param other the filter to chain
 * @return a new ContentFilter as described above
 */
public ContentFilter orApply(ContentFilter other) {}

}

/**
 * Contains the state representing a change in the content for a
 * TextInputControl. This object is passed to any registered
 * {@code contentFilter} on the TextInputControl whenever the text
 * for the TextInputControl is modified.
 * 
 * This class contains state and convenience methods for 
determining what

 * change occurred on the control. It also has a reference to the
 * TextInputControl itself so that the developer may query any 
other
 * state on the control. Note that you should never modify the 
state

 * of the control directly from within the contentFilter handler.
 * 
 * 
 * The ContentChange is mutable, but not observable. It should 
be used

 * only for the life of a single change. It is intended that the
 * ContentChange will be modified from within the contentFilter.
 * 
 */
public static final class ContentChange implements Cloneable{

/**
 * Gets the control associated with t

Re: Formatted text field API (RT-14000, RT-30881)

2014-06-11 Thread Martin Sladecek
I already posted a comment in JIRA (RT-30881) that we should make the 
value writable.
Anyhow, we should move the discussion to JIRA to keep everything at one 
place.


Thanks,
-Martin
On 11.6.2014 18:14, Scott Palmer wrote:
I already have a use for a bi-directional binding.  I have a UI that 
shows properties of a component. The component's properties can be 
updated via the UI, and also by other events from background processes 
that are running, or even just as a reaction to some other property 
changing.  So I need the binding from the model to the control to be 
bi-directional. The UI view is both read/write.  The properties can be 
numbers, rational numbers expressed as fractions ##/###, times 
HH:MM:SS, enum values, etc.


(My app has some complex requirements so in actual fact a simple 
binding probably isn't enough.  But in principle it could be.)


Or just think of a spreadsheet in Google docs being edited by two 
people on a network... I want to be able to update a cell, and I want 
to see when someone else updates it.  Two different read/write fields 
connected to the same model.


I just thought of something else. Can this be easily used as the field 
for a editable ComboBox?


Scott


On Wed, Jun 11, 2014 at 10:08 AM, Martin Sladecek 
mailto:martin.slade...@oracle.com>> wrote:


Although I'm not sure the second one can be considered a use-case,
I agree that somebody might want uneditable field with some format
(and it's up to the developer to make it uneditable), so I'll make
the value rw.

-Martin

On 11.6.2014 16:03, Scott Palmer wrote:

There are two cases for this:
- a regular binding could be used with a read-only
FormattedTextField
for cases where you want the text representation shown in the
UI and
have it selectable and readable for copy/paste.
- a bi-directional binding should "just work"

Scott

On Wed, Jun 11, 2014 at 9:59 AM, Martin Sladecek
mailto:martin.slade...@oracle.com>> wrote:

Binding the property would mean the text field can be
edited (the field is
still editable), but it's content cannot be committed (by
either pressing
ENTER or focusing out of the field), so it's content is
practically
irrelevant.
If you think there's a reasonable use case for this, there
should be no
problem with having writable value.

-Martin


On 11.6.2014 15:53, Scott Palmer wrote:

In FormattedTextField why is the value property
returned as a
read-only property?
This control should allow bi-directional bindings to
the value property.

Scott

On Wed, Jun 11, 2014 at 4:50 AM, Martin Sladecek
mailto:martin.slade...@oracle.com>> wrote:

Hello,
I would like to start some discussion about
formatted text field API. The
related JIRA issues are RT-14000 (formatted text
field) and RT-30881
(content filter).

The RT-30881 defines a content filter for all text
input controls (in
TextInputControl class), like TextField and
TextArea. This was originally
implemented by Richard Bair and briefly discussed
here:


http://mail.openjdk.java.net/pipermail/openjfx-dev/2012-December/004687.html.
I've tried to build formatted text field on top of
that (and made some
changes to the API) since content filtering is
something most formatted
text
fields will use.

First, the TextInputControl additions:

* contentFilter property of type
ObjectProperty

So let's look at the content filter and content
change (both nested
classes
of TextInputControl):

/**
   * Content Filter specifies the filter to be
used with {@link
TextInputControl#contentFilterProperty()}.
   * It allow user to intercept and modify any
change done to the text
content.
   * To avoid content that's not valid for the
filter, it's possible
to
assign a default value supplier for the filter.
   * 
   * The filter itself is an {@code
UnaryOperator} that accepts {@link
   

Re: Formatted text field API (RT-14000, RT-30881)

2014-06-11 Thread Scott Palmer
I already have a use for a bi-directional binding.  I have a UI that shows
properties of a component. The component's properties can be updated via
the UI, and also by other events from background processes that are
running, or even just as a reaction to some other property changing.  So I
need the binding from the model to the control to be bi-directional. The UI
view is both read/write.  The properties can be numbers, rational numbers
expressed as fractions ##/###, times HH:MM:SS, enum values, etc.

(My app has some complex requirements so in actual fact a simple binding
probably isn't enough.  But in principle it could be.)

Or just think of a spreadsheet in Google docs being edited by two people on
a network... I want to be able to update a cell, and I want to see when
someone else updates it.  Two different read/write fields connected to the
same model.

I just thought of something else. Can this be easily used as the field for
a editable ComboBox?

Scott


On Wed, Jun 11, 2014 at 10:08 AM, Martin Sladecek <
martin.slade...@oracle.com> wrote:

> Although I'm not sure the second one can be considered a use-case, I agree
> that somebody might want uneditable field with some format (and it's up to
> the developer to make it uneditable), so I'll make the value rw.
>
> -Martin
>
> On 11.6.2014 16:03, Scott Palmer wrote:
>
>> There are two cases for this:
>> - a regular binding could be used with a read-only FormattedTextField
>> for cases where you want the text representation shown in the UI and
>> have it selectable and readable for copy/paste.
>> - a bi-directional binding should "just work"
>>
>> Scott
>>
>> On Wed, Jun 11, 2014 at 9:59 AM, Martin Sladecek
>>  wrote:
>>
>>> Binding the property would mean the text field can be edited (the field
>>> is
>>> still editable), but it's content cannot be committed (by either pressing
>>> ENTER or focusing out of the field), so it's content is practically
>>> irrelevant.
>>> If you think there's a reasonable use case for this, there should be no
>>> problem with having writable value.
>>>
>>> -Martin
>>>
>>>
>>> On 11.6.2014 15:53, Scott Palmer wrote:
>>>
 In FormattedTextField why is the value property returned as a
 read-only property?
 This control should allow bi-directional bindings to the value property.

 Scott

 On Wed, Jun 11, 2014 at 4:50 AM, Martin Sladecek
  wrote:

> Hello,
> I would like to start some discussion about formatted text field API.
> The
> related JIRA issues are RT-14000 (formatted text field) and RT-30881
> (content filter).
>
> The RT-30881 defines a content filter for all text input controls (in
> TextInputControl class), like TextField and TextArea. This was
> originally
> implemented by Richard Bair and briefly discussed here:
>
> http://mail.openjdk.java.net/pipermail/openjfx-dev/2012-
> December/004687.html.
> I've tried to build formatted text field on top of that (and made some
> changes to the API) since content filtering is something most formatted
> text
> fields will use.
>
> First, the TextInputControl additions:
>
> * contentFilter property of type ObjectProperty
>
> So let's look at the content filter and content change (both nested
> classes
> of TextInputControl):
>
> /**
>* Content Filter specifies the filter to be used with {@link
> TextInputControl#contentFilterProperty()}.
>* It allow user to intercept and modify any change done to the
> text
> content.
>* To avoid content that's not valid for the filter, it's
> possible
> to
> assign a default value supplier for the filter.
>* 
>* The filter itself is an {@code UnaryOperator} that accepts
> {@link
> javafx.scene.control.TextInputControl.ContentChange} object.
>* It should return a {@link
> javafx.scene.control.TextInputControl.ContentChange} object that
> contains
> the actual (filtered)
>* change. Returning null rejects the change.
>* 
>* If default value supplier is provided, it is used when the
> {@code
> ContentFilter} is assigned to a {@code TextInputControl}
>* and it's current text is invalid. It is expected that the
> provided
> default value is accepted by the filtering operator.
>*/
>   public static class ContentFilter {
>
>   /**
>* Creates a new filter with the providing filtering
> operator.
>* @param filter the filtering operator
>*
>* @throws java.lang.NullPointerException if filter is null
>*/
>   public ContentFilter(UnaryOperator filter) {}
>
>   /**
>* Creates a new filter with the providing filtering operator
> and
> default value supplier.
>   

Re: Formatted text field API (RT-14000, RT-30881)

2014-06-11 Thread Martin Sladecek
Although I'm not sure the second one can be considered a use-case, I 
agree that somebody might want uneditable field with some format (and 
it's up to the developer to make it uneditable), so I'll make the value rw.


-Martin
On 11.6.2014 16:03, Scott Palmer wrote:

There are two cases for this:
- a regular binding could be used with a read-only FormattedTextField
for cases where you want the text representation shown in the UI and
have it selectable and readable for copy/paste.
- a bi-directional binding should "just work"

Scott

On Wed, Jun 11, 2014 at 9:59 AM, Martin Sladecek
 wrote:

Binding the property would mean the text field can be edited (the field is
still editable), but it's content cannot be committed (by either pressing
ENTER or focusing out of the field), so it's content is practically
irrelevant.
If you think there's a reasonable use case for this, there should be no
problem with having writable value.

-Martin


On 11.6.2014 15:53, Scott Palmer wrote:

In FormattedTextField why is the value property returned as a
read-only property?
This control should allow bi-directional bindings to the value property.

Scott

On Wed, Jun 11, 2014 at 4:50 AM, Martin Sladecek
 wrote:

Hello,
I would like to start some discussion about formatted text field API. The
related JIRA issues are RT-14000 (formatted text field) and RT-30881
(content filter).

The RT-30881 defines a content filter for all text input controls (in
TextInputControl class), like TextField and TextArea. This was originally
implemented by Richard Bair and briefly discussed here:

http://mail.openjdk.java.net/pipermail/openjfx-dev/2012-December/004687.html.
I've tried to build formatted text field on top of that (and made some
changes to the API) since content filtering is something most formatted
text
fields will use.

First, the TextInputControl additions:

* contentFilter property of type ObjectProperty

So let's look at the content filter and content change (both nested
classes
of TextInputControl):

/**
   * Content Filter specifies the filter to be used with {@link
TextInputControl#contentFilterProperty()}.
   * It allow user to intercept and modify any change done to the text
content.
   * To avoid content that's not valid for the filter, it's possible
to
assign a default value supplier for the filter.
   * 
   * The filter itself is an {@code UnaryOperator} that accepts {@link
javafx.scene.control.TextInputControl.ContentChange} object.
   * It should return a {@link
javafx.scene.control.TextInputControl.ContentChange} object that contains
the actual (filtered)
   * change. Returning null rejects the change.
   * 
   * If default value supplier is provided, it is used when the {@code
ContentFilter} is assigned to a {@code TextInputControl}
   * and it's current text is invalid. It is expected that the
provided
default value is accepted by the filtering operator.
   */
  public static class ContentFilter {

  /**
   * Creates a new filter with the providing filtering operator.
   * @param filter the filtering operator
   *
   * @throws java.lang.NullPointerException if filter is null
   */
  public ContentFilter(UnaryOperator filter) {}

  /**
   * Creates a new filter with the providing filtering operator
and
default value supplier.
   * @param filter the filtering operator
   * @param defaultValue the default value or null
   *
   * @throws java.lang.NullPointerException if filter is null
   */
  public ContentFilter(UnaryOperator filter,
Supplier defaultValue) {}

  /**
   * The filtering operator of this filter.
   * @return the operator
   */
  public UnaryOperator getFilter() {}

  /**
   * The default value provider of this filter
   * @return the default value provider or null
   */
  public Supplier getDefaultValue() {}

  /**
   * Chains this filter with a filtering operator. The other
filtering
operator is used only if this
   * filter's operator rejects the operation. The default value of
the
new {@code ContentFilter} is the same
   * as of this filter.
   * @param other the filtering operator to chain
   * @return a new ContentFilter as described above
   */
  public ContentFilter orApply(UnaryOperator other)
{}

  /**
   * Chains this filter with a filtering operator of another
{@code
ContentFilter}. The other filtering operator is used only if this
   * filter's operator rejects the operation. The default value of
the
new {@code ContentFilter} is the same
   * as of this filter.
   * @param other the filter to chain
   * @return a new ContentFilter as described above
   */
  public ContentFilter orApply(ContentFilter other) {}

  }

/**
 

Re: Formatted text field API (RT-14000, RT-30881)

2014-06-11 Thread Martin Sladecek
Binding the property would mean the text field can be edited (the field 
is still editable), but it's content cannot be committed (by either 
pressing ENTER or focusing out of the field), so it's content is 
practically irrelevant.
If you think there's a reasonable use case for this, there should be no 
problem with having writable value.


-Martin

On 11.6.2014 15:53, Scott Palmer wrote:

In FormattedTextField why is the value property returned as a
read-only property?
This control should allow bi-directional bindings to the value property.

Scott

On Wed, Jun 11, 2014 at 4:50 AM, Martin Sladecek
 wrote:

Hello,
I would like to start some discussion about formatted text field API. The
related JIRA issues are RT-14000 (formatted text field) and RT-30881
(content filter).

The RT-30881 defines a content filter for all text input controls (in
TextInputControl class), like TextField and TextArea. This was originally
implemented by Richard Bair and briefly discussed here:
http://mail.openjdk.java.net/pipermail/openjfx-dev/2012-December/004687.html.
I've tried to build formatted text field on top of that (and made some
changes to the API) since content filtering is something most formatted text
fields will use.

First, the TextInputControl additions:

* contentFilter property of type ObjectProperty

So let's look at the content filter and content change (both nested classes
of TextInputControl):

   /**
  * Content Filter specifies the filter to be used with {@link
TextInputControl#contentFilterProperty()}.
  * It allow user to intercept and modify any change done to the text
content.
  * To avoid content that's not valid for the filter, it's possible to
assign a default value supplier for the filter.
  * 
  * The filter itself is an {@code UnaryOperator} that accepts {@link
javafx.scene.control.TextInputControl.ContentChange} object.
  * It should return a {@link
javafx.scene.control.TextInputControl.ContentChange} object that contains
the actual (filtered)
  * change. Returning null rejects the change.
  * 
  * If default value supplier is provided, it is used when the {@code
ContentFilter} is assigned to a {@code TextInputControl}
  * and it's current text is invalid. It is expected that the provided
default value is accepted by the filtering operator.
  */
 public static class ContentFilter {

 /**
  * Creates a new filter with the providing filtering operator.
  * @param filter the filtering operator
  *
  * @throws java.lang.NullPointerException if filter is null
  */
 public ContentFilter(UnaryOperator filter) {}

 /**
  * Creates a new filter with the providing filtering operator and
default value supplier.
  * @param filter the filtering operator
  * @param defaultValue the default value or null
  *
  * @throws java.lang.NullPointerException if filter is null
  */
 public ContentFilter(UnaryOperator filter,
Supplier defaultValue) {}

 /**
  * The filtering operator of this filter.
  * @return the operator
  */
 public UnaryOperator getFilter() {}

 /**
  * The default value provider of this filter
  * @return the default value provider or null
  */
 public Supplier getDefaultValue() {}

 /**
  * Chains this filter with a filtering operator. The other filtering
operator is used only if this
  * filter's operator rejects the operation. The default value of the
new {@code ContentFilter} is the same
  * as of this filter.
  * @param other the filtering operator to chain
  * @return a new ContentFilter as described above
  */
 public ContentFilter orApply(UnaryOperator other) {}

 /**
  * Chains this filter with a filtering operator of another {@code
ContentFilter}. The other filtering operator is used only if this
  * filter's operator rejects the operation. The default value of the
new {@code ContentFilter} is the same
  * as of this filter.
  * @param other the filter to chain
  * @return a new ContentFilter as described above
  */
 public ContentFilter orApply(ContentFilter other) {}

 }

/**
  * Contains the state representing a change in the content for a
  * TextInputControl. This object is passed to any registered
  * {@code contentFilter} on the TextInputControl whenever the text
  * for the TextInputControl is modified.
  * 
  * This class contains state and convenience methods for determining
what
  * change occurred on the control. It also has a reference to the
  * TextInputControl itself so that the developer may query any other
  * state on the control. Note that you should never modify the state
  * of the control directly from within the contentFilter handler

Formatted text field API (RT-14000, RT-30881)

2014-06-11 Thread Martin Sladecek

Hello,
I would like to start some discussion about formatted text field API. 
The related JIRA issues are RT-14000 (formatted text field) and RT-30881 
(content filter).


The RT-30881 defines a content filter for all text input controls (in 
TextInputControl class), like TextField and TextArea. This was 
originally implemented by Richard Bair and briefly discussed here: 
http://mail.openjdk.java.net/pipermail/openjfx-dev/2012-December/004687.html. 
I've tried to build formatted text field on top of that (and made some 
changes to the API) since content filtering is something most formatted 
text fields will use.


First, the TextInputControl additions:

* contentFilter property of type ObjectProperty

So let's look at the content filter and content change (both nested 
classes of TextInputControl):


  /**
 * Content Filter specifies the filter to be used with {@link 
TextInputControl#contentFilterProperty()}.
 * It allow user to intercept and modify any change done to the 
text content.
 * To avoid content that's not valid for the filter, it's possible 
to assign a default value supplier for the filter.

 * 
 * The filter itself is an {@code UnaryOperator} that accepts 
{@link javafx.scene.control.TextInputControl.ContentChange} object.
 * It should return a {@link 
javafx.scene.control.TextInputControl.ContentChange} object that 
contains the actual (filtered)

 * change. Returning null rejects the change.
 * 
 * If default value supplier is provided, it is used when the 
{@code ContentFilter} is assigned to a {@code TextInputControl}
 * and it's current text is invalid. It is expected that the 
provided default value is accepted by the filtering operator.

 */
public static class ContentFilter {

/**
 * Creates a new filter with the providing filtering operator.
 * @param filter the filtering operator
 *
 * @throws java.lang.NullPointerException if filter is null
 */
public ContentFilter(UnaryOperator filter) {}

/**
 * Creates a new filter with the providing filtering operator 
and default value supplier.

 * @param filter the filtering operator
 * @param defaultValue the default value or null
 *
 * @throws java.lang.NullPointerException if filter is null
 */
public ContentFilter(UnaryOperator filter, 
Supplier defaultValue) {}


/**
 * The filtering operator of this filter.
 * @return the operator
 */
public UnaryOperator getFilter() {}

/**
 * The default value provider of this filter
 * @return the default value provider or null
 */
public Supplier getDefaultValue() {}

/**
 * Chains this filter with a filtering operator. The other 
filtering operator is used only if this
 * filter's operator rejects the operation. The default value 
of the new {@code ContentFilter} is the same

 * as of this filter.
 * @param other the filtering operator to chain
 * @return a new ContentFilter as described above
 */
public ContentFilter orApply(UnaryOperator other) {}

/**
 * Chains this filter with a filtering operator of another 
{@code ContentFilter}. The other filtering operator is used only if this
 * filter's operator rejects the operation. The default value 
of the new {@code ContentFilter} is the same

 * as of this filter.
 * @param other the filter to chain
 * @return a new ContentFilter as described above
 */
public ContentFilter orApply(ContentFilter other) {}

}

/**
 * Contains the state representing a change in the content for a
 * TextInputControl. This object is passed to any registered
 * {@code contentFilter} on the TextInputControl whenever the text
 * for the TextInputControl is modified.
 * 
 * This class contains state and convenience methods for 
determining what

 * change occurred on the control. It also has a reference to the
 * TextInputControl itself so that the developer may query any 
other
 * state on the control. Note that you should never modify the 
state

 * of the control directly from within the contentFilter handler.
 * 
 * 
 * The ContentChange is mutable, but not observable. It should 
be used

 * only for the life of a single change. It is intended that the
 * ContentChange will be modified from within the contentFilter.
 * 
 */
public static final class ContentChange implements Cloneable{

/**
 * Gets the control associated with this change.
 * @return The control associated with this change. This will 
never be null.

 */
public final TextInputControl getControl() {}

/**
 * Gets the start index into the {@link 
javafx.scene.control.TextInp