| /* |
| * Copyright 2007 Google Inc. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| * use this file except in compliance with the License. You may obtain a copy of |
| * the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| * License for the specific language governing permissions and limitations under |
| * the License. |
| */ |
| |
| package com.google.gwt.user.client.ui; |
| |
| /** |
| * {@link KeyboardListenerCollection} used to correctly hook up event listeners |
| * to the composite's wrapped widget. |
| * |
| * <p> |
| * For example, {@link Composite} widgets often need to listen to events |
| * generated on their wrapped widget. Upon the firing of a wrapped widget's |
| * event, the composite widget must fire its own listeners with itself as the |
| * source of the event. To use a {@link DelegatingKeyboardListenerCollection}, |
| * simply use the {@link DelegatingKeyboardListenerCollection} instead of a |
| * {@link KeyboardListenerCollection}. For example, in {@link SuggestBox}, the |
| * following code is used to listen to keyboard events on the {@link SuggestBox} |
| * underlying widget. |
| * </p> |
| * |
| * <pre> |
| * public void addKeyboardListener(KeyboardListener listener) { |
| * if (keyboardListeners == null) { |
| * keyboardListeners = new DelegatingKeyboardListenerCollection(this, box); |
| * } |
| * keyboardListeners.add(listener); |
| * } |
| *</pre> |
| * |
| * @deprecated Use {@link Widget#delegateEvent} instead |
| */ |
| @Deprecated |
| public class DelegatingKeyboardListenerCollection extends |
| KeyboardListenerCollection implements KeyboardListener { |
| |
| private final Widget owner; |
| |
| /** |
| * Constructor for {@link DelegatingKeyboardListenerCollection}. |
| * |
| * @param owner owner of listeners |
| * @param delegatedTo source of events |
| */ |
| public DelegatingKeyboardListenerCollection(Widget owner, |
| SourcesKeyboardEvents delegatedTo) { |
| this.owner = owner; |
| delegatedTo.addKeyboardListener(this); |
| } |
| |
| public void onKeyDown(Widget sender, char keyCode, int modifiers) { |
| fireKeyDown(owner, keyCode, modifiers); |
| } |
| |
| public void onKeyPress(Widget sender, char keyCode, int modifiers) { |
| fireKeyPress(owner, keyCode, modifiers); |
| } |
| |
| public void onKeyUp(Widget sender, char keyCode, int modifiers) { |
| fireKeyUp(owner, keyCode, modifiers); |
| } |
| } |