1 /*
2 * Copyright 2006-2016 The JGUIraffe Team.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License")
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sf.jguiraffe.gui.platform.swing.builder.event;
17
18 import java.awt.event.ActionEvent;
19 import java.awt.event.ActionListener;
20
21 import net.sf.jguiraffe.gui.builder.event.FormActionEvent;
22 import net.sf.jguiraffe.gui.builder.event.FormActionListener;
23 import net.sf.jguiraffe.gui.builder.event.FormEventManager;
24 import net.sf.jguiraffe.gui.builder.event.FormListenerType;
25 import net.sf.jguiraffe.gui.forms.ComponentHandler;
26
27 /**
28 * <p>
29 * A specific event adapter for Swing action events.
30 * </p>
31 *
32 * @author Oliver Heger
33 * @version $Id: ActionEventAdapter.java 205 2012-01-29 18:29:57Z oheger $
34 */
35 class ActionEventAdapter extends SwingEventAdapter implements ActionListener
36 {
37 /**
38 * Creates a new instance of {@code ActionEventAdapter} that is associated
39 * with an event manager.
40 *
41 * @param eventManager the event manager (must not be <b>null</b>)
42 * @param handler the component handler
43 * @param name the component's name
44 * @throws IllegalArgumentException if the event manager is <b>null</b>
45 */
46 public ActionEventAdapter(FormEventManager eventManager,
47 ComponentHandler<?> handler, String name)
48 {
49 super(eventManager, handler, name);
50 }
51
52 /**
53 * Creates a new instance of {@code ActionEventAdapter} that is associated
54 * with the specified event listener.
55 *
56 * @param actionListener the action listener (must not be <b>null</b>)
57 * @param handler the component handler
58 * @param name the component name
59 * @throws IllegalArgumentException if the event listener is <b>null</b>
60 */
61 public ActionEventAdapter(FormActionListener actionListener,
62 ComponentHandler<?> handler, String name)
63 {
64 super(actionListener, handler, name);
65 }
66
67 /**
68 * Call back for action events.
69 *
70 * @param event the action event
71 */
72 public void actionPerformed(ActionEvent event)
73 {
74 fireEvent(createFormEvent(event));
75 }
76
77 /**
78 * Creates a <code>FormActionEvent</code> from the passed in Swing action
79 * event.
80 *
81 * @param event the Swing action event
82 * @return the general form action event
83 */
84 protected FormActionEvent createFormEvent(ActionEvent event)
85 {
86 return new FormActionEvent(event, getHandler(), getName(), event
87 .getActionCommand());
88 }
89
90 /**
91 * Returns the form listener type of this adapter.
92 *
93 * @return the listener type
94 */
95 @Override
96 protected FormListenerType getListenerType()
97 {
98 return FormListenerType.ACTION;
99 }
100 }