You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Bill van Melle <bi...@gmail.com> on 2011/01/20 03:16:47 UTC

Support for display of rich text?

I want to be able to display text runs with bold/italic, font changes, etc.
 The tutorial overview says "TextArea - A component for viewing or entering
multiple lines of (optionally formatted) text.", but the javadoc says "A
component that allows a user to enter multiple lines of *unformatted *text."
 There are a bunch of classes rooted at org.apache.pivot.wtk.text.Node that
seem to be intended for showing rich text, but no documentation other than
the scanty javadoc.  Do any of them work?  Are there examples anywhere?

Re: Support for display of rich text?

Posted by Greg Brown <gk...@verizon.net>.
> anyway, this doesn't work:
> 
>   <TextNode>Some text</TextNode>
> 
> but this does:
> 
>   <TextNode text="Some text"/>

Ah, of course. BXMLSerializer needs a minor modification to allow inline text to work for TextNode.

> So a working example of what I wanted might be
> 
>   <Paragraph>
>     <Span font="{bold:true}">
>       <TextNode text="Label:"/>
>     </Span>
>     <TextNode text=" something of interest "/>
>     <Span font="{italic:true}">
>       <TextNode text="(some remark)"/>
>     </Span>
>   </Paragraph>
> 
> It would be very nice if whatever magic on Paragraph allows
> 
>   <Paragraph>This is a plain text paragraph</Paragraph>
> 
> would allow my example to be expressed as
> 
>   <Paragraph>
>     <Span font="{bold:true}">Label:</Span>
>     <Span> something of interest </Span>
>     <Span font="{italic:true}">(some remark)</Span>
>   </Paragraph>

I just checked in a minor update to Span. If you build from trunk, let me know if it works.

G


Re: Support for display of rich text?

Posted by Bill van Melle <bi...@gmail.com>.
Belated thanks for the bxml fix.  I updated to the latest trunk, and it
seems to do what I want.  However, since for the moment I need to stick with
the official release, I'll put up with the klunky syntax for a while.

I've filed https://issues.apache.org/jira/browse/PIVOT-715 on the splotchy
background issue.

Re: Support for display of rich text?

Posted by Greg Brown <gk...@verizon.net>.
Yes, that is why it is currently considered "experimental".  ;-)

On Jan 25, 2011, at 9:49 PM, Bill van Melle wrote:

> Having said all that, something rather buggy occurs if you set a background color.  Try running this:
> 
> <Window maximized="true"
>     xmlns:bxml="http://pivot.apache.org/bxml" 
>     xmlns="org.apache.pivot.wtk">
> 	<TextPane>
> 		<Document xmlns="org.apache.pivot.wtk.text" bxml:id="docMain">
> 			<Paragraph backgroundColor="yellow">
> 				<Span font="{bold:true}">
> 					<TextNode text="Label:" />
> 				</Span>
> 				<TextNode text=" something of interest " />
> 				<Span font="{italic:true}">
> 					<TextNode text="(some remark)" />
> 				</Span>
> 			</Paragraph>
> 		</Document>
> 	</TextPane>
> </Window>
> 
> When I run it, I get three disconnected splotches of yellow, the third of which only repaints itself when the second one does.  So yes, I guess the support is a little buggy :-).


Re: Support for display of rich text?

Posted by Bill van Melle <bi...@gmail.com>.
Having said all that, something rather buggy occurs if you set a background
color.  Try running this:

<Window maximized="true"
    xmlns:bxml="http://pivot.apache.org/bxml"
    xmlns="org.apache.pivot.wtk">
<TextPane>
<Document xmlns="org.apache.pivot.wtk.text" bxml:id="docMain">
<Paragraph backgroundColor="yellow">
<Span font="{bold:true}">
<TextNode text="Label:" />
</Span>
<TextNode text=" something of interest " />
<Span font="{italic:true}">
<TextNode text="(some remark)" />
</Span>
</Paragraph>
</Document>
</TextPane>
</Window>

When I run it, I get three disconnected splotches of yellow, the third of
which only repaints itself when the second one does.  So yes, I guess the
support is a little buggy :-).

Re: Support for display of rich text?

Posted by Bill van Melle <bi...@gmail.com>.
(oops, send button pressed itself prematurely)

anyway, this doesn't work:

  <TextNode>Some text</TextNode>

but this does:

  <TextNode text="Some text"/>

So a working example of what I wanted might be

  <Paragraph>
    <Span font="{bold:true}">
      <TextNode text="Label:"/>
    </Span>
    <TextNode text=" something of interest "/>
    <Span font="{italic:true}">
      <TextNode text="(some remark)"/>
    </Span>
  </Paragraph>

It would be very nice if whatever magic on Paragraph allows

  <Paragraph>This is a plain text paragraph</Paragraph>

would allow my example to be expressed as

  <Paragraph>
    <Span font="{bold:true}">Label:</Span>
    <Span> something of interest </Span>
    <Span font="{italic:true}">(some remark)</Span>
  </Paragraph>

Re: Support for display of rich text?

Posted by Bill van Melle <bi...@gmail.com>.
Thanks for the namespace and font spec tips.  After considerably more
fooling around, I realized that TextNode doesn't take text inline, the way
Paragraph does, but it doesn't complain if you try.  So this doesn't work:

<TextNode>Some text</TextNode>

Re: Support for display of rich text?

Posted by Greg Brown <gk...@verizon.net>.
>   <TextPane>
>     <t:Document>
>       <t:Paragraph>
>         <t:Span font="BOLD">
>           <t:TextNode>Capacity:</t:TextNode>
>         </t:Span>
>         <t:TextNode>something</t:TextNode>
>       </t:Paragraph>
>     </t:Document>
>   </TextPane>

I didn't implement support for styled text, but you should be able to do something along these lines. For the value of the "font" attribute, try "{bold:true}". That will apply the bold style to the current theme font. If you want to be more specific, you can also specify a name and size property, or you can use the format defined by java.awt.Font.decode().

FWIW, you could simplify your markup by declaring your Document node as follows:

<Document xmlns="org.apache.pivot.wtk.text">

That way, you don't need to include the "t" prefix on each sub-element.

G



Re: Support for display of rich text?

Posted by Bill van Melle <bi...@gmail.com>.
Thanks.  The demo works, and I can see there's a lot of capability here, but
I'm finding the text model kind of impenetrable.  To simply display rich
text, I need a TextPane, inside of which is a Document, inside of which are
Nodes.  One kind of Node is a Paragraph.  I see from the demo that I can put
plain text into a Paragraph.  How do I put styled text into it?

For example, in WPF I can do this:

  <TextBlock TextWrapping="Wrap">
    <Run FontWeight="Bold">Capacity:</Run>
    <Run>24 tons</Run>
    <Run FontStyle="Italic">(unloaded)</Run>
  </TextBlock>

What's the corresponding thing in BXML?  Seems like I have to do something
with Span objects, but it's very unclear what. I tried doing things like
this (where t: is the text package prefix):

  <TextPane>
    <t:Document>
      <t:Paragraph>
        <t:Span font="BOLD">
          <t:TextNode>Capacity:</t:TextNode>
        </t:Span>
        <t:TextNode>something</t:TextNode>
      </t:Paragraph>
    </t:Document>
  </TextPane>

but nothing at all displayed.

Or how would I do it programmatically?

Re: Support for display of rich text?

Posted by Chris Bartlett <cb...@gmail.com>.
Bill,

There was a major reworking of TextArea for Pivot 2.0.
Some info is listed on the wiki here.

https://cwiki.apache.org/PIVOT/major-feature-changes-between-15x-and-20.html
PIVOT-555 Re-implement TextArea
PIVOT-31 Add rich text support to TextPane (formerly TextArea)

There is a demo application for TextPane in the demos project which is
included in the Pivot 2,0 source download, or directly from SVN
http://pivot.apache.org/download.cgi#2.0
http://svn.apache.org/repos/asf/pivot/tags/v2.0/demos/src/org/apache/pivot/demos/text/

As mentioned on the wiki, TextPane is relatively new and untested.  We would
welcome JIRA tickets for any bugs/improvements you may find, or better yet,
patches addressing them!

Chris

On 20 January 2011 09:16, Bill van Melle <bi...@gmail.com> wrote:

> I want to be able to display text runs with bold/italic, font changes, etc.
>  The tutorial overview says "TextArea - A component for viewing or entering
> multiple lines of (optionally formatted) text.", but the javadoc says "A
> component that allows a user to enter multiple lines of *unformatted *text."
>  There are a bunch of classes rooted at org.apache.pivot.wtk.text.Node that
> seem to be intended for showing rich text, but no documentation other than
> the scanty javadoc.  Do any of them work?  Are there examples anywhere?