Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / docs / source / Component3.html
index 7454945..fcd7f6e 100644 (file)
@@ -3,8 +3,8 @@
 <head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <title>The source code</title>
-  <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
-  <script type="text/javascript" src="../prettify/prettify.js"></script>
+  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
+  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
   <style type="text/css">
     .highlight { display: block; background-color: #ddd; }
   </style>
  * manages and holds a `Surface` instance: an interface that has
  * an SVG or VML implementation depending on the browser capabilities and where
  * Sprites can be appended.
- * {@img Ext.draw.Component/Ext.draw.Component.png Ext.draw.Component component}
+ *
  * One way to create a draw component is:
- * 
+ *
+ *     @example
  *     var drawComponent = Ext.create('Ext.draw.Component', {
  *         viewBox: false,
  *         items: [{
  *             y: 100
  *         }]
  *     });
- *   
+ *
  *     Ext.create('Ext.Window', {
  *         width: 215,
  *         height: 235,
  *         layout: 'fit',
  *         items: [drawComponent]
  *     }).show();
- * 
+ *
  * In this case we created a draw component and added a sprite to it.
  * The *type* of the sprite is *circle* so if you run this code you'll see a yellow-ish
  * circle in a Window. When setting `viewBox` to `false` we are responsible for setting the object's position and
- * dimensions accordingly. 
- * 
+ * dimensions accordingly.
+ *
  * You can also add sprites by using the surface's add method:
- *    
+ *
  *     drawComponent.surface.add({
  *         type: 'circle',
  *         fill: '#79BB3F',
@@ -58,7 +59,7 @@
  *         x: 100,
  *         y: 100
  *     });
- *  
+ *
  * For more information on Sprites, the core elements added to a draw component's surface,
  * refer to the Ext.draw.Sprite documentation.
  */
@@ -78,7 +79,7 @@ Ext.define('Ext.draw.Component', {
     /* End Definitions */
 
 <span id='Ext-draw-Component-cfg-enginePriority'>    /**
-</span>     * @cfg {Array} enginePriority
+</span>     * @cfg {String[]} enginePriority
      * Defines the priority order for which Surface implementation to use. The first
      * one supported by the current environment will be used.
      */
@@ -100,60 +101,50 @@ Ext.define('Ext.draw.Component', {
      * Turn on autoSize support which will set the bounding div's size to the natural size of the contents. Defaults to false.
      */
     autoSize: false,
-    
+
 <span id='Ext-draw-Component-cfg-gradients'>    /**
-</span>     * @cfg {Array} gradients (optional) Define a set of gradients that can be used as `fill` property in sprites.
+</span>     * @cfg {Object[]} gradients (optional) Define a set of gradients that can be used as `fill` property in sprites.
      * The gradients array is an array of objects with the following properties:
      *
-     * &lt;ul&gt;
-     * &lt;li&gt;&lt;strong&gt;id&lt;/strong&gt; - string - The unique name of the gradient.&lt;/li&gt;
-     * &lt;li&gt;&lt;strong&gt;angle&lt;/strong&gt; - number, optional - The angle of the gradient in degrees.&lt;/li&gt;
-     * &lt;li&gt;&lt;strong&gt;stops&lt;/strong&gt; - object - An object with numbers as keys (from 0 to 100) and style objects
-     * as values&lt;/li&gt;
-     * &lt;/ul&gt;
-     * 
-     
-     For example:
-     
-     &lt;pre&gt;&lt;code&gt;
-        gradients: [{
-            id: 'gradientId',
-            angle: 45,
-            stops: {
-                0: {
-                    color: '#555'
-                },
-                100: {
-                    color: '#ddd'
-                }
-            }
-        },  {
-            id: 'gradientId2',
-            angle: 0,
-            stops: {
-                0: {
-                    color: '#590'
-                },
-                20: {
-                    color: '#599'
-                },
-                100: {
-                    color: '#ddd'
-                }
-            }
-        }]
-     &lt;/code&gt;&lt;/pre&gt;
-     
-     Then the sprites can use `gradientId` and `gradientId2` by setting the fill attributes to those ids, for example:
-     
-     &lt;pre&gt;&lt;code&gt;
-        sprite.setAttributes({
-            fill: 'url(#gradientId)'
-        }, true);
-     &lt;/code&gt;&lt;/pre&gt;
-     
+     *  - `id` - string - The unique name of the gradient.
+     *  - `angle` - number, optional - The angle of the gradient in degrees.
+     *  - `stops` - object - An object with numbers as keys (from 0 to 100) and style objects as values
+     *
+     * ## Example
+     *
+     *     gradients: [{
+     *         id: 'gradientId',
+     *         angle: 45,
+     *         stops: {
+     *             0: {
+     *                 color: '#555'
+     *             },
+     *             100: {
+     *                 color: '#ddd'
+     *             }
+     *         }
+     *     }, {
+     *         id: 'gradientId2',
+     *         angle: 0,
+     *         stops: {
+     *             0: {
+     *                 color: '#590'
+     *             },
+     *             20: {
+     *                 color: '#599'
+     *             },
+     *             100: {
+     *                 color: '#ddd'
+     *             }
+     *         }
+     *     }]
+     *
+     * Then the sprites can use `gradientId` and `gradientId2` by setting the fill attributes to those ids, for example:
+     *
+     *     sprite.setAttributes({
+     *         fill: 'url(#gradientId)'
+     *     }, true);
      */
-
     initComponent: function() {
         this.callParent(arguments);
 
@@ -179,22 +170,22 @@ Ext.define('Ext.draw.Component', {
             bbox, items, width, height, x, y;
         me.callParent(arguments);
 
-        me.createSurface();
-
-        items = me.surface.items;
+        if (me.createSurface() !== false) {
+            items = me.surface.items;
 
-        if (viewBox || autoSize) {
-            bbox = items.getBBox();
-            width = bbox.width;
-            height = bbox.height;
-            x = bbox.x;
-            y = bbox.y;
-            if (me.viewBox) {
-                me.surface.setViewBox(x, y, width, height);
-            }
-            else {
-                // AutoSized
-                me.autoSizeSurface();
+            if (viewBox || autoSize) {
+                bbox = items.getBBox();
+                width = bbox.width;
+                height = bbox.height;
+                x = bbox.x;
+                y = bbox.y;
+                if (me.viewBox) {
+                    me.surface.setViewBox(x, y, width, height);
+                }
+                else {
+                    // AutoSized
+                    me.autoSizeSurface();
+                }
             }
         }
     },
@@ -228,9 +219,7 @@ Ext.define('Ext.draw.Component', {
      * instantiate based on the 'enginePriority' config. Once the Surface instance is
      * created you can use the handle to that instance to add sprites. For example:
      *
-     &lt;pre&gt;&lt;code&gt;
-        drawComponent.surface.add(sprite);
-     &lt;/code&gt;&lt;/pre&gt;
+     *     drawComponent.surface.add(sprite);
      */
     createSurface: function() {
         var surface = Ext.draw.Surface.create(Ext.apply({}, {
@@ -238,8 +227,13 @@ Ext.define('Ext.draw.Component', {
                 height: this.height,
                 renderTo: this.el
             }, this.initialConfig));
+        if (!surface) {
+            // In case we cannot create a surface, return false so we can stop
+            return false;
+        }
         this.surface = surface;
 
+
         function refire(eventName) {
             return function(e) {
                 this.fireEvent(eventName, e);
@@ -260,7 +254,7 @@ Ext.define('Ext.draw.Component', {
 
 <span id='Ext-draw-Component-method-onDestroy'>    /**
 </span>     * @private
-     * 
+     *
      * Clean up the Surface instance on component destruction
      */
     onDestroy: function() {