| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Florian Pirchner <florian.pirchner@gmail.com> - Initial implementation |
| */ |
| package org.eclipse.osbp.vaadin.addons.designer.overlay.client.widgets; |
| |
| import com.google.gwt.event.dom.client.ClickEvent; |
| import com.google.gwt.event.dom.client.ClickHandler; |
| import com.google.gwt.user.client.DOM; |
| import com.google.gwt.user.client.Event; |
| import com.google.gwt.user.client.ui.Button; |
| |
| // TODO: Auto-generated Javadoc |
| /** |
| * The Class OButtonWidget. |
| */ |
| public class OButtonWidget extends Button implements ClickHandler { |
| |
| /** The Constant CLASSNAME. */ |
| private static final String CLASSNAME = "o-button-widget"; |
| |
| /** The handler. */ |
| private OButtonClickHandler handler; |
| |
| /** The click pending. */ |
| private boolean clickPending; |
| |
| /** The custom event type. */ |
| private String customEventType; |
| |
| /** |
| * Instantiates a new o button widget. |
| */ |
| public OButtonWidget() { |
| getElement().setClassName(CLASSNAME); |
| initDOM(); |
| } |
| |
| /** |
| * Inits the dom. |
| */ |
| private void initDOM() { |
| addClickHandler(this); |
| sinkEvents(Event.ONMOUSEDOWN | Event.ONLOAD | Event.ONMOUSEMOVE); |
| } |
| |
| /** |
| * Gets the click handler. |
| * |
| * @return the click handler |
| */ |
| public OButtonClickHandler getClickHandler() { |
| return handler; |
| } |
| |
| /** |
| * Sets the click handler. |
| * |
| * @param handler the new click handler |
| */ |
| public void setClickHandler(OButtonClickHandler handler) { |
| this.handler = handler; |
| } |
| |
| /** |
| * Gets the custom event type. |
| * |
| * @return the custom event type |
| */ |
| public String getCustomEventType() { |
| return customEventType; |
| } |
| |
| /** |
| * Sets the custom event type. |
| * |
| * @param customEventType the new custom event type |
| */ |
| public void setCustomEventType(String customEventType) { |
| this.customEventType = customEventType; |
| } |
| |
| /** |
| * Destroy. |
| */ |
| public void destroy() { |
| } |
| |
| /* (non-Javadoc) |
| * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event.dom.client.ClickEvent) |
| */ |
| @Override |
| public void onClick(ClickEvent event) { |
| if (clickPending) { |
| handler.clicked(new OButtonClickEvent(this, customEventType)); |
| } |
| } |
| |
| /* (non-Javadoc) |
| * @see com.google.gwt.user.client.ui.Widget#onBrowserEvent(com.google.gwt.user.client.Event) |
| */ |
| @Override |
| public void onBrowserEvent(Event event) { |
| super.onBrowserEvent(event); |
| |
| if (DOM.eventGetType(event) == Event.ONMOUSEDOWN && event.getButton() == Event.BUTTON_LEFT) { |
| clickPending = true; |
| } else if (DOM.eventGetType(event) == Event.ONMOUSEMOVE) { |
| clickPending = false; |
| } else if (DOM.eventGetType(event) == Event.ONMOUSEOUT) { |
| if (clickPending) { |
| click(); |
| } |
| clickPending = false; |
| } |
| } |
| } |