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