View Javadoc

1   /*
2    * Copyright 2006 Robert Hanson <iamroberthanson AT gmail.com>
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  
17  package org.gwtwidgets.client.temp;
18  
19  import com.google.gwt.user.client.DOM;
20  import com.google.gwt.user.client.Event;
21  import com.google.gwt.user.client.ui.FocusPanel;
22  import com.google.gwt.user.client.ui.MouseListener;
23  import com.google.gwt.user.client.ui.MouseListenerCollection;
24  import com.google.gwt.user.client.ui.Widget;
25  
26  
27  public class TFocusPanel extends FocusPanel
28  {
29      private MouseListenerCollection mouseListeners;
30  
31  
32  
33      public TFocusPanel (Widget w)
34      {
35          super(w);
36      }
37  
38      public void addMouseListener (MouseListener listener)
39      {
40          super.addMouseListener(listener);
41          if (mouseListeners == null) {
42              mouseListeners = new TMouseListenerCollection();
43          }
44          mouseListeners.add(listener);
45      }
46  
47      public void onBrowserEvent (Event event)
48      {
49          switch (DOM.eventGetType(event)) {
50              case Event.ONMOUSEDOWN:
51              case Event.ONMOUSEUP:
52              case Event.ONMOUSEMOVE:
53                  if (mouseListeners != null) {
54                      mouseListeners.fireMouseEvent(this, event);
55                  }
56                  break;
57              default:
58                  super.onBrowserEvent(event);
59                  break;
60          }
61      }
62  
63      public void removeMouseListener (MouseListener listener)
64      {
65          super.removeMouseListener(listener);
66          if (mouseListeners != null) {
67              mouseListeners.remove(listener);
68          }
69      }
70  }