pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Bartlett <cbartlet...@gmail.com>
Subject Re: Intelligent stripping of whitespace in bxml?
Date Thu, 03 Mar 2011 10:25:34 GMT
Bill,

Perhaps extending Pivot's  org.apache.pivot.util.Resources class will meet
your needs?

See this tutorial section on Localization.
http://pivot.apache.org/tutorials/localization.html

If you put your text into a Pivot style JSON resource bundle and supply that
bundle to BXMLSerializer as shown in the example, it will resolve the
resource keys to values.

You should be able to create your own subclass of
org.apache.pivot.util.Resources, and override the get(String) method to do
some pre-processing on the String before it is returned.
This might be a simple regexp to compress 2 or more adjacent spaces into a
single space, or go further and also convert some custom string/token into
new lines.

A little more info is available here
http://pivot.apache.org/tutorials/bxml-primer.html

Chris


On 3 March 2011 08:51, Bill van Melle <bill.van.melle@gmail.com> wrote:

> Is there any mechanism for distinguishing significant and insignificant
> whitespace inside a bxml element?  I'm thinking in particular of the case
> where I want to put a whole paragraph of text (or even more) inside a Label.
>  BXML lets you do this:
>
> <Label ...>
>    <text>whatever</text>
> </Label>
>
> but if it's a whole lot more text than that...
>
> <Label ...>
>    <text>
>       ...It would be nice if one could put multiple lines of
>       text into a single text element for the sake of readability,
>       but still have it interpreted as a single line of text for
>       the Label control to wrap at whatever the width of the
>       Label component turns out to be.
>    </text>
> </Label>
>
> If I do (the equivalent of) this in WPF, the parser helpfully turns all
> those runs of whitespace into single spaces, and trims the front and back.
>  To have the whitespace interpreted literally, there's some crud you can add
> to the parent element.  There's also an inline element <LineBreak/> for
> explicit newlines.
>
> Is there anything of the sort in the BXML parser?  Without thinking about
> it, I wrote some bxml like the above, and it almost fooled me.  If I look at
> the label text in the debugger, I can see that it consumed the file
> literally, so there are stretches of whitespace including newlines, but the
> Label component doesn't handle it literally.  Unfortunately, it also doesn't
> handle it quite the way I want, and how it does handle it seems to be
> platform-dependent.  On XP, the leading whitespace goes away, and the
> stretches of newline + spaces turn into zero(!) spaces.  On the mac, it
> looks like the newlines are discarded and all the spaces are kept, resulting
> in some big white gaps in the resulting text.
>
> Or am I forced to put all my text into a single line?  In which case I
> might as well have written it as
>
> <Label ... text="...long string of text..." />
>

Mime
View raw message