-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4172958
By: alfred_doeblin
The signature of the constructor of the class Event reads like follows:
public Event(java.lang.String name,
Component target,
java.lang.Object data)
Constructs a simple event.
Parameters:
target - a component, or null to indicate broadcasting the event to all root components.
data - an arbitary data
However I think 'target' is an extremely inappropiate name; it's not the target that matters --after all it's usually the components that have an interest in a certain event that will receive it-- but the 'source' (which, of course, is what this parameter is meant to stand for).
There is more weird stuff scattered along the code, but this one is specially misleading, for it just expresses the opposite to what it should be --and actually is.
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4176130
By: henrichen
Please see Events.postEvent() and you should know why it is "target" rather than "source" ;).
/henri
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4176498
By: alfred_doeblin
I had done it before posting; of course, doing Events.postEvent amounts to injecting a programmatically created event into the system, which declares to have originated on the component named 'target'.
When a listener to events of the type displayed by the posted event receives it, it will see that the 'target' of the event, i.e., its source, is just the 'target' specified when invoking postEvent.
In other words: it's the source of the event that listeners perceive --and are actually interested in. This is very logical, for the 'target' of an event can only be a listener... and listeners know themselves very well, not needing any event to tell them.
Developers may think of the originating component as a target; but users of the api will indefectibly have the opposite point of view. For instance, java.util.EventObject follows this naming convention: it really makes sense and is very easy to understand.
With kind regards
Alfred
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4178575
By: frankiec
Until I read this I was putting the "target" as the component of where I was sending the event.
API Recommendation:
Event(String name, Component source, Object data)
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4185516
By: tomyeh
Well, it is a bit late to change some method name like this.
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4187575
By: frankiec
Tom,
I understand the apprehension to change but we (developers) are not new to going through this. If it makes sense, improves readability and is consistent with the true nature of the objective than it is a good change!
All too often I've seen frameworks decay due to pollution and resistance to refactor because of the installed base.
And it is a syntactical change not a semantic change, it won't break anything or cause anyone to have to search/replace or anything like that unless I'm missing something. Even if it did we all possess tools that can make the change within seconds...even in very large applications.
My 0.02
Frank
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4187634
By: frankiec
My apologies.
Yes, the event.getTarget() would need to change to event.getSource().
Frank
I suppose it depends on your perspective. If you are posting an event you a firing it at a target. If you are listening for an event you might want to know where it came from which is the source. So it seems Events.postEvent(target...) is correct but it should be event.getSource(). Really it seems it should be Events.postEvent(source, target) where source is the context I am within when I fire the event and target is only useful for finding the listener. Then the listener could call event.getSource to communicate with the sender. In the case of onClick for a button, the button is the sender of the event so should be the result of event.getSource().
Just my two cents...
/Daryl
Asked: 2007-02-22 18:09:22 +0800
Seen: 455 times
Last updated: Mar 24 '10