/** * Fails in all modes due to an HtmlUnit bug: offsetWidth always returns 1256. TODO(t.broyer): * file a new HtmlUnit bug. Similar to http://sourceforge.net/p/htmlunit/bugs/1447/ */ @DoNotRunWith(Platform.HtmlUnitBug) public void testCustomImageClass() { ImageResource resource = widgetUi.prettyImage; Image widget = widgetUi.fooImage; assertEquals(resource.getWidth(), widget.getOffsetWidth()); assertEquals(resource.getHeight(), widget.getOffsetHeight()); assertEquals(resource.getTop(), widget.getOriginTop()); assertEquals(resource.getLeft(), widget.getOriginLeft()); }
private DivIcon createIcon(String label) { ImageResource markerImage = SiteFormResources.INSTANCE.blankMarker(); DivIconOptions iconOptions = new DivIconOptions(); iconOptions.setClassName(SiteFormResources.INSTANCE.style().locationMarker()); iconOptions.setIconSize(new Point(markerImage.getWidth(), markerImage.getHeight())); iconOptions.setIconAnchor(new Point(markerImage.getWidth() / 2, markerImage.getHeight())); iconOptions.setHtml(label); DivIcon icon = new DivIcon(iconOptions); return icon; }
/** * Fails in all modes due to an HtmlUnit bug: offsetWidth always returns 1256. TODO(t.broyer): * file a new HtmlUnit bug. Similar to http://sourceforge.net/p/htmlunit/bugs/1447/ */ @DoNotRunWith(Platform.HtmlUnitBug) public void testImageResourceInImageWidget() { ImageResource resource = widgetUi.prettyImage; Image widget = widgetUi.babyWidget; assertEquals(resource.getWidth(), widget.getOffsetWidth()); assertEquals(resource.getHeight(), widget.getOffsetHeight()); assertEquals(resource.getTop(), widget.getOriginTop()); assertEquals(resource.getLeft(), widget.getOriginLeft()); assertEquals("expected alt text", widget.getAltText()); assertEquals("expected style name", widget.getStyleName()); }
@Test public void imageResource() { // Arrange ImageResource testImageResource = MyClientBundle.INSTANCE.testImageResource(); // Act String name = testImageResource.getName(); String url = testImageResource.getSafeUri().asString(); int heigh = testImageResource.getHeight(); int left = testImageResource.getLeft(); int width = testImageResource.getWidth(); int top = testImageResource.getTop(); String toString = testImageResource.toString(); // Assert assertEquals("testImageResource", name); assertEquals( "http://127.0.0.1:8888/gwt_test_utils_module/com/octo/gwt/test/resources/testImageResource.gif", url); assertEquals(0, heigh); assertEquals(0, left); assertEquals(0, width); assertEquals(0, top); assertEquals( "com.octo.gwt.test.internal.resources.ImageResourceCallback generated for 'com.octo.gwt.test.resources.MyClientBundle.testImageResource()'", toString); assertEquals(testImageResource, MyClientBundle.INSTANCE.testImageResource()); }
@Override public Void apply(Element context, Value jsNode, int index) { Value propertyValue = jsNode.getProperty(TYPE); String kType = propertyValue.asString(); ImageResource imageResource = getImage(KomodoType.getKomodoType(kType)); /* * setAttribute will just set the attribute name to xlink:href and not * treat it as a ns prefix. */ setElementAttributeNS( context, XLINK_NAMESPACE, HTML_HREF, imageResource.getSafeUri().asString()); context.setAttribute(HTML_WIDTH, Integer.toString(imageResource.getWidth())); context.setAttribute(HTML_HEIGHT, Integer.toString(imageResource.getHeight())); return null; }
@Override public void show(Detail detail) { ImageResource res = detail.imageResource(); if (res.getWidth() > IMG_MAX_WIDTH || res.getHeight() > IMG_MAX_HEIGHT) { setInSlot( DetailsPresenter.IMAGE, new FitImage(res.getSafeUri().asString(), IMG_MAX_WIDTH, IMG_MAX_HEIGHT)); } else { setInSlot(DetailsPresenter.IMAGE, new Image(res)); } main.clear(); main.add(detail.main()); side.clear(); side.add(detail.side()); title.setText(detail.title()); }
public static Widget getMessage(ImageResource imageResource, String customMessage) { HorizontalPanel hp = new HorizontalPanel(); hp.setSpacing(5); hp.add(new Image(imageResource.getSafeUri())); InlineLabel label = new InlineLabel(customMessage); label.getElement().getStyle().setFontWeight(Style.FontWeight.NORMAL); label.getElement().getStyle().setFloat(Style.Float.LEFT); hp.add(label); return hp; }
protected ImageData getImageData(Object image) { ImageData imageData = new ImageData(); if (image instanceof ImageResource) { ImageResource imageResource = (ImageResource) image; imageData.height = imageResource.getHeight(); imageData.width = imageResource.getWidth(); } else if (image instanceof ComposedImage) { ComposedImage composedImage = (ComposedImage) image; List<ComposedImage.Size> sizes = new ArrayList<ComposedImage.Size>(); List<Object> images = new ArrayList<Object>(composedImage.getImages()); List<ImageData> nestedImagesData = new ArrayList<ImageData>(); for (Object nestedImage : images) { ImageData nestedImageData = getImageData(nestedImage); ComposedImage.Size size = new ComposedImage.Size(); size.height = nestedImageData.height; size.width = nestedImageData.width; sizes.add(size); nestedImagesData.add(nestedImageData); } } return imageData; }
@Override public void render(Context context, Object value, SafeHtmlBuilder safeHtmlBuilder) { StringBuilder sb = new StringBuilder(); Object image = itemDelegator.getImage(value); if (image instanceof ImageResource) { ImageResource imageResource = (ImageResource) image; sb.append("<div style='position:relative;padding-left:"); sb.append(imageResource.getWidth() + 6); sb.append("px;'>"); sb.append("<div style=\"position:absolute;left:0px;top:0px;height:100%;"); sb.append("width:").append(imageResource.getWidth()).append("px;"); sb.append("background:url('").append(imageResource.getURL()).append("') "); sb.append("no-repeat scroll center center transparent;"); sb.append("\"></div>"); sb.append(itemDelegator.getText(value)); sb.append("</div>"); } else if (image instanceof ComposedImage) { ComposedImage composedImage = (ComposedImage) image; List<ComposedImage.Size> sizes = new ArrayList<ComposedImage.Size>(); List<Object> images = new ArrayList<Object>(composedImage.getImages()); List<ImageData> nestedImagesData = new ArrayList<ImageData>(); for (Object nestedImage : images) { ImageData nestedImageData = getImageData(nestedImage); ComposedImage.Size size = new ComposedImage.Size(); size.height = nestedImageData.height; size.width = nestedImageData.width; sizes.add(size); nestedImagesData.add(nestedImageData); } ComposedImage.Size size = composedImage.getSize(sizes); sb.append("<div style='position:relative;padding-left:"); sb.append(size.width + 6); sb.append("px;'>"); List<ComposedImage.Point> drawPoints = composedImage.getDrawPoints(size); int i = 0; for (ComposedImage.Point drawPoint : drawPoints) { ImageResource nestedImage = (ImageResource) images.get(i++); sb.append("<div style=\"position:absolute;left:") .append(drawPoint.x) .append("px;top:") .append(drawPoint.y) .append("px;height:100%;"); sb.append("width:").append(nestedImage.getWidth()).append("px;"); sb.append("background:url('").append(nestedImage.getURL()).append("') "); sb.append("no-repeat scroll center center transparent;"); sb.append("\"></div>"); } sb.append(itemDelegator.getText(value)); sb.append("</div>"); } else { sb.append(itemDelegator.getText(value)); } safeHtmlBuilder.appendHtmlConstant(sb.toString()); }
/** * Sets the image to use in this menu button. * * @param image */ public void setImage(ImageResource image) { this.image = image; Image imageHtml = new Image(image.getSafeUri()); Style imageStyle = imageHtml.getElement().getStyle(); imageStyle.setDisplay(Display.BLOCK); imageStyle.setProperty("margin", "1.25em auto 0"); imageStyle.setProperty("maxWidth", "60%"); imageStyle.setPosition(Position.ABSOLUTE); imageStyle.setTop(0, Unit.PX); imageStyle.setRight(0, Unit.PX); imageStyle.setBottom(0, Unit.PX); imageStyle.setLeft(0, Unit.PX); panel.add(imageHtml); }
@Test public void checkChildOverrideWithAnnotation() { // Setup ImageResource testImageResource = MyOverridedClientBundle.INSTANCE.testImageResource(); // Test String name = testImageResource.getName(); String url = testImageResource.getURL(); int heigh = testImageResource.getHeight(); int left = testImageResource.getLeft(); int width = testImageResource.getWidth(); int top = testImageResource.getTop(); // Assert Assert.assertEquals("testImageResource", name); Assert.assertEquals( "http://127.0.0.1:8888/gwt_test_utils_module/com/octo/gwt/test/resources/override/override_testImageResource.gif", url); Assert.assertEquals(0, heigh); Assert.assertEquals(0, left); Assert.assertEquals(0, width); Assert.assertEquals(0, top); }
public ImageElement getInternalImage(ImageResource resource) { ImageElement img = Document.get().createImageElement(); img.setSrc(resource.getSafeUri().asString()); return img; }
@SuppressWarnings("deprecation") public void setResource(ImageResource resource) { this.resource = resource; generateBackground(resource.getURL()); }
public static AbstractImagePrototype getAbstractImagePrototype(ImageResource icon) { return IconHelper.createPath(icon.getURL(), icon.getWidth(), icon.getHeight()); }