Design for mirroring keytyped events for a shared editor
Hi there,
Can anyone suggest a layout for an algorithm which will allow a shared editor to handle keytyped events and have that mirrored in the listening client?
So far the received packets get added to a JEditorPane by a setText() call, but this is useless as it overwrites anything in the JEditorPane.. As every KeyTyped event is fired the packet gets sent to another client that needs to append them to the JEditorPane. But I also need to consider the Caret position, deleted text, tab and space (everything under the sun that could happen when someone is editing text in the JEditorPane).
Has anyone got any suggestions as to how to correctly tackle this problem..
Thanks : -)
Adrian
[724 byte] By [
ADBROWNa] at [2007-9-28 3:14:51]

Seems to me you shouldn't send the key events to the listener. You want to identify changes that are made to the underlying document and send those. So for example, if you insert the character "a" at position 178, you send a message to the listener containing that information, so that the listener can do the same to its document.
It may be possible but I still wouldn't do it that way. Mainly because key events aren't sufficient to synchronize two documents. It's possible to change a document without a keyevent occurring -- for example if you press Ctrl-V on many computers, it will paste the contents of the clipboard into the document. I don't know if you get a key event in this case, but even if you do it doesn't tell you enough to synchronize the remote document properly.