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 net.sf.jguiraffe.gui.builder.event.FormChangeEvent;
19 import net.sf.jguiraffe.gui.builder.event.FormChangeListener;
20 import net.sf.jguiraffe.gui.builder.event.FormEventManager;
21 import net.sf.jguiraffe.gui.builder.event.FormListenerType;
22 import net.sf.jguiraffe.gui.forms.ComponentHandler;
23
24 /**
25 * <p>
26 * A specific event adapter for change events.
27 * </p>
28 *
29 * @author Oliver Heger
30 * @version $Id: ChangeEventAdapter.java 205 2012-01-29 18:29:57Z oheger $
31 */
32 class ChangeEventAdapter extends SwingEventAdapter implements ChangeListener
33 {
34 /**
35 * Creates a new instance of {@code ChangeEventAdapter} that passes received
36 * events to the {@code FormEventManager}.
37 *
38 * @param eventManager the {@code FormEventManager} (must not be
39 * <b>null</b>)
40 * @param handler the component handler
41 * @param name the component name
42 * @throws IllegalArgumentException if the event manager is undefined
43 */
44 public ChangeEventAdapter(FormEventManager eventManager,
45 ComponentHandler<?> handler, String name)
46 {
47 super(eventManager, handler, name);
48 }
49
50 /**
51 * Creates a new instance of {@code ChangeEventAdapter} that passes received
52 * events to a {@code FormChangeListener}.
53 *
54 * @param listener the {@code FormChangeListener} (must not be <b>null</b>)
55 * @param handler the component handler
56 * @param name the component name
57 * @throws IllegalArgumentException if the event listener is undefined
58 */
59 public ChangeEventAdapter(FormChangeListener listener,
60 ComponentHandler<?> handler, String name)
61 {
62 super(listener, handler, name);
63 }
64
65 /**
66 * Call back method for change events.
67 *
68 * @param event the event
69 */
70 public void componentChanged(Object event)
71 {
72 fireEvent(createChangeEvent(event));
73 }
74
75 /**
76 * Creates a general form change event from the passed in Swing event.
77 *
78 * @param event the original event
79 * @return the form event
80 */
81 protected FormChangeEvent createChangeEvent(Object event)
82 {
83 return new FormChangeEvent(event, getHandler(), getName());
84 }
85
86 /**
87 * Returns the event listener type for this adapter.
88 *
89 * @return the listener type
90 */
91 @Override
92 protected FormListenerType getListenerType()
93 {
94 return FormListenerType.CHANGE;
95 }
96 }