[do not yet merge] Refactor EventSource
While working on #28, I noticed that there's quite some code duplication in this project which could be eliminated.
My solution is to factor out the common code into an abstract class EventSource, and into SwingObservable.create.
You will observe that some of my new XxxEventSource classes implement the addListenerForComponent/removeListenerFromComponent methods, while others don't. The reason for this irregularity is that there are two kinds of Swing events:
- The easy ones: All Swing classes supporting such events share a common superclass or interface with an
addXxxListenerandremoveXxxListenermethod. Examples: All Swing classes supportingKeyEventinherit fromComponent, and all Swing classes supportingItemEventimplementItemSelectable. - The tricky ones: There's no such a common superclass or interface for all Swing classes supporting the event. Examples:
ActionEvent,ChangeEvent.
My solution works for both of them, and is only slightly more verbose for the tricky ones.
Consider this PR as a preview. I've only performed the refactoring for a few event sources, and before we do it for all of them, I'd like to know what others think of it.
Any updates on this?