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 |
|
---|
11 | /**
|
---|
12 | * Action wrapper that delegates to a {@link ParameterizedAction} object using
|
---|
13 | * a specific set of parameters.
|
---|
14 | */
|
---|
15 | public class ParameterizedActionDecorator implements Action {
|
---|
16 |
|
---|
17 | private final ParameterizedAction action;
|
---|
18 | private final Map<String, Object> parameters;
|
---|
19 |
|
---|
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 | */
|
---|
25 | public ParameterizedActionDecorator(ParameterizedAction action, Map<String, Object> parameters) {
|
---|
26 | this.action = action;
|
---|
27 | this.parameters = new HashMap<>(parameters);
|
---|
28 | }
|
---|
29 |
|
---|
30 | @Override
|
---|
31 | public void addPropertyChangeListener(PropertyChangeListener listener) {
|
---|
32 | action.addPropertyChangeListener(listener);
|
---|
33 | }
|
---|
34 |
|
---|
35 | @Override
|
---|
36 | public Object getValue(String key) {
|
---|
37 | return action.getValue(key);
|
---|
38 | }
|
---|
39 |
|
---|
40 | @Override
|
---|
41 | public boolean isEnabled() {
|
---|
42 | return action.isEnabled();
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Override
|
---|
46 | public void putValue(String key, Object value) {
|
---|
47 | action.putValue(key, value);
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | public void removePropertyChangeListener(PropertyChangeListener listener) {
|
---|
52 | action.removePropertyChangeListener(listener);
|
---|
53 | }
|
---|
54 |
|
---|
55 | @Override
|
---|
56 | public void setEnabled(boolean b) {
|
---|
57 | action.setEnabled(b);
|
---|
58 | }
|
---|
59 |
|
---|
60 | @Override
|
---|
61 | public void actionPerformed(ActionEvent e) {
|
---|
62 | action.actionPerformed(e, parameters);
|
---|
63 | }
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Get the parameters used to invoke the wrapped action.
|
---|
67 | * @return the parameters used to invoke the wrapped action
|
---|
68 | */
|
---|
69 | public Map<String, Object> getParameters() {
|
---|
70 | return parameters;
|
---|
71 | }
|
---|
72 | }
|
---|