pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Brown <gk_br...@verizon.net>
Subject Re: Default scripting Listeners
Date Wed, 08 Dec 2010 12:46:57 GMT
> Is there a way to define a listener, as an element in bxml file, for use in more than
one component, as a dereference attribute value? For example:
> ...
> <Window xmlns="org.apache.pivot.wtk"
>     xmlns:bxml="http://pivot.apache.org/bxml">
>     
>     <ButtonListener bxml:id="listener">
>         function buttonPressed(button) {
>             // Handle event
>         }
>     </ButtonListener>
>     
>     <PushButton buttonData="Click Me!" buttonPressListeners="$listener"/>    
>     <PushButton buttonData="Click Me Again!" buttonPressListeners="$listener"/>
>         
> </Window>

You could do this in script as follows:

<bxml:script>
function onButtonPress() {
    ...
}
</bxml:script>

<PushButton buttonData="Click Me!" ButtonPressListener.buttonPressed="onButtonPress()"/>
   
<PushButton buttonData="Click Me Again!" ButtonPressListener.buttonPressed="onButtonPress()"/>

FYI, the "ButtonPressListener" qualifier is necessary so BXMLSerializer knows which interface
defines the handler event.

You could also do this in Java using the listener list directly:

ButtonPressListener buttonPressListener = new ButtonPressListener() {
    public void buttonPressed(Button button) {
        ...
    }
}

pushButton1.getButtonPressListeners().add(buttonPressListener);
pushButton2.getButtonPressListeners().add(buttonPressListener);

G


Mime
View raw message