Package uic.action

Actions to connect widgets with each other; or with your logic.

See:
          Description

Interface Summary
PropertyChangedAction.PropertyChangeCreator  
 

Class Summary
AbstractButtonAction When your users click on any object extending an AbstractButton (JButton, JCheckBox, etc) a method of your choosing will be invoked.
ComponentEscapeAction An event to respond to <escape> released in JTextComponents.
ComponentFocusGainedAction An event to respond to focusGained signals.
ComponentFocusLostAction An event to respond to focusLost signals.
ComponentKeyboardAction An event to respond to <escape> released in JTextComponents.
ComponentMouseClickedAction When your users clicks on a component added to this action the target method will be invoked.
ComponentResizedAction An event to respond to a widget being shown on screen.
ComponentShownAction An event to respond to a widget being shown on screen.
DocumentChangedAction An event to respond to document change signals.
ItemSelectableAction When your users select an item from an ItemSelectable object a method of your choosing will be invoked.
JCheckBoxMenuItemAction An event to respond to changes in JCheckBoxMenuItem.
JRadioButtonMenuItemAction An event to respond to changes in JRadioButtonMenuItem.
JSpinnerChangeAction An event to respond to changes in the JSpinner.
JTextComponentEnterAction An event to respond to <enter> released in JTextComponents.
JTreeDoubleClickAction When your users double click an item in a tree, a method of your choosing will be invoked.
ListDeselectionAction Notify you if the user deselects the last entry in a list or table.
ListDoubleClickAction When your users double click an item from a list/table a method of your choosing will be invoked.
ListSelectionAction When your users select an item from a List or JTable component a method of your choosing will be invoked.
PropertyChangedAction An event to respond to firePropertyChange signals.
SwingAction  
WindowRepresenterToolBarAddedAction An event to respond to ToolBar events.
WindowRepresenterToolBarRemovedAction An event to respond to ToolBar events.
 

Package uic.action Description

Actions to connect widgets with each other; or with your logic. In order to let user events, such as clicking a button or pressing enter, be handled by your application you need to connect the widgets (called View) with your Controller class. The action framework allows you to do that in a single line of code for most cases.

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 AbstractButtonAction.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 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.

More options can be found on the API docs of UICSimpleAction.Arguments and each action in this package has different arguments which can be passed.



Copyright © 2002-2004 Thomas Zander Available under the Free Apache licence