More JavaDoc improvements.
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package net.java.html.canvas;
20 import java.util.Objects;
21 import java.util.ServiceLoader;
22 import net.java.html.canvas.spi.GraphicsEnvironment;
25 * Image represents an Image Resource defined by a path.
29 public final class Image {
32 private int cacheHash;
33 private Object cached;
35 /** Creates a new image referencing a specified URL.
36 * @param src the (relative) URL to the image
37 * @return an object representing the image
39 public static Image create(String src) {
40 return new Image(src);
43 private Image(String src) {
47 void cache(Object toCache) {
48 this.cached = toCache;
49 cacheHash = hashCode();
52 private boolean isCached() {
53 return cacheHash == hashCode();
57 return isCached() ? cached : null;
60 public String getSrc() {
65 * get the width of this Image. Might be an expensive operation, depending on the
66 * GraphicsEnvironment, it might need to be rendered.
67 * @return the width of this Image.
69 public int getWidth() {
70 ServiceLoader<GraphicsEnvironment> loader = ServiceLoader.load(GraphicsEnvironment.class);
71 GraphicsEnvironment ge = null;
72 for (GraphicsEnvironment graphicsEnvironment : loader) {
73 ge = graphicsEnvironment;
76 return ge.getWidth(this, cached);
80 * get the height of this Image. Might be an expensive operation, depending on the
81 * GraphicsEnvironment, it might need to be rendered.
82 * @return the height of this Image.
84 public int getHeight() {
85 ServiceLoader<GraphicsEnvironment> loader = ServiceLoader.load(GraphicsEnvironment.class);
86 GraphicsEnvironment ge = null;
87 for (GraphicsEnvironment graphicsEnvironment : loader) {
88 ge = graphicsEnvironment;
91 return ge.getHeight(this, cached);
95 public int hashCode() {
97 hash = 59 * hash + Objects.hashCode(this.src) ^ (cached == null ? 1231 : 1237);
102 public boolean equals(Object obj) {
106 if (getClass() != obj.getClass()) {
109 final Image other = (Image) obj;
110 if (!Objects.equals(this.src, other.src)) {
113 if ((cached == null) != (other.getCached() == null)) {