javaquery/canvas/src/main/java/net/java/html/canvas/Image.java
author Anton Epple <toni.epple@eppleton.de>
Mon, 27 May 2013 08:30:18 +0200
branchcanvas
changeset 1144 5bf850c5b7f1
child 1153 edda08aba469
permissions -rw-r--r--
Readded Image and ImageData to have the complete API again. No need to use Data in API anymore. Added caching to Image. Image are not required to be added to the page anymore, but are created in javaScript instead.
toni@1144
     1
/**
toni@1144
     2
 * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
toni@1144
     3
 * <jaroslav.tulach@apidesign.org>
toni@1144
     4
 *
toni@1144
     5
 * This program is free software: you can redistribute it and/or modify it under
toni@1144
     6
 * the terms of the GNU General Public License as published by the Free Software
toni@1144
     7
 * Foundation, version 2 of the License.
toni@1144
     8
 *
toni@1144
     9
 * This program is distributed in the hope that it will be useful, but WITHOUT
toni@1144
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
toni@1144
    11
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
toni@1144
    12
 * details.
toni@1144
    13
 *
toni@1144
    14
 * You should have received a copy of the GNU General Public License along with
toni@1144
    15
 * this program. Look for COPYING file in the top folder. If not, see
toni@1144
    16
 * http://opensource.org/licenses/GPL-2.0.
toni@1144
    17
 */
toni@1144
    18
package net.java.html.canvas;
toni@1144
    19
toni@1144
    20
import java.util.Objects;
toni@1144
    21
toni@1144
    22
/**
toni@1144
    23
 * Image represents an Image defined by a Path.
toni@1144
    24
 *
toni@1144
    25
 *
toni@1144
    26
 * @author antonepple
toni@1144
    27
 */
toni@1144
    28
public class Image {
toni@1144
    29
toni@1144
    30
    private String src;
toni@1144
    31
    private Object cached;
toni@1144
    32
    private int cacheHash;
toni@1144
    33
toni@1144
    34
    void Image(String src) {
toni@1144
    35
        this.src = src;
toni@1144
    36
    }
toni@1144
    37
toni@1144
    38
    void cache(Object toCache) {
toni@1144
    39
        cacheHash = hashCode();
toni@1144
    40
        this.cached = toCache;
toni@1144
    41
    }
toni@1144
    42
toni@1144
    43
    private boolean isCached() {
toni@1144
    44
        return cacheHash == hashCode();
toni@1144
    45
    }
toni@1144
    46
toni@1144
    47
    Object getCached() {
toni@1144
    48
        return isCached() ? cached : null;
toni@1144
    49
    }
toni@1144
    50
toni@1144
    51
    public String getSrc() {
toni@1144
    52
        return src;
toni@1144
    53
    }
toni@1144
    54
toni@1144
    55
    @Override
toni@1144
    56
    public int hashCode() {
toni@1144
    57
        int hash = 7;
toni@1144
    58
        hash = 59 * hash + Objects.hashCode(this.src);
toni@1144
    59
        return hash;
toni@1144
    60
    }
toni@1144
    61
toni@1144
    62
    @Override
toni@1144
    63
    public boolean equals(Object obj) {
toni@1144
    64
        if (obj == null) {
toni@1144
    65
            return false;
toni@1144
    66
        }
toni@1144
    67
        if (getClass() != obj.getClass()) {
toni@1144
    68
            return false;
toni@1144
    69
        }
toni@1144
    70
        final Image other = (Image) obj;
toni@1144
    71
        if (!Objects.equals(this.src, other.src)) {
toni@1144
    72
            return false;
toni@1144
    73
        }
toni@1144
    74
        return true;
toni@1144
    75
    }
toni@1144
    76
 
toni@1144
    77
}