PStyledText - any chance to find the document's character from mouse position?

12 views
Skip to first unread message

jles...@gmx.de

unread,
Feb 10, 2015, 2:40:54 PM2/10/15
to piccolo...@googlegroups.com
Hi Piccolos
I have a nasty question:
I use PStyledText to display structured text containing text portions which are supposed to work like "hyper links". I.e. if the user moves the mouse over particular text portions, the mouse pointer should be changed and the user can navigate to another screen by clicking the mouse. So somehow I have to figure out if the current mouse position (which I can get from a PInputEventHanler) correlates with the position of particular text portions in the PStyledText's underlying Document.

I haven't found any hints for that from the documentation or the source code and I know that this is complicated challenge. How ever, maybe you have some inspiring ideas.

Kind regards,
Jan
 

Michael Heuer

unread,
Feb 10, 2015, 2:47:42 PM2/10/15
to piccolo...@googlegroups.com
Hello Jan,

You may be able to find inspiration from the hyperlink handling code in PHtmlView, from here down

http://code.google.com/p/piccolo2d/source/browse/piccolo2d.java/trunk/core/src/main/java/org/piccolo2d/nodes/PHtmlView.java#334

but those rely on Swing JLabel and View which don't exactly translate to PStyledText.

Hope this helps,

   michael



--
You received this message because you are subscribed to the Google Groups "Piccolo2D Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to piccolo2d-use...@googlegroups.com.
To post to this group, send email to piccolo...@googlegroups.com.
Visit this group at http://groups.google.com/group/piccolo2d-users.
For more options, visit https://groups.google.com/d/optout.

jles...@gmx.de

unread,
Feb 10, 2015, 3:10:29 PM2/10/15
to piccolo...@googlegroups.com
Well, maybe. I just had a short look on that component, and as far as I can see it relies completely on Java's magic function viewToModel() in JTextComponent which does the whole job. But I will check if I can find some reusable code snippets in the Swing jungle ;-)

Thanks for the hint,
Jan

jles...@gmx.de

unread,
Feb 11, 2015, 5:20:30 AM2/11/15
to piccolo...@googlegroups.com
Michael,
I found a pretty nice solution - tricky but simple.
All my "hyperlinks" have a special dotted underlining. So based on my earlier patch consideration für PStyledText I can override drawUnderlineAndStrikethroughAfterText and keep the rectangles of text which have this underlining in a list. From the list index of the clicked rectancle I can easily determine the link text in the document.

Well, in fact it becomes a bit more complecated with link text which includes line breaks. But who needs things like that ;-)

Regards,
Jan

Reply all
Reply to author
Forward
0 new messages