Discern user and programatic updates on fields

Hi,

I'm playing a little with a little proof of concept MVC framework with Groovy and I've some doubts:

What is the best and less intrusive way to detect for example when a JFormattedTextField or TextField has changed by "program code" (listener on model for example) or by user actions (text editing...)?

For example for JFormattedTextField I can listen to the value property but then I don't know if it was modified by a listener on the model, or by user editing. And of course if it was for a listener on the model and I notify again the controller to update the model then I get a infinite cycle.

There's a way of do that without extending the JFormattedTextField or TextField? Extending it I know a solution that I think it will work:

Extend the field with a changed boolean.

When the focus enter the field clear the changed boolean

Implement a DocumentListener that updates the boolean

When the focus is lost inform the controller only if the boolean has changed.

It's a good way to do that?

Or there's better one?

[1094 byte] By [Joan_Pujola] at [2007-11-27 2:33:00]
# 1
This is what usually is done. The best thing about document-view separation is to allow anyone (UI / API) to change the model. To prevent infinite loops you either set some boolean flag or set a temporary client property on the relevant control.
kirillga at 2007-7-12 2:49:13 > top of Java-index,Desktop,Core GUI APIs...
# 2
http://java.sun.com/docs/books/tutorial/uiswing/events/index.html http://java.sun.com/developer/technicalArticles/javase/mvc/
java_2006a at 2007-7-12 2:49:13 > top of Java-index,Desktop,Core GUI APIs...
# 3
A lot of thanks, the second article it's very nice and completely talks about my question.Thanks :)
Joan_Pujola at 2007-7-12 2:49:13 > top of Java-index,Desktop,Core GUI APIs...