RxSwing icon indicating copy to clipboard operation
RxSwing copied to clipboard

[do not yet merge] Refactor EventSource

Open samuelgruetter opened this issue 9 years ago • 1 comments

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 addXxxListener and removeXxxListener method. Examples: All Swing classes supporting KeyEvent inherit from Component, and all Swing classes supporting ItemEvent implement ItemSelectable.
  • 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.

samuelgruetter avatar Sep 26 '15 15:09 samuelgruetter

Any updates on this?

Petikoch avatar Aug 26 '16 09:08 Petikoch