pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Bartlett <cbartlet...@gmail.com>
Subject Re: Why can't I set a TabPane's buttonPadding to a dictionary?
Date Wed, 19 Oct 2011 04:55:35 GMT
It is due to the different setters in the TabPane's skin.

The 'buttonPadding' style only has explicit setters for Insets and int
void setButtonPadding(Insets)
void setButtonPadding(int)

But 'padding' has setters for these.
void setPadding(Dictionary<String,?> padding)
void setPadding(Insets padding)
void setPadding(int padding)
void setPadding(Number padding)
void setPadding(String padding)

Off the top of my head, I think it is because BXMLSerializer handles
the parsing of the 'styles' attribute (via Pivot's JSONSerializer) and
produces a HashMap.  BXMLSerializer then tries to find a setter in
TerraTabPaneSkin that accepts a HashMap.

As you see above, 'padding' has a setter which a Dictionary argument,
but 'buttonPadding' doesn't, so it fails, but only after trying to
coerce the HashMap to an Inset.

This current process is simple and transparent, but means that if you
had a skin with 10 different style properties that controlled various
padding settings, each would need to have the same multiple setters in
order to maintain a level of consistency and flexibility for those

BXMLSerializer could perhaps go one step further in the coercion phase
and attempt to find a single parameter constructor on the
'destination' type which accepts the 'source' type?  (I haven't fully
thought through the implications of this, so it might not work or be
desirable behaviour.)  Then the multiple setters could be removed, and
the various constructors used instead.


On 19 October 2011 11:16, Bill van Melle <bill.van.melle@gmail.com> wrote:
> I must be missing something really obvious here.  TablePane happily
> accepts a padding value expressed as a dictionary.  So does Label.
> But when the bxml serializer gets down to the TabPane below where I
> try to set its buttonPadding to the same dictionary, it barfs, saying
> "Unable to coerce org.apache.pivot.collections.HashMap to class
> org.apache.pivot.wtk.Insets".  Aren't the padding values also of type
> Insets?  What am I doing wrong?
> <Window xmlns="org.apache.pivot.wtk">
>  <TablePane styles="{padding:{left:10,right:10,top:5,bottom:5}}">
>    <columns>
>      <TablePane.Column width="1*" />
>    </columns>
>    <TablePane.Row>
>      <Label text="Some text"
> styles="{padding:{left:10,right:10,top:5,bottom:5}}" />
>    </TablePane.Row>
>    <TablePane.Row>
>      <TabPane styles="{buttonPadding:{left:10,right:10,top:5,bottom:5}}" >
>        <BoxPane TabPane.tabData="Test" />
>      </TabPane>
>    </TablePane.Row>
>  </TablePane>
> </Window>

View raw message