We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProcessing DevelopmentLibraries,  Tool Development › Textfield for Processing
Page Index Toggle Pages: 1
Textfield for Processing (Read 2414 times)
Textfield for Processing
Jun 14th, 2007, 10:00am
 
Hi all,

I just wanted to share with everyone what I've been working on: a full-featured re-implementation of a text input box for Processing. I'm trying to recreate the standard text box functionality (keyboard movement, mouse control, cut-copy-paste, etc. etc.) using Processing, drawing the text to an offscreen Java2D buffer and then copying it back into the main stage (this can be a Java2D or P3D stage) as necessary. I would greatly appreciate any feedback or bug reports -- once I clean up and optimize the code, I'd like to release it as a library for Processing.

Check out the demo here (you will need to accept a security warning, as it accesses the system clipboard for cut/paste):

http://pantheon.yale.edu/~gej5/SoC/week-2-phylowidget/

Some other random notes about this implementation:
 - Even if you transform the stage using rotate(), scale(), or translate() functions, the text field still captures the correct mouse movement.
 - I also created a very simple FocusManager object, which is designed to make sure only one text box has focus if a bunch of them are on screen.
 - I'm currently using the Graphics2D object's AffineTransform to get the model coordinates for a given MouseEvent... seems that there is no equivalent to modelX/Y/Z() for the 2D stuff.

Cheers,
 greg
Re: Textfield for Processing
Reply #1 - Jul 6th, 2007, 3:49am
 
Greg -

Pretty sweet, been playing around with the text box.  I really like that it gets the clipboard stuff, that makes it feel less like a Java applet and more like a real program!

A few things for the next version:

1) For some reason, key repeat doesn't seem to be working, though it doesn't look like you're blocking it, so something must be happening higher up the chain that's keeping the events from being sent properly to the textbox class.  Probably a simple fix once located.

2) There are a few OSX issues, such as meta+V not pasting (ctrl+v still works, but is a bit foreign on the Mac), and pressing the meta key alone scrolls the box in an odd way.  I forget off the top of my head how the meta key shows up as a key event, but therein lies the solution...also, on OSX, meta+right goes to the end of the line and meta+left goes to the start, and alt (a.k.a. "option") + left/right jump by words.  Lacking home/end keys, some people become quite addicted to these shortcuts, so they might be useful to add.

3) In native text boxes, a double click often selects the nearest word, and a triple one would select the whole box - I find this very useful, it could be good to add if you're going for a solid feel.  Once the whole box is selected, further clicks do nothing until a time delay has passed with no clicks (i.e. new clicks reset the timer), at which point another click simply places the cursor at the location as usual, clearing the selection.

4) Very slight bug - when you start selecting text, if you then drag all the way to the beginning of the line, it often highlights the first two characters as a single unit instead of separate characters (i.e. there's no way to select all but the first character starting from the right).  Minor, but probably not too tough to fix.

Good stuff, I'll definitely be using this class once you're done tinkering with it.

-Eric
Re: Textfield for Processing
Reply #2 - Jul 6th, 2007, 3:17pm
 
Very nice indeed. A little slow to load on my machine but it seems to work very well. This is something I need for a project now so I would be glad to help in helping with development in any way possible---I'll post any bugs I find here. I'm also in need of an editable drop-down menu, which I think could use this component as a base.
Re: Textfield for Processing
Reply #3 - Jul 10th, 2007, 9:31pm
 
Figured out one thing about the meta key here - something is actually being inserted as a character into the string, though in this font it's not showing up as a character.  Probably just need to catch this key separately.
Re: Textfield for Processing
Reply #4 - Jul 10th, 2007, 10:07pm
 
the way to deal with it is to use Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() and then test for that. also, use keyTyped() rather than keyPressed() events, because keyPressed() events will fire events for each key (including alt, cmd, etc) but keyTyped will fire for the compound of key events (i.e. alt-n or cmd-q or whatever). (this is behavior inherited from java)
Re: Textfield for Processing
Reply #5 - Jul 13th, 2007, 9:20am
 
This is starting to go severely off topic, but speaking of the difference between keyPressed() and keyTyped(), I notice that both of them fire repeated events when you hold a key, whereas I would usually think that keyPressed() should only be called on the initial keypress.  Is this a bug, or is it actually the desired behavior?  It's easy enough to just set up an input wrapper that filters out the repeats, but it always seemed a little bit odd to me the way it works currently.
Re: Textfield for Processing
Reply #6 - Jul 13th, 2007, 1:38pm
 
it's all a bit odd, but it's what's inherited from the jvm. it's complex enough that it doesn't make sense for us to rewrite it.. so if it's a bug it's sun's bug (or a bug specific to the jvm you're using).
Page Index Toggle Pages: 1