1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g2d.svg;
14 //import static org.apache.batik.util.SVGConstants.SVG_NONE_VALUE;
16 //import org.apache.batik.util.CSSConstants;
19 * @author Tuukka Lehtonen
21 public class FillDesc {
23 // public static final FillDesc NO_FILL = new FillDesc(SVG_NONE_VALUE) {
25 // public String toStyleString() {
26 // return "fill:none;";
29 // public void setFillRule(FillRule rule) {
30 // throw new UnsupportedOperationException("immutable object");
33 // public void setOpacity(double opacity) {
34 // throw new UnsupportedOperationException("immutable object");
37 // public void setPaint(String paint) {
38 // throw new UnsupportedOperationException("immutable object");
43 //private static final String[] ruleConv = { "nonzero", "evenodd" };
53 private double opacity;
56 * nonzero | evenodd | inherit
58 private FillRule fillRule;
62 this(StyleConstants.INHERIT, 1, FillRule.nonzero);
65 public FillDesc(String paint) {
66 this(paint, 1, FillRule.nonzero);
69 public FillDesc(String paint, double opacity) {
70 this(paint, opacity, FillRule.nonzero);
73 public FillDesc(String paint, double opacity, FillRule fillRule) {
75 this.opacity = opacity;
76 this.fillRule = fillRule != null ? fillRule : FillRule.nonzero;
79 public String getPaint() {
83 public void setPaint(String paint) {
87 public double getOpacity() {
91 public void setOpacity(double opacity) {
92 this.opacity = opacity;
95 public FillRule getFillRule() {
99 public void setFillRule(FillRule rule) {
100 this.fillRule = rule;
104 * Returns the hashcode for this stroke.
106 * @return a hash code for this stroke.
108 public int hashCode() {
109 int hash = paint.hashCode();
110 hash = hash * 31 + (int) Double.doubleToLongBits(opacity);
111 hash = hash * 31 + fillRule.hashCode();
116 * Returns true if this BasicStroke represents the same stroking operation
117 * as the given argument.
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>.
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>
130 public boolean equals(Object obj) {
131 if (!(obj instanceof FillDesc)) {
135 FillDesc fd = (FillDesc) obj;
136 if (opacity != fd.opacity) {
139 if (!fillRule.equals(fd.fillRule)) {
145 // public String toStyleString() {
146 // StringBuilder s = new StringBuilder(64);
148 // s.append(CSSConstants.CSS_FILL_PROPERTY);
152 // if (!paint.equals(CSSConstants.CSS_NONE_VALUE)) {
153 // s.append(CSSConstants.CSS_FILL_OPACITY_PROPERTY);
155 // s.append(opacity);
157 // s.append(CSSConstants.CSS_FILL_RULE_PROPERTY);
159 // s.append(fillRule);
163 // return s.toString();