[3175] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.actions;
|
---|
| 3 |
|
---|
| 4 | import java.awt.event.ActionEvent;
|
---|
| 5 | import java.beans.PropertyChangeListener;
|
---|
| 6 | import java.util.HashMap;
|
---|
| 7 | import java.util.Map;
|
---|
| 8 |
|
---|
| 9 | import javax.swing.Action;
|
---|
| 10 |
|
---|
[12546] | 11 | /**
|
---|
| 12 | * Action wrapper that delegates to a {@link ParameterizedAction} object using
|
---|
| 13 | * a specific set of parameters.
|
---|
| 14 | */
|
---|
[3175] | 15 | public class ParameterizedActionDecorator implements Action {
|
---|
| 16 |
|
---|
| 17 | private final ParameterizedAction action;
|
---|
| 18 | private final Map<String, Object> parameters;
|
---|
| 19 |
|
---|
[12546] | 20 | /**
|
---|
| 21 | * Constructs a new ParameterizedActionDecorator.
|
---|
| 22 | * @param action the action that is invoked by this wrapper
|
---|
| 23 | * @param parameters parameters used for invoking the action
|
---|
| 24 | */
|
---|
[3175] | 25 | public ParameterizedActionDecorator(ParameterizedAction action, Map<String, Object> parameters) {
|
---|
| 26 | this.action = action;
|
---|
[7005] | 27 | this.parameters = new HashMap<>(parameters);
|
---|
[3175] | 28 | }
|
---|
| 29 |
|
---|
[6084] | 30 | @Override
|
---|
[3175] | 31 | public void addPropertyChangeListener(PropertyChangeListener listener) {
|
---|
| 32 | action.addPropertyChangeListener(listener);
|
---|
| 33 | }
|
---|
[8510] | 34 |
|
---|
[6084] | 35 | @Override
|
---|
[3175] | 36 | public Object getValue(String key) {
|
---|
| 37 | return action.getValue(key);
|
---|
| 38 | }
|
---|
[8510] | 39 |
|
---|
[6084] | 40 | @Override
|
---|
[3175] | 41 | public boolean isEnabled() {
|
---|
| 42 | return action.isEnabled();
|
---|
| 43 | }
|
---|
[8510] | 44 |
|
---|
[6084] | 45 | @Override
|
---|
[3175] | 46 | public void putValue(String key, Object value) {
|
---|
| 47 | action.putValue(key, value);
|
---|
| 48 | }
|
---|
[8510] | 49 |
|
---|
[6084] | 50 | @Override
|
---|
[3175] | 51 | public void removePropertyChangeListener(PropertyChangeListener listener) {
|
---|
| 52 | action.removePropertyChangeListener(listener);
|
---|
| 53 | }
|
---|
[8510] | 54 |
|
---|
[6084] | 55 | @Override
|
---|
[3175] | 56 | public void setEnabled(boolean b) {
|
---|
| 57 | action.setEnabled(b);
|
---|
| 58 | }
|
---|
[8510] | 59 |
|
---|
[6084] | 60 | @Override
|
---|
[3175] | 61 | public void actionPerformed(ActionEvent e) {
|
---|
| 62 | action.actionPerformed(e, parameters);
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[12546] | 65 | /**
|
---|
| 66 | * Get the parameters used to invoke the wrapped action.
|
---|
| 67 | * @return the parameters used to invoke the wrapped action
|
---|
| 68 | */
|
---|
[3175] | 69 | public Map<String, Object> getParameters() {
|
---|
| 70 | return parameters;
|
---|
| 71 | }
|
---|
| 72 | }
|
---|