toni@1144: /** toni@1144: * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach toni@1144: * toni@1144: * toni@1144: * This program is free software: you can redistribute it and/or modify it under toni@1144: * the terms of the GNU General Public License as published by the Free Software toni@1144: * Foundation, version 2 of the License. toni@1144: * toni@1144: * This program is distributed in the hope that it will be useful, but WITHOUT toni@1144: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS toni@1144: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more toni@1144: * details. toni@1144: * toni@1144: * You should have received a copy of the GNU General Public License along with toni@1144: * this program. Look for COPYING file in the top folder. If not, see toni@1144: * http://opensource.org/licenses/GPL-2.0. toni@1144: */ toni@1144: package net.java.html.canvas; toni@1144: toni@1144: import java.util.Objects; toni@1144: toni@1144: /** toni@1144: * Image represents an Image defined by a Path. toni@1144: * toni@1144: * toni@1144: * @author antonepple toni@1144: */ toni@1144: public class Image { toni@1144: toni@1144: private String src; toni@1144: private Object cached; toni@1144: private int cacheHash; toni@1144: toni@1144: void Image(String src) { toni@1144: this.src = src; toni@1144: } toni@1144: toni@1144: void cache(Object toCache) { toni@1144: cacheHash = hashCode(); toni@1144: this.cached = toCache; toni@1144: } toni@1144: toni@1144: private boolean isCached() { toni@1144: return cacheHash == hashCode(); toni@1144: } toni@1144: toni@1144: Object getCached() { toni@1144: return isCached() ? cached : null; toni@1144: } toni@1144: toni@1144: public String getSrc() { toni@1144: return src; toni@1144: } toni@1144: toni@1144: @Override toni@1144: public int hashCode() { toni@1144: int hash = 7; toni@1144: hash = 59 * hash + Objects.hashCode(this.src); toni@1144: return hash; toni@1144: } toni@1144: toni@1144: @Override toni@1144: public boolean equals(Object obj) { toni@1144: if (obj == null) { toni@1144: return false; toni@1144: } toni@1144: if (getClass() != obj.getClass()) { toni@1144: return false; toni@1144: } toni@1144: final Image other = (Image) obj; toni@1144: if (!Objects.equals(this.src, other.src)) { toni@1144: return false; toni@1144: } toni@1144: return true; toni@1144: } toni@1144: toni@1144: }