source: josm/trunk/src/org/openstreetmap/josm/actions/ParameterizedActionDecorator.java@ 13071

Last change on this file since 13071 was 12546, checked in by bastiK, 7 years ago

see #14794 - javadoc

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import java.awt.event.ActionEvent;
5import java.beans.PropertyChangeListener;
6import java.util.HashMap;
7import java.util.Map;
8
9import javax.swing.Action;
10
11/**
12 * Action wrapper that delegates to a {@link ParameterizedAction} object using
13 * a specific set of parameters.
14 */
15public 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}
Note: See TracBrowser for help on using the repository browser.