Grouped Style subclasses as static inner classes of Style canvas
authorAnton Epple <toni.epple@eppleton.de>
Mon, 27 May 2013 10:18:43 +0200
branchcanvas
changeset 115042e29ceb8371
parent 1149 78c3cdffe719
child 1151 d6047ef47a68
Grouped Style subclasses as static inner classes of Style
javaquery/canvas/src/main/java/net/java/html/canvas/Color.java
javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java
javaquery/canvas/src/main/java/net/java/html/canvas/LinearGradient.java
javaquery/canvas/src/main/java/net/java/html/canvas/Pattern.java
javaquery/canvas/src/main/java/net/java/html/canvas/RadialGradient.java
javaquery/canvas/src/main/java/net/java/html/canvas/Style.java
     1.1 --- a/javaquery/canvas/src/main/java/net/java/html/canvas/Color.java	Mon May 27 10:04:39 2013 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,27 +0,0 @@
     1.4 -/*
     1.5 - * To change this template, choose Tools | Templates
     1.6 - * and open the template in the editor.
     1.7 - */
     1.8 -package net.java.html.canvas;
     1.9 -
    1.10 -/**
    1.11 - *
    1.12 - * @author antonepple
    1.13 - */
    1.14 -public class Color extends Style{
    1.15 -    
    1.16 -    String web;
    1.17 -
    1.18 -    /**
    1.19 -     * Creates an RGB color specified with an HTML or CSS attribute string.
    1.20 -     * @param webColor Colordefined as 
    1.21 -     */
    1.22 -    Color(String webColor) {
    1.23 -        this.web = web;
    1.24 -    }
    1.25 -    
    1.26 -    public String getAsString(){
    1.27 -        return web;
    1.28 -    }
    1.29 -    
    1.30 -}
     2.1 --- a/javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java	Mon May 27 10:04:39 2013 +0200
     2.2 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java	Mon May 27 10:18:43 2013 +0200
     2.3 @@ -17,6 +17,10 @@
     2.4   */
     2.5  package net.java.html.canvas;
     2.6  
     2.7 +import net.java.html.canvas.Style.Color;
     2.8 +import net.java.html.canvas.Style.LinearGradient;
     2.9 +import net.java.html.canvas.Style.Pattern;
    2.10 +import net.java.html.canvas.Style.RadialGradient;
    2.11  import net.java.html.canvas.spi.GraphicsEnvironment;
    2.12  
    2.13  /**
    2.14 @@ -302,7 +306,7 @@
    2.15      }
    2.16  
    2.17      public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1){
    2.18 -        return new LinearGradient(x0, y0, x1, y1);
    2.19 +        return new Style.LinearGradient(x0, y0, x1, y1);
    2.20      }
    2.21  
    2.22      public Pattern createPattern(Image image, String repeat){
    2.23 @@ -312,6 +316,10 @@
    2.24      public RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1){
    2.25          return new RadialGradient(x0, y0, r0, x1, y1, r1);
    2.26      }
    2.27 +    
    2.28 +    public Color getWebColor(String webColor){
    2.29 +        return new Style.Color(webColor);
    2.30 +    }
    2.31  
    2.32      public Image getImageForPath(String path){
    2.33          return graphicsEnvironmentImpl.getImageForPath(path);
     3.1 --- a/javaquery/canvas/src/main/java/net/java/html/canvas/LinearGradient.java	Mon May 27 10:04:39 2013 +0200
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,125 +0,0 @@
     3.4 -/**
     3.5 - * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
     3.6 - * <jaroslav.tulach@apidesign.org>
     3.7 - *
     3.8 - * This program is free software: you can redistribute it and/or modify it under
     3.9 - * the terms of the GNU General Public License as published by the Free Software
    3.10 - * Foundation, version 2 of the License.
    3.11 - *
    3.12 - * This program is distributed in the hope that it will be useful, but WITHOUT
    3.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    3.14 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    3.15 - * details.
    3.16 - *
    3.17 - * You should have received a copy of the GNU General Public License along with
    3.18 - * this program. Look for COPYING file in the top folder. If not, see
    3.19 - * http://opensource.org/licenses/GPL-2.0.
    3.20 - */
    3.21 -package net.java.html.canvas;
    3.22 -
    3.23 -import java.util.HashMap;
    3.24 -import java.util.Objects;
    3.25 -
    3.26 -/**
    3.27 - *
    3.28 - * @author antonepple
    3.29 - */
    3.30 -public class LinearGradient extends Style {
    3.31 -
    3.32 -    HashMap<Double,String> stops;
    3.33 -    
    3.34 -    double x0, y0, x1, y1;
    3.35 -
    3.36 -    LinearGradient( double x0, double y0, double x1, double y1) {
    3.37 -        this.x0 = x0;
    3.38 -        this.y0 = y0;
    3.39 -        this.x1 = x1;
    3.40 -        this.y1 = y1;
    3.41 -    }
    3.42 -
    3.43 -    
    3.44 -    
    3.45 -    void addColorStop(double position, String color){
    3.46 -        if (stops == null) stops = new HashMap<>();
    3.47 -        stops.put(position, color);
    3.48 -    }
    3.49 -
    3.50 -    public HashMap<Double, String> getStops() {
    3.51 -        return stops;
    3.52 -    }
    3.53 -
    3.54 -    public void setStops(HashMap<Double, String> stops) {
    3.55 -        this.stops = stops;
    3.56 -    }
    3.57 -
    3.58 -    public double getX0() {
    3.59 -        return x0;
    3.60 -    }
    3.61 -
    3.62 -    public void setX0(double x0) {
    3.63 -        this.x0 = x0;
    3.64 -    }
    3.65 -
    3.66 -    public double getY0() {
    3.67 -        return y0;
    3.68 -    }
    3.69 -
    3.70 -    public void setY0(double y0) {
    3.71 -        this.y0 = y0;
    3.72 -    }
    3.73 -
    3.74 -    public double getX1() {
    3.75 -        return x1;
    3.76 -    }
    3.77 -
    3.78 -    public void setX1(double x1) {
    3.79 -        this.x1 = x1;
    3.80 -    }
    3.81 -
    3.82 -    public double getY1() {
    3.83 -        return y1;
    3.84 -    }
    3.85 -
    3.86 -    public void setY1(double y1) {
    3.87 -        this.y1 = y1;
    3.88 -    }
    3.89 -
    3.90 -    @Override
    3.91 -    public int hashCode() {
    3.92 -        int hash = 7;
    3.93 -        hash = 29 * hash + Objects.hashCode(this.stops);
    3.94 -        hash = 29 * hash + (int) (Double.doubleToLongBits(this.x0) ^ (Double.doubleToLongBits(this.x0) >>> 32));
    3.95 -        hash = 29 * hash + (int) (Double.doubleToLongBits(this.y0) ^ (Double.doubleToLongBits(this.y0) >>> 32));
    3.96 -        hash = 29 * hash + (int) (Double.doubleToLongBits(this.x1) ^ (Double.doubleToLongBits(this.x1) >>> 32));
    3.97 -        hash = 29 * hash + (int) (Double.doubleToLongBits(this.y1) ^ (Double.doubleToLongBits(this.y1) >>> 32));
    3.98 -        return hash;
    3.99 -    }
   3.100 -
   3.101 -    @Override
   3.102 -    public boolean equals(Object obj) {
   3.103 -        if (obj == null) {
   3.104 -            return false;
   3.105 -        }
   3.106 -        if (getClass() != obj.getClass()) {
   3.107 -            return false;
   3.108 -        }
   3.109 -        final LinearGradient other = (LinearGradient) obj;
   3.110 -        if (!Objects.equals(this.stops, other.stops)) {
   3.111 -            return false;
   3.112 -        }
   3.113 -        if (Double.doubleToLongBits(this.x0) != Double.doubleToLongBits(other.x0)) {
   3.114 -            return false;
   3.115 -        }
   3.116 -        if (Double.doubleToLongBits(this.y0) != Double.doubleToLongBits(other.y0)) {
   3.117 -            return false;
   3.118 -        }
   3.119 -        if (Double.doubleToLongBits(this.x1) != Double.doubleToLongBits(other.x1)) {
   3.120 -            return false;
   3.121 -        }
   3.122 -        if (Double.doubleToLongBits(this.y1) != Double.doubleToLongBits(other.y1)) {
   3.123 -            return false;
   3.124 -        }
   3.125 -        return true;
   3.126 -    }
   3.127 -    
   3.128 -}
     4.1 --- a/javaquery/canvas/src/main/java/net/java/html/canvas/Pattern.java	Mon May 27 10:04:39 2013 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,52 +0,0 @@
     4.4 -/**
     4.5 - * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
     4.6 - * <jaroslav.tulach@apidesign.org>
     4.7 - *
     4.8 - * This program is free software: you can redistribute it and/or modify it under
     4.9 - * the terms of the GNU General Public License as published by the Free Software
    4.10 - * Foundation, version 2 of the License.
    4.11 - *
    4.12 - * This program is distributed in the hope that it will be useful, but WITHOUT
    4.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    4.14 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    4.15 - * details.
    4.16 - *
    4.17 - * You should have received a copy of the GNU General Public License along with
    4.18 - * this program. Look for COPYING file in the top folder. If not, see
    4.19 - * http://opensource.org/licenses/GPL-2.0.
    4.20 - */
    4.21 -package net.java.html.canvas;
    4.22 -
    4.23 -/**
    4.24 - *
    4.25 - * @author antonepple
    4.26 - */
    4.27 - public final class Pattern extends Style{
    4.28 -    
    4.29 -    Image imageResource; 
    4.30 -    String repeat;
    4.31 -
    4.32 -    Pattern(Image imageResource, String repeat) {
    4.33 -        this.imageResource = imageResource;
    4.34 -        this.repeat = repeat;
    4.35 -    }
    4.36 -    
    4.37 -    public Image getImageResource() {
    4.38 -        return imageResource;
    4.39 -    }
    4.40 -
    4.41 -    public void setImageResource(Image imageResource) {
    4.42 -        this.imageResource = imageResource;
    4.43 -    }
    4.44 -
    4.45 -    public String getRepeat() {
    4.46 -        return repeat;
    4.47 -    }
    4.48 -
    4.49 -    public void setRepeat(String repeat) {
    4.50 -        this.repeat = repeat;
    4.51 -    }
    4.52 -    
    4.53 -    
    4.54 -    
    4.55 -}
     5.1 --- a/javaquery/canvas/src/main/java/net/java/html/canvas/RadialGradient.java	Mon May 27 10:04:39 2013 +0200
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,80 +0,0 @@
     5.4 -/**
     5.5 - * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
     5.6 - * <jaroslav.tulach@apidesign.org>
     5.7 - *
     5.8 - * This program is free software: you can redistribute it and/or modify it under
     5.9 - * the terms of the GNU General Public License as published by the Free Software
    5.10 - * Foundation, version 2 of the License.
    5.11 - *
    5.12 - * This program is distributed in the hope that it will be useful, but WITHOUT
    5.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    5.14 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    5.15 - * details.
    5.16 - *
    5.17 - * You should have received a copy of the GNU General Public License along with
    5.18 - * this program. Look for COPYING file in the top folder. If not, see
    5.19 - * http://opensource.org/licenses/GPL-2.0.
    5.20 - */
    5.21 -package net.java.html.canvas;
    5.22 -
    5.23 -/**
    5.24 - *
    5.25 - * @author antonepple
    5.26 - */
    5.27 -public final class RadialGradient extends LinearGradient {
    5.28 -
    5.29 -    
    5.30 -    private double r0, r1;
    5.31 -
    5.32 -    RadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
    5.33 -        super(x0, y0, x1, y1);
    5.34 -        this.r0 = r0;
    5.35 -        this.r1 = r1;
    5.36 -    }
    5.37 -
    5.38 -    public double getR0() {
    5.39 -        return r0;
    5.40 -    }
    5.41 -
    5.42 -    public void setR0(double r0) {
    5.43 -        this.r0 = r0;
    5.44 -    }
    5.45 -
    5.46 -    public double getR1() {
    5.47 -        return r1;
    5.48 -    }
    5.49 -
    5.50 -    public void setR1(double r1) {
    5.51 -        this.r1 = r1;
    5.52 -    }
    5.53 -
    5.54 -    @Override
    5.55 -    public int hashCode() {
    5.56 -        int hash = super.hashCode();
    5.57 -        hash = 17 * hash + (int) (Double.doubleToLongBits(this.r0) ^ (Double.doubleToLongBits(this.r0) >>> 32));
    5.58 -        hash = 17 * hash + (int) (Double.doubleToLongBits(this.r1) ^ (Double.doubleToLongBits(this.r1) >>> 32));
    5.59 -
    5.60 -        return hash;
    5.61 -    }
    5.62 -
    5.63 -    @Override
    5.64 -    public boolean equals(Object obj) {
    5.65 -        if (obj == null) {
    5.66 -            return false;
    5.67 -        }
    5.68 -        if (getClass() != obj.getClass()) {
    5.69 -            return false;
    5.70 -        }
    5.71 -        if (!super.equals(obj)) {
    5.72 -            return false;
    5.73 -        }
    5.74 -        final RadialGradient other = (RadialGradient) obj;
    5.75 -        if (Double.doubleToLongBits(this.r0) != Double.doubleToLongBits(other.r0)) {
    5.76 -            return false;
    5.77 -        }
    5.78 -        if (Double.doubleToLongBits(this.r1) != Double.doubleToLongBits(other.r1)) {
    5.79 -            return false;
    5.80 -        }
    5.81 -        return true;
    5.82 -    }
    5.83 -}
     6.1 --- a/javaquery/canvas/src/main/java/net/java/html/canvas/Style.java	Mon May 27 10:04:39 2013 +0200
     6.2 +++ b/javaquery/canvas/src/main/java/net/java/html/canvas/Style.java	Mon May 27 10:18:43 2013 +0200
     6.3 @@ -17,6 +17,9 @@
     6.4   */
     6.5  package net.java.html.canvas;
     6.6  
     6.7 +import java.util.HashMap;
     6.8 +import java.util.Objects;
     6.9 +
    6.10  /**
    6.11   *
    6.12   * @author antonepple
    6.13 @@ -29,19 +32,19 @@
    6.14      Style() {
    6.15      }
    6.16  
    6.17 -    public static final RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
    6.18 +    static final RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
    6.19          return new RadialGradient(x0, y0, r0, x1, y1, r1);
    6.20      }
    6.21  
    6.22 -    public static final LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) {
    6.23 +    static final LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) {
    6.24          return new LinearGradient(x0, y0, x1, y1);
    6.25      }
    6.26  
    6.27 -    public static final Pattern createPattern(Image imageResource, String repeat) {
    6.28 +    static final Pattern createPattern(Image imageResource, String repeat) {
    6.29          return new Pattern(imageResource, repeat);
    6.30      }
    6.31  
    6.32 -    public static final Color createColor(String webColor) {
    6.33 +    static final Color getWebColor(String webColor) {
    6.34          return new Color(webColor);
    6.35      }
    6.36  
    6.37 @@ -57,4 +60,204 @@
    6.38      Object getCached() {
    6.39          return isCached() ? cached : null;
    6.40      }
    6.41 +
    6.42 +    public static final class Pattern extends Style {
    6.43 +
    6.44 +        private Image imageResource;
    6.45 +        private String repeat;
    6.46 +
    6.47 +        Pattern(Image imageResource, String repeat) {
    6.48 +            this.imageResource = imageResource;
    6.49 +            this.repeat = repeat;
    6.50 +        }
    6.51 +
    6.52 +        public Image getImageResource() {
    6.53 +            return imageResource;
    6.54 +        }
    6.55 +
    6.56 +        public void setImageResource(Image imageResource) {
    6.57 +            this.imageResource = imageResource;
    6.58 +        }
    6.59 +
    6.60 +        public String getRepeat() {
    6.61 +            return repeat;
    6.62 +        }
    6.63 +
    6.64 +        public void setRepeat(String repeat) {
    6.65 +            this.repeat = repeat;
    6.66 +        }
    6.67 +    }
    6.68 +
    6.69 +    public static final class Color extends Style {
    6.70 +
    6.71 +        private String web;
    6.72 +
    6.73 +        /**
    6.74 +         * Creates an RGB color specified with an HTML or CSS attribute string.
    6.75 +         *
    6.76 +         * @param webColor Colordefined as
    6.77 +         */
    6.78 +        Color(String webColor) {
    6.79 +            this.web = web;
    6.80 +        }
    6.81 +
    6.82 +        public String getAsString() {
    6.83 +            return web;
    6.84 +        }
    6.85 +    }
    6.86 +
    6.87 +    public static class LinearGradient extends Style {
    6.88 +
    6.89 +        private HashMap<Double, String> stops;
    6.90 +        private double x0, y0, x1, y1;
    6.91 +
    6.92 +        LinearGradient(double x0, double y0, double x1, double y1) {
    6.93 +            this.x0 = x0;
    6.94 +            this.y0 = y0;
    6.95 +            this.x1 = x1;
    6.96 +            this.y1 = y1;
    6.97 +        }
    6.98 +
    6.99 +        void addColorStop(double position, String color) {
   6.100 +            if (stops == null) {
   6.101 +                stops = new HashMap<>();
   6.102 +            }
   6.103 +            stops.put(position, color);
   6.104 +        }
   6.105 +
   6.106 +        public HashMap<Double, String> getStops() {
   6.107 +            return stops;
   6.108 +        }
   6.109 +
   6.110 +        public void setStops(HashMap<Double, String> stops) {
   6.111 +            this.stops = stops;
   6.112 +        }
   6.113 +
   6.114 +        public double getX0() {
   6.115 +            return x0;
   6.116 +        }
   6.117 +
   6.118 +        public void setX0(double x0) {
   6.119 +            this.x0 = x0;
   6.120 +        }
   6.121 +
   6.122 +        public double getY0() {
   6.123 +            return y0;
   6.124 +        }
   6.125 +
   6.126 +        public void setY0(double y0) {
   6.127 +            this.y0 = y0;
   6.128 +        }
   6.129 +
   6.130 +        public double getX1() {
   6.131 +            return x1;
   6.132 +        }
   6.133 +
   6.134 +        public void setX1(double x1) {
   6.135 +            this.x1 = x1;
   6.136 +        }
   6.137 +
   6.138 +        public double getY1() {
   6.139 +            return y1;
   6.140 +        }
   6.141 +
   6.142 +        public void setY1(double y1) {
   6.143 +            this.y1 = y1;
   6.144 +        }
   6.145 +
   6.146 +        @Override
   6.147 +        public int hashCode() {
   6.148 +            int hash = 7;
   6.149 +            hash = 29 * hash + Objects.hashCode(this.stops);
   6.150 +            hash = 29 * hash + (int) (Double.doubleToLongBits(this.x0) ^ (Double.doubleToLongBits(this.x0) >>> 32));
   6.151 +            hash = 29 * hash + (int) (Double.doubleToLongBits(this.y0) ^ (Double.doubleToLongBits(this.y0) >>> 32));
   6.152 +            hash = 29 * hash + (int) (Double.doubleToLongBits(this.x1) ^ (Double.doubleToLongBits(this.x1) >>> 32));
   6.153 +            hash = 29 * hash + (int) (Double.doubleToLongBits(this.y1) ^ (Double.doubleToLongBits(this.y1) >>> 32));
   6.154 +            return hash;
   6.155 +        }
   6.156 +
   6.157 +        @Override
   6.158 +        public boolean equals(Object obj) {
   6.159 +            if (obj == null) {
   6.160 +                return false;
   6.161 +            }
   6.162 +            if (getClass() != obj.getClass()) {
   6.163 +                return false;
   6.164 +            }
   6.165 +            final LinearGradient other = (LinearGradient) obj;
   6.166 +            if (!Objects.equals(this.stops, other.stops)) {
   6.167 +                return false;
   6.168 +            }
   6.169 +            if (Double.doubleToLongBits(this.x0) != Double.doubleToLongBits(other.x0)) {
   6.170 +                return false;
   6.171 +            }
   6.172 +            if (Double.doubleToLongBits(this.y0) != Double.doubleToLongBits(other.y0)) {
   6.173 +                return false;
   6.174 +            }
   6.175 +            if (Double.doubleToLongBits(this.x1) != Double.doubleToLongBits(other.x1)) {
   6.176 +                return false;
   6.177 +            }
   6.178 +            if (Double.doubleToLongBits(this.y1) != Double.doubleToLongBits(other.y1)) {
   6.179 +                return false;
   6.180 +            }
   6.181 +            return true;
   6.182 +        }
   6.183 +    }
   6.184 +
   6.185 +    public static final class RadialGradient extends LinearGradient {
   6.186 +
   6.187 +        private double r0, r1;
   6.188 +
   6.189 +        RadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
   6.190 +            super(x0, y0, x1, y1);
   6.191 +            this.r0 = r0;
   6.192 +            this.r1 = r1;
   6.193 +        }
   6.194 +
   6.195 +        public double getR0() {
   6.196 +            return r0;
   6.197 +        }
   6.198 +
   6.199 +        public void setR0(double r0) {
   6.200 +            this.r0 = r0;
   6.201 +        }
   6.202 +
   6.203 +        public double getR1() {
   6.204 +            return r1;
   6.205 +        }
   6.206 +
   6.207 +        public void setR1(double r1) {
   6.208 +            this.r1 = r1;
   6.209 +        }
   6.210 +
   6.211 +        @Override
   6.212 +        public int hashCode() {
   6.213 +            int hash = super.hashCode();
   6.214 +            hash = 17 * hash + (int) (Double.doubleToLongBits(this.r0) ^ (Double.doubleToLongBits(this.r0) >>> 32));
   6.215 +            hash = 17 * hash + (int) (Double.doubleToLongBits(this.r1) ^ (Double.doubleToLongBits(this.r1) >>> 32));
   6.216 +
   6.217 +            return hash;
   6.218 +        }
   6.219 +
   6.220 +        @Override
   6.221 +        public boolean equals(Object obj) {
   6.222 +            if (obj == null) {
   6.223 +                return false;
   6.224 +            }
   6.225 +            if (getClass() != obj.getClass()) {
   6.226 +                return false;
   6.227 +            }
   6.228 +            if (!super.equals(obj)) {
   6.229 +                return false;
   6.230 +            }
   6.231 +            final RadialGradient other = (RadialGradient) obj;
   6.232 +            if (Double.doubleToLongBits(this.r0) != Double.doubleToLongBits(other.r0)) {
   6.233 +                return false;
   6.234 +            }
   6.235 +            if (Double.doubleToLongBits(this.r1) != Double.doubleToLongBits(other.r1)) {
   6.236 +                return false;
   6.237 +            }
   6.238 +            return true;
   6.239 +        }
   6.240 +    }
   6.241  }