List of usage examples for com.google.gwt.resources.client ImageResource getWidth
int getWidth();
From source file:app.dnd.drag.DraggableCellDecorator.java
License:Apache License
/** * Construct a new {@link IconCellDecorator}. * * @param dragSource - drag source//from ww w .j ava2 s .c om * @param dragController - drag controller * @param dndResources dndResources * @param cell the cell to decorate * @param valign the vertical alignment attribute of the contents * @param spacing the pixel space between the icon and the cell */ public DraggableCellDecorator(DragSource dragSource, DragController dragController, DNDResources dndResources, Cell<C> cell, HasVerticalAlignment.VerticalAlignmentConstant valign, int spacing) { this.dragSource = dragSource; this.dragController = dragController; if (template == null) { template = GWT.create(Template.class); } this.cell = cell; this.dragHandlerClass = dndResources.css().dragHandler(); ImageResource icon = dndResources.images().dragHandle(); this.iconHtml = getImageHtml(icon, valign, false); this.imageWidth = icon.getWidth() + spacing; this.placeHolderHtml = getImageHtml(icon, valign, true); }
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.// w w w . ja v a 2 s.c om * * @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.ui.list.BasicListItemRenderer.java
License:Open Source License
@Override public void render(Element listItemBase, M item) { if (icons != null) { ImageResource icon = findIcon(item); int padding = defaultPadding; if (icon != null) { ImageResourceUtils.applyImageResource(listItemBase, icon, IMAGE_PADDING_LEFT_PX + "px", "center"); padding = IMAGE_PADDING_LEFT_PX + icon.getWidth() + IMAGE_PADDING_RIGHT_PX; }/* w w w.ja v a 2 s. c o m*/ // By breaking this up we can avoid overriding the listItems hover state listItemBase.getStyle().setPaddingLeft(padding, CSSStyleDeclaration.Unit.PX); } listItemBase.setTextContent(item.toString()); }
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 ww . j av a2 s. c om*/ */ 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 a 2s . 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 ww. ja va 2 s . c o 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 w w . j a v a2 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://w w w . j av a 2 s . co 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); }//w w w. j a v a 2 s . c om } // 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; }