@Retention(value=RUNTIME)
@Target(value=FIELD)
public @interface Action
A component binding that will call a method when an action occurs. This can be applied to
any object that has an "addActionListener" method that takes an ActionListener
.
Normally used for any sort of JButton
or for a JTextField
.
public class BoundJCheckBoxExample {
public static class Model extends DefaultBindableModel {
private boolean state;
public void setState(boolean state) {
this.state = state;
update();
}
public boolean isState() {
return state;
}
}
public static class Controller {
private final Model model;
public Controller(Model model) {
this.model = model;
}
public void setToTrue() {
model.setState(true);
}
public void setToFalse() {
model.setState(false);
}
}
private final Model model = new Model();
@Bindable
private final Controller controller = new Controller(model);
@Bound(to = "state")
private final JCheckBox box = new JCheckBox("State");
@Bound(to = "state")
private final JLabel stateLabel = new JLabel("?");
@Action(call = "setToTrue")
private final JButton trueButton = new JButton("Set True");
@Action(call = "setToFalse")
private final JButton falseButton = new JButton("Set False");
private final JPanel panel = new JPanel();
private final Bindings bindings = Bindings.standard();
public BoundJCheckBoxExample() {
// ... layout panel ...
bindings.bind(this);
}
// main()
}
The following are callable from @Actions:
Bindings.bind(Object)
if the class is marked as
Bindable
.Bindable
(as in the example).BindableModel
.
Strings passed into call()
are disambiguated as follows:
Bound
Modifier and Type | Required Element and Description |
---|---|
java.lang.String |
call
The name of the method to call when the action occurs.
|
public abstract java.lang.String call
BindingContext
.