001 package asquare.gwt.tk.client.ui.behavior;
002
003 import com.google.gwt.user.client.DOM;
004 import com.google.gwt.user.client.Event;
005 import com.google.gwt.user.client.ui.Widget;
006
007 /**
008 * A controller which applies the specified style name to the widget.
009 */
010 public class DragStyleController extends ControllerAdaptor
011 {
012 private final Widget m_target;
013 private final String m_styleName;
014
015 public DragStyleController(Widget target, String styleName)
016 {
017 super(Event.ONMOUSEDOWN | Event.ONMOUSEUP, DragStyleController.class);
018 m_target = target;
019 m_styleName = styleName;
020 }
021
022 public void onBrowserEvent(Widget widget, Event event)
023 {
024 if (DOM.eventGetType(event) == Event.ONMOUSEDOWN)
025 {
026 m_target.addStyleName(m_styleName);
027 }
028 else
029 {
030 m_target.removeStyleName(m_styleName);
031 }
032 }
033 }