package com.eas.widgets;
import com.eas.core.HasPublished;
import com.eas.core.XElement;
import com.eas.menu.HasComponentPopupMenu;
import com.eas.menu.PlatypusPopupMenu;
import com.eas.ui.HasEventsExecutor;
import com.eas.ui.HasJsFacade;
import com.eas.ui.events.EventsExecutor;
import com.eas.ui.events.HasHideHandlers;
import com.eas.ui.events.HasShowHandlers;
import com.eas.ui.events.HideEvent;
import com.eas.ui.events.HideHandler;
import com.eas.ui.events.ShowEvent;
import com.eas.ui.events.ShowHandler;
import com.eas.widgets.boxes.ImageLabel;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.event.dom.client.ContextMenuEvent;
import com.google.gwt.event.dom.client.ContextMenuHandler;
import com.google.gwt.event.logical.shared.HasResizeHandlers;
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.client.ui.RequiresResize;
public class PlatypusLabel extends ImageLabel implements RequiresResize, HasJsFacade, HasComponentPopupMenu, HasEventsExecutor, HasShowHandlers, HasHideHandlers, HasResizeHandlers {
protected EventsExecutor eventsExecutor;
protected PlatypusPopupMenu menu;
protected String name;
protected JavaScriptObject published;
public PlatypusLabel(String aTitle, boolean asHtml, ImageResource aImage) {
super(aTitle, asHtml, aImage);
getElement().<XElement> cast().addResizingTransitionEnd(this);
}
public PlatypusLabel(String aTitle, boolean asHtml) {
this(aTitle, asHtml, null);
}
public PlatypusLabel() {
this("", false);
}
@Override
public HandlerRegistration addResizeHandler(ResizeHandler handler) {
return addHandler(handler, ResizeEvent.getType());
}
@Override
public void onResize() {
if (isAttached()) {
ResizeEvent.fire(this, getElement().getOffsetWidth(), getElement().getOffsetHeight());
}
}
@Override
public HandlerRegistration addHideHandler(HideHandler handler) {
return addHandler(handler, HideEvent.getType());
}
@Override
public HandlerRegistration addShowHandler(ShowHandler handler) {
return addHandler(handler, ShowEvent.getType());
}
@Override
public void setVisible(boolean visible) {
boolean oldValue = isVisible();
super.setVisible(visible);
if (oldValue != visible) {
if (visible) {
ShowEvent.fire(this, this);
} else {
HideEvent.fire(this, this);
}
}
}
@Override
public EventsExecutor getEventsExecutor() {
return eventsExecutor;
}
@Override
public void setEventsExecutor(EventsExecutor aExecutor) {
eventsExecutor = aExecutor;
}
@Override
public PlatypusPopupMenu getPlatypusPopupMenu() {
return menu;
}
protected HandlerRegistration menuTriggerReg;
@Override
public void setPlatypusPopupMenu(PlatypusPopupMenu aMenu) {
if (menu != aMenu) {
if (menuTriggerReg != null)
menuTriggerReg.removeHandler();
menu = aMenu;
if (menu != null) {
menuTriggerReg = super.addDomHandler(new ContextMenuHandler() {
@Override
public void onContextMenu(ContextMenuEvent event) {
event.preventDefault();
event.stopPropagation();
menu.setPopupPosition(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
menu.show();
}
}, ContextMenuEvent.getType());
}
}
}
@Override
public String getJsName() {
return name;
}
@Override
public void setJsName(String aValue) {
name = aValue;
}
public JavaScriptObject getPublished() {
return published;
}
@Override
public void setPublished(JavaScriptObject aValue) {
if (published != aValue) {
published = aValue;
if (published != null) {
publish(this, aValue);
}
}
}
private native static void publish(HasPublished aWidget, JavaScriptObject published)/*-{
published.opaque = false;
Object.defineProperty(published, "text", {
get : function() {
return aWidget.@com.eas.widgets.PlatypusLabel::getText()();
},
set : function(aValue) {
aWidget.@com.eas.widgets.PlatypusLabel::setText(Ljava/lang/String;)(aValue!=null?''+aValue:null);
}
});
Object.defineProperty(published, "icon", {
get : function() {
return aWidget.@com.eas.widgets.PlatypusLabel::getImageResource()();
},
set : function(aValue) {
aWidget.@com.eas.widgets.PlatypusLabel::setImageResource(Lcom/google/gwt/resources/client/ImageResource;)(aValue);
}
});
Object.defineProperty(published, "iconTextGap", {
get : function() {
return aWidget.@com.eas.widgets.PlatypusLabel::getIconTextGap()();
},
set : function(aValue) {
aWidget.@com.eas.widgets.PlatypusLabel::setIconTextGap(I)(aValue);
}
});
Object.defineProperty(published, "horizontalTextPosition", {
get : function() {
return aWidget.@com.eas.widgets.PlatypusLabel::getHorizontalTextPosition()();
},
set : function(aValue) {
aWidget.@com.eas.widgets.PlatypusLabel::setHorizontalTextPosition(I)(+aValue);
}
});
Object.defineProperty(published, "verticalTextPosition", {
get : function() {
return aWidget.@com.eas.widgets.PlatypusLabel::getVerticalTextPosition()();
},
set : function(aValue) {
aWidget.@com.eas.widgets.PlatypusLabel::setVerticalTextPosition(I)(+aValue);
}
});
Object.defineProperty(published, "horizontalAlignment", {
get : function() {
return aWidget.@com.eas.widgets.PlatypusLabel::getHorizontalAlignment()();
},
set : function(aValue) {
aWidget.@com.eas.widgets.PlatypusLabel::setHorizontalAlignment(I)(+aValue);
}
});
Object.defineProperty(published, "verticalAlignment", {
get : function() {
return aWidget.@com.eas.widgets.PlatypusLabel::getVerticalAlignment()();
},
set : function(aValue) {
aWidget.@com.eas.widgets.PlatypusLabel::setVerticalAlignment(I)(+aValue);
}
});
}-*/;
}