Java tutorial
/** * Copyright 2008-2015 Qualogy Solutions B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.qualogy.qafe.mgwt.client.ui.component; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.ui.HasEnabled; import com.google.gwt.user.client.ui.Label; import com.googlecode.mgwt.dom.client.event.tap.HasTapHandlers; import com.googlecode.mgwt.dom.client.event.tap.TapEvent; import com.googlecode.mgwt.dom.client.event.tap.TapHandler; import com.googlecode.mgwt.dom.client.event.touch.HasTouchHandlers; import com.googlecode.mgwt.dom.client.event.touch.TouchCancelHandler; import com.googlecode.mgwt.dom.client.event.touch.TouchEndHandler; import com.googlecode.mgwt.dom.client.event.touch.TouchHandler; import com.googlecode.mgwt.dom.client.event.touch.TouchMoveHandler; import com.googlecode.mgwt.dom.client.event.touch.TouchStartHandler; import com.googlecode.mgwt.dom.client.recognizer.longtap.HasLongTapHandlers; import com.googlecode.mgwt.dom.client.recognizer.longtap.LongTapEvent; import com.googlecode.mgwt.dom.client.recognizer.longtap.LongTapHandler; import com.googlecode.mgwt.ui.client.widget.touch.GestureUtility; import com.qualogy.qafe.mgwt.client.ui.events.DataChangeHandler; public class QLabel extends Label implements HasData, HasEnabled, HasTapHandlers, HasLongTapHandlers, HasTouchHandlers, HasDisplayname { private boolean enabled; private GestureUtility gestureUtility; private String dataName; public QLabel(String text) { this(text, false); } public QLabel(String text, boolean bold) { super(text); if (bold) { getElement().getStyle().setProperty("fontWeight", "bold"); } gestureUtility = new GestureUtility(this); } @Override public boolean isEnabled() { return enabled; } @Override public void setEnabled(boolean enabled) { this.enabled = enabled; if (enabled) { removeStyleName(ComponentHelper.STYLE_DISABLED); } else { setStyleName(ComponentHelper.STYLE_DISABLED); } } @Override public HandlerRegistration addDataChangeHandler(DataChangeHandler handler) { return ComponentHelper.addDataChangeHandler(this, handler); } @Override public HandlerRegistration addTapHandler(TapHandler handler) { gestureUtility.ensureTapRecognizer(); return addHandler(handler, TapEvent.getType()); } @Override public HandlerRegistration addLongTapHandler(LongTapHandler handler) { gestureUtility.ensureLongTapRecognizer(); return addHandler(handler, LongTapEvent.getType()); } @Override public void setDataName(String dataName) { this.dataName = dataName; } @Override public String getDataName() { return dataName; } @Override public void setData(Object data) { String value = ComponentHelper.toString(data, ""); Object oldData = getData(); super.setText(value); Object newData = getData(); ComponentHelper.handleDataChange(this, newData, oldData); } @Override public Object getData() { return super.getText(); } @Override public Object getDataModel() { return getData(); } @Override public Object getModel() { return getData(); } @Override public void setText(String text) { setData(text); } @Override public HandlerRegistration addTouchStartHandler(TouchStartHandler handler) { return ComponentHelper.addTouchStartHandler(this, handler); } @Override public HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler) { return ComponentHelper.addTouchMoveHandler(this, handler); } @Override public HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler) { return ComponentHelper.addTouchCancelHandler(this, handler); } @Override public HandlerRegistration addTouchEndHandler(TouchEndHandler handler) { return ComponentHelper.addTouchEndHandler(this, handler); } @Override public HandlerRegistration addTouchHandler(TouchHandler handler) { return ComponentHelper.addTouchHandler(this, handler); } @Override public String getDisplayname() { return getText(); } @Override public void setDisplayname(String displayname) { setText(displayname); } }