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