javaquery/canvas/src/main/java/net/java/html/canvas/Style.java
author Anton Epple <toni.epple@eppleton.de>
Fri, 24 May 2013 12:29:58 +0200
branchcanvas
changeset 1141 69c81bdaf193
parent 1136 591d06d8e06f
child 1144 5bf850c5b7f1
permissions -rw-r--r--
added caching to style
toni@1129
     1
/**
toni@1129
     2
 * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
toni@1129
     3
 * <jaroslav.tulach@apidesign.org>
toni@1129
     4
 *
toni@1129
     5
 * This program is free software: you can redistribute it and/or modify it under
toni@1129
     6
 * the terms of the GNU General Public License as published by the Free Software
toni@1129
     7
 * Foundation, version 2 of the License.
toni@1129
     8
 *
toni@1129
     9
 * This program is distributed in the hope that it will be useful, but WITHOUT
toni@1129
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
toni@1129
    11
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
toni@1129
    12
 * details.
toni@1129
    13
 *
toni@1129
    14
 * You should have received a copy of the GNU General Public License along with
toni@1129
    15
 * this program. Look for COPYING file in the top folder. If not, see
toni@1129
    16
 * http://opensource.org/licenses/GPL-2.0.
toni@1129
    17
 */
toni@1129
    18
package net.java.html.canvas;
toni@1129
    19
toni@1129
    20
/**
toni@1129
    21
 *
toni@1129
    22
 * @author antonepple
toni@1129
    23
 */
toni@1132
    24
public class Style {
toni@1132
    25
toni@1141
    26
    private Object cached;
toni@1141
    27
    private int cacheHash;
toni@1141
    28
toni@1132
    29
    Style() {
toni@1132
    30
    }
toni@1141
    31
toni@1141
    32
    public static final RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
toni@1132
    33
        return new RadialGradient(x0, y0, r0, x1, y1, r1);
toni@1132
    34
    }
toni@1141
    35
toni@1141
    36
    public static final LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) {
toni@1132
    37
        return new LinearGradient(x0, y0, x1, y1);
toni@1132
    38
    }
toni@1141
    39
toni@1141
    40
    public static final Pattern createPattern(ImageData imageData, String repeat) {
toni@1132
    41
        return new Pattern(imageData, repeat);
toni@1132
    42
    }
toni@1141
    43
toni@1141
    44
    void cache(Object toCache) {
toni@1141
    45
        cacheHash = hashCode();
toni@1141
    46
        this.cached = toCache;
toni@1141
    47
    }
toni@1141
    48
toni@1141
    49
    private boolean isCached() {
toni@1141
    50
        return cacheHash == hashCode();
toni@1141
    51
    }
toni@1141
    52
toni@1141
    53
    Object getCached() {
toni@1141
    54
        return isCached() ? cached : null;
toni@1141
    55
    }
toni@1129
    56
}