Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / July 2007

Tip: Looking for answers? Try searching our database.

in-place editing of text on a canvas

Thread view: 
ravi.phor.U@gmail.com - 12 Jul 2007 12:55 GMT
Hi All,

We are working on a Whiteboard application. We have a feature where
text can be written on the canvas. Currently we popup up a dialog to
enter text to be written and then use a text area to display it on the
canvas.
We would like to have in-place text editing without moving to a
separate dialog. Can anyone give some pointers as to how it can be
achieved. We would also like to use rich text editing (using multiple
colors and fonts in the same text.) Any help is appreciated.

Thank you for reading
cheers

Ravi
Roedy Green - 12 Jul 2007 23:41 GMT
>We would like to have in-place text editing without moving to a
>separate dialog.

see http://mindprod.com/jgloss/event11.html

Basically you will have field keystroke events, and keep a map of
strings and where they should be painted.

Every time you get a paint request, you quickly find the strings that
overlap the clip region and render them with drawString.

A suitable structure might be an ArrayList sorted by y.  You can then
use binary search to rapidly find the first and last string to paint.

For each string, you have a reference to a Font object, a Color
object, and a text string.

Next you probably want commands to move, delete, edit etc. Basically
the key here is to field a mouse click event, then find the string in
your list closest to the click. The Hanging Moss algorithm
http://mindprod.com/jgloss/hangingmoss.html might be the way to fly if
you have a lot of strings.  If there are only a few, a linear search
should suffice.  It determining distance, you need only a rough
metric. e.g..
(abs (x1-x2) + abs( y1-y2)
or
(( x1-x2)*(x1-x2)+( y1-y2)*(y1-x2)

You might have a look at the code for JDisplay.  It uses lists of
Tokens (that give text, colour and font) and renders them. It does not
support on the fly editing, but it does support finding which strings
to render given the clipregion.  You could use that code unmodified to
do a write-only white-board. See
http://mindprod.com/products1.html#JDISPLAY

I think you will discover hundreds of people have written similar apps
before you, at least primitive ones.  Do some digging for open source.
Even Java In A Nutshell has a primitive example.
http://mindprod.com/jgloss/nutshell.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.