/** * Replaces the button icon <b>but</b> does not save icon reference into parent {@code icon} * attribute. * * @param icon The button icon to display. */ private void replaceIcon(final AbstractImagePrototype icon) { if (rendered) { El oldIcon = buttonEl.selectNode("." + baseStyle + "-image"); if (oldIcon != null) { oldIcon.remove(); el().removeStyleName(baseStyle + "-text-icon", baseStyle + "-icon", baseStyle + "-noicon"); } el().addStyleName( (icon != null ? (!Util.isEmptyString(html) ? " " + baseStyle + "-text-icon" : " " + baseStyle + "-icon") : " " + baseStyle + "-noicon")); Element e = null; if (icon != null) { e = (Element) icon.createElement().cast(); Accessibility.setRole(e, "presentation"); fly(e).addStyleName(baseStyle + "-image"); buttonEl.insertFirst(e); El.fly(e).makePositionable(true); } autoWidth(); alignIcon(e); } }
/** * Sets the button's icon style. The style name should match a CSS style that specifies a * background image using the following format: * * <pre> * * <code> .my-icon { background: url(images/icons/my-icon.png) no-repeat * center left !important; } </code> * * </pre> * * @param icon the icon */ public void setIcon(AbstractImagePrototype icon) { if (rendered) { if (buttonEl.selectNode("img") != null) { buttonEl.selectNode("img").remove(); el().removeStyleName("x-btn-text-icon", "x-btn-icon", "x-btn-noicon"); } el().addStyleName( (icon != null ? ((text != null && text.length() > 0) ? " x-btn-text-icon" : " x-btn-icon") : " x-btn-noicon")); if (icon != null) { Element e = (Element) icon.createElement().cast(); buttonEl.insertFirst(e); El.fly(e).makePositionable(true); String align = "b-b"; if (iconAlign == IconAlign.BOTTOM) { align = "b-b"; } else if (iconAlign == IconAlign.TOP) { align = "t-t"; } else if (iconAlign == IconAlign.LEFT) { align = "tl-tl"; } else if (iconAlign == IconAlign.RIGHT) { align = "tr-tr"; } El.fly(e).alignTo(buttonEl.dom, align, null); } } this.icon = icon; }
/** * Sets the item's icon. * * @param icon the icon */ public void setIcon(AbstractImagePrototype icon) { this.icon = icon; if (rendered) { El node = el().selectNode(".x-tab-image"); if (node != null) { node.remove(); } if (icon != null) { Element e = icon.createElement().cast(); e.setClassName("x-tab-image"); el().appendChild(e); } el().setStyleName("x-tab-with-icon", icon != null); } }