[jira] Created: (LANG-580) Add Event Support Utilities

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] Created: (LANG-580) Add Event Support Utilities

ASF GitHub Bot (Jira)
Add Event Support Utilities
---------------------------

                 Key: LANG-580
                 URL: https://issues.apache.org/jira/browse/LANG-580
             Project: Commons Lang
          Issue Type: New Feature
          Components: General
    Affects Versions: 3.0
         Environment: Java SE 5.0+
            Reporter: Michael Wooten
            Priority: Minor
             Fix For: 3.0


I would like to propose some support be added to Lang for basic event handling. This would be based on the way that PropertyChangeSupport can be used to add and remove listeners and post events.

Add interface EventSupport<L extends EventListener>

addListener(L listener)
The signature for the method that can add a listener of some subtype of EventListener

removeListener(L listener)
The signature for the method that can remove a listener of some subtype of EventListener

Add class AbstractEventSupport implements EventSupport<L>, Iterable<L>

AbstractEventSupport(Object eventSource)
Constructs a new AbstractEventSupport object and associates it with the object that will be used as the source of all events (much like PropertyChangeSupport).

addListener(L)
An implementation that adds a listener to an internal collection.

removeListener(L)
An implementation that removes a listener from an internal collection.

iterator()
Returns an iterator over the attached listeners.

getSource()
Returns a reference to the source object of all events.

The best way to describe this would be to demonstrate an example of how it can be used.

public class ButtonPressedEventSupport extends AbstractEventSupport<ButtonPressedListener> {

    public ButtonPressedEventSupport(Object source) { super(source); }

    public void fireButtonPressed(Button button) {
        ButtonPressedEvent bpe = new ButtonPressedEvent(getSource(), button);
        for (ButtonPressedListener listener : this)
        {
            listener.buttonPressed(bpe);
        }
    }
}

public class MyWindow implements EventSupport<ButtonPressedListener> {
     private final ButtonPressedEventSupport buttonPressedEventSupport;

     public MyWindow { buttonPressedEventSupport = new ButtonPressedEventSupport(this); }

     public void addListener(ButtonPressedListener listener) { buttonPressedEventSupport.addListener(listener); }

     public void removeListener(ButtonPressedListener listener) { buttonPressedEventSupport.removeListener(listener); }

     ...

    private void onDetectButtonPressed(Button button) {
        buttonPressedEventSupport.fireButtonPressed(button);
    }
}

I haven't compiled the above code. It's just an example of how these classes could be used so that you're not constantly rewriting the code and interfaces for adding and removing listeners, and it provides a fairly easy method of creating methods to fire events.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (LANG-580) Add Event Support Utilities

ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/LANG-580?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12797257#action_12797257 ]

Oliver Heger commented on LANG-580:
-----------------------------------

I like the idea to add support for event listeners to [lang] because it can be tricky to implement this in a thread-safe and performant way.

That said I am not sure how much benefit the proposed solution would actually offer. IMO support for event listeners has two aspects: storing the registered listeners (i.e. the implementation of the {{addListener()}} and {{removeListener()}} methods, and firing events (i.e. {{fireXXX()}} methods). The {{EventSupport}} interface and the {{AbstractEventSupport}} class mainly focus on the former.

The JDK contains at least two classes I am aware of that are well suited for managing event listeners:
* {{javax.swing.event.EventListenerList}} is used by Swing and is a bit more complicated because it can deal with event listeners of multiple types.
* {{java.util.concurrent.CopyOnWriteArrayList}} is from its semantics a proper choice for storing event listeners.

So {{AbstractEventSupport}} would probably be a thin wrapper over one of these classes. Would this really provide benefit for users? If we could add some support for the {{fire()}} methods, the answer would be a clear yes, but I don't know how this can be achieved (it would probably be easier if Java had support for closures).

> Add Event Support Utilities
> ---------------------------
>
>                 Key: LANG-580
>                 URL: https://issues.apache.org/jira/browse/LANG-580
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: General
>    Affects Versions: 3.0
>         Environment: Java SE 5.0+
>            Reporter: Michael Wooten
>            Priority: Minor
>             Fix For: 3.0
>
>   Original Estimate: 96h
>  Remaining Estimate: 96h
>
> I would like to propose some support be added to Lang for basic event handling. This would be based on the way that PropertyChangeSupport can be used to add and remove listeners and post events.
> Add interface EventSupport<L extends EventListener>
> addListener(L listener)
> The signature for the method that can add a listener of some subtype of EventListener
> removeListener(L listener)
> The signature for the method that can remove a listener of some subtype of EventListener
> Add class AbstractEventSupport implements EventSupport<L>, Iterable<L>
> AbstractEventSupport(Object eventSource)
> Constructs a new AbstractEventSupport object and associates it with the object that will be used as the source of all events (much like PropertyChangeSupport).
> addListener(L)
> An implementation that adds a listener to an internal collection.
> removeListener(L)
> An implementation that removes a listener from an internal collection.
> iterator()
> Returns an iterator over the attached listeners.
> getSource()
> Returns a reference to the source object of all events.
> The best way to describe this would be to demonstrate an example of how it can be used.
> public class ButtonPressedEventSupport extends AbstractEventSupport<ButtonPressedListener> {
>     public ButtonPressedEventSupport(Object source) { super(source); }
>     public void fireButtonPressed(Button button) {
>         ButtonPressedEvent bpe = new ButtonPressedEvent(getSource(), button);
>         for (ButtonPressedListener listener : this)
>         {
>             listener.buttonPressed(bpe);
>         }
>     }
> }
> public class MyWindow implements EventSupport<ButtonPressedListener> {
>      private final ButtonPressedEventSupport buttonPressedEventSupport;
>      public MyWindow { buttonPressedEventSupport = new ButtonPressedEventSupport(this); }
>      public void addListener(ButtonPressedListener listener) { buttonPressedEventSupport.addListener(listener); }
>      public void removeListener(ButtonPressedListener listener) { buttonPressedEventSupport.removeListener(listener); }
>      ...
>     private void onDetectButtonPressed(Button button) {
>         buttonPressedEventSupport.fireButtonPressed(button);
>     }
> }
> I haven't compiled the above code. It's just an example of how these classes could be used so that you're not constantly rewriting the code and interfaces for adding and removing listeners, and it provides a fairly easy method of creating methods to fire events.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (LANG-580) Add Event Support Utilities

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/LANG-580?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated LANG-580:
-------------------------------

    Fix Version/s:     (was: 3.0)
                   3.1

No backwards compat issues, so moving to 3.1. If resolved before 3.0 is released please assign to 3.0.

> Add Event Support Utilities
> ---------------------------
>
>                 Key: LANG-580
>                 URL: https://issues.apache.org/jira/browse/LANG-580
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: General
>    Affects Versions: 3.0
>         Environment: Java SE 5.0+
>            Reporter: Michael Wooten
>            Priority: Minor
>             Fix For: 3.1
>
>   Original Estimate: 96h
>  Remaining Estimate: 96h
>
> I would like to propose some support be added to Lang for basic event handling. This would be based on the way that PropertyChangeSupport can be used to add and remove listeners and post events.
> Add interface EventSupport<L extends EventListener>
> addListener(L listener)
> The signature for the method that can add a listener of some subtype of EventListener
> removeListener(L listener)
> The signature for the method that can remove a listener of some subtype of EventListener
> Add class AbstractEventSupport implements EventSupport<L>, Iterable<L>
> AbstractEventSupport(Object eventSource)
> Constructs a new AbstractEventSupport object and associates it with the object that will be used as the source of all events (much like PropertyChangeSupport).
> addListener(L)
> An implementation that adds a listener to an internal collection.
> removeListener(L)
> An implementation that removes a listener from an internal collection.
> iterator()
> Returns an iterator over the attached listeners.
> getSource()
> Returns a reference to the source object of all events.
> The best way to describe this would be to demonstrate an example of how it can be used.
> public class ButtonPressedEventSupport extends AbstractEventSupport<ButtonPressedListener> {
>     public ButtonPressedEventSupport(Object source) { super(source); }
>     public void fireButtonPressed(Button button) {
>         ButtonPressedEvent bpe = new ButtonPressedEvent(getSource(), button);
>         for (ButtonPressedListener listener : this)
>         {
>             listener.buttonPressed(bpe);
>         }
>     }
> }
> public class MyWindow implements EventSupport<ButtonPressedListener> {
>      private final ButtonPressedEventSupport buttonPressedEventSupport;
>      public MyWindow { buttonPressedEventSupport = new ButtonPressedEventSupport(this); }
>      public void addListener(ButtonPressedListener listener) { buttonPressedEventSupport.addListener(listener); }
>      public void removeListener(ButtonPressedListener listener) { buttonPressedEventSupport.removeListener(listener); }
>      ...
>     private void onDetectButtonPressed(Button button) {
>         buttonPressedEventSupport.fireButtonPressed(button);
>     }
> }
> I haven't compiled the above code. It's just an example of how these classes could be used so that you're not constantly rewriting the code and interfaces for adding and removing listeners, and it provides a fairly easy method of creating methods to fire events.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (LANG-580) Add Event Support Utilities

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/LANG-580?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael Wooten updated LANG-580:
--------------------------------

    Attachment: commons-lang-event-support.patch

This patch adds a new package under lang3 called "event" and several new classes inside of it. The patch adds the described "EventSupport" interface, as well as an abstract implementation called AbstractEventSupport with documentation on how to subclass it. The patch also adds the ReflectiveEventSupport class with support for firing events based on method name or Method objects.

> Add Event Support Utilities
> ---------------------------
>
>                 Key: LANG-580
>                 URL: https://issues.apache.org/jira/browse/LANG-580
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: General
>    Affects Versions: 3.0
>         Environment: Java SE 5.0+
>            Reporter: Michael Wooten
>            Priority: Minor
>             Fix For: 3.1
>
>         Attachments: commons-lang-event-support.patch
>
>   Original Estimate: 96h
>  Remaining Estimate: 96h
>
> I would like to propose some support be added to Lang for basic event handling. This would be based on the way that PropertyChangeSupport can be used to add and remove listeners and post events.
> Add interface EventSupport<L extends EventListener>
> addListener(L listener)
> The signature for the method that can add a listener of some subtype of EventListener
> removeListener(L listener)
> The signature for the method that can remove a listener of some subtype of EventListener
> Add class AbstractEventSupport implements EventSupport<L>, Iterable<L>
> AbstractEventSupport(Object eventSource)
> Constructs a new AbstractEventSupport object and associates it with the object that will be used as the source of all events (much like PropertyChangeSupport).
> addListener(L)
> An implementation that adds a listener to an internal collection.
> removeListener(L)
> An implementation that removes a listener from an internal collection.
> iterator()
> Returns an iterator over the attached listeners.
> getSource()
> Returns a reference to the source object of all events.
> The best way to describe this would be to demonstrate an example of how it can be used.
> public class ButtonPressedEventSupport extends AbstractEventSupport<ButtonPressedListener> {
>     public ButtonPressedEventSupport(Object source) { super(source); }
>     public void fireButtonPressed(Button button) {
>         ButtonPressedEvent bpe = new ButtonPressedEvent(getSource(), button);
>         for (ButtonPressedListener listener : this)
>         {
>             listener.buttonPressed(bpe);
>         }
>     }
> }
> public class MyWindow implements EventSupport<ButtonPressedListener> {
>      private final ButtonPressedEventSupport buttonPressedEventSupport;
>      public MyWindow { buttonPressedEventSupport = new ButtonPressedEventSupport(this); }
>      public void addListener(ButtonPressedListener listener) { buttonPressedEventSupport.addListener(listener); }
>      public void removeListener(ButtonPressedListener listener) { buttonPressedEventSupport.removeListener(listener); }
>      ...
>     private void onDetectButtonPressed(Button button) {
>         buttonPressedEventSupport.fireButtonPressed(button);
>     }
> }
> I haven't compiled the above code. It's just an example of how these classes could be used so that you're not constantly rewriting the code and interfaces for adding and removing listeners, and it provides a fairly easy method of creating methods to fire events.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (LANG-580) Add Event Support Utilities

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/LANG-580?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael Wooten updated LANG-580:
--------------------------------

    Fix Version/s: 3.0
                       (was: 3.1)

Moving back to 3.0 since patch was added.

> Add Event Support Utilities
> ---------------------------
>
>                 Key: LANG-580
>                 URL: https://issues.apache.org/jira/browse/LANG-580
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: General
>    Affects Versions: 3.0
>         Environment: Java SE 5.0+
>            Reporter: Michael Wooten
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: commons-lang-event-support.patch
>
>   Original Estimate: 96h
>  Remaining Estimate: 96h
>
> I would like to propose some support be added to Lang for basic event handling. This would be based on the way that PropertyChangeSupport can be used to add and remove listeners and post events.
> Add interface EventSupport<L extends EventListener>
> addListener(L listener)
> The signature for the method that can add a listener of some subtype of EventListener
> removeListener(L listener)
> The signature for the method that can remove a listener of some subtype of EventListener
> Add class AbstractEventSupport implements EventSupport<L>, Iterable<L>
> AbstractEventSupport(Object eventSource)
> Constructs a new AbstractEventSupport object and associates it with the object that will be used as the source of all events (much like PropertyChangeSupport).
> addListener(L)
> An implementation that adds a listener to an internal collection.
> removeListener(L)
> An implementation that removes a listener from an internal collection.
> iterator()
> Returns an iterator over the attached listeners.
> getSource()
> Returns a reference to the source object of all events.
> The best way to describe this would be to demonstrate an example of how it can be used.
> public class ButtonPressedEventSupport extends AbstractEventSupport<ButtonPressedListener> {
>     public ButtonPressedEventSupport(Object source) { super(source); }
>     public void fireButtonPressed(Button button) {
>         ButtonPressedEvent bpe = new ButtonPressedEvent(getSource(), button);
>         for (ButtonPressedListener listener : this)
>         {
>             listener.buttonPressed(bpe);
>         }
>     }
> }
> public class MyWindow implements EventSupport<ButtonPressedListener> {
>      private final ButtonPressedEventSupport buttonPressedEventSupport;
>      public MyWindow { buttonPressedEventSupport = new ButtonPressedEventSupport(this); }
>      public void addListener(ButtonPressedListener listener) { buttonPressedEventSupport.addListener(listener); }
>      public void removeListener(ButtonPressedListener listener) { buttonPressedEventSupport.removeListener(listener); }
>      ...
>     private void onDetectButtonPressed(Button button) {
>         buttonPressedEventSupport.fireButtonPressed(button);
>     }
> }
> I haven't compiled the above code. It's just an example of how these classes could be used so that you're not constantly rewriting the code and interfaces for adding and removing listeners, and it provides a fairly easy method of creating methods to fire events.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (LANG-580) Add Event Support Utilities

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/LANG-580?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12884643#action_12884643 ]

James Carman commented on LANG-580:
-----------------------------------

I actually have something similar to this, but I generate a proxy object to let the user fire events.  So, you'd have a method that returns "L."  When the user calls methods on that object, it would fire that event on all listeners currently registered.  It avoids the call to iterator() and encapsulates things a bit better.

> Add Event Support Utilities
> ---------------------------
>
>                 Key: LANG-580
>                 URL: https://issues.apache.org/jira/browse/LANG-580
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: General
>    Affects Versions: 3.0
>         Environment: Java SE 5.0+
>            Reporter: Michael Wooten
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: commons-lang-event-support.patch
>
>   Original Estimate: 96h
>  Remaining Estimate: 96h
>
> I would like to propose some support be added to Lang for basic event handling. This would be based on the way that PropertyChangeSupport can be used to add and remove listeners and post events.
> Add interface EventSupport<L extends EventListener>
> addListener(L listener)
> The signature for the method that can add a listener of some subtype of EventListener
> removeListener(L listener)
> The signature for the method that can remove a listener of some subtype of EventListener
> Add class AbstractEventSupport implements EventSupport<L>, Iterable<L>
> AbstractEventSupport(Object eventSource)
> Constructs a new AbstractEventSupport object and associates it with the object that will be used as the source of all events (much like PropertyChangeSupport).
> addListener(L)
> An implementation that adds a listener to an internal collection.
> removeListener(L)
> An implementation that removes a listener from an internal collection.
> iterator()
> Returns an iterator over the attached listeners.
> getSource()
> Returns a reference to the source object of all events.
> The best way to describe this would be to demonstrate an example of how it can be used.
> public class ButtonPressedEventSupport extends AbstractEventSupport<ButtonPressedListener> {
>     public ButtonPressedEventSupport(Object source) { super(source); }
>     public void fireButtonPressed(Button button) {
>         ButtonPressedEvent bpe = new ButtonPressedEvent(getSource(), button);
>         for (ButtonPressedListener listener : this)
>         {
>             listener.buttonPressed(bpe);
>         }
>     }
> }
> public class MyWindow implements EventSupport<ButtonPressedListener> {
>      private final ButtonPressedEventSupport buttonPressedEventSupport;
>      public MyWindow { buttonPressedEventSupport = new ButtonPressedEventSupport(this); }
>      public void addListener(ButtonPressedListener listener) { buttonPressedEventSupport.addListener(listener); }
>      public void removeListener(ButtonPressedListener listener) { buttonPressedEventSupport.removeListener(listener); }
>      ...
>     private void onDetectButtonPressed(Button button) {
>         buttonPressedEventSupport.fireButtonPressed(button);
>     }
> }
> I haven't compiled the above code. It's just an example of how these classes could be used so that you're not constantly rewriting the code and interfaces for adding and removing listeners, and it provides a fairly easy method of creating methods to fire events.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (LANG-580) Add Event Support Utilities

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/LANG-580?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12889571#action_12889571 ]

Henri Yandell commented on LANG-580:
------------------------------------

I've committed your patch Michael - looked good :)

James - can you propose your change as a patch to Michael's now committed code?

> Add Event Support Utilities
> ---------------------------
>
>                 Key: LANG-580
>                 URL: https://issues.apache.org/jira/browse/LANG-580
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: General
>    Affects Versions: 3.0
>         Environment: Java SE 5.0+
>            Reporter: Michael Wooten
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: commons-lang-event-support.patch
>
>   Original Estimate: 96h
>  Remaining Estimate: 96h
>
> I would like to propose some support be added to Lang for basic event handling. This would be based on the way that PropertyChangeSupport can be used to add and remove listeners and post events.
> Add interface EventSupport<L extends EventListener>
> addListener(L listener)
> The signature for the method that can add a listener of some subtype of EventListener
> removeListener(L listener)
> The signature for the method that can remove a listener of some subtype of EventListener
> Add class AbstractEventSupport implements EventSupport<L>, Iterable<L>
> AbstractEventSupport(Object eventSource)
> Constructs a new AbstractEventSupport object and associates it with the object that will be used as the source of all events (much like PropertyChangeSupport).
> addListener(L)
> An implementation that adds a listener to an internal collection.
> removeListener(L)
> An implementation that removes a listener from an internal collection.
> iterator()
> Returns an iterator over the attached listeners.
> getSource()
> Returns a reference to the source object of all events.
> The best way to describe this would be to demonstrate an example of how it can be used.
> public class ButtonPressedEventSupport extends AbstractEventSupport<ButtonPressedListener> {
>     public ButtonPressedEventSupport(Object source) { super(source); }
>     public void fireButtonPressed(Button button) {
>         ButtonPressedEvent bpe = new ButtonPressedEvent(getSource(), button);
>         for (ButtonPressedListener listener : this)
>         {
>             listener.buttonPressed(bpe);
>         }
>     }
> }
> public class MyWindow implements EventSupport<ButtonPressedListener> {
>      private final ButtonPressedEventSupport buttonPressedEventSupport;
>      public MyWindow { buttonPressedEventSupport = new ButtonPressedEventSupport(this); }
>      public void addListener(ButtonPressedListener listener) { buttonPressedEventSupport.addListener(listener); }
>      public void removeListener(ButtonPressedListener listener) { buttonPressedEventSupport.removeListener(listener); }
>      ...
>     private void onDetectButtonPressed(Button button) {
>         buttonPressedEventSupport.fireButtonPressed(button);
>     }
> }
> I haven't compiled the above code. It's just an example of how these classes could be used so that you're not constantly rewriting the code and interfaces for adding and removing listeners, and it provides a fairly easy method of creating methods to fire events.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (LANG-580) Add Event Support Utilities

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/LANG-580?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael Wooten updated LANG-580:
--------------------------------

    Attachment: commons-lang-events-package-html.txt

Adds the missing package.html file for the events package.

> Add Event Support Utilities
> ---------------------------
>
>                 Key: LANG-580
>                 URL: https://issues.apache.org/jira/browse/LANG-580
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: General
>    Affects Versions: 3.0
>         Environment: Java SE 5.0+
>            Reporter: Michael Wooten
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: commons-lang-event-support.patch, commons-lang-events-package-html.txt
>
>   Original Estimate: 96h
>  Remaining Estimate: 96h
>
> I would like to propose some support be added to Lang for basic event handling. This would be based on the way that PropertyChangeSupport can be used to add and remove listeners and post events.
> Add interface EventSupport<L extends EventListener>
> addListener(L listener)
> The signature for the method that can add a listener of some subtype of EventListener
> removeListener(L listener)
> The signature for the method that can remove a listener of some subtype of EventListener
> Add class AbstractEventSupport implements EventSupport<L>, Iterable<L>
> AbstractEventSupport(Object eventSource)
> Constructs a new AbstractEventSupport object and associates it with the object that will be used as the source of all events (much like PropertyChangeSupport).
> addListener(L)
> An implementation that adds a listener to an internal collection.
> removeListener(L)
> An implementation that removes a listener from an internal collection.
> iterator()
> Returns an iterator over the attached listeners.
> getSource()
> Returns a reference to the source object of all events.
> The best way to describe this would be to demonstrate an example of how it can be used.
> public class ButtonPressedEventSupport extends AbstractEventSupport<ButtonPressedListener> {
>     public ButtonPressedEventSupport(Object source) { super(source); }
>     public void fireButtonPressed(Button button) {
>         ButtonPressedEvent bpe = new ButtonPressedEvent(getSource(), button);
>         for (ButtonPressedListener listener : this)
>         {
>             listener.buttonPressed(bpe);
>         }
>     }
> }
> public class MyWindow implements EventSupport<ButtonPressedListener> {
>      private final ButtonPressedEventSupport buttonPressedEventSupport;
>      public MyWindow { buttonPressedEventSupport = new ButtonPressedEventSupport(this); }
>      public void addListener(ButtonPressedListener listener) { buttonPressedEventSupport.addListener(listener); }
>      public void removeListener(ButtonPressedListener listener) { buttonPressedEventSupport.removeListener(listener); }
>      ...
>     private void onDetectButtonPressed(Button button) {
>         buttonPressedEventSupport.fireButtonPressed(button);
>     }
> }
> I haven't compiled the above code. It's just an example of how these classes could be used so that you're not constantly rewriting the code and interfaces for adding and removing listeners, and it provides a fairly easy method of creating methods to fire events.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (LANG-580) Add Event Support Utilities

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/LANG-580?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12891091#action_12891091 ]

Michael Wooten commented on LANG-580:
-------------------------------------

I realized that I forgot the package.html file. I have added a second
patch which includes the package.html file.




> Add Event Support Utilities
> ---------------------------
>
>                 Key: LANG-580
>                 URL: https://issues.apache.org/jira/browse/LANG-580
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: General
>    Affects Versions: 3.0
>         Environment: Java SE 5.0+
>            Reporter: Michael Wooten
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: commons-lang-event-support.patch, commons-lang-events-package-html.txt
>
>   Original Estimate: 96h
>  Remaining Estimate: 96h
>
> I would like to propose some support be added to Lang for basic event handling. This would be based on the way that PropertyChangeSupport can be used to add and remove listeners and post events.
> Add interface EventSupport<L extends EventListener>
> addListener(L listener)
> The signature for the method that can add a listener of some subtype of EventListener
> removeListener(L listener)
> The signature for the method that can remove a listener of some subtype of EventListener
> Add class AbstractEventSupport implements EventSupport<L>, Iterable<L>
> AbstractEventSupport(Object eventSource)
> Constructs a new AbstractEventSupport object and associates it with the object that will be used as the source of all events (much like PropertyChangeSupport).
> addListener(L)
> An implementation that adds a listener to an internal collection.
> removeListener(L)
> An implementation that removes a listener from an internal collection.
> iterator()
> Returns an iterator over the attached listeners.
> getSource()
> Returns a reference to the source object of all events.
> The best way to describe this would be to demonstrate an example of how it can be used.
> public class ButtonPressedEventSupport extends AbstractEventSupport<ButtonPressedListener> {
>     public ButtonPressedEventSupport(Object source) { super(source); }
>     public void fireButtonPressed(Button button) {
>         ButtonPressedEvent bpe = new ButtonPressedEvent(getSource(), button);
>         for (ButtonPressedListener listener : this)
>         {
>             listener.buttonPressed(bpe);
>         }
>     }
> }
> public class MyWindow implements EventSupport<ButtonPressedListener> {
>      private final ButtonPressedEventSupport buttonPressedEventSupport;
>      public MyWindow { buttonPressedEventSupport = new ButtonPressedEventSupport(this); }
>      public void addListener(ButtonPressedListener listener) { buttonPressedEventSupport.addListener(listener); }
>      public void removeListener(ButtonPressedListener listener) { buttonPressedEventSupport.removeListener(listener); }
>      ...
>     private void onDetectButtonPressed(Button button) {
>         buttonPressedEventSupport.fireButtonPressed(button);
>     }
> }
> I haven't compiled the above code. It's just an example of how these classes could be used so that you're not constantly rewriting the code and interfaces for adding and removing listeners, and it provides a fairly easy method of creating methods to fire events.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (LANG-580) Add Event Support Utilities

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/LANG-580?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12891102#action_12891102 ]

James Carman commented on LANG-580:
-----------------------------------

Michael,

I've committed my event support stuff to trunk.  Take a look, I think you'll like what you see.  To fire events with my stuff, all you have to do is:

{code:title=MyActionListenerSource.java|borderStyle=solid}
public class MyActionListenerSource
{
    EventListenerSupport<ActionListener> listeners = EventListenerSupport.create(ActionListener.class);
   
    public void doSomethingCool()
    {
      ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "somethingCool");
      listeners.fire().actionPerformed(e);
    }
}
{code}

You don't have to subclass the support class, you just use it directly.  This gets rid of using the event names to fire events.  You just call the event listener methods directly yourself.

> Add Event Support Utilities
> ---------------------------
>
>                 Key: LANG-580
>                 URL: https://issues.apache.org/jira/browse/LANG-580
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: General
>    Affects Versions: 3.0
>         Environment: Java SE 5.0+
>            Reporter: Michael Wooten
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: commons-lang-event-support.patch, commons-lang-events-package-html.txt
>
>   Original Estimate: 96h
>  Remaining Estimate: 96h
>
> I would like to propose some support be added to Lang for basic event handling. This would be based on the way that PropertyChangeSupport can be used to add and remove listeners and post events.
> Add interface EventSupport<L extends EventListener>
> addListener(L listener)
> The signature for the method that can add a listener of some subtype of EventListener
> removeListener(L listener)
> The signature for the method that can remove a listener of some subtype of EventListener
> Add class AbstractEventSupport implements EventSupport<L>, Iterable<L>
> AbstractEventSupport(Object eventSource)
> Constructs a new AbstractEventSupport object and associates it with the object that will be used as the source of all events (much like PropertyChangeSupport).
> addListener(L)
> An implementation that adds a listener to an internal collection.
> removeListener(L)
> An implementation that removes a listener from an internal collection.
> iterator()
> Returns an iterator over the attached listeners.
> getSource()
> Returns a reference to the source object of all events.
> The best way to describe this would be to demonstrate an example of how it can be used.
> public class ButtonPressedEventSupport extends AbstractEventSupport<ButtonPressedListener> {
>     public ButtonPressedEventSupport(Object source) { super(source); }
>     public void fireButtonPressed(Button button) {
>         ButtonPressedEvent bpe = new ButtonPressedEvent(getSource(), button);
>         for (ButtonPressedListener listener : this)
>         {
>             listener.buttonPressed(bpe);
>         }
>     }
> }
> public class MyWindow implements EventSupport<ButtonPressedListener> {
>      private final ButtonPressedEventSupport buttonPressedEventSupport;
>      public MyWindow { buttonPressedEventSupport = new ButtonPressedEventSupport(this); }
>      public void addListener(ButtonPressedListener listener) { buttonPressedEventSupport.addListener(listener); }
>      public void removeListener(ButtonPressedListener listener) { buttonPressedEventSupport.removeListener(listener); }
>      ...
>     private void onDetectButtonPressed(Button button) {
>         buttonPressedEventSupport.fireButtonPressed(button);
>     }
> }
> I haven't compiled the above code. It's just an example of how these classes could be used so that you're not constantly rewriting the code and interfaces for adding and removing listeners, and it provides a fairly easy method of creating methods to fire events.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (LANG-580) Add Event Support Utilities

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/LANG-580?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael Wooten updated LANG-580:
--------------------------------

    Attachment: commons-lang-events-merged.patch

This patch provides a best-of-both-worlds approach of both mine and James Carman's contributions. The EventSupport interface and AbstractEventSupport classes both remain, James Carman's EventListenerSupport has been changed to extend AbstractEventSupport, and the ReflectiveEventSupport class  has been removed in favor of James's class. The unit tests required one minor change to compile, but pass.

> Add Event Support Utilities
> ---------------------------
>
>                 Key: LANG-580
>                 URL: https://issues.apache.org/jira/browse/LANG-580
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: General
>    Affects Versions: 3.0
>         Environment: Java SE 5.0+
>            Reporter: Michael Wooten
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: commons-lang-event-support.patch, commons-lang-events-merged.patch, commons-lang-events-package-html.txt
>
>   Original Estimate: 96h
>  Remaining Estimate: 96h
>
> I would like to propose some support be added to Lang for basic event handling. This would be based on the way that PropertyChangeSupport can be used to add and remove listeners and post events.
> Add interface EventSupport<L extends EventListener>
> addListener(L listener)
> The signature for the method that can add a listener of some subtype of EventListener
> removeListener(L listener)
> The signature for the method that can remove a listener of some subtype of EventListener
> Add class AbstractEventSupport implements EventSupport<L>, Iterable<L>
> AbstractEventSupport(Object eventSource)
> Constructs a new AbstractEventSupport object and associates it with the object that will be used as the source of all events (much like PropertyChangeSupport).
> addListener(L)
> An implementation that adds a listener to an internal collection.
> removeListener(L)
> An implementation that removes a listener from an internal collection.
> iterator()
> Returns an iterator over the attached listeners.
> getSource()
> Returns a reference to the source object of all events.
> The best way to describe this would be to demonstrate an example of how it can be used.
> public class ButtonPressedEventSupport extends AbstractEventSupport<ButtonPressedListener> {
>     public ButtonPressedEventSupport(Object source) { super(source); }
>     public void fireButtonPressed(Button button) {
>         ButtonPressedEvent bpe = new ButtonPressedEvent(getSource(), button);
>         for (ButtonPressedListener listener : this)
>         {
>             listener.buttonPressed(bpe);
>         }
>     }
> }
> public class MyWindow implements EventSupport<ButtonPressedListener> {
>      private final ButtonPressedEventSupport buttonPressedEventSupport;
>      public MyWindow { buttonPressedEventSupport = new ButtonPressedEventSupport(this); }
>      public void addListener(ButtonPressedListener listener) { buttonPressedEventSupport.addListener(listener); }
>      public void removeListener(ButtonPressedListener listener) { buttonPressedEventSupport.removeListener(listener); }
>      ...
>     private void onDetectButtonPressed(Button button) {
>         buttonPressedEventSupport.fireButtonPressed(button);
>     }
> }
> I haven't compiled the above code. It's just an example of how these classes could be used so that you're not constantly rewriting the code and interfaces for adding and removing listeners, and it provides a fairly easy method of creating methods to fire events.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (LANG-580) Add Event Support Utilities

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/LANG-580?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12891231#action_12891231 ]

Michael Wooten commented on LANG-580:
-------------------------------------

James,

I'm proposing a best-of-both-worlds approach. I have added a patch to
the LANG-580 JIRA entry that combines both your classes and my own. I
changed your EventListenerSupport class to extend my
AbstractEventSupport class and removed the duplicated methods. This
leaves the AbstractEventSupport class as an extensible class that can
be extended as described in its JavaDocs, and replaces the
ReflectiveEventSupport implementation with your EventListenerSupport
implementation, which I agree is a far better solution.

I would prefer that the EventSupport interface remains, as it provides
a generic way to easily identify a class as being able to add and
remove listeners. I also think that there is a case for leaving
AbstractEventSupport, since it is designed to be extended and models
the behavior of PropertyChangeSupport.

There is also a new patch for LANG-580 that adds the package.html
file. This will probably need to be updated to include descriptions of
your classes.

Thanks.

-Michael




> Add Event Support Utilities
> ---------------------------
>
>                 Key: LANG-580
>                 URL: https://issues.apache.org/jira/browse/LANG-580
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: General
>    Affects Versions: 3.0
>         Environment: Java SE 5.0+
>            Reporter: Michael Wooten
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: commons-lang-event-support.patch, commons-lang-events-merged.patch, commons-lang-events-package-html.txt
>
>   Original Estimate: 96h
>  Remaining Estimate: 96h
>
> I would like to propose some support be added to Lang for basic event handling. This would be based on the way that PropertyChangeSupport can be used to add and remove listeners and post events.
> Add interface EventSupport<L extends EventListener>
> addListener(L listener)
> The signature for the method that can add a listener of some subtype of EventListener
> removeListener(L listener)
> The signature for the method that can remove a listener of some subtype of EventListener
> Add class AbstractEventSupport implements EventSupport<L>, Iterable<L>
> AbstractEventSupport(Object eventSource)
> Constructs a new AbstractEventSupport object and associates it with the object that will be used as the source of all events (much like PropertyChangeSupport).
> addListener(L)
> An implementation that adds a listener to an internal collection.
> removeListener(L)
> An implementation that removes a listener from an internal collection.
> iterator()
> Returns an iterator over the attached listeners.
> getSource()
> Returns a reference to the source object of all events.
> The best way to describe this would be to demonstrate an example of how it can be used.
> public class ButtonPressedEventSupport extends AbstractEventSupport<ButtonPressedListener> {
>     public ButtonPressedEventSupport(Object source) { super(source); }
>     public void fireButtonPressed(Button button) {
>         ButtonPressedEvent bpe = new ButtonPressedEvent(getSource(), button);
>         for (ButtonPressedListener listener : this)
>         {
>             listener.buttonPressed(bpe);
>         }
>     }
> }
> public class MyWindow implements EventSupport<ButtonPressedListener> {
>      private final ButtonPressedEventSupport buttonPressedEventSupport;
>      public MyWindow { buttonPressedEventSupport = new ButtonPressedEventSupport(this); }
>      public void addListener(ButtonPressedListener listener) { buttonPressedEventSupport.addListener(listener); }
>      public void removeListener(ButtonPressedListener listener) { buttonPressedEventSupport.removeListener(listener); }
>      ...
>     private void onDetectButtonPressed(Button button) {
>         buttonPressedEventSupport.fireButtonPressed(button);
>     }
> }
> I haven't compiled the above code. It's just an example of how these classes could be used so that you're not constantly rewriting the code and interfaces for adding and removing listeners, and it provides a fairly easy method of creating methods to fire events.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Resolved: (LANG-580) Add Event Support Utilities

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/LANG-580?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

James Carman resolved LANG-580.
-------------------------------

    Resolution: Won't Fix

We've decided to go with the EventListenerSupport concrete class instead of an abstract class.

> Add Event Support Utilities
> ---------------------------
>
>                 Key: LANG-580
>                 URL: https://issues.apache.org/jira/browse/LANG-580
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: General
>    Affects Versions: 3.0
>         Environment: Java SE 5.0+
>            Reporter: Michael Wooten
>            Assignee: James Carman
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: commons-lang-event-support.patch, commons-lang-events-merged.patch, commons-lang-events-package-html.txt
>
>   Original Estimate: 96h
>  Remaining Estimate: 96h
>
> I would like to propose some support be added to Lang for basic event handling. This would be based on the way that PropertyChangeSupport can be used to add and remove listeners and post events.
> Add interface EventSupport<L extends EventListener>
> addListener(L listener)
> The signature for the method that can add a listener of some subtype of EventListener
> removeListener(L listener)
> The signature for the method that can remove a listener of some subtype of EventListener
> Add class AbstractEventSupport implements EventSupport<L>, Iterable<L>
> AbstractEventSupport(Object eventSource)
> Constructs a new AbstractEventSupport object and associates it with the object that will be used as the source of all events (much like PropertyChangeSupport).
> addListener(L)
> An implementation that adds a listener to an internal collection.
> removeListener(L)
> An implementation that removes a listener from an internal collection.
> iterator()
> Returns an iterator over the attached listeners.
> getSource()
> Returns a reference to the source object of all events.
> The best way to describe this would be to demonstrate an example of how it can be used.
> public class ButtonPressedEventSupport extends AbstractEventSupport<ButtonPressedListener> {
>     public ButtonPressedEventSupport(Object source) { super(source); }
>     public void fireButtonPressed(Button button) {
>         ButtonPressedEvent bpe = new ButtonPressedEvent(getSource(), button);
>         for (ButtonPressedListener listener : this)
>         {
>             listener.buttonPressed(bpe);
>         }
>     }
> }
> public class MyWindow implements EventSupport<ButtonPressedListener> {
>      private final ButtonPressedEventSupport buttonPressedEventSupport;
>      public MyWindow { buttonPressedEventSupport = new ButtonPressedEventSupport(this); }
>      public void addListener(ButtonPressedListener listener) { buttonPressedEventSupport.addListener(listener); }
>      public void removeListener(ButtonPressedListener listener) { buttonPressedEventSupport.removeListener(listener); }
>      ...
>     private void onDetectButtonPressed(Button button) {
>         buttonPressedEventSupport.fireButtonPressed(button);
>     }
> }
> I haven't compiled the above code. It's just an example of how these classes could be used so that you're not constantly rewriting the code and interfaces for adding and removing listeners, and it provides a fairly easy method of creating methods to fire events.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Reopened: (LANG-580) Add Event Support Utilities

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/LANG-580?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell reopened LANG-580:
--------------------------------


> Add Event Support Utilities
> ---------------------------
>
>                 Key: LANG-580
>                 URL: https://issues.apache.org/jira/browse/LANG-580
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: General
>    Affects Versions: 3.0
>         Environment: Java SE 5.0+
>            Reporter: Michael Wooten
>            Assignee: James Carman
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: commons-lang-event-support.patch, commons-lang-events-merged.patch, commons-lang-events-package-html.txt
>
>   Original Estimate: 96h
>  Remaining Estimate: 96h
>
> I would like to propose some support be added to Lang for basic event handling. This would be based on the way that PropertyChangeSupport can be used to add and remove listeners and post events.
> Add interface EventSupport<L extends EventListener>
> addListener(L listener)
> The signature for the method that can add a listener of some subtype of EventListener
> removeListener(L listener)
> The signature for the method that can remove a listener of some subtype of EventListener
> Add class AbstractEventSupport implements EventSupport<L>, Iterable<L>
> AbstractEventSupport(Object eventSource)
> Constructs a new AbstractEventSupport object and associates it with the object that will be used as the source of all events (much like PropertyChangeSupport).
> addListener(L)
> An implementation that adds a listener to an internal collection.
> removeListener(L)
> An implementation that removes a listener from an internal collection.
> iterator()
> Returns an iterator over the attached listeners.
> getSource()
> Returns a reference to the source object of all events.
> The best way to describe this would be to demonstrate an example of how it can be used.
> public class ButtonPressedEventSupport extends AbstractEventSupport<ButtonPressedListener> {
>     public ButtonPressedEventSupport(Object source) { super(source); }
>     public void fireButtonPressed(Button button) {
>         ButtonPressedEvent bpe = new ButtonPressedEvent(getSource(), button);
>         for (ButtonPressedListener listener : this)
>         {
>             listener.buttonPressed(bpe);
>         }
>     }
> }
> public class MyWindow implements EventSupport<ButtonPressedListener> {
>      private final ButtonPressedEventSupport buttonPressedEventSupport;
>      public MyWindow { buttonPressedEventSupport = new ButtonPressedEventSupport(this); }
>      public void addListener(ButtonPressedListener listener) { buttonPressedEventSupport.addListener(listener); }
>      public void removeListener(ButtonPressedListener listener) { buttonPressedEventSupport.removeListener(listener); }
>      ...
>     private void onDetectButtonPressed(Button button) {
>         buttonPressedEventSupport.fireButtonPressed(button);
>     }
> }
> I haven't compiled the above code. It's just an example of how these classes could be used so that you're not constantly rewriting the code and interfaces for adding and removing listeners, and it provides a fairly easy method of creating methods to fire events.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Closed: (LANG-580) Add Event Support Utilities

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/LANG-580?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell closed LANG-580.
------------------------------

    Resolution: Fixed

Reclosing as fixed - Michael's issue led to the final code even if it wasn't solely his patch. We ended up with event support utilities.

> Add Event Support Utilities
> ---------------------------
>
>                 Key: LANG-580
>                 URL: https://issues.apache.org/jira/browse/LANG-580
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: General
>    Affects Versions: 3.0
>         Environment: Java SE 5.0+
>            Reporter: Michael Wooten
>            Assignee: James Carman
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: commons-lang-event-support.patch, commons-lang-events-merged.patch, commons-lang-events-package-html.txt
>
>   Original Estimate: 96h
>  Remaining Estimate: 96h
>
> I would like to propose some support be added to Lang for basic event handling. This would be based on the way that PropertyChangeSupport can be used to add and remove listeners and post events.
> Add interface EventSupport<L extends EventListener>
> addListener(L listener)
> The signature for the method that can add a listener of some subtype of EventListener
> removeListener(L listener)
> The signature for the method that can remove a listener of some subtype of EventListener
> Add class AbstractEventSupport implements EventSupport<L>, Iterable<L>
> AbstractEventSupport(Object eventSource)
> Constructs a new AbstractEventSupport object and associates it with the object that will be used as the source of all events (much like PropertyChangeSupport).
> addListener(L)
> An implementation that adds a listener to an internal collection.
> removeListener(L)
> An implementation that removes a listener from an internal collection.
> iterator()
> Returns an iterator over the attached listeners.
> getSource()
> Returns a reference to the source object of all events.
> The best way to describe this would be to demonstrate an example of how it can be used.
> public class ButtonPressedEventSupport extends AbstractEventSupport<ButtonPressedListener> {
>     public ButtonPressedEventSupport(Object source) { super(source); }
>     public void fireButtonPressed(Button button) {
>         ButtonPressedEvent bpe = new ButtonPressedEvent(getSource(), button);
>         for (ButtonPressedListener listener : this)
>         {
>             listener.buttonPressed(bpe);
>         }
>     }
> }
> public class MyWindow implements EventSupport<ButtonPressedListener> {
>      private final ButtonPressedEventSupport buttonPressedEventSupport;
>      public MyWindow { buttonPressedEventSupport = new ButtonPressedEventSupport(this); }
>      public void addListener(ButtonPressedListener listener) { buttonPressedEventSupport.addListener(listener); }
>      public void removeListener(ButtonPressedListener listener) { buttonPressedEventSupport.removeListener(listener); }
>      ...
>     private void onDetectButtonPressed(Button button) {
>         buttonPressedEventSupport.fireButtonPressed(button);
>     }
> }
> I haven't compiled the above code. It's just an example of how these classes could be used so that you're not constantly rewriting the code and interfaces for adding and removing listeners, and it provides a fairly easy method of creating methods to fire events.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (LANG-580) Add Event Support Utilities

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/LANG-580?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael Wooten updated LANG-580:
--------------------------------

    Attachment: commons-lang-event-support-docs.patch

Adds some additional documentation to the EventListenerSupport class, and changes the "count" method to package private so it can be used in tests but will not be exposed to external users.

> Add Event Support Utilities
> ---------------------------
>
>                 Key: LANG-580
>                 URL: https://issues.apache.org/jira/browse/LANG-580
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: General
>    Affects Versions: 3.0
>         Environment: Java SE 5.0+
>            Reporter: Michael Wooten
>            Assignee: James Carman
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: commons-lang-event-support-docs.patch, commons-lang-event-support.patch, commons-lang-events-merged.patch, commons-lang-events-package-html.txt
>
>   Original Estimate: 96h
>  Remaining Estimate: 96h
>
> I would like to propose some support be added to Lang for basic event handling. This would be based on the way that PropertyChangeSupport can be used to add and remove listeners and post events.
> Add interface EventSupport<L extends EventListener>
> addListener(L listener)
> The signature for the method that can add a listener of some subtype of EventListener
> removeListener(L listener)
> The signature for the method that can remove a listener of some subtype of EventListener
> Add class AbstractEventSupport implements EventSupport<L>, Iterable<L>
> AbstractEventSupport(Object eventSource)
> Constructs a new AbstractEventSupport object and associates it with the object that will be used as the source of all events (much like PropertyChangeSupport).
> addListener(L)
> An implementation that adds a listener to an internal collection.
> removeListener(L)
> An implementation that removes a listener from an internal collection.
> iterator()
> Returns an iterator over the attached listeners.
> getSource()
> Returns a reference to the source object of all events.
> The best way to describe this would be to demonstrate an example of how it can be used.
> public class ButtonPressedEventSupport extends AbstractEventSupport<ButtonPressedListener> {
>     public ButtonPressedEventSupport(Object source) { super(source); }
>     public void fireButtonPressed(Button button) {
>         ButtonPressedEvent bpe = new ButtonPressedEvent(getSource(), button);
>         for (ButtonPressedListener listener : this)
>         {
>             listener.buttonPressed(bpe);
>         }
>     }
> }
> public class MyWindow implements EventSupport<ButtonPressedListener> {
>      private final ButtonPressedEventSupport buttonPressedEventSupport;
>      public MyWindow { buttonPressedEventSupport = new ButtonPressedEventSupport(this); }
>      public void addListener(ButtonPressedListener listener) { buttonPressedEventSupport.addListener(listener); }
>      public void removeListener(ButtonPressedListener listener) { buttonPressedEventSupport.removeListener(listener); }
>      ...
>     private void onDetectButtonPressed(Button button) {
>         buttonPressedEventSupport.fireButtonPressed(button);
>     }
> }
> I haven't compiled the above code. It's just an example of how these classes could be used so that you're not constantly rewriting the code and interfaces for adding and removing listeners, and it provides a fairly easy method of creating methods to fire events.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Reopened: (LANG-580) Add Event Support Utilities

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/LANG-580?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell reopened LANG-580:
--------------------------------


Reopening for the additional patch to be considered.

> Add Event Support Utilities
> ---------------------------
>
>                 Key: LANG-580
>                 URL: https://issues.apache.org/jira/browse/LANG-580
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: General
>    Affects Versions: 3.0
>         Environment: Java SE 5.0+
>            Reporter: Michael Wooten
>            Assignee: James Carman
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: commons-lang-event-support-docs.patch, commons-lang-event-support.patch, commons-lang-events-merged.patch, commons-lang-events-package-html.txt
>
>   Original Estimate: 96h
>  Remaining Estimate: 96h
>
> I would like to propose some support be added to Lang for basic event handling. This would be based on the way that PropertyChangeSupport can be used to add and remove listeners and post events.
> Add interface EventSupport<L extends EventListener>
> addListener(L listener)
> The signature for the method that can add a listener of some subtype of EventListener
> removeListener(L listener)
> The signature for the method that can remove a listener of some subtype of EventListener
> Add class AbstractEventSupport implements EventSupport<L>, Iterable<L>
> AbstractEventSupport(Object eventSource)
> Constructs a new AbstractEventSupport object and associates it with the object that will be used as the source of all events (much like PropertyChangeSupport).
> addListener(L)
> An implementation that adds a listener to an internal collection.
> removeListener(L)
> An implementation that removes a listener from an internal collection.
> iterator()
> Returns an iterator over the attached listeners.
> getSource()
> Returns a reference to the source object of all events.
> The best way to describe this would be to demonstrate an example of how it can be used.
> public class ButtonPressedEventSupport extends AbstractEventSupport<ButtonPressedListener> {
>     public ButtonPressedEventSupport(Object source) { super(source); }
>     public void fireButtonPressed(Button button) {
>         ButtonPressedEvent bpe = new ButtonPressedEvent(getSource(), button);
>         for (ButtonPressedListener listener : this)
>         {
>             listener.buttonPressed(bpe);
>         }
>     }
> }
> public class MyWindow implements EventSupport<ButtonPressedListener> {
>      private final ButtonPressedEventSupport buttonPressedEventSupport;
>      public MyWindow { buttonPressedEventSupport = new ButtonPressedEventSupport(this); }
>      public void addListener(ButtonPressedListener listener) { buttonPressedEventSupport.addListener(listener); }
>      public void removeListener(ButtonPressedListener listener) { buttonPressedEventSupport.removeListener(listener); }
>      ...
>     private void onDetectButtonPressed(Button button) {
>         buttonPressedEventSupport.fireButtonPressed(button);
>     }
> }
> I haven't compiled the above code. It's just an example of how these classes could be used so that you're not constantly rewriting the code and interfaces for adding and removing listeners, and it provides a fairly easy method of creating methods to fire events.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Resolved: (LANG-580) Add Event Support Utilities

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/LANG-580?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

James Carman resolved LANG-580.
-------------------------------

    Resolution: Fixed

Patch applied, SVN revision 978864

> Add Event Support Utilities
> ---------------------------
>
>                 Key: LANG-580
>                 URL: https://issues.apache.org/jira/browse/LANG-580
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: General
>    Affects Versions: 3.0
>         Environment: Java SE 5.0+
>            Reporter: Michael Wooten
>            Assignee: James Carman
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: commons-lang-event-support-docs.patch, commons-lang-event-support.patch, commons-lang-events-merged.patch, commons-lang-events-package-html.txt
>
>   Original Estimate: 96h
>  Remaining Estimate: 96h
>
> I would like to propose some support be added to Lang for basic event handling. This would be based on the way that PropertyChangeSupport can be used to add and remove listeners and post events.
> Add interface EventSupport<L extends EventListener>
> addListener(L listener)
> The signature for the method that can add a listener of some subtype of EventListener
> removeListener(L listener)
> The signature for the method that can remove a listener of some subtype of EventListener
> Add class AbstractEventSupport implements EventSupport<L>, Iterable<L>
> AbstractEventSupport(Object eventSource)
> Constructs a new AbstractEventSupport object and associates it with the object that will be used as the source of all events (much like PropertyChangeSupport).
> addListener(L)
> An implementation that adds a listener to an internal collection.
> removeListener(L)
> An implementation that removes a listener from an internal collection.
> iterator()
> Returns an iterator over the attached listeners.
> getSource()
> Returns a reference to the source object of all events.
> The best way to describe this would be to demonstrate an example of how it can be used.
> public class ButtonPressedEventSupport extends AbstractEventSupport<ButtonPressedListener> {
>     public ButtonPressedEventSupport(Object source) { super(source); }
>     public void fireButtonPressed(Button button) {
>         ButtonPressedEvent bpe = new ButtonPressedEvent(getSource(), button);
>         for (ButtonPressedListener listener : this)
>         {
>             listener.buttonPressed(bpe);
>         }
>     }
> }
> public class MyWindow implements EventSupport<ButtonPressedListener> {
>      private final ButtonPressedEventSupport buttonPressedEventSupport;
>      public MyWindow { buttonPressedEventSupport = new ButtonPressedEventSupport(this); }
>      public void addListener(ButtonPressedListener listener) { buttonPressedEventSupport.addListener(listener); }
>      public void removeListener(ButtonPressedListener listener) { buttonPressedEventSupport.removeListener(listener); }
>      ...
>     private void onDetectButtonPressed(Button button) {
>         buttonPressedEventSupport.fireButtonPressed(button);
>     }
> }
> I haven't compiled the above code. It's just an example of how these classes could be used so that you're not constantly rewriting the code and interfaces for adding and removing listeners, and it provides a fairly easy method of creating methods to fire events.

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.