1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/Image.java Mon May 27 08:30:18 2013 +0200
1.3 @@ -0,0 +1,77 @@
1.4 +/**
1.5 + * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
1.6 + * <jaroslav.tulach@apidesign.org>
1.7 + *
1.8 + * This program is free software: you can redistribute it and/or modify it under
1.9 + * the terms of the GNU General Public License as published by the Free Software
1.10 + * Foundation, version 2 of the License.
1.11 + *
1.12 + * This program is distributed in the hope that it will be useful, but WITHOUT
1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.14 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.15 + * details.
1.16 + *
1.17 + * You should have received a copy of the GNU General Public License along with
1.18 + * this program. Look for COPYING file in the top folder. If not, see
1.19 + * http://opensource.org/licenses/GPL-2.0.
1.20 + */
1.21 +package net.java.html.canvas;
1.22 +
1.23 +import java.util.Objects;
1.24 +
1.25 +/**
1.26 + * Image represents an Image defined by a Path.
1.27 + *
1.28 + *
1.29 + * @author antonepple
1.30 + */
1.31 +public class Image {
1.32 +
1.33 + private String src;
1.34 + private Object cached;
1.35 + private int cacheHash;
1.36 +
1.37 + void Image(String src) {
1.38 + this.src = src;
1.39 + }
1.40 +
1.41 + void cache(Object toCache) {
1.42 + cacheHash = hashCode();
1.43 + this.cached = toCache;
1.44 + }
1.45 +
1.46 + private boolean isCached() {
1.47 + return cacheHash == hashCode();
1.48 + }
1.49 +
1.50 + Object getCached() {
1.51 + return isCached() ? cached : null;
1.52 + }
1.53 +
1.54 + public String getSrc() {
1.55 + return src;
1.56 + }
1.57 +
1.58 + @Override
1.59 + public int hashCode() {
1.60 + int hash = 7;
1.61 + hash = 59 * hash + Objects.hashCode(this.src);
1.62 + return hash;
1.63 + }
1.64 +
1.65 + @Override
1.66 + public boolean equals(Object obj) {
1.67 + if (obj == null) {
1.68 + return false;
1.69 + }
1.70 + if (getClass() != obj.getClass()) {
1.71 + return false;
1.72 + }
1.73 + final Image other = (Image) obj;
1.74 + if (!Objects.equals(this.src, other.src)) {
1.75 + return false;
1.76 + }
1.77 + return true;
1.78 + }
1.79 +
1.80 +}