Product \ Actions

main API Code Example

Any action from the user is coupled with a method call in your classes by an action class in the package. This causes a user action to execute the method of your choice in your controller class with optional arguments which are associated with the action. As an example:

    public void initGui() {
        JCheckBox checkBox = new JCheckBox("click me");
        add(checkBox);
        new AbstractButtonAction(this, "toggled").add(checkBox);
    }
    public void toggled(boolean on) {
        System.out.println("toggled: "+ on);
    }

When the user action to check, or uncheck the checkbox occurs this code will cause the 'toggled' method to be called. Since the AbstractButtonAction allows several different arguments (defined in the class as fields starting with ARGUMENT) the target method can have one or more arguments. The boolean argument is one of the default target signatures, namely the ARGUMENT_SELECTED.

The same creation of AbstractButtonAction would have called the toggled method even if the method would have other arguments, since the action will try to use any of the default target signatures as listed in the javadoc of the action. Each action can have different default target signatures.

These method declarations would have worked just as well using the creation of the AbstractButtonAction like the above code does;

    public void toggled(int modifiers)
    public void toggled(Object sourceOfEvent)

createArguments

Any action also allows you to use any combination of the arguments that are not listed in the default target arguments, as well as several other advanced argument options.
On each action class you can call the static method uic.model.UICSimpleAction.createArguments to create an Arguments object and then you can fill that arguments object with the exact expected arguments you want your target method to be called with.

For example:

    public void initGui() {
        JCheckBox first = new JCheckBox("First");
        JCheckBox second = new JCheckBox("Second");
        JCheckBox last = new JCheckBox("Last");
            ..
        new AbstractButtonAction(second, "setEnabled",        // action 1
            AbstractButtonAction.createArguments()
                .addArgument(AbstractButtonAction.ARGUMENT_SELECTED) // simple argument
            ).add(first);

        new AbstractButtonAction(last, "setSelected",         // action 2
            AbstractButtonAction.createArguments()
                .addNotArgument(AbstractButtonAction.ARGUMENT_SELECTED)
            ).add(first);
    }

Action 1, in this example is the longer version of what the first example also did, but now using the createArguments() method. Note how you can have as many addArgument lines as you need arguments for your target method. Simply add the 'simple argument' line as many times as needed.

Action 2 uses the addNotArgument method with an argument that is a boolean, the effect is that the selected state from the first checkbox is inversed before it is passed to the target method of action 2. The target method is not on our class; its on another JCheckBox, as passed as first argument. On the checkbox the method "setSelected" is called.
This action effectively unchecks the last checkbox when the first is checked, and checks it when the first is checked.