diff -r 633572e14095 -r 088331d4cb76 javaquery/canvas/src/main/java/net/java/html/canvas/Image.java --- a/javaquery/canvas/src/main/java/net/java/html/canvas/Image.java Mon May 27 14:13:01 2013 +0200 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/Image.java Sat Sep 07 18:25:09 2013 +0200 @@ -18,6 +18,8 @@ package net.java.html.canvas; import java.util.Objects; +import java.util.ServiceLoader; +import net.java.html.canvas.spi.GraphicsEnvironment; /** * Image represents an Image Resource defined by a path. @@ -30,13 +32,17 @@ private Object cached; private int cacheHash; - Image(String src) { + public static Image create(String src) { + return new Image(src); + } + + private Image(String src) { this.src = src; } void cache(Object toCache) { + this.cached = toCache; cacheHash = hashCode(); - this.cached = toCache; } private boolean isCached() { @@ -51,10 +57,30 @@ return src; } + public int getWidth() { + ServiceLoader loader = ServiceLoader.load(GraphicsEnvironment.class); + GraphicsEnvironment ge = null; + for (GraphicsEnvironment graphicsEnvironment : loader) { + ge = graphicsEnvironment; + break; + } + return ge.getWidth(this, cached); + } + + public int getHeight() { + ServiceLoader loader = ServiceLoader.load(GraphicsEnvironment.class); + GraphicsEnvironment ge = null; + for (GraphicsEnvironment graphicsEnvironment : loader) { + ge = graphicsEnvironment; + break; + } + return ge.getHeight(this, cached); + } + @Override public int hashCode() { int hash = 7; - hash = 59 * hash + Objects.hashCode(this.src) ^ (cached==null? 1231 : 1237); + hash = 59 * hash + Objects.hashCode(this.src) ^ (cached == null ? 1231 : 1237); return hash; } @@ -70,10 +96,9 @@ if (!Objects.equals(this.src, other.src)) { return false; } - if ((cached==null) != (other.getCached()==null)){ + if ((cached == null) != (other.getCached() == null)) { return false; } return true; } - }