KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > user > client > ui > DelegatingFocusListenerCollection


1 /*
2  * Copyright 2006 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * 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, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16
17 package com.google.gwt.user.client.ui;
18
19 /**
20  * {@link FocusListenerCollection} used to correctly hook up listeners which
21  * need to listen to events from another source.
22  * <p>
23  * For example, {@link Composite} widgets often need to listen to events
24  * generated on their wrapped widget. Upon the firing of a wrapped widget's
25  * event, the composite widget must fire its own listeners with itself as the
26  * source of the event. To use a {@link DelegatingFocusListenerCollection},
27  * simply use the {@link DelegatingFocusListenerCollection} instead of a
28  * {@link FocusListenerCollection}. For example, in {@link SuggestBox}, the
29  * following code is used to listen to focus events on the {@link SuggestBox}'s
30  * underlying widget.
31  * </p>
32  *
33  * <pre>
34  * public void addFocusListener(FocusListener listener) {
35  * if (focusListeners == null) {
36  * focusListeners = new DelegatingFocusListenerCollection(this, box);
37  * }
38  * focusListeners.add(listener);
39  * }
40  *</pre>
41  */

42 public class DelegatingFocusListenerCollection extends FocusListenerCollection
43     implements FocusListener {
44
45   private final Widget owner;
46
47   /**
48    * Constructor for {@link DelegatingFocusListenerCollection}. *
49    *
50    * @param owner owner of listeners
51    * @param delegatedTo source of events
52    */

53   public DelegatingFocusListenerCollection(Widget owner,
54       SourcesFocusEvents delegatedTo) {
55     this.owner = owner;
56     delegatedTo.addFocusListener(this);
57   }
58
59   public void onFocus(Widget sender) {
60     super.fireFocus(owner);
61   }
62
63   public void onLostFocus(Widget sender) {
64     super.fireLostFocus(owner);
65   }
66 }
67
Popular Tags