View Javadoc

1   /**********************************************
2    * Copyright (C) 2009 Lukas Laag
3    * This file is part of Vectomatic.
4    * 
5    * Vectomatic is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    * 
10   * Vectomatic is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with Vectomatic.  If not, see http://www.gnu.org/licenses/
17   **********************************************/
18  package org.vectomatic.client.rep.controller;
19  
20  import com.google.gwt.user.client.DOM;
21  import com.google.gwt.user.client.Event;
22  import com.google.gwt.user.client.ui.Image;
23  import com.google.gwt.user.client.ui.MouseListener;
24  import com.google.gwt.user.client.ui.MouseListenerCollection;
25  import com.google.gwt.user.client.ui.SourcesMouseEvents;
26  import com.google.gwt.user.client.ui.ToggleButton;
27  import com.gwt.components.client.TooltipListener;
28  
29  /**
30   * Customized ToggleButton class with a tooltip and an associated controller.
31   * @author Lukas Laag
32   */
33  public class MouseControllerButton extends ToggleButton implements SourcesMouseEvents {
34      private MouseListenerCollection _mouseListeners;
35      public IController controller;
36      
37      public MouseControllerButton(Image icon, String tooltip, IController controller) {
38  		super(icon);
39  		this.controller = controller;
40  	    // Unneeded since this is done at the CustomButton level
41  		// sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS | Event.FOCUSEVENTS);
42  		addMouseListener(new TooltipListener(tooltip, 3000));
43  	}
44  	
45  	public void addMouseListener(MouseListener listener) {
46  		if (_mouseListeners == null) {
47  			_mouseListeners = new MouseListenerCollection();
48  		}
49  		_mouseListeners.add(listener);
50  	}
51  	
52  	public void removeMouseListener(MouseListener listener) {
53  		if (_mouseListeners != null) {
54  			_mouseListeners.remove(listener);
55  		}
56  	}
57  	
58  	@Override
59  	public void onBrowserEvent(Event event) {
60  		switch (DOM.eventGetType(event)) {
61  			case Event.ONMOUSEDOWN:
62  			case Event.ONMOUSEUP:
63  			case Event.ONMOUSEMOVE:
64  			case Event.ONMOUSEOVER:
65  			case Event.ONMOUSEOUT: {
66  				if (_mouseListeners != null)
67  					_mouseListeners.fireMouseEvent(this, event);
68  				break;
69  			}
70  		}
71  		super.onBrowserEvent(event);
72  	}
73  }
74