01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: package com.google.gwt.user.client.ui;
17:
18: import com.google.gwt.user.client.DOM;
19: import com.google.gwt.user.client.Event;
20:
21: import java.util.ArrayList;
22:
23: /**
24: * A helper class for implementers of the
25: * {@link com.google.gwt.user.client.ui.SourcesFocusEvents} interface. This
26: * subclass of {@link ArrayList} assumes that all objects added to it will be of
27: * type {@link com.google.gwt.user.client.ui.FocusListener}.
28: */
29: public class FocusListenerCollection extends ArrayList<FocusListener> {
30:
31: /**
32: * Fires a focus event to all listeners.
33: *
34: * @param sender the widget sending the event.
35: */
36: public void fireFocus(Widget sender) {
37: for (FocusListener listener : this ) {
38: listener.onFocus(sender);
39: }
40: }
41:
42: /**
43: * A helper for widgets that source focus events.
44: *
45: * @param sender the widget sending the event.
46: * @param event the {@link Event DOM event} received by the widget.
47: */
48: public void fireFocusEvent(Widget sender, Event event) {
49: switch (DOM.eventGetType(event)) {
50: case Event.ONFOCUS:
51: fireFocus(sender);
52: break;
53:
54: case Event.ONBLUR:
55: fireLostFocus(sender);
56: break;
57: }
58: }
59:
60: /**
61: * Fires a lost-focus event to all listeners.
62: *
63: * @param sender the widget sending the event.
64: */
65: public void fireLostFocus(Widget sender) {
66: for (FocusListener listener : this) {
67: listener.onLostFocus(sender);
68: }
69: }
70: }
|