예제 #1
0
 @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());
 }
  @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);
  }
예제 #3
0
 @SuppressWarnings("deprecation")
 public void setResource(ImageResource resource) {
   this.resource = resource;
   generateBackground(resource.getURL());
 }
예제 #4
0
 public static AbstractImagePrototype getAbstractImagePrototype(ImageResource icon) {
   return IconHelper.createPath(icon.getURL(), icon.getWidth(), icon.getHeight());
 }