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 org.vectomatic.client.rep.view.DrawingView;
21  
22  import com.google.gwt.user.client.DOM;
23  import com.google.gwt.user.client.Event;
24  import com.google.gwt.user.client.ui.ClickListener;
25  import com.google.gwt.user.client.ui.Image;
26  import com.google.gwt.user.client.ui.MouseListener;
27  import com.google.gwt.user.client.ui.MouseListenerCollection;
28  import com.google.gwt.user.client.ui.PushButton;
29  import com.google.gwt.user.client.ui.SourcesMouseEvents;
30  import com.google.gwt.user.client.ui.Widget;
31  import com.gwt.components.client.TooltipListener;
32  
33  /**
34   * Customized PushButton class with a tooltip.
35   * @author Lukas Laag
36   */
37  public class ControllerPushButton extends PushButton implements SourcesMouseEvents, ClickListener {
38      private MouseListenerCollection mouseListeners;
39      private IController _controller;
40      private DrawingView _view;
41      
42  	ControllerPushButton(DrawingView view, Image icon, Image disabledIcon, String tooltip, IController controller) {
43  		super(icon);
44  		_view = view;
45  		getUpDisabledFace().setImage(disabledIcon);
46  		_controller = controller;
47  	    // Unneeded since this is done at the CustomButton level
48  		// sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS | Event.FOCUSEVENTS);
49  		addMouseListener(new TooltipListener(tooltip, 3000));
50  		addClickListener(this);
51  	}
52  	
53  	public void addMouseListener(MouseListener listener) {
54  		if (mouseListeners == null) {
55  			mouseListeners = new MouseListenerCollection();
56  		}
57  		mouseListeners.add(listener);
58  	}
59  	
60  	public void removeMouseListener(MouseListener listener) {
61  		if (mouseListeners != null) {
62  			mouseListeners.remove(listener);
63  		}
64  	}
65  	
66  	@Override
67  	public void onBrowserEvent(Event event) {
68  		switch (DOM.eventGetType(event)) {
69  			case Event.ONMOUSEDOWN:
70  			case Event.ONMOUSEUP:
71  			case Event.ONMOUSEMOVE:
72  			case Event.ONMOUSEOVER:
73  			case Event.ONMOUSEOUT: {
74  				if (mouseListeners != null) {
75  					mouseListeners.fireMouseEvent(this, event);
76  				}
77  				break;
78  			}
79  		}
80  		super.onBrowserEvent(event);
81  	}
82  
83  	public void onClick(Widget sender) {
84  		_controller.activate(_view);
85  	}
86  }
87