decorate Swing Actions - Java Swing

Java examples for Swing:Action

Description

decorate Swing Actions

Demo Code


//package com.java2s;

import java.util.Iterator;
import java.util.Map;

import javax.swing.Action;

public class Main {
    public static Action[] decorateActions(Action[] actions,
            Map[] decorations) {//from   w ww  .  j ava2  s. c om
        if (actions == null || decorations == null) {
            throw new NullPointerException();
        } else if (actions.length != decorations.length) {
            throw new IllegalArgumentException(
                    "Number of actions not the same as the "
                            + " number of decorations: " + actions.length
                            + ", " + decorations.length);
        }
        for (int i = 0; i < actions.length; i++) {
            decorateAction(actions[i], decorations[i]);
        }
        return actions;
    }

    public static Action decorateAction(Action action, Map decorations) {
        for (Iterator i = decorations.keySet().iterator(); i.hasNext();) {
            String key = i.next().toString();
            action.putValue(key, decorations.get(key));
        }
        return action;
    }
}

Related Tutorials