1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.gwtwidgets.client.svg;
18
19 import org.gwtwidgets.client.style.Color;
20 import org.gwtwidgets.client.ext.Namespace;
21
22
23 public class SVGLinearGradient implements SVGGradient
24 {
25 private String id;
26 private SVGLinearGradientWidget widget;
27 private Namespace ns;
28
29
30
31 protected SVGLinearGradient (Namespace ns, String id)
32 {
33 this.id = id;
34 this.ns = ns;
35 this.widget = new SVGLinearGradientWidget(ns, id);
36 }
37
38 protected SVGLinearGradientWidget getWidget ()
39 {
40 return widget;
41 }
42
43 public String getId ()
44 {
45 return id;
46 }
47
48
49 /***
50 * Set a gradient stop
51 * @param percent 1-100
52 * @param color
53 */
54 public SVGLinearGradient addStop (int percent, Color color)
55 {
56 SVGStop stop = new SVGStop(ns);
57 stop.setOffset(percent + "%");
58 stop.setStopColor(color);
59 this.getWidget().add(stop);
60 return this;
61 }
62
63 public SVGLinearGradient addStop (int percent, double opacity, Color color)
64 {
65 SVGStop stop = new SVGStop(ns);
66 stop.setOffset(percent + "%");
67 stop.setOpacity(opacity);
68 stop.setStopColor(color);
69 this.getWidget().add(stop);
70 return this;
71 }
72
73 public SVGLinearGradient setVector (int x1Percent, int y1Percent, int x2Percent, int y2Percent)
74 {
75 SVGWidget w = getWidget();
76 w.setAttributeNS(w.getElement(), "gradientUnits", "objectBoundingBox");
77 w.setAttributeNS(w.getElement(), "x1", x1Percent + "%");
78 w.setAttributeNS(w.getElement(), "y1", y1Percent + "%");
79 w.setAttributeNS(w.getElement(), "x2", x2Percent + "%");
80 w.setAttributeNS(w.getElement(), "y2", y2Percent + "%");
81 return this;
82 }
83
84
85 public class SVGLinearGradientWidget extends SVGContainerBase
86 {
87
88 protected SVGLinearGradientWidget (Namespace ns, String id)
89 {
90 setElement(createNsElement(ns, "linearGradient"));
91 setAttributeNS(getElement(), "id", id);
92 }
93
94 }
95
96 }