Example usage for com.google.gwt.resources.client ImageResource getHeight

List of usage examples for com.google.gwt.resources.client ImageResource getHeight

Introduction

In this page you can find the example usage for com.google.gwt.resources.client ImageResource getHeight.

Prototype

int getHeight();

Source Link

Document

Returns the height of the image.

Usage

From source file:app.dnd.drag.DraggableCellDecorator.java

License:Apache License

/**
 * Get the HTML representation of an image. Visible for testing.
 *
 * @param res           the {@link ImageResource} to render as HTML
 * @param valign        the vertical alignment
 * @param isPlaceholder if true, do not include the background image
 * @return the rendered HTML//from  www . j  ava 2 s . co m
 */
SafeHtml getImageHtml(ImageResource res, HasVerticalAlignment.VerticalAlignmentConstant valign,
        boolean isPlaceholder) {
    // Get the HTML for the image.
    SafeHtml image;
    if (isPlaceholder) {
        image = SafeHtmlUtils.fromTrustedString("<div></div>");
    } else {
        AbstractImagePrototype proto = AbstractImagePrototype.create(res);
        image = SafeHtmlUtils.fromTrustedString(proto.getHTML());
    }

    // Create the wrapper based on the vertical alignment.
    if (HasVerticalAlignment.ALIGN_TOP == valign) {
        return template.imageWrapperTop(direction, image, dragHandlerClass);
    } else if (HasVerticalAlignment.ALIGN_BOTTOM == valign) {
        return template.imageWrapperBottom(direction, image, dragHandlerClass);
    } else {
        int halfHeight = (int) Math.round(res.getHeight() / 2.0);
        return template.imageWrapperMiddle(direction, halfHeight, image, dragHandlerClass);
    }
}

From source file:com.emitrom.ti4j.mobile.client.ui.ImageView.java

License:Apache License

/**
 * Set the image of the image view according to a blob, and then clip it
 * using a GWT image resource.//from  w  w w.  ja  v  a 2 s. com
 * 
 * @param blob
 *            The blob
 * @param resource
 *            The resource
 */
public void setImage(Blob blob, ImageResource resource) {
    setImage(blob.imageAsCropped(resource.getLeft(), resource.getTop(), resource.getHeight(),
            resource.getWidth()));
}

From source file:com.google.collide.client.util.ImageResourceUtils.java

License:Open Source License

/**
 * Applies the image resource to the specified element. The image will be
 * centered, and the height and width will be set to the height and width of
 * the image.//  w w w  .  j  a v a2s.c  o  m
 */
public static void applyImageResource(Element elem, ImageResource image) {
    applyImageResource(elem, image, "center", "center");
    elem.getStyle().setHeight(image.getHeight(), "px");
    elem.getStyle().setWidth(image.getWidth(), "px");
}

From source file:com.google.speedtracer.client.util.dom.ImageResourceElementCreator.java

License:Apache License

public static Element createElementFrom(ImageResource resource) {
    SpanElement img = DocumentExt.get().createSpanElement();
    String style = "url(" + resource.getURL() + ") no-repeat " + (-resource.getLeft() + "px ")
            + (-resource.getTop() + "px");
    img.getStyle().setProperty("background", style);
    img.getStyle().setPropertyPx("width", resource.getWidth());
    img.getStyle().setPropertyPx("height", resource.getHeight());
    img.getStyle().setDisplay(Display.INLINE_BLOCK);
    return img;//from   ww  w  . j  a  v  a2  s.  c  o  m
}

From source file:com.googlecode.mgwt.image.client.ImageConverter.java

License:Apache License

public void convert(final ImageResource resource, String color,
        final ImageConverterCallback imageConverterCallback) {

    if (color == null) {
        throw new IllegalArgumentException();
    }/*from w w  w .  j  a v a  2s.co  m*/

    if (!color.startsWith("#")) {
        throw new IllegalArgumentException();
    }

    color = maybeExpandColor(color);

    final int hexColor = Integer.parseInt(color.substring(1), 16);

    final int red = hexColor >> 16 & 0xFF;
    final int green = hexColor >> 8 & 0xFF;
    final int blue = hexColor & 0xFF;

    final int height = resource.getHeight();
    final int width = resource.getWidth();

    loadImage(resource.getSafeUri().asString(), width, height, new LoadImageCallback() {

        @Override
        public void onSuccess(ImageElement imageElement) {

            Canvas canvas = Canvas.createIfSupported();
            canvas.getElement().setPropertyInt("height", height);
            canvas.getElement().setPropertyInt("width", width);

            Context2d context = canvas.getContext2d();
            context.drawImage(imageElement, 0, 0);
            ImageData imageData = context.getImageData(0, 0, width, height);

            CanvasPixelArray canvasPixelArray = imageData.getData();

            for (int i = 0; i < canvasPixelArray.getLength(); i += 4) {
                canvasPixelArray.set(i, red);
                canvasPixelArray.set(i + 1, green);
                canvasPixelArray.set(i + 2, blue);
                canvasPixelArray.set(i + 3, canvasPixelArray.get(i + 3));
            }
            context.putImageData(imageData, 0, 0);
            imageConverterCallback.onSuccess(new ConvertedImageResource(canvas.toDataUrl("image/png"),
                    resource.getWidth(), resource.getHeight()));
        }
    });
}

From source file:com.mecatran.otp.gwt.client.view.ItineraryDetailsWidget.java

License:Open Source License

/**
 * Build the background image for the widget, according to the mode. Draw
 * the mode image and a solid line below it with the route color (if in
 * transit mode) or a dotted line (if in road mode). Set the
 * background-image to the generated image for the given widget.
 *///from w ww .  j av  a  2 s.c  o m
public static void styleComponentWithMode(final Widget widget, TransportMode mode, String color) {
    PlannerResources resources = PlannerResources.INSTANCE;
    ImageResource baseImage = null;
    boolean road = false;
    switch (mode) {
    case WALK:
        road = true;
        color = "#666666";
        baseImage = resources.modeWalkPng();
        break;
    case BICYCLE:
        road = true;
        color = "#23C30B";
        baseImage = resources.modeBicyclePng();
        break;
    case BICYCLE_RENTAL:
        road = true;
        color = "#23C30B";
        baseImage = resources.modeBikeRentalPng();
        break;
    case CAR:
        road = true;
        color = "#333333";
        baseImage = resources.modeCarPng();
        break;
    default:
    case BUS:
        baseImage = resources.modeBusPng();
        break;
    case TRAM:
        baseImage = resources.modeTramPng();
        break;
    case FERRY:
        baseImage = resources.modeFerryPng();
        break;
    case GONDOLA:
        baseImage = resources.modeGondolaPng();
        break;
    case PLANE:
        baseImage = resources.modePlanePng();
        break;
    case RAIL:
        baseImage = resources.modeRailPng();
        break;
    case SUBWAY:
        baseImage = resources.modeSubwayPng();
        break;
    case TROLLEY:
        baseImage = resources.modeTrolleyPng();
        break;
    }
    final String url = baseImage.getSafeUri().asString();
    final Canvas canvas = Canvas.createIfSupported();
    if (canvas != null) {
        int width = baseImage.getWidth();
        int height = 1000;
        canvas.setCoordinateSpaceWidth(width);
        canvas.setCoordinateSpaceHeight(height);
        final Context2d context = canvas.getContext2d();
        context.setLineCap(LineCap.BUTT);
        if (road) {
            context.setStrokeStyle(CssColor.make(color));
            context.setLineWidth(4);
            for (int y = baseImage.getHeight(); y < 1000; y += 7) {
                context.moveTo(width / 2, y);
                context.lineTo(width / 2, y + 5);
            }
            context.stroke();
        } else {
            context.setStrokeStyle(CssColor.make("#000000"));
            context.setLineWidth(5);
            context.moveTo(width / 2, 0);
            context.lineTo(width / 2, height - 1);
            context.stroke();
            context.setStrokeStyle(CssColor.make(color));
            context.setLineWidth(4);
            context.moveTo(width / 2, 0);
            context.lineTo(width / 2, height - 1);
            context.stroke();
        }
        /*
         * HACK ALERT! Image.onLoad event does not fire up when using
         * internal resources (URL is internal data), but using the image
         * immediately does not work (image does not seems to be ready). We
         * defer the processing of the image rendering to a timer delayed a
         * bit.
         */
        Timer timer = new Timer() {
            @Override
            public void run() {
                Image image = new Image(url);
                ImageElement e = ImageElement.as(image.getElement());
                context.drawImage(e, 0, 0);
                String url2 = canvas.toDataUrl("image/png");
                widget.getElement().getStyle().setBackgroundImage("url('" + url2 + "')");
            }
        };
        timer.schedule(500);
    } else {
        widget.getElement().getStyle().setBackgroundImage("url('" + url + "')");
    }
}

From source file:com.mecatran.otp.gwt.client.view.OpenLayersItinerary.java

License:Open Source License

private VectorFeature createFeatureFromMode(TransportMode mode, boolean leftish, Point position,
        double opacity) {
    ImageResource imageResource;
    switch (mode) {
    case WALK:/*from  w  w w .j ava2s  . c  o  m*/
        imageResource = leftish ? PlannerResources.INSTANCE.modemaplWalkPng()
                : PlannerResources.INSTANCE.modemaprWalkPng();
        break;
    case BICYCLE:
    case BICYCLE_RENTAL: // TODO Make dedicated icon
        imageResource = leftish ? PlannerResources.INSTANCE.modemaplBicyclePng()
                : PlannerResources.INSTANCE.modemaprBicyclePng();
        break;
    case BUS:
        imageResource = leftish ? PlannerResources.INSTANCE.modemaplBusPng()
                : PlannerResources.INSTANCE.modemaprBusPng();
        break;
    case CAR:
        imageResource = leftish ? PlannerResources.INSTANCE.modemaplCarPng()
                : PlannerResources.INSTANCE.modemaprCarPng();
        break;
    case FERRY:
        imageResource = leftish ? PlannerResources.INSTANCE.modemaplFerryPng()
                : PlannerResources.INSTANCE.modemaprFerryPng();
        break;
    case GONDOLA:
        imageResource = leftish ? PlannerResources.INSTANCE.modemaplGondolaPng()
                : PlannerResources.INSTANCE.modemaprGondolaPng();
        break;
    case PLANE:
        imageResource = leftish ? PlannerResources.INSTANCE.modemaplPlanePng()
                : PlannerResources.INSTANCE.modemaprPlanePng();
        break;
    case RAIL:
        imageResource = leftish ? PlannerResources.INSTANCE.modemaplRailPng()
                : PlannerResources.INSTANCE.modemaprRailPng();
        break;
    case SUBWAY:
        imageResource = leftish ? PlannerResources.INSTANCE.modemaplSubwayPng()
                : PlannerResources.INSTANCE.modemaprSubwayPng();
        break;
    case TRAM:
        imageResource = leftish ? PlannerResources.INSTANCE.modemaplTramPng()
                : PlannerResources.INSTANCE.modemaprTramPng();
        break;
    case TROLLEY:
        imageResource = leftish ? PlannerResources.INSTANCE.modemaplTrolleyPng()
                : PlannerResources.INSTANCE.modemaprTrolleyPng();
        break;
    default:
        return null;
    }
    Style pointStyle = new Style();
    pointStyle.setExternalGraphic(imageResource.getSafeUri().asString());
    pointStyle.setGraphicSize(imageResource.getWidth(), imageResource.getHeight());
    Pixel anchor = leftish ? new Pixel(-34, -34) : new Pixel(0, -34);
    pointStyle.setGraphicOffset(anchor.x(), anchor.y());
    pointStyle.setFillOpacity(1.0 * opacity);
    pointStyle.setStrokeOpacity(1.0 * opacity);
    VectorFeature retval = new VectorFeature(position, pointStyle);
    retval.getAttributes().setAttribute(OpenLayersPlannerMapWidget.WAYPOINT_DRAGGABLE_KEY, false);
    return retval;
}

From source file:com.mecatran.otp.gwt.client.view.OpenLayersPOILayer.java

License:Open Source License

public void updatePOIList(String sourceId, java.util.Map<String, POIBean> pois) {
    // Remove only POI coming from the same sourceId
    if (layer.getFeatures() != null) {
        for (VectorFeature feature : layer.getFeatures()) {
            String poiSource = feature.getAttributes().getAttributeAsString("sourceId");
            if (poiSource.equals(sourceId))
                layer.removeFeature(feature);
        }//from   ww w.  j  av  a2  s  . co  m
    }
    // Order POI on z-index = latitude
    List<POIBean> poiList = new ArrayList<POIBean>(pois.values());
    Collections.sort(poiList, new Comparator<POIBean>() {
        @Override
        public int compare(POIBean o1, POIBean o2) {
            double delta = o2.getLocation().getLat() - o1.getLocation().getLat();
            return delta < 0.0 ? -1 : +1;
        }
    });
    for (POIBean poi : poiList) {
        ImageResource imageResource = POIUtils.getPoiIcon(poi.getType());
        String imageUrl = imageResource.getSafeUri().asString();

        Style pointStyle = new Style();
        pointStyle.setExternalGraphic(imageUrl);
        pointStyle.setGraphicSize(imageResource.getWidth(), imageResource.getHeight());
        // HACK ALERT! Assume all POI icons the same size.
        Pixel anchor = new Pixel(-12, -30);
        pointStyle.setGraphicOffset(anchor.x(), anchor.y());
        pointStyle.setFillOpacity(1.0);
        pointStyle.setStrokeOpacity(1.0);
        LonLat position = convertLonLat(poi.getLocation());
        Point point = new Point(position.lon(), position.lat());
        VectorFeature marker = new VectorFeature(point, pointStyle);
        // TODO Set POI name as <h3>title</h3>?
        marker.getAttributes().setAttribute(OpenLayersPlannerMapWidget.POPUP_CONTENT_KEY,
                poi.getHtmlDescription());
        marker.getAttributes().setAttribute(OpenLayersPlannerMapWidget.POPUP_CLASS_KEY, "poi-popup");
        layer.addFeature(marker);
    }
    layer.setDisplayInLayerSwitcher(!poiList.isEmpty());
}

From source file:com.mecatran.otp.gwt.client.view.OpenLayersWaypoint.java

License:Open Source License

private VectorFeature createFeatureFromImageResource(ImageResource imageResource, Pixel anchor, Point position,
        double opacity) {
    Style pointStyle = new Style();
    pointStyle.setExternalGraphic(imageResource.getSafeUri().asString());
    pointStyle.setGraphicSize(imageResource.getWidth(), imageResource.getHeight());
    pointStyle.setGraphicOffset(anchor.x(), anchor.y());
    pointStyle.setFillOpacity(1.0 * opacity);
    pointStyle.setStrokeOpacity(1.0 * opacity);
    VectorFeature retval = new VectorFeature(position, pointStyle);
    return retval;
}

From source file:com.mgwt.imustlearn.client.ui.CellListWithButtons.java

License:Apache License

public void setIcons(Element element, ImageResource icon, boolean active) {
    ImageResource highlight = MGWTStyle.getTheme().getMGWTClientBundle().getButtonBarHighlightImage();

    if (icon == null)
        return;/*  www  .  j av a2  s . c  o m*/

    if (!active) {
        element.getStyle().setBackgroundImage("url(" + icon.getSafeUri().asString() + ")");

        if (MGWT.getOsDetection().isRetina() || MGWT.getOsDetection().isIPadRetina()) {
            element.getStyle().setProperty("backgroundSize",
                    (icon.getWidth() / 2) + "px " + (icon.getHeight() / 2) + "px");
        }
    } else {

        // don't set active state if we don't have a hightlight icon...
        //            if (highlight == null) {
        //                return;
        //            }

        element.getStyle().setBackgroundImage(
                "url(" + highlight.getSafeUri().asString() + "), url(" + icon.getSafeUri().asString() + ")");
        if (MGWT.getOsDetection().isRetina() || MGWT.getOsDetection().isIPadRetina()) {
            element.getStyle().setProperty("backgroundSize",
                    (highlight.getWidth()) + "px " + (highlight.getHeight()) + "px, " + (icon.getWidth() / 2)
                            + "px " + (icon.getHeight() / 2) + "px");
        }
    }

}