You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by aappddeevv <aa...@verizon.net> on 2010/06/27 14:25:36 UTC

binding adapter to automatically transport styles between components?

I seem to write a lot of code to databinding styles between components and
when I looked at the pivot library there was a lot style copying especially
where simple conditional logic was involved e.g. enabled/disabled.

 

Is there a component in the library that automatically binds the styles
between 2 different components and can handle simple conditional logic?


RE: binding adapter to automatically transport styles between components?

Posted by aappddeevv <aa...@verizon.net>.
I need to run it down. I may have been mistaken due to my error. The code is
there to do it of course.

 

 

 

From: Greg Brown [mailto:gkbrown@mac.com] 
Sent: Monday, June 28, 2010 5:46 PM
To: user@pivot.apache.org
Subject: Re: binding adapter to automatically transport styles between
components?

 

It looks like some skins do not bind to the styles from the component so if
the component has setStyles called, the skin is not consistently updated.

 

That doesn't sound right. Can you provide an example?

 


RE: binding adapter to automatically transport styles between components?

Posted by aappddeevv <aa...@verizon.net>.
I need to run it down. I may have been mistaken due to my error. The code is
there to do it of course.

 

 

 

From: Greg Brown [mailto:gkbrown@mac.com] 
Sent: Monday, June 28, 2010 5:46 PM
To: user@pivot.apache.org
Subject: Re: binding adapter to automatically transport styles between
components?

 

It looks like some skins do not bind to the styles from the component so if
the component has setStyles called, the skin is not consistently updated.

 

That doesn't sound right. Can you provide an example?

 


Re: binding adapter to automatically transport styles between components?

Posted by Greg Brown <gk...@mac.com>.
> It looks like some skins do not bind to the styles from the component so if the component has setStyles called, the skin is not consistently updated.

That doesn't sound right. Can you provide an example?


RE: binding adapter to automatically transport styles between components?

Posted by aappddeevv <aa...@verizon.net>.
Implemented the style binding and the annotation. I have attached the
individual style binding object. It looks like some skins do not bind to the
styles from the component so if the component has setStyles called, the skin
is not consistently updated. Is this the intended behavior? If not, perhaps
we should flip this email over to the dev list. You can always override
styleUpdated in a skin but this will work on any including renderers so it's
a convenience.

 

 

 

 

 

From: aappddeevv [mailto:aappddeevv@verizon.net] 
Sent: Sunday, June 27, 2010 11:51 PM
To: user@pivot.apache.org
Subject: RE: binding adapter to automatically transport styles between
components?

 

I fiddled with this using an ITD.  It works as described below for
conditional styles, however, it looks like skins keep style information in
java instance variables and exposes them through java properties and
setters. 

 

In order to make default/baseline styles work transparently, so they never
have to be set explicitly, the Skin class would need to expose a method like
String getStyles() that returns a JSON string of the styles relevant to the
skin and therefore settable.  This would remove the need to set the base
style directly because the "default baseline" could be obtained from the
skin directly. I don't think you can robustly infer the styles from java
property getters since there would be other getters that are not styles.
Hence, an ITD would have to be written for every skin which is too much
work.  Style properties that are settable could be annotated with a new
@PivotStyle annotation to make the class/instance scanable. This comment
probably applies to renderers as well.

 

I'll work on a style binding API to see what it might look like using the
number rule as a typical use case.

 

I think the pivot style annotation would be a good general purpose addition
to pivot. It could also help with tooling so perhaps that's the key output
of this.

 

 

From: aappddeevv [mailto:aappddeevv@verizon.net] 
Sent: Sunday, June 27, 2010 8:49 PM
To: user@pivot.apache.org
Subject: RE: binding adapter to automatically transport styles between
components?

 

My number ruler is a good use case although tiny. It needs to match the
background and font of the "ruled" component. When the ruled component
changes, the numbers ruler needs to change its font and background color. In
this case, the binding occurs between a component and a skin. But the same
idea applies across a component and a renderer or skin and renderer, etc. at
least based on the code that I saw.

 

Void bindStyle(Component source, String style, BeanAdapter target)

 

That's not quite right but its something like that and I am not sure what
class that would live in at all or just a separate object on its own. I can
setup a BeanAdapter target. It would be good for the BeanAdapter to have a
setBean(newObjectWithSameClass) and a BeanAdapter(Class<?> type) so you can
change the target object out. This is a lot like jgoodies value models but I
don't think pivot needs to be value-model based.

 

As for the simple conditional logic, something like:

 

Class Component  . {

  Void setConditionalStyle(String jsonCriteriaString, String
styleToUseWhenCriteriaIsMet);

Void setBaseStyle(String
styleToUseByDefaultOrAsABaseToApplyConditionalStyleOnTopOf);

}

 

So you can call setConditionalStyle("{enabled:true,hover:true}",
"{backgroundColor:'#ff0000',color:'#00ff00'}") and
setBaseStyle("{backgroundColor:'#0000ff'}").

 

The base style is applied when no criteria is met, when a criteria is met,
the base style is applied then the criteria-triggered style. Anything that
can be expressed as a number, Boolean or string could be a trigger since
json makes this easy.in fact I really, really like json syntax when used
this way and its easier to specify than wpf. Trigger styles could conflict
on triggering but there's never a good answer for settling a tie, just pick
the first.

 

This is a mix between jgoodies, wpf and pivot but focused on styles ala the
pivot way. I could probably work up an ITD to show how this could work. You
will need to flatten the property changes in the component class so
triggering is easier.right now they are buried in multiple listener classes.
But other than this, pivot has all the machinery it needs to make this easy
to create.

 

 

From: Greg Brown [mailto:gkbrown@mac.com] 
Sent: Sunday, June 27, 2010 9:06 AM
To: user@pivot.apache.org
Subject: Re: binding adapter to automatically transport styles between
components?

 

I don't think so, but can you describe the use case in a little more detail?
e.g. given components A and B, what might code that uses such a class look
like? Is there a comparable feature in another framework that we could look
at as an example?

 

 

On Jun 27, 2010, at 8:25 AM, aappddeevv wrote:

 

I seem to write a lot of code to databinding styles between components and
when I looked at the pivot library there was a lot style copying especially
where simple conditional logic was involved e.g. enabled/disabled.

 

Is there a component in the library that automatically binds the styles
between 2 different components and can handle simple conditional logic?

 


RE: binding adapter to automatically transport styles between components?

Posted by aappddeevv <aa...@verizon.net>.
I fiddled with this using an ITD.  It works as described below for
conditional styles, however, it looks like skins keep style information in
java instance variables and exposes them through java properties and
setters. 

 

In order to make default/baseline styles work transparently, so they never
have to be set explicitly, the Skin class would need to expose a method like
String getStyles() that returns a JSON string of the styles relevant to the
skin and therefore settable.  This would remove the need to set the base
style directly because the "default baseline" could be obtained from the
skin directly. I don't think you can robustly infer the styles from java
property getters since there would be other getters that are not styles.
Hence, an ITD would have to be written for every skin which is too much
work.  Style properties that are settable could be annotated with a new
@PivotStyle annotation to make the class/instance scanable. This comment
probably applies to renderers as well.

 

I'll work on a style binding API to see what it might look like using the
number rule as a typical use case.

 

I think the pivot style annotation would be a good general purpose addition
to pivot. It could also help with tooling so perhaps that's the key output
of this.

 

 

From: aappddeevv [mailto:aappddeevv@verizon.net] 
Sent: Sunday, June 27, 2010 8:49 PM
To: user@pivot.apache.org
Subject: RE: binding adapter to automatically transport styles between
components?

 

My number ruler is a good use case although tiny. It needs to match the
background and font of the "ruled" component. When the ruled component
changes, the numbers ruler needs to change its font and background color. In
this case, the binding occurs between a component and a skin. But the same
idea applies across a component and a renderer or skin and renderer, etc. at
least based on the code that I saw.

 

Void bindStyle(Component source, String style, BeanAdapter target)

 

That's not quite right but its something like that and I am not sure what
class that would live in at all or just a separate object on its own. I can
setup a BeanAdapter target. It would be good for the BeanAdapter to have a
setBean(newObjectWithSameClass) and a BeanAdapter(Class<?> type) so you can
change the target object out. This is a lot like jgoodies value models but I
don't think pivot needs to be value-model based.

 

As for the simple conditional logic, something like:

 

Class Component  . {

  Void setConditionalStyle(String jsonCriteriaString, String
styleToUseWhenCriteriaIsMet);

Void setBaseStyle(String
styleToUseByDefaultOrAsABaseToApplyConditionalStyleOnTopOf);

}

 

So you can call setConditionalStyle("{enabled:true,hover:true}",
"{backgroundColor:'#ff0000',color:'#00ff00'}") and
setBaseStyle("{backgroundColor:'#0000ff'}").

 

The base style is applied when no criteria is met, when a criteria is met,
the base style is applied then the criteria-triggered style. Anything that
can be expressed as a number, Boolean or string could be a trigger since
json makes this easy.in fact I really, really like json syntax when used
this way and its easier to specify than wpf. Trigger styles could conflict
on triggering but there's never a good answer for settling a tie, just pick
the first.

 

This is a mix between jgoodies, wpf and pivot but focused on styles ala the
pivot way. I could probably work up an ITD to show how this could work. You
will need to flatten the property changes in the component class so
triggering is easier.right now they are buried in multiple listener classes.
But other than this, pivot has all the machinery it needs to make this easy
to create.

 

 

From: Greg Brown [mailto:gkbrown@mac.com] 
Sent: Sunday, June 27, 2010 9:06 AM
To: user@pivot.apache.org
Subject: Re: binding adapter to automatically transport styles between
components?

 

I don't think so, but can you describe the use case in a little more detail?
e.g. given components A and B, what might code that uses such a class look
like? Is there a comparable feature in another framework that we could look
at as an example?

 

 

On Jun 27, 2010, at 8:25 AM, aappddeevv wrote:

 

I seem to write a lot of code to databinding styles between components and
when I looked at the pivot library there was a lot style copying especially
where simple conditional logic was involved e.g. enabled/disabled.

 

Is there a component in the library that automatically binds the styles
between 2 different components and can handle simple conditional logic?

 


RE: binding adapter to automatically transport styles between components?

Posted by aappddeevv <aa...@verizon.net>.
My number ruler is a good use case although tiny. It needs to match the
background and font of the "ruled" component. When the ruled component
changes, the numbers ruler needs to change its font and background color. In
this case, the binding occurs between a component and a skin. But the same
idea applies across a component and a renderer or skin and renderer, etc. at
least based on the code that I saw.

 

Void bindStyle(Component source, String style, BeanAdapter target)

 

That's not quite right but its something like that and I am not sure what
class that would live in at all or just a separate object on its own. I can
setup a BeanAdapter target. It would be good for the BeanAdapter to have a
setBean(newObjectWithSameClass) and a BeanAdapter(Class<?> type) so you can
change the target object out. This is a lot like jgoodies value models but I
don't think pivot needs to be value-model based.

 

As for the simple conditional logic, something like:

 

Class Component  . {



  Void setConditionalStyle(String jsonCriteriaString, String
styleToUseWhenCriteriaIsMet);

Void setBaseStyle(String
styleToUseByDefaultOrAsABaseToApplyConditionalStyleOnTopOf);

}

 

So you can call setConditionalStyle("{enabled:true,hover:true}",
"{backgroundColor:'#ff0000',color:'#00ff00'}") and
setBaseStyle("{backgroundColor:'#0000ff'}").

 

The base style is applied when no criteria is met, when a criteria is met,
the base style is applied then the criteria-triggered style. Anything that
can be expressed as a number, Boolean or string could be a trigger since
json makes this easy.in fact I really, really like json syntax when used
this way and its easier to specify than wpf. Trigger styles could conflict
on triggering but there's never a good answer for settling a tie, just pick
the first.

 

This is a mix between jgoodies, wpf and pivot but focused on styles ala the
pivot way. I could probably work up an ITD to show how this could work. You
will need to flatten the property changes in the component class so
triggering is easier.right now they are buried in multiple listener classes.
But other than this, pivot has all the machinery it needs to make this easy
to create.

 

 

From: Greg Brown [mailto:gkbrown@mac.com] 
Sent: Sunday, June 27, 2010 9:06 AM
To: user@pivot.apache.org
Subject: Re: binding adapter to automatically transport styles between
components?

 

I don't think so, but can you describe the use case in a little more detail?
e.g. given components A and B, what might code that uses such a class look
like? Is there a comparable feature in another framework that we could look
at as an example?

 

 

On Jun 27, 2010, at 8:25 AM, aappddeevv wrote:





I seem to write a lot of code to databinding styles between components and
when I looked at the pivot library there was a lot style copying especially
where simple conditional logic was involved e.g. enabled/disabled.

 

Is there a component in the library that automatically binds the styles
between 2 different components and can handle simple conditional logic?

 


Re: binding adapter to automatically transport styles between components?

Posted by Greg Brown <gk...@mac.com>.
I don't think so, but can you describe the use case in a little more detail? e.g. given components A and B, what might code that uses such a class look like? Is there a comparable feature in another framework that we could look at as an example?


On Jun 27, 2010, at 8:25 AM, aappddeevv wrote:

> I seem to write a lot of code to databinding styles between components and when I looked at the pivot library there was a lot style copying especially where simple conditional logic was involved e.g. enabled/disabled.
>  
> Is there a component in the library that automatically binds the styles between 2 different components and can handle simple conditional logic?