Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[do not yet merge] Refactor EventSource #29

Open
wants to merge 5 commits into
base: 0.x
Choose a base branch
from

Conversation

samuelgruetter
Copy link
Contributor

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.

@Petikoch
Copy link
Contributor

Any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants