Apache pivot : Getting button (togglebutton) state

130 Views Asked by At

my name is Javier, from Spain

At first, apologize for my inexperience, and for my english :)

This is question anyway:

I'm looking for getting a button state in Apache Pivot. I've tried with many listeners, without result. I don't find any property as "state", "value" or similar.

The closest thing I've found is:

    //Intercepta los eventos de toggleButton
    BotonGenerico.getButtonStateListeners() .add(new ButtonStateListener() {                  

        @Override
        public void stateChanged(Button button, State previousState) {
            System.out.println("Changed!");
        }
    });

But doesn't seem working.

Thanks

1

There are 1 best solutions below

0
Javier On

I'm going to answer myself, after researching the issue, if anyone is interested:

In Apache Pivot there is no control called "toggle button" as such. Instead of this, i can use the control called "button".

In my case, "BotonGenerico" can transformed in ToggleButton, only changing the toggleButton property via setToggleButton:

BotonGenerico.setToggleButton(true); 

After this, I can view or change it state, via getState and setState:

BotonGenerico.setState(State.SELECTED);
BotonGenerico.getState(); 
//State can be State.SELECTED, State.UNSELECTED or State.MIXED

On many cases, we have to work with 'components', instead 'pushbuttons' (p.e. in some events as mouseMove, mouseOut. focusedChanged...). Casting that mentioned 'component' to button, is simply to manipulate.

Sample:

//Changes PushButton background color when focus changed
@Override
public void focusedChanged(Component component, Component obverseComponent) {
//casting component and obverseComponent in order to convert it in PushButtons
PushButton botonComponent=(PushButton) component;
PushButton botonObverseComponent=(PushButton) obverseComponent;

    if (botonComponent.isToggleButton()) {                        
        if (botonComponent.getState() != State.SELECTED) {
            System.out.println("Selected");
            botonComponent.getStyles().put("backgroundColor", #000000);
        }
    }
}

Hope this helps.