1

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

ljgw
  • 2,751
  • 1
  • 20
  • 39
Javier
  • 189
  • 3
  • 16
  • Welcome to Stackoverflow :) nothing to apology. just keep your question or answer clear and helpful. :) – Aman Gupta Dec 02 '13 at 15:29
  • Hi Aman. Thanks for your welcome. I will try to be more explicit: I'm working with a button, with the property 'toggglebutton' sets to true (Apache Pivot doesn't provides any control called "ToggleButton" as is). The only issue is how to get it state, or wich is the right property to get :) Thanks – Javier Dec 02 '13 at 15:35
  • 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 – Javier Dec 02 '13 at 16:23
  • if you think this resolve your issue, then post it as answer to your question and accept it. kudos – Aman Gupta Dec 02 '13 at 17:49
  • I tried to do it, but system doesn't let me do in a few time, because i'm a novice yet :) Thank you anyway for your interest Aman :) – Javier Dec 02 '13 at 21:33

1 Answers1

0

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.

Javier
  • 189
  • 3
  • 16