001 
002 /*
003  *  JScripter Standard 1.0 - To Script In Java
004  *  Copyright (C) 2008-2011  J.J.Liu<jianjunliu@126.com> <http://www.jscripter.org>
005  *  
006  *  This program is free software: you can redistribute it and/or modify
007  *  it under the terms of the GNU Affero General Public License as published by
008  *  the Free Software Foundation, either version 3 of the License, or
009  *  (at your option) any later version.
010  *  
011  *  This program is distributed in the hope that it will be useful,
012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014  *  GNU Affero General Public License for more details.
015  *  
016  *  You should have received a copy of the GNU Affero General Public License
017  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
018  */
019 
020 package js.user;
021 
022 import js.*;
023 import js.core.*;
024 
025 /**
026  * <p>An <b>opaque</b> class representing JavaScript client-side objects of the global 
027  * {@link JsClient#CanvasGradient}</tt> class.</p>
028  * <p>An object of this opaque class represents a color gradient that may be assigned to 
029  * both the {@link JsCanvasRenderingContext2D#strokeStyle} and {@link JsCanvasRenderingContext2D#fillStyle} 
030  * properties of a {@link JsCanvasRenderingContext2D#strokeStyle} object. The 
031  * {@link JsCanvasRenderingContext2D#createLinearGradient(Number, Number, Number, Number)} 
032  * and {@link JsCanvasRenderingContext2D#createRadialGradient(Number, Number, Number, Number, Number, Number)} 
033  * methods both return objects of this class.</p>
034  * <p>Once you have created an object of this class, use {@link JsCanvasGradient#addColorStop(Number, String)} 
035  * method to specify what colors should appear at what positions within the gradient. 
036  * Between the positions you specify, colors are interpolated to create a smooth gradient 
037  * or fade. Transparent black stops are created implicitly at the start and end points of 
038  * the gradient.</p>
039  *
040  * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
041  *
042  * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be
043  * generated into the target codes. Re-compilers must exit with error on the operations of
044  * accessing that kind of class objects.
045  * The <tt>checkcast</tt> operation to the class literal of this interface must be ignored
046  * and <tt>instanceof</tt> to it always <tt>true</tt>.
047  */
048 public class JsCanvasGradient extends JsClient.CanvasGradient.Prototype
049 {
050     /**
051      * <p>An <b>opaque</b> class representing members of its enclosing <b>opaque</b> type.</p>
052      * <p>Note that, this class is <b>opaque</b> but its constructors are all <b>internal</b>. 
053      * This class and the subclasses of this class are used to declare either <b>opaque</b> 
054      * <tt>public</tt> instance fields of the opaque type {@link js.Var.Member} or the 
055      * <b>opaque</b> <tt>public</tt> static fields of other <b>opaque</b> types while their 
056      * constructors are used to define the fields inside <b>opaque</b> classes. Under 
057      * either circumstance, the field names must be exactly same as the member names, as 
058      * the <b>opaque</b> fields of <b>opaque</b> types are resolved by re-compilers directly 
059      * based on the field names.</p>
060      *
061      * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
062      * 
063      * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be created
064      * in the target codes. Re-compilers must exit with error on operations accessing that kind 
065      * of class objects.
066      * Re-compilers must resolve an <b>opaque</b> instance field declared by this class in
067      * {@link js.Var.Member} or its subclasses to the JavaScript identifier: 
068      * <pre>q.m</pre>
069      * where <tt>m</tt> is the identifier of the field name and <tt>q</tt> is the identifier
070      * resolved from the instance of the enclosing member. Re-compilers must resolve an 
071      * <b>opaque</b> static field declared by this class in <b>opaque</b> types other than 
072      * {@link js.Var.Member} and its subclasses to the JavaScript identifier: 
073      * <pre>m</pre>
074      * where <tt>m</tt> is the identifier of the field name. And re-compilers must report
075      * error on the access to <b>opaque</b> fields declared by this class under any other 
076      * circumstances.
077      */
078     public static class Member extends JsClient.CanvasGradient.Prototype.Member
079     {
080         /**
081          * <p>Internally constructs a member based on a qualifying member.</p>
082          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
083          * or <b>internal</b> classes or class members.</p>
084          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
085          * <b>opaque</b>. This constructor is used to define <b>opaque</b> instance fields 
086          * declared in the declaring class of this constructor itself or its subclasses. 
087          * Under this circumstance, the field names must be exactly same as the member 
088          * names, as the <b>opaque</b> instance fields of the <b>opaque</b> type 
089          * {@link js.Var.Member} or its subclasses are resolved by re-compilers directly
090          * to their names appending to the name resolved from the specified qualifying 
091          * member with a dot in between.</p>
092          * @param q A qualifying member
093          * @param mid The ID of the member to construct
094          * @since 1.0
095          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
096          */
097         public Member(JsObject.Member q, Mid mid) {
098             super(q, mid);
099         }
100         /**
101          * <p>Internally constructs a member without a qualifying member.</p>
102          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
103          * or <b>internal</b> classes or class members.</p>
104          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
105          * <b>opaque</b>. This constructor is used to define <b>opaque</b> static fields, 
106          * declared in <b>opaque</b> types other than the declaring class of this constructor 
107          * itself and its subclasses. Under this circumstance, the field names must be
108          * exactly same as the member names, as the <b>opaque</b> static fields of <b>opaque</b>
109          * types are generally resolved by re-compilers directly to identifiers of their names.</p>
110          * @param mid The ID of the member to construct
111          * @since 1.0
112          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
113          */
114         public Member(Mid mid) {
115             super(mid);
116         }
117         @Override
118         /**
119          * <p>Evaluates the property, represented by the current member instance, of the
120          * argument object.</p>
121          * @param o The argument object
122          * @return The value of the current member based on the object argument.
123          * @since 1.0
124          * @javascript Re-compilers must convert the instance invocation of this method into
125          * the JavaScript expression: 
126          * <pre>o.m</pre>
127          * where <tt>m</tt> is the identifier name resolved from the current member
128          * instance of the invocation.
129          */
130         public JsCanvasGradient with(ObjectLike o) {
131             return new JsCanvasGradient(super.with(o));
132         }
133     }
134 
135     /**
136      * <p>Casts an <b>opaque</b> object to the current <b>opaque</b> type by wrapping it
137      * with the wrapping constructor.</p>
138      * @param var The argument of an <b>opaque</b> object.
139      * @since 1.0
140      * @javascript Re-compilers must ignore the construction operation of this constructor,
141      * that is, replacing it with its only argument.
142      */
143     public JsCanvasGradient(JsObject var) {
144         super(var);
145     }
146 
147     @Override
148     /**
149      * <p>Returns the primitive value associated with the current instance, if there is one.
150      * This invocation simply returns the instance itself for the current instance is an 
151      * object and there is no primitive value for it.</p>
152      * @return The current object itself.
153      * @since 1.0
154      * @javascript Re-compilers must convert the instance invocation of this method directly
155      * into a JavaScript invocation on its current object instance without changing the 
156      * method name, but expanding variable arguments, if any, into comma-separated values. 
157      */
158     public JsCanvasGradient valueOf() {
159         return new JsCanvasGradient((JsObject)var().valueOf());
160     }
161     /**
162      * <p>Specifies a color and position for the gradient.</p>
163      * <p>This method provides the mechanism for describing color changes in a gradient. It 
164      * may be called one or more times to change the color at particular percentages 
165      * between the gradient's start and end points.</p>
166      * <p>If this method is never called on a gradient, the gradient is transparent. At 
167      * least one color stop must be specified to produce a visible color gradient.</p>
168      * @param offset A floating-point value in the range 0.0 to 1.0 that represents a 
169      * fraction between the start and end points of the gradient. An offset of 0 
170      * corresponds to the start point, and an offset of 1 corresponds to the end point.
171      * @param color Specifies the color to be displayed at the specified offset, as a 
172      * CSS color string. Colors at other points along the gradient are interpolated based 
173      * on this and any other color stops.
174      * @since 1.0
175      * @javascript Re-compilers must convert the instance invocation of this method directly
176      * into a JavaScript invocation on its current object instance without changing the 
177      * method name, but expanding variable arguments, if any, into comma-separated values. 
178      */
179     public final void addColorStop(Number offset, String color) {
180         call(addColorStop, new Vars<Object>().add(offset).add(color));
181     }
182 }