You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by JohnRodey <ti...@yahoo.com> on 2010/06/01 17:29:13 UTC

Re: Adding font properties to a TextArea

Hey Greg,  I'm starting to look into adding this functionality again.  I am
planning on attempting to add a decorator to my text area that will
highlight text occurrances of words that were entered in a "find" text input
box.

Do you have any suggestions were to start?  From the examples provided, it
looks like they all decorate a component, but don't change depending on the
components value.  I can get the text from the text area and see if the
entered string matches anything, but how do I correlate that to how to draw
the highlight box?  The text area can be scrollable and resizable too, which
I assume won't be a problem, I just wanted to mention that.

Thanks
-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Adding-font-properties-to-a-TextArea-tp444141p861890.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Adding font properties to a TextArea

Posted by JohnRodey <ti...@yahoo.com>.
You're right Greg, I was doing my logic in the update method, so my text
highlighting was on top of my text, and since its not transparent it was
blocking the text.  To get around that I just decorated an ImageView that
was under my TextArea.  But I tried moving my logic to the prepare method
and it worked great so now my highlighter decorates the TextArea directly.

Thanks!
-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Adding-font-properties-to-a-TextArea-tp444141p867650.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Adding font properties to a TextArea

Posted by Greg Brown <gk...@mac.com>.
> That worked great!  I used the fillRect() method to draw the rectangle on an
> ImageView behind my TextArea.  If the end character was of a different y
> value than the start character I just don't highlight it, which is no
> problem since I only support highlighting single words.

Glad it worked. Just curious - why you are drawing on an ImageView? Could you simply attach a decorator to the TextArea itself and call fillRect() in the prepare() method?

> One other question, if I have a tabpane and click between tabs the focus
> goes to the first component.  Say I want to switch focus to a different
> component by default, is the only way to change that behavior by using a
> tabpaneselectionlistener?

That's one option. You could also listen for visibility changes on the tab component itself, or you could attach a custom focus traversal policy to the tab component (assuming it is a container; I'd probably start with this option and fall back to one of the others if it doesn't work for some reason):

  http://pivot.apache.org/1.4/docs/api/org/apache/pivot/wtk/FocusTraversalPolicy.html

You might be able to extend ContainerSkin.IndexFocusTraversalPolicy and override the getNextComponent() method. When the component argument is null and direction is FORWARD, you could return your custom first component.

G


Re: Adding font properties to a TextArea

Posted by JohnRodey <ti...@yahoo.com>.
That worked great!  I used the fillRect() method to draw the rectangle on an
ImageView behind my TextArea.  If the end character was of a different y
value than the start character I just don't highlight it, which is no
problem since I only support highlighting single words.

One other question, if I have a tabpane and click between tabs the focus
goes to the first component.  Say I want to switch focus to a different
component by default, is the only way to change that behavior by using a
tabpaneselectionlistener?
-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Adding-font-properties-to-a-TextArea-tp444141p865855.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Adding font properties to a TextArea

Posted by Greg Brown <gk...@mac.com>.
This may not actually be that tough. TextArea currently provides a getCharacterBounds() method - you can determine the bounding area of the range you want to highlight by calling this method for the first and last character in the range. Note that the highlight shape may not always be a rectangle - when text wraps, your highlighted area may span multiple lines. However, handling this condition is also not terribly difficult.


On Jun 1, 2010, at 4:27 PM, Noel Grandin wrote:

> Hi Rodney
> 
> I think you're better off waiting until we implement RichTextArea
> support in the next version of Pivot, then you will be able to set
> styles on sections of the text.
> Calculating the location and size of the text is quite a complex job,
> not something you can easily do from outside the component.
> 
> If you want this really desperately, you could download the source and
> patch it with the necessary support yourself.
> Have a look at
> https://issues.apache.org/jira/browse/PIVOT-31
> 
> Regards, Noel
> 
> On Tue, Jun 1, 2010 at 17:29, JohnRodey <ti...@yahoo.com> wrote:
>> 
>> Hey Greg,  I'm starting to look into adding this functionality again.  I am
>> planning on attempting to add a decorator to my text area that will
>> highlight text occurrances of words that were entered in a "find" text input
>> box.
>> 
>> Do you have any suggestions were to start?  From the examples provided, it
>> looks like they all decorate a component, but don't change depending on the
>> components value.  I can get the text from the text area and see if the
>> entered string matches anything, but how do I correlate that to how to draw
>> the highlight box?  The text area can be scrollable and resizable too, which
>> I assume won't be a problem, I just wanted to mention that.
>> 
>> Thanks
>> --
>> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Adding-font-properties-to-a-TextArea-tp444141p861890.html
>> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
>> 


Re: Adding font properties to a TextArea

Posted by Noel Grandin <no...@gmail.com>.
Hi Rodney

I think you're better off waiting until we implement RichTextArea
support in the next version of Pivot, then you will be able to set
styles on sections of the text.
Calculating the location and size of the text is quite a complex job,
not something you can easily do from outside the component.

If you want this really desperately, you could download the source and
patch it with the necessary support yourself.
Have a look at
https://issues.apache.org/jira/browse/PIVOT-31

Regards, Noel

On Tue, Jun 1, 2010 at 17:29, JohnRodey <ti...@yahoo.com> wrote:
>
> Hey Greg,  I'm starting to look into adding this functionality again.  I am
> planning on attempting to add a decorator to my text area that will
> highlight text occurrances of words that were entered in a "find" text input
> box.
>
> Do you have any suggestions were to start?  From the examples provided, it
> looks like they all decorate a component, but don't change depending on the
> components value.  I can get the text from the text area and see if the
> entered string matches anything, but how do I correlate that to how to draw
> the highlight box?  The text area can be scrollable and resizable too, which
> I assume won't be a problem, I just wanted to mention that.
>
> Thanks
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Adding-font-properties-to-a-TextArea-tp444141p861890.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
>