/** * * @return a decorated label containing an undescribed image. */ private WDecoratedLabel makeAntiPatternLabel() { return new WDecoratedLabel(new WImage("/image/information.png", "")); }
/** * Creates an example image to display as the "logo" for a card. * * @param cardType the type of card to generate the logo for. * @return a new image for the card. */ private WImage createCardImage(final String cardType) { WImage image = new WImage(); image.setAccessibleText(cardType); image.setImage(new TextImage(cardType, new Dimension(50, 30))); return image; }
/** * @param text the label text * @param statusText the status text * @return the decorated label */ private WDecoratedLabel makeHeadingLabel(final String text, final String statusText) { return new WDecoratedLabel(new WImage("/image/information.png", "Informative heading"), new WText(text), new WStyledText(statusText, WStyledText.Type.EMPHASISED)); }
/** * Construct example. */ public WImageCachedExample() { // Cached dynamic image (ie has cache key) WImage image = new WImage(); image.setCacheKey("CacheKeyDemo"); image.setImage(new DynamicImage("Cached")); add(image); // Dynamic image that is not cached image = new WImage(); image.setImage(new DynamicImage("No cache")); add(image); }
@Test public void testRendererCorrectlyConfigured() { WImage image = new WImage(); Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(image) instanceof WImageRenderer); }
WMenu menu = new WMenu(WMenu.MenuType.TREE); WDecoratedLabel dLabel = new WDecoratedLabel(null, new WText("Settings Menu"), new WImage( "/image/settings.png", "settings")); WSubMenu settings = new WSubMenu(dLabel); menu.add(settings); settings.add(new WMenuItem(new WDecoratedLabel(null, new WText("Account Settings"), new WImage("/image/user-properties.png", "user properties")))); settings.add(new WMenuItem(new WDecoratedLabel(null, new WText("Personal Details"), new WImage("/image/user.png", "user")))); WSubMenu addressSub = new WSubMenu(new WDecoratedLabel(null, new WText("Address Details"), new WImage("/image/address-book-open.png", "address book"))); addressSub.setMode(WSubMenu.MenuMode.LAZY); settings.add(addressSub); addressSub.add(new WMenuItem(new WDecoratedLabel(null, new WText("Home Address"), new WImage("/image/home.png", "home")))); addressSub.add(new WMenuItem(new WDecoratedLabel(null, new WText("Work Address"), new WImage("/image/wrench.png", "work")))); addressSub.add(new WMenuItem(new WDecoratedLabel(null, new WText("Postal Address"), new WImage("/image/mail-post.png", "postal"))));
@Test public void testStaticImageUrl() { WImage image1 = new WImage("/image/x1.gif", "text1"); WImage image2 = new WImage("/image/x1.gif", "text2"); WImage image3 = new WImage("/image/x2.gif", "text2"); WContainer container = new WContainer(); container.add(image1); container.add(image2); container.add(image3); setActiveContext(createUIContext()); Assert.assertEquals("Image urls should match for the same image", image1.getTargetUrl(), image2.getTargetUrl()); Assert.assertFalse("Image urls should differ for different images", image1.getTargetUrl(). equals(image3.getTargetUrl())); }
WFigure figure = new WFigure(new WImage(IMAGE_RESOURCE), "Basic Figure"); box.add(figure); figure.setMargin(DEFAULT_MARGIN); box.setMargin(DEFAULT_BOX_MARGIN); add(box); figure = new WFigure(new WImage(IMAGE_RESOURCE), "Eager Figure"); figure.setMode(FigureMode.EAGER); figure.setMargin(DEFAULT_MARGIN); layout.addField("Show and hide lazy figure", chb); figure = new WFigure(new WImage(IMAGE_RESOURCE), "Lazy Figure"); figure.setMode(FigureMode.LAZY); figure.setMargin(DEFAULT_MARGIN);
/** * Creates an example menu item using an image. * * @param resource the name of the image resource * @param desc the description for the image * @param cacheKey the cache key for this image * @param selectedMenuText the WText to display the selected menu item. * @return a menu item using an image */ private WMenuItem createImageMenuItem(final String resource, final String desc, final String cacheKey, final WText selectedMenuText) { WImage image = new WImage(resource, desc); image.setCacheKey(cacheKey); WDecoratedLabel label = new WDecoratedLabel(image, new WText(desc), null); WMenuItem menuItem = new WMenuItem(label, new ExampleMenuAction(selectedMenuText)); menuItem.setActionObject(desc); return menuItem; }
/** * Creates an example menu item using an image. * * @param resource the name of the image resource * @param desc the description for the image * @param cacheKey the cache key for this image * @param selectedMenuText the WText to display the selected menu item. * @return a menu item using an image */ private WMenuItem createImageMenuItem(final String resource, final String desc, final String cacheKey, final WText selectedMenuText) { WImage image = new WImage(resource, desc); image.setCacheKey(cacheKey); WDecoratedLabel label = new WDecoratedLabel(image, new WText(desc), null); WMenuItem menuItem = new WMenuItem(label, new ExampleMenuAction(selectedMenuText)); menuItem.setActionObject(desc); return menuItem; }
@Test public void testButtonImageToolTipRender() throws IOException, SAXException, XpathException { WButton button = new WButton(); String expected = "alt text"; WImage buttonImage = new WImage("http://localhost/image.png", expected); button.setImage(buttonImage.getImage()); assertXpathEvaluatesTo(expected, "//html:button/@title", button); } }
@Test public void testButtonImageToolTipRender() throws IOException, SAXException, XpathException { WLink link = new WLink(); String expected = "alt text"; WImage buttonImage = new WImage("http://localhost/image.png", expected); link.setImage(buttonImage.getImage()); assertXpathEvaluatesTo(expected, "//ui:link/@toolTip", link); }
@Test public void testSetCacheKey() throws IOException { final String defaultKey = "DEFAULT KEY"; final String testKey = "TEST KEY"; WImage image = new WImage(); Assert.assertNull("CacheKey should be null by default", image.getCacheKey()); image.setCacheKey(defaultKey); Assert.assertEquals("Incorrect value returned for default cache key", defaultKey, image. getCacheKey()); image.setLocked(true); setActiveContext(createUIContext()); Assert.assertEquals("Incorrect value returned for default cache key with user context", defaultKey, image.getCacheKey()); image.setCacheKey(testKey); Assert.assertEquals("Incorrect value returned for cache key with user context", testKey, image.getCacheKey()); resetContext(); Assert.assertEquals("Incorrect value returned for default cache key", defaultKey, image. getCacheKey()); }
content.setBytes(data); WImage image = new WImage(); image.setLocked(true);
WImage labelImage = new WImage("/image/success.png", "I still like bananas"); labelImage.setHtmlClass("wc-valign-bottom"); rb1Label.add(labelImage); WLabel rb2Label = new WLabel("", rb2); labelImage = new WImage("/image/error.png", "I still dislike bananas"); labelImage.setHtmlClass("wc-valign-bottom"); rb2Label.add(labelImage);
WImage linkImage = new WImage("/image/attachment.png", "Add attachment"); exampleLink.setImage(linkImage.getImage()); exampleLink.setImagePosition((ImagePosition) ddImagePosition.getSelected());
@Test public void testXssEscaping() throws IOException, SAXException, XpathException { WImage image = new WImage(); MockImage content = new MockImage(); content.setDescription(getMaliciousAttribute("html:img")); setActiveContext(createUIContext()); image.setImage(content); assertSafeContent(image); image.setImageUrl(getMaliciousAttribute()); assertSafeContent(image); } }
@Test public void testSetImage() { MockImage sessionImage = new MockImage(); MockImage defaultImage = new MockImage(); WImage image = new WImage(); image.setImage(defaultImage); image.setLocked(true); setActiveContext(createUIContext()); Assert.assertSame("Default image should be returned when no user specific image set", defaultImage, image.getImage()); Assert.assertTrue("Should be in default state when no user specific image set", image. isDefaultState()); setActiveContext(createUIContext()); image.setImage(sessionImage); Assert.assertSame("Session image should be returned when set", sessionImage, image. getImage()); Assert.assertFalse("Should not be in default state when session image set", image. isDefaultState()); resetContext(); Assert.assertSame("Default image should not be changed", defaultImage, image.getImage()); }
tabset.addTab(container, "(no selection)", WTabSet.TAB_MODE_CLIENT); WImage srcImage = new WImage(new ImageResource("/image/text-x-source.png", "View Source")); srcImage.setCacheKey("srcTabImage"); tabset.addTab(source, new WDecoratedLabel(srcImage), WTabSet.TAB_MODE_LAZY).setToolTip("View Source");