Package com.palantir.ptoss.cinch.swing
Annotation Type Action
-
@Retention(RUNTIME) @Target(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
Here's an example of using @Action annotations:ActionListener
. Normally used for any sort ofJButton
or for aJTextField
.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() }
Methods available to @Actions
The following are callable from @Actions:
- Methods on the class passed into
Bindings.bind(Object)
if the class is marked asBindable
. - Any methods in fields that are marked
Bindable
(as in the example). - Any methods in fields that implement
BindableModel
.
Disambiguation
Strings passed into
call()
are disambiguated as follows:- If the string uniquely identifies a model property or bindable method then there is no problem.
- If there are two or more possibilities then you must specify the field name in the string like "model1.state" or "fileController.close".
- You can always use the long form in (2) even if the short form would suffice.
- See Also:
Bound
- Methods on the class passed into
-
-
Required Element Summary
Required Elements Modifier and Type Required Element Description java.lang.String
call
The name of the method to call when the action occurs.
-
-
-
Element Detail
-
call
java.lang.String call
The name of the method to call when the action occurs. Must be accessible in theBindingContext
.
-
-