Using Comparators to define Event notification order?
Im pondering bug: 4178930 Swing models need pre- and post-listeners
And am considering attacking it not from the point of adding pre and post listeners, but allowing the user to define the order in which events are delivered to the various listeners. One way that Im considering is allowing the user to set a Comparator for a specific class of EventListeners. This Comparator would be fed back to the EventListenerList in the particular JComponent and when notification time came it would use that Comparator to define the order.
From the users perspective it would probably be a call like so:
From that users perspective this seems ok. If the user needs to define a simple pre and post listener ordering, he should be able to do this. Or if there is an ordering that isn't as simple as pre-doit-post order he can also do it. A danger would be if he messes with any necessary ordering that Swing is requiring.
Implementing this internally would require somewhere around 42 classes to be worked on. The monkeywrench is this idiom:
which returns the internal array of listeners, and notification is based off of that array. Most likely every case would need to do something different if it had a Comparator for the listener class.