Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ActionForwarder |
|
| 1.0;1 |
1 | /* | |
2 | * Copyright (c) 2009, Swiss Federal Department of Defence Civil Protection and Sport | |
3 | * (http://www.vbs.admin.ch) | |
4 | * Copyright (c) 2009, Ergon Informatik AG (http://www.ergon.ch) | |
5 | * All rights reserved. | |
6 | * | |
7 | * Licensed under the Open Permis License which accompanies this distribution, | |
8 | * and is available at http://www.openpermis.org/BSDlicenceKent.txt | |
9 | */ | |
10 | package org.openpermis.editor.policy.gui; | |
11 | ||
12 | import java.awt.event.ActionEvent; | |
13 | import java.awt.event.ActionListener; | |
14 | ||
15 | import javax.swing.Action; | |
16 | ||
17 | ||
18 | /** | |
19 | * Action listener that triggers an action on execution. | |
20 | * @since 0.1.0 | |
21 | */ | |
22 | public class ActionForwarder | |
23 | implements ActionListener | |
24 | { | |
25 | ||
26 | //---- Static | |
27 | ||
28 | /** | |
29 | * Default command used to trigger the action. | |
30 | * @since 0.1.0 | |
31 | */ | |
32 | public static final String COMMAND = "action"; | |
33 | ||
34 | //---- State | |
35 | ||
36 | /** | |
37 | * The action to trigger. | |
38 | * @since 0.1.0 | |
39 | */ | |
40 | private Action action; | |
41 | ||
42 | /** | |
43 | * The command to pass. | |
44 | * @since 0.1.0 | |
45 | */ | |
46 | private final String command; | |
47 | ||
48 | //---- Constructors | |
49 | ||
50 | /** | |
51 | * Creates a new action listener. | |
52 | * @note Uses {@link #COMMAND} as command. | |
53 | * @param action the action to execute. | |
54 | * @since 0.1.0 | |
55 | */ | |
56 | public ActionForwarder (Action action) { | |
57 | 0 | this(action, COMMAND); |
58 | 0 | } |
59 | ||
60 | /** | |
61 | * Creates a new action listener. | |
62 | * @param action the action to execute. | |
63 | * @param command the command to issue. | |
64 | * @since 0.1.0 | |
65 | */ | |
66 | 0 | public ActionForwarder (Action action, String command) { |
67 | 0 | this.action = action; |
68 | 0 | this.command = command; |
69 | 0 | } |
70 | ||
71 | //---- ActionListener | |
72 | ||
73 | /** | |
74 | * @since 0.1.0 | |
75 | */ | |
76 | public void actionPerformed (ActionEvent e) { | |
77 | 0 | this.action.actionPerformed( |
78 | new ActionEvent( | |
79 | e.getSource(), | |
80 | ActionEvent.ACTION_PERFORMED, | |
81 | this.command | |
82 | ) | |
83 | ); | |
84 | 0 | } |
85 | ||
86 | } |