javaquery/canvas/src/main/java/net/java/html/canvas/LinearGradient.java
author Anton Epple <toni.epple@eppleton.de>
Fri, 24 May 2013 12:29:58 +0200
branchcanvas
changeset 1141 69c81bdaf193
parent 1132 368626597f1a
permissions -rw-r--r--
added caching to style
toni@1119
     1
/**
toni@1119
     2
 * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
toni@1119
     3
 * <jaroslav.tulach@apidesign.org>
toni@1119
     4
 *
toni@1119
     5
 * This program is free software: you can redistribute it and/or modify it under
toni@1119
     6
 * the terms of the GNU General Public License as published by the Free Software
toni@1119
     7
 * Foundation, version 2 of the License.
toni@1119
     8
 *
toni@1119
     9
 * This program is distributed in the hope that it will be useful, but WITHOUT
toni@1119
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
toni@1119
    11
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
toni@1119
    12
 * details.
toni@1119
    13
 *
toni@1119
    14
 * You should have received a copy of the GNU General Public License along with
toni@1119
    15
 * this program. Look for COPYING file in the top folder. If not, see
toni@1119
    16
 * http://opensource.org/licenses/GPL-2.0.
toni@1111
    17
 */
toni@1111
    18
package net.java.html.canvas;
toni@1111
    19
toni@1129
    20
import java.util.HashMap;
toni@1141
    21
import java.util.Objects;
toni@1129
    22
toni@1111
    23
/**
toni@1111
    24
 *
toni@1111
    25
 * @author antonepple
toni@1111
    26
 */
toni@1132
    27
public class LinearGradient extends Style {
toni@1116
    28
toni@1129
    29
    HashMap<Double,String> stops;
toni@1129
    30
    
toni@1129
    31
    double x0, y0, x1, y1;
toni@1129
    32
toni@1132
    33
    LinearGradient( double x0, double y0, double x1, double y1) {
toni@1131
    34
        this.x0 = x0;
toni@1131
    35
        this.y0 = y0;
toni@1131
    36
        this.x1 = x1;
toni@1131
    37
        this.y1 = y1;
toni@1131
    38
    }
toni@1131
    39
toni@1131
    40
    
toni@1131
    41
    
toni@1129
    42
    void addColorStop(double position, String color){
toni@1129
    43
        if (stops == null) stops = new HashMap<>();
toni@1129
    44
        stops.put(position, color);
toni@1129
    45
    }
toni@1129
    46
toni@1129
    47
    public HashMap<Double, String> getStops() {
toni@1129
    48
        return stops;
toni@1129
    49
    }
toni@1129
    50
toni@1129
    51
    public void setStops(HashMap<Double, String> stops) {
toni@1129
    52
        this.stops = stops;
toni@1129
    53
    }
toni@1129
    54
toni@1129
    55
    public double getX0() {
toni@1129
    56
        return x0;
toni@1129
    57
    }
toni@1129
    58
toni@1129
    59
    public void setX0(double x0) {
toni@1129
    60
        this.x0 = x0;
toni@1129
    61
    }
toni@1129
    62
toni@1129
    63
    public double getY0() {
toni@1129
    64
        return y0;
toni@1129
    65
    }
toni@1129
    66
toni@1129
    67
    public void setY0(double y0) {
toni@1129
    68
        this.y0 = y0;
toni@1129
    69
    }
toni@1129
    70
toni@1129
    71
    public double getX1() {
toni@1129
    72
        return x1;
toni@1129
    73
    }
toni@1129
    74
toni@1129
    75
    public void setX1(double x1) {
toni@1129
    76
        this.x1 = x1;
toni@1129
    77
    }
toni@1129
    78
toni@1129
    79
    public double getY1() {
toni@1129
    80
        return y1;
toni@1129
    81
    }
toni@1129
    82
toni@1129
    83
    public void setY1(double y1) {
toni@1129
    84
        this.y1 = y1;
toni@1129
    85
    }
toni@1141
    86
toni@1141
    87
    @Override
toni@1141
    88
    public int hashCode() {
toni@1141
    89
        int hash = 7;
toni@1141
    90
        hash = 29 * hash + Objects.hashCode(this.stops);
toni@1141
    91
        hash = 29 * hash + (int) (Double.doubleToLongBits(this.x0) ^ (Double.doubleToLongBits(this.x0) >>> 32));
toni@1141
    92
        hash = 29 * hash + (int) (Double.doubleToLongBits(this.y0) ^ (Double.doubleToLongBits(this.y0) >>> 32));
toni@1141
    93
        hash = 29 * hash + (int) (Double.doubleToLongBits(this.x1) ^ (Double.doubleToLongBits(this.x1) >>> 32));
toni@1141
    94
        hash = 29 * hash + (int) (Double.doubleToLongBits(this.y1) ^ (Double.doubleToLongBits(this.y1) >>> 32));
toni@1141
    95
        return hash;
toni@1141
    96
    }
toni@1141
    97
toni@1141
    98
    @Override
toni@1141
    99
    public boolean equals(Object obj) {
toni@1141
   100
        if (obj == null) {
toni@1141
   101
            return false;
toni@1141
   102
        }
toni@1141
   103
        if (getClass() != obj.getClass()) {
toni@1141
   104
            return false;
toni@1141
   105
        }
toni@1141
   106
        final LinearGradient other = (LinearGradient) obj;
toni@1141
   107
        if (!Objects.equals(this.stops, other.stops)) {
toni@1141
   108
            return false;
toni@1141
   109
        }
toni@1141
   110
        if (Double.doubleToLongBits(this.x0) != Double.doubleToLongBits(other.x0)) {
toni@1141
   111
            return false;
toni@1141
   112
        }
toni@1141
   113
        if (Double.doubleToLongBits(this.y0) != Double.doubleToLongBits(other.y0)) {
toni@1141
   114
            return false;
toni@1141
   115
        }
toni@1141
   116
        if (Double.doubleToLongBits(this.x1) != Double.doubleToLongBits(other.x1)) {
toni@1141
   117
            return false;
toni@1141
   118
        }
toni@1141
   119
        if (Double.doubleToLongBits(this.y1) != Double.doubleToLongBits(other.y1)) {
toni@1141
   120
            return false;
toni@1141
   121
        }
toni@1141
   122
        return true;
toni@1141
   123
    }
toni@1129
   124
    
toni@1111
   125
}