All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.googlecode.gwt.test.internal.patchers.ImagePatcher Maven / Gradle / Ivy

There is a newer version: 0.63
Show newest version
package com.googlecode.gwt.test.internal.patchers;

import com.google.gwt.dom.client.ImageElement;
import com.google.gwt.user.client.ui.Image;
import com.googlecode.gwt.test.patchers.PatchClass;
import com.googlecode.gwt.test.patchers.PatchMethod;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

@PatchClass(Image.class)
class ImagePatcher {

    private static final Pattern PATTERN = Pattern.compile("^(\\d+).*$");

    @PatchMethod
    static int getHeight(Image image) {
        return getDim(image, "height");
    }

    @PatchMethod
    static int getWidth(Image image) {
        return getDim(image, "width");
    }

    private static int getDim(Image image, String dim) {
        ImageElement elem = image.getElement().cast();
        String width = elem.getStyle().getProperty(dim);
        if (width == null) {
            return 0;
        }
        Matcher m = PATTERN.matcher(width);
        if (m.matches()) {
            return Integer.parseInt(m.group(1));
        }
        return 0;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy