/** * Renders a copy of the given icon, with a different Wicket ID. * @param icon the icon to render * @param newId the new Wicket ID * @return a copy of the given icon */ public static HippoIcon copy(final HippoIcon icon, final String newId) { if (icon instanceof SpriteIcon) { return new SpriteIcon(newId, (SpriteIcon)icon); } else if (icon instanceof InlineSvgIcon) { return new InlineSvgIcon(newId, (InlineSvgIcon)icon); } else if (icon instanceof ResourceIcon) { return new ResourceIcon(newId, (ResourceIcon)icon); } throw new IllegalStateException("Expected HippoIcon's class to be either SpriteIcon, InlineSvgIcon or ResourceIcon, but got " + icon.getClass()); }
@Override protected void onBeforeRender() { Fragment fragment; final ResourceReference icon = getIcon(); if (icon.getExtension().equalsIgnoreCase("svg")) { fragment = new Fragment(WICKET_ID_CONTAINER, WICKET_FRAGMENT_SVG, this); fragment.add(new InlineSvg(WICKET_ID_SVG, icon, getExtraCssClasses())); } else { fragment = new Fragment (WICKET_ID_CONTAINER, WICKET_FRAGMENT_IMAGE, this); final Image image = new CachingImage(WICKET_ID_IMAGE, icon); image.add(CssClass.append(getExtraCssClasses())); fragment.add(image); if (width >= 0) { image.add(AttributeModifier.replace("width", width)); } if (height >= 0) { image.add(AttributeModifier.replace("height", height)); } } fragment.setRenderBodyOnly(true); addOrReplace(fragment); super.onBeforeRender(); } }
private ResourceIcon(final String newId, final ResourceIcon original) { this(newId, original.getIcon(), original.width, original.height); copyExtraCssClasses(original); }
/** * Renders an icon stored in a resource which is referenced by a Wicket model. * When the icon's file extension is '.svg', the icon is rendered as an inline SVG image. * @param id the Wicket id of the icon * @param model the model containing the resource to render * @return the icon component */ public static HippoIcon fromResourceModel(final String id, final IModel<ResourceReference> model) { return new ResourceIcon(id, model, -1, -1); }
/** * Renders an icon stored in a resource, including 'width' and 'height' attributes. * When the icon's file extension is '.svg', the icon is rendered as an inline SVG image. * @param id the Wicket id of the icon * @param reference the resource to render * @param width the width of the icon in pixels * @param height the height of the icon in pixels * @return the icon component */ public static HippoIcon fromResource(final String id, final ResourceReference reference, final int width, final int height) { return new ResourceIcon(id, reference, width, height); }
private ResourceIcon(final String id, final IModel<ResourceReference> model, final int width, final int height) { super(id, model); this.width = width; this.height = height; setRenderBodyOnly(true); }