Re: Programmatically Generating Physical Key
Hi Anurag, Thanks for clearing up your use case. I think Reinier guessed it right the first time. What you'll need to do to implement that kind of functionality is as he suggested, using a violator pattern to access the list of keyboard listeners and then firing onKeyPress for each of them. You can inspire yourself from the example below, used to access the private StackPanel.setStackVisible() method and visibleStack field through JSNI: private native void violate(StackPanel stackPanel) /*-{ stackpan...@com.google.gwt.user.client.ui.stackpanel ::setStackVisible(IZ)(stackpan...@com.google.gwt.user.client.ui.stackpanel::visibleStack, false); stackpan...@com.google.gwt.user.client.ui.stackpanel::visibleStack = -1; }-*/; You would essentially do something similar, except to access the keyboard listener collection instead. It seems like it might be generally useful to create RichTextArea buttons that could issue key combinations for these kind of rich text operations. If this sounds reasonable to you, feel free to add it to the Issue Tracker so that others can track and star it based on interest. Issue Tracker: http://code.google.com/p/google-web-toolkit/issues/list Hope that helps, -Sumit Chandel On Wed, Jan 7, 2009 at 10:58 PM, Anurag Tripathi anurag...@gmail.comwrote: Thanks Sumit for getting back on this ! My scenario is something like this - On pressing Ctrl+z/Ctrl+y, browser performs Undo/Redo in RichTextArea, I want to support this functionality in Buttons, So my intention was rather than capturing onBrowserEvents(EventPreviews) just generate ctrl +z/ctrl+y programmatically on clicking on buttons and let them browser to handle. This will remove javascript quirks too. And I didn't find any undo/redo implemenations in RichTextArea. _Anurag On Jan 7, 1:11 pm, Reinier Zwitserloot reini...@gmail.com wrote: I assume you meant faking the pressing of a key on the keyboard. You can't do that directly, no, but you can sort-of call the keylisteners on any particular object. For example, let's say you have a TextBox instance called 'textBox', and you want to simulate pressing the 'X' button. You'll need to do two things: 1) Simulate the effect of the X button on the textBox itself, which means updating the text inside by inserting an X at the current cursor position. 2) Call all keyboardlisteners on textBox. #2 can be done with some technically nonsupported hackery - each implementation of SourcesKeyboardEvents in GWT at least has an internal private object of type 'KeyboardListeners', called 'keyboardListeners'. While its private, you can still get at it via JSNI (look that up) which doesn't know about 'private' and thus allows it. Once you have the keyboardListeners, which is really just an ArrayList, you can loop through them and fire the appropriate call (e.g. onKeyPress) on all of them. The reason GWT doesn't support this directly is because javascript doesn't support it either. GWT isn't magic; it cannot make things that are impossible on the target platform possible. On Jan 2, 2:26 pm, Anurag Tripathi anurag...@gmail.com wrote: Can we programmatically generate physical keys in GWT ? Scenario : I want to generate some key on clicking in Button ! If anyone has any idea on this, please let me know - _Anurag --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: Programmatically Generating Physical Key
I assume you meant faking the pressing of a key on the keyboard. You can't do that directly, no, but you can sort-of call the keylisteners on any particular object. For example, let's say you have a TextBox instance called 'textBox', and you want to simulate pressing the 'X' button. You'll need to do two things: 1) Simulate the effect of the X button on the textBox itself, which means updating the text inside by inserting an X at the current cursor position. 2) Call all keyboardlisteners on textBox. #2 can be done with some technically nonsupported hackery - each implementation of SourcesKeyboardEvents in GWT at least has an internal private object of type 'KeyboardListeners', called 'keyboardListeners'. While its private, you can still get at it via JSNI (look that up) which doesn't know about 'private' and thus allows it. Once you have the keyboardListeners, which is really just an ArrayList, you can loop through them and fire the appropriate call (e.g. onKeyPress) on all of them. The reason GWT doesn't support this directly is because javascript doesn't support it either. GWT isn't magic; it cannot make things that are impossible on the target platform possible. On Jan 2, 2:26 pm, Anurag Tripathi anurag...@gmail.com wrote: Can we programmatically generate physical keys in GWT ? Scenario : I want to generate some key on clicking in Button ! If anyone has any idea on this, please let me know - _Anurag --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: Programmatically Generating Physical Key
Hi Anurag, What would this key be used for? It seems counter-intuitive to generate a key on the client-side, since typically keys are used in trust models, and most trust models begin with the server rather than the client. Could you elaborate a little more on what you would like to do? In terms of actually generating a key on the client, you could perform a web search for JavaScript key generation that would turn up useful results, and use a suitable key generating schema in GWT using JavaScript Native Interface methods. You might also find the emulated Random class useful if you intend on writing your key generation algorithm in GWT code. Random class: http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/Random.html Hope that helps, -Sumit Chandel On Fri, Jan 2, 2009 at 8:26 AM, Anurag Tripathi anurag...@gmail.com wrote: Can we programmatically generate physical keys in GWT ? Scenario : I want to generate some key on clicking in Button ! If anyone has any idea on this, please let me know - _Anurag --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Programmatically Generating Physical Key
Can we programmatically generate physical keys in GWT ? Scenario : I want to generate some key on clicking in Button ! If anyone has any idea on this, please let me know - _Anurag --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Google Web Toolkit group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---