]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/svg/FillDesc.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / svg / FillDesc.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.g2d.svg;\r
13 \r
14 //import static org.apache.batik.util.SVGConstants.SVG_NONE_VALUE;\r
15 //\r
16 //import org.apache.batik.util.CSSConstants;\r
17 \r
18 /**\r
19  * @author Tuukka Lehtonen\r
20  */\r
21 public class FillDesc {\r
22 \r
23 //    public static final FillDesc NO_FILL = new FillDesc(SVG_NONE_VALUE) {\r
24 //        @Override\r
25 //        public String toStyleString() {\r
26 //            return "fill:none;";\r
27 //        }\r
28 //        @Override\r
29 //        public void setFillRule(FillRule rule) {\r
30 //            throw new UnsupportedOperationException("immutable object");\r
31 //        }\r
32 //        @Override\r
33 //        public void setOpacity(double opacity) {\r
34 //            throw new UnsupportedOperationException("immutable object");\r
35 //        }\r
36 //        @Override\r
37 //        public void setPaint(String paint) {\r
38 //            throw new UnsupportedOperationException("immutable object");\r
39 //        }\r
40 //    };\r
41 \r
42 \r
43     //private static final String[] ruleConv      = { "nonzero", "evenodd" };\r
44 \r
45     /**\r
46      * paint | inherit\r
47      */\r
48     private String paint;\r
49 \r
50     /**\r
51      * [0,1] | "inherit"\r
52      */\r
53     private double opacity;\r
54 \r
55     /**\r
56      * nonzero | evenodd | inherit\r
57      */\r
58     private FillRule fillRule;\r
59 \r
60     \r
61     public FillDesc() {\r
62         this(StyleConstants.INHERIT, 1, FillRule.nonzero);\r
63     }\r
64     \r
65     public FillDesc(String paint) {\r
66         this(paint, 1, FillRule.nonzero);\r
67     }\r
68     \r
69     public FillDesc(String paint, double opacity) {\r
70         this(paint, opacity, FillRule.nonzero);\r
71     }\r
72     \r
73     public FillDesc(String paint, double opacity, FillRule fillRule) {\r
74         this.paint = paint;\r
75         this.opacity = opacity;\r
76         this.fillRule = fillRule != null ? fillRule : FillRule.nonzero;\r
77     }\r
78 \r
79     public String getPaint() {\r
80         return paint;\r
81     }\r
82     \r
83     public void setPaint(String paint) {\r
84         this.paint = paint;\r
85     }\r
86     \r
87     public double getOpacity() {\r
88         return opacity;\r
89     }\r
90     \r
91     public void setOpacity(double opacity) {\r
92         this.opacity = opacity;\r
93     }\r
94     \r
95     public FillRule getFillRule() {\r
96         return fillRule;\r
97     }\r
98     \r
99     public void setFillRule(FillRule rule) {\r
100         this.fillRule = rule;\r
101     }\r
102     \r
103     /**\r
104      * Returns the hashcode for this stroke.\r
105      * \r
106      * @return a hash code for this stroke.\r
107      */\r
108     public int hashCode() {\r
109         int hash = paint.hashCode();\r
110         hash = hash * 31 + (int) Double.doubleToLongBits(opacity);\r
111         hash = hash * 31 + fillRule.hashCode();\r
112         return hash;\r
113     }\r
114 \r
115     /**\r
116      * Returns true if this BasicStroke represents the same stroking operation\r
117      * as the given argument.\r
118      * \r
119      * <p>\r
120      * Tests if a specified object is equal to this <code>Stroke</code> by\r
121      * first testing if it is a <code>BasicStroke</code> and then comparing\r
122      * its width, join, cap, miter limit, dash, and dash phase attributes with\r
123      * those of this <code>Stroke</code>.\r
124      * \r
125      * @param obj the specified object to compare to this <code>Stroke</code>\r
126      * @return <code>true</code> if the width, join, cap, miter limit, dash,\r
127      *         and dash phase are the same for both objects; <code>false</code>\r
128      *         otherwise.\r
129      */\r
130     public boolean equals(Object obj) {\r
131         if (!(obj instanceof FillDesc)) {\r
132             return false;\r
133         }\r
134 \r
135         FillDesc fd = (FillDesc) obj;\r
136         if (opacity != fd.opacity) {\r
137             return false;\r
138         }\r
139         if (!fillRule.equals(fd.fillRule)) {\r
140             return false;\r
141         }\r
142         return true;\r
143     }\r
144     \r
145 //    public String toStyleString() {\r
146 //        StringBuilder s = new StringBuilder(64);\r
147 //        \r
148 //        s.append(CSSConstants.CSS_FILL_PROPERTY);\r
149 //        s.append(':');\r
150 //        s.append(paint);\r
151 //        s.append(';');\r
152 //        if (!paint.equals(CSSConstants.CSS_NONE_VALUE)) {\r
153 //            s.append(CSSConstants.CSS_FILL_OPACITY_PROPERTY);\r
154 //            s.append(':');\r
155 //            s.append(opacity);\r
156 //            s.append(';');\r
157 //            s.append(CSSConstants.CSS_FILL_RULE_PROPERTY);\r
158 //            s.append(':');\r
159 //            s.append(fillRule);\r
160 //            s.append(';');\r
161 //        }\r
162 //        \r
163 //        return s.toString();\r
164 //    }\r
165     \r
166 }\r