1 /****************************************************************************
  2  Copyright (c) 2011-2012 cocos2d-x.org
  3  Copyright (c) 2013-2014 Chukong Technologies Inc.
  4 
  5  http://www.cocos2d-x.org
  6 
  7  Permission is hereby granted, free of charge, to any person obtaining a copy
  8  of this software and associated documentation files (the "Software"), to deal
  9  in the Software without restriction, including without limitation the rights
 10  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 11  copies of the Software, and to permit persons to whom the Software is
 12  furnished to do so, subject to the following conditions:
 13 
 14  The above copyright notice and this permission notice shall be included in
 15  all copies or substantial portions of the Software.
 16 
 17  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 20  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 21  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 22  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 23  THE SOFTWARE.
 24  ****************************************************************************/
 25 
 26 (function(){
 27     var factoryCreate = ccs.objectFactory;
 28 
 29     factoryCreate.registerType({_className:"ButtonReader", _fun: ccs.ButtonReader});
 30     factoryCreate.registerType({_className: "CheckBoxReader", _fun: ccs.CheckBoxReader});
 31     factoryCreate.registerType({_className: "SliderReader", _fun: ccs.SliderReader});
 32     factoryCreate.registerType({_className: "ImageViewReader", _fun: ccs.ImageViewReader});
 33     factoryCreate.registerType({_className: "LoadingBarReader", _fun: ccs.LoadingBarReader});
 34     factoryCreate.registerType({_className: "TextAtlasReader", _fun: ccs.LabelAtlasReader});
 35     factoryCreate.registerType({_className: "TextReader", _fun: ccs.LabelReader});
 36     factoryCreate.registerType({_className: "TextBMFontReader", _fun: ccs.LabelBMFontReader});
 37     factoryCreate.registerType({_className: "TextFieldReader", _fun: ccs.TextFieldReader});
 38     factoryCreate.registerType({_className: "LayoutReader", _fun: ccs.LayoutReader});
 39     factoryCreate.registerType({_className: "PageViewReader", _fun: ccs.PageViewReader});
 40     factoryCreate.registerType({_className: "ScrollViewReader", _fun: ccs.ScrollViewReader});
 41     factoryCreate.registerType({_className: "ListViewReader", _fun: ccs.ListViewReader});
 42     factoryCreate.registerType({_className: "WidgetReader", _fun: ccs.WidgetReader});
 43 
 44     factoryCreate.registerType({_className: "Button", _fun: ccui.Button});
 45     factoryCreate.registerType({_className: "CheckBox", _fun: ccui.CheckBox});
 46     factoryCreate.registerType({_className: "ImageView", _fun: ccui.ImageView});
 47     factoryCreate.registerType({_className: "Text", _fun: ccui.Text});
 48     factoryCreate.registerType({_className: "TextAtlas", _fun: ccui.TextAtlas});
 49     factoryCreate.registerType({_className: "TextBMFont", _fun: ccui.TextBMFont});
 50     factoryCreate.registerType({_className: "LoadingBar", _fun: ccui.LoadingBar});
 51     factoryCreate.registerType({_className: "Slider", _fun: ccui.Slider});
 52     factoryCreate.registerType({_className: "TextField", _fun: ccui.TextField});
 53     factoryCreate.registerType({_className: "Layout", _fun: ccui.Layout});
 54     factoryCreate.registerType({_className: "ListView", _fun: ccui.ListView});
 55     factoryCreate.registerType({_className: "PageView", _fun: ccui.PageView});
 56     factoryCreate.registerType({_className: "ScrollView", _fun: ccui.ScrollView});
 57 
 58 })();
 59 
 60 /**
 61  * ccs.uiReader is a singleton object which is the reader for Cocos Studio ui.
 62  * @class
 63  * @name ccs.uiReader
 64  */
 65 ccs.uiReader = /** @lends ccs.uiReader# */{
 66     _filePath: "",
 67     _olderVersion: false,
 68     _fileDesignSizes: {},
 69     _mapObject: {},
 70     _mapParseSelector: {},
 71 
 72     /**
 73      * Gets the version number by version string.
 74      * @param {String} str version string.
 75      * @returns {Number}
 76      */
 77     getVersionInteger: function (str) {
 78         if(!str)
 79             return 0;
 80         var strVersion = str;
 81         var versionLength = strVersion.length;
 82         if (versionLength < 7) {
 83             return 0;
 84         }
 85         var pos = strVersion.indexOf(".");
 86         var t = strVersion.substr(0, pos);
 87         strVersion = strVersion.substr(pos + 1, versionLength - 1);
 88 
 89         pos = strVersion.indexOf(".");
 90         var h = strVersion.substr(0, pos);
 91         strVersion = strVersion.substr(pos + 1, versionLength - 1);
 92 
 93         pos = strVersion.indexOf(".");
 94         var te = strVersion.substr(0, pos);
 95         strVersion = strVersion.substr(pos + 1, versionLength - 1);
 96 
 97         pos = strVersion.indexOf(".");
 98         var s = (pos == -1) ? strVersion : strVersion.substr(0, pos);
 99 
100         var it = parseInt(t);
101         var ih = parseInt(h);
102         var ite = parseInt(te);
103         var is = parseInt(s);
104 
105         return (it * 1000 + ih * 100 + ite * 10 + is);
106     },
107 
108     /**
109      * stores the designSize of UI file.
110      * @param {String} fileName
111      * @param {cc.Size} size
112      */
113     storeFileDesignSize: function (fileName, size) {
114         this._fileDesignSizes[fileName] = size;
115     },
116 
117     /**
118      * Gets the design size by filename.
119      * @param {String} fileName
120      * @returns {cc.Size}
121      */
122     getFileDesignSize: function (fileName) {
123         return this._fileDesignSizes[fileName];
124     },
125 
126     /**
127      * Creates uiWidget from a json file that exported by cocostudio UI editor
128      * @param {String} fileName
129      * @returns {ccui.Widget}
130      */
131     widgetFromJsonFile: function (fileName) {
132         var jsonDict = cc.loader.getRes(fileName);
133         if(!jsonDict) throw "Please load the resource first : " + fileName;
134 
135         var tempFilePath = cc.path.dirname(fileName);
136         this._filePath = tempFilePath == "" ? tempFilePath : tempFilePath + "/";
137 
138         var fileVersion = jsonDict["version"];
139         var pReader, widget;
140         var versionInteger = this.getVersionInteger(fileVersion);
141         if (fileVersion) {
142             if (versionInteger < 250) {
143                 pReader = new ccs.WidgetPropertiesReader0250();
144                 widget = pReader.createWidget(jsonDict, this._filePath, fileName);
145             } else {
146                 pReader = new ccs.WidgetPropertiesReader0300();
147                 widget = pReader.createWidget(jsonDict, this._filePath, fileName);
148             }
149         } else {
150             pReader = new ccs.WidgetPropertiesReader0250();
151             widget = pReader.createWidget(jsonDict, this._filePath, fileName);
152         }
153 
154         if (!fileVersion || versionInteger < 250) {
155             this._olderVersion = true;
156         }
157         jsonDict = null;
158         return widget;
159     },
160 
161     /**
162      * Resets the states and clear the file design sizes.
163      */
164     clear: function () {
165         this._filePath = "";
166         this._olderVersion = false;
167         this._fileDesignSizes = {};
168     },
169 
170     /**
171      * Registers class type and callback.
172      * @param {String} classType
173      * @param {ccs.objectFactory} ins
174      * @param {Object} object
175      * @param {function} callback
176      */
177     registerTypeAndCallBack: function(classType, ins, object, callback){
178         var factoryCreate = ccs.objectFactory;
179         var t = new ccs.TInfo(classType, ins);
180         factoryCreate.registerType(t);
181 
182         if(object)
183             this._mapObject[classType] = object;
184         if(callback)
185             this._mapParseSelector[classType] = callback;
186     },
187 
188     /**
189      * Returns the file path
190      * @returns {string}
191      */
192     getFilePath: function(){
193         return this._filePath;
194     },
195 
196     /**
197      * Returns the parsed object map.
198      * @returns {Object}
199      */
200     getParseObjectMap: function(){
201         return this._mapObject;
202     },
203 
204     /**
205      * Returns the parsed callback map.
206      * @returns {*}
207      */
208     getParseCallBackMap: function(){
209         return this._mapParseSelector;
210     }
211 };
212 
213 /**
214  * The base class of widget properties reader. It parse the foundation properties of widget.
215  * @class
216  * @extends ccs.Class
217  */
218 ccs.WidgetPropertiesReader = ccs.Class.extend(/** @lends ccs.WidgetPropertiesReader# */{
219     _filePath: "",
220 
221     /**
222      * Create a widget object by json object.
223      * @param {Object} jsonDict
224      * @param {String} fullPath
225      * @param {String} fileName
226      */
227     createWidget: function (jsonDict, fullPath, fileName) {
228     },
229 
230     /**
231      * Parses the widget properties.
232      * @param {Object} data
233      */
234     widgetFromJsonDictionary: function (data) {
235     },
236 
237     _createGUI: function(className){
238         var name = this._getGUIClassName(className);
239         return ccs.objectFactory.createObject(name);
240     },
241 
242     _getGUIClassName: function(name){
243         var convertedClassName = name;
244         if (name == "Panel")
245             convertedClassName = "Layout";
246         else if (name == "TextArea")
247             convertedClassName = "Text";
248         else if (name == "TextButton")
249             convertedClassName = "Button";
250         else if (name == "Label")
251             convertedClassName = "Text";
252         else if (name == "LabelAtlas")
253             convertedClassName = "TextAtlas";
254         else if (name == "LabelBMFont")
255             convertedClassName = "TextBMFont";
256         return convertedClassName;
257     },
258 
259     _getWidgetReaderClassName: function(className){
260         // create widget reader to parse properties of widget
261         var readerName = className;
262         if (readerName == "Panel")
263             readerName = "Layout";
264         else if (readerName == "TextArea")
265             readerName = "Text";
266         else if (readerName == "TextButton")
267             readerName = "Button";
268         else if (readerName == "Label")
269             readerName = "Text";
270         else if (readerName == "LabelAtlas")
271             readerName = "TextAtlas";
272         else if (readerName == "LabelBMFont")
273             readerName = "TextBMFont";
274         readerName += "Reader";
275         return readerName;
276     },
277 
278     _getWidgetReaderClassNameFromWidget: function(widget){
279         var readerName = "";
280         // 1st., custom widget parse properties of parent widget with parent widget reader
281         if (widget instanceof ccui.Button)
282             readerName = "ButtonReader";
283         else if (widget instanceof ccui.CheckBox)
284             readerName = "CheckBoxReader";
285         else if (widget instanceof ccui.ImageView)
286             readerName = "ImageViewReader";
287         else if (widget instanceof ccui.TextAtlas)
288             readerName = "TextAtlasReader";
289         else if (widget instanceof ccui.TextBMFont)
290             readerName = "TextBMFontReader";
291         else if (widget instanceof ccui.Text)
292             readerName = "TextReader";
293         else if (widget instanceof ccui.LoadingBar)
294             readerName = "LoadingBarReader";
295         else if (widget instanceof ccui.Slider)
296             readerName = "SliderReader";
297         else if (widget instanceof ccui.TextField)
298             readerName = "TextFieldReader";
299         else if (widget instanceof ccui.ListView)
300             readerName = "ListViewReader";
301         else if (widget instanceof ccui.PageView)
302             readerName = "PageViewReader";
303         else if (widget instanceof ccui.ScrollView)
304             readerName = "ScrollViewReader";
305         else if (widget instanceof ccui.Layout)
306             readerName = "LayoutReader";
307         else if (widget instanceof ccui.Widget)
308             readerName = "WidgetReader";
309 
310         return readerName;
311     },
312 
313     _createWidgetReaderProtocol: function(className){
314         return ccs.objectFactory.createObject(className);
315     }
316 });
317 
318 /**
319  * The widget properties reader to parse Cocostudio exported file v0.3 -- v1.0
320  * @class
321  * @extends ccs.WidgetPropertiesReader
322  */
323 ccs.WidgetPropertiesReader0250 = ccs.WidgetPropertiesReader.extend(/** @lends ccs.WidgetPropertiesReader0250# */{
324     /**
325      * Creates a widget by json object.
326      * @param {Object} jsonDict
327      * @param {string} fullPath
328      * @param {string} fileName
329      * @returns {*}
330      */
331     createWidget: function (jsonDict, fullPath, fileName) {
332         this._filePath = fullPath == "" ? fullPath : cc.path.join(fullPath, "/");
333         var textures = jsonDict["textures"];
334         for (var i = 0; i < textures.length; i++) {
335             var file = textures[i];
336             var tp = fullPath;
337             tp += file;
338             cc.spriteFrameCache.addSpriteFrames(tp);
339         }
340         var fileDesignWidth = jsonDict["designWidth"];
341         var fileDesignHeight = jsonDict["designHeight"];
342         if (fileDesignWidth <= 0 || fileDesignHeight <= 0) {
343             cc.log("Read design size error!");
344             var winSize = cc.director.getWinSize();
345             ccs.uiReader.storeFileDesignSize(fileName, winSize);
346         } else
347             ccs.uiReader.storeFileDesignSize(fileName, cc.size(fileDesignWidth, fileDesignHeight));
348         var widgetTree = jsonDict["widgetTree"];
349         var widget = this.widgetFromJsonDictionary(widgetTree);
350 
351         var size = widget.getContentSize();
352         if (size.width == 0 && size.height == 0)
353             widget.setSize(cc.size(fileDesignWidth, fileDesignHeight));
354 
355         var actions = jsonDict["animation"];
356         ccs.actionManager.initWithDictionary(fileName, actions, widget);
357         widgetTree = null;
358         actions = null;
359         return widget;
360     },
361 
362     /**
363      * Creates a widget by json dictionary.
364      * @param {Object} data
365      * @returns {ccui.Widget}
366      */
367     widgetFromJsonDictionary: function (data) {
368         var widget = null;
369         var classname = data["classname"];
370         var uiOptions = data["options"];
371         if (classname == "Button") {
372             widget = ccui.Button.create();
373             this.setPropsForButtonFromJsonDictionary(widget, uiOptions);
374         } else if (classname == "CheckBox") {
375             widget = ccui.CheckBox.create();
376             this.setPropsForCheckBoxFromJsonDictionary(widget, uiOptions);
377         } else if (classname == "Label") {
378             widget = ccui.Text.create();
379             this.setPropsForLabelFromJsonDictionary(widget, uiOptions);
380         } else if (classname == "LabelAtlas") {
381             widget = ccui.TextAtlas.create();
382             this.setPropsForLabelAtlasFromJsonDictionary(widget, uiOptions);
383         } else if (classname == "LoadingBar") {
384             widget = ccui.LoadingBar.create();
385             this.setPropsForLoadingBarFromJsonDictionary(widget, uiOptions);
386         } else if (classname == "ScrollView") {
387             widget = ccui.ScrollView.create();
388             this.setPropsForScrollViewFromJsonDictionary(widget, uiOptions);
389         } else if (classname == "TextArea") {
390             widget = ccui.Text.create();
391             this.setPropsForLabelFromJsonDictionary(widget, uiOptions);
392         } else if (classname == "TextButton") {
393             widget = ccui.Button.create();
394             this.setPropsForButtonFromJsonDictionary(widget, uiOptions);
395         } else if (classname == "TextField") {
396             widget = ccui.TextField.create();
397             this.setPropsForTextFieldFromJsonDictionary(widget, uiOptions);
398         } else if (classname == "ImageView") {
399             widget = ccui.ImageView.create();
400             this.setPropsForImageViewFromJsonDictionary(widget, uiOptions);
401         } else if (classname == "Panel") {
402             widget = ccui.Layout.create();
403             this.setPropsForLayoutFromJsonDictionary(widget, uiOptions);
404         } else if (classname == "Slider") {
405             widget = ccui.Slider.create();
406             this.setPropsForSliderFromJsonDictionary(widget, uiOptions);
407         } else if (classname == "LabelBMFont") {
408             widget = ccui.TextBMFont.create();
409             this.setPropsForLabelBMFontFromJsonDictionary(widget, uiOptions);
410         } else if (classname == "DragPanel") {
411             widget = ccui.ScrollView.create();
412             this.setPropsForScrollViewFromJsonDictionary(widget, uiOptions);
413         }
414         var children = data["children"];
415         for (var i = 0; i < children.length; i++) {
416             var subData = children[i];
417             var child = this.widgetFromJsonDictionary(subData);
418             if (child)
419                 widget.addChild(child);
420             subData = null;
421         }
422         uiOptions = null;
423         return widget;
424     },
425 
426     /**
427      * Sets widget's properties from json dictionary.
428      * @param {ccui.Widget} widget
429      * @param {Object} options the json dictionary.
430      */
431     setPropsForWidgetFromJsonDictionary: function (widget, options) {
432         if (options["ignoreSize"] !== undefined)
433             widget.ignoreContentAdaptWithSize(options["ignoreSize"]);
434 
435         var w = options["width"];
436         var h = options["height"];
437         widget.setSize(cc.size(w, h));
438 
439         widget.setTag(options["tag"]);
440         widget.setActionTag(options["actiontag"]);
441         widget.setTouchEnabled(options["touchAble"]);
442         var name = options["name"];
443         var widgetName = name ? name : "default";
444         widget.setName(widgetName);
445         var x = options["x"];
446         var y = options["y"];
447         widget.setPosition(cc.p(x, y));
448         if (options["scaleX"] !== undefined) {
449             widget.setScaleX(options["scaleX"]);
450         }
451         if (options["scaleY"] !== undefined) {
452             widget.setScaleY(options["scaleY"]);
453         }
454         if (options["rotation"] !== undefined) {
455             widget.setRotation(options["rotation"]);
456         }
457         if (options["visible"] !== undefined) {
458             widget.setVisible(options["visible"]);
459         }
460 
461         var z = options["ZOrder"];
462         widget.setLocalZOrder(z);
463     },
464 
465     /**
466      * Sets all widgets' properties from json dictionary.
467      */
468     setPropsForAllWidgetFromJsonDictionary: function(){},
469 
470     /**
471      * Sets all custom widget's properties from json dictionary.
472      */
473     setPropsForAllCustomWidgetFromJsonDictionary: function(){},
474 
475     /**
476      * Sets widget's color, anchor point, flipped properties from json object.
477      * @param {ccui.Widget} widget
478      * @param {Object} options json object.
479      */
480     setColorPropsForWidgetFromJsonDictionary: function (widget, options) {
481         if (options["opacity"] !== undefined) {
482             widget.setOpacity(options["opacity"]);
483         }
484         var colorR = options["colorR"] !== undefined ? options["colorR"] : 255;
485         var colorG = options["colorG"] !== undefined ? options["colorG"] : 255;
486         var colorB = options["colorB"] !== undefined ? options["colorB"] : 255;
487         widget.setColor(cc.color(colorR, colorG, colorB));
488         var apx = options["anchorPointX"] !== undefined ? options["anchorPointX"] : ((widget.getWidgetType() == ccui.Widget.TYPE_WIDGET) ? 0.5 : 0);
489         var apy = options["anchorPointY"] !== undefined ? options["anchorPointY"] : ((widget.getWidgetType() == ccui.Widget.TYPE_WIDGET) ? 0.5 : 0);
490         widget.setAnchorPoint(apx, apy);
491         var flipX = options["flipX"];
492         var flipY = options["flipY"];
493         widget.setFlippedX(flipX);
494         widget.setFlippedY(flipY);
495     },
496 
497     /**
498      * Sets ccui.Button's properties from json object.
499      * @param {ccui.Button} widget
500      * @param {Object} options
501      */
502     setPropsForButtonFromJsonDictionary: function (widget, options) {
503         this.setPropsForWidgetFromJsonDictionary(widget, options);
504         var button = widget;
505         var scale9Enable = options["scale9Enable"];
506         button.setScale9Enabled(scale9Enable);
507 
508         var normalFileName = options["normal"];
509         var pressedFileName = options["pressed"];
510         var disabledFileName = options["disabled"];
511 
512         var normalFileName_tp = normalFileName ? this._filePath + normalFileName : null;
513         var pressedFileName_tp = pressedFileName ? this._filePath + pressedFileName : null;
514         var disabledFileName_tp = disabledFileName ? this._filePath + disabledFileName : null;
515         var useMergedTexture = options["useMergedTexture"];
516         if (scale9Enable) {
517             var cx = options["capInsetsX"];
518             var cy = options["capInsetsY"];
519             var cw = options["capInsetsWidth"];
520             var ch = options["capInsetsHeight"];
521 
522             if (useMergedTexture)
523                 button.loadTextures(normalFileName, pressedFileName, disabledFileName, ccui.Widget.PLIST_TEXTURE);
524             else
525                 button.loadTextures(normalFileName_tp, pressedFileName_tp, disabledFileName_tp);
526             //button.setCapInsets(cc.rect(cx, cy, cw, ch));
527             if (options["scale9Width"] !== undefined && options["scale9Height"] !== undefined) {
528                 var swf = options["scale9Width"];
529                 var shf = options["scale9Height"];
530                 button.setSize(cc.size(swf, shf));
531             }
532         } else {
533             if (useMergedTexture)
534                 button.loadTextures(normalFileName, pressedFileName, disabledFileName, ccui.Widget.PLIST_TEXTURE);
535             else
536                 button.loadTextures(normalFileName_tp, pressedFileName_tp, disabledFileName_tp);
537         }
538         if (options["text"] !== undefined) {
539             var text = options["text"] || "";
540             if (text)
541                 button.setTitleText(text);
542         }
543         if (options["fontSize"] !== undefined) {
544             button.setTitleFontSize(options["fontSize"]);
545         }
546         if (options["fontName"] !== undefined) {
547             button.setTitleFontName(options["fontName"]);
548         }
549         var cr = options["textColorR"] !== undefined ? options["textColorR"] : 255;
550         var cg = options["textColorG"] !== undefined ? options["textColorG"] : 255;
551         var cb = options["textColorB"] !== undefined ? options["textColorB"] : 255;
552         var tc = cc.color(cr, cg, cb);
553         button.setTitleColor(tc);
554         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
555     },
556 
557     /**
558      * Sets ccui.CheckBox's properties from json object.
559      * @param {ccui.CheckBox} widget
560      * @param {Object} options
561      */
562     setPropsForCheckBoxFromJsonDictionary: function (widget, options) {
563         this.setPropsForWidgetFromJsonDictionary(widget, options);
564         var checkBox = widget;
565         var backGroundFileName = options["backGroundBox"];
566         var backGroundSelectedFileName = options["backGroundBoxSelected"];
567         var frontCrossFileName = options["frontCross"];
568         var backGroundDisabledFileName = options["backGroundBoxDisabled"];
569         var frontCrossDisabledFileName = options["frontCrossDisabled"];
570 
571         var locFilePath = this._filePath;
572 
573         var backGroundFileName_tp = backGroundFileName ? locFilePath + backGroundFileName : null;
574         var backGroundSelectedFileName_tp = backGroundSelectedFileName ? locFilePath + backGroundSelectedFileName : null;
575         var frontCrossFileName_tp = frontCrossFileName ? locFilePath + frontCrossFileName : null;
576         var backGroundDisabledFileName_tp = backGroundDisabledFileName ? locFilePath + backGroundDisabledFileName : null;
577         var frontCrossDisabledFileName_tp = frontCrossDisabledFileName ? locFilePath + frontCrossDisabledFileName : null;
578         var useMergedTexture = options["useMergedTexture"];
579 
580         if (useMergedTexture) {
581             checkBox.loadTextures(backGroundFileName, backGroundSelectedFileName, frontCrossFileName, backGroundDisabledFileName, frontCrossDisabledFileName, ccui.Widget.PLIST_TEXTURE);
582         }
583         else {
584             checkBox.loadTextures(backGroundFileName_tp, backGroundSelectedFileName_tp, frontCrossFileName_tp, backGroundDisabledFileName_tp, frontCrossDisabledFileName_tp);
585         }
586 
587         checkBox.setSelectedState(options["selectedState"] || false);
588         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
589     },
590 
591     /**
592      * Sets ccui.ImageView's properties from json object.
593      * @param {ccui.ImageView} widget
594      * @param {Object} options
595      */
596     setPropsForImageViewFromJsonDictionary: function (widget, options) {
597         this.setPropsForWidgetFromJsonDictionary(widget, options);
598 
599         var imageView = widget;
600         var imageFileName = options["fileName"];
601         var scale9Enable = options["scale9Enable"] || false;
602         imageView.setScale9Enabled(scale9Enable);
603 
604         var tp_i = this._filePath;
605         var imageFileName_tp = null;
606         if (imageFileName)
607             imageFileName_tp = tp_i + imageFileName;
608 
609         var useMergedTexture = options["useMergedTexture"];
610         if (scale9Enable) {
611             if (useMergedTexture) {
612                 imageView.loadTexture(imageFileName, ccui.Widget.PLIST_TEXTURE);
613             }
614             else {
615                 imageView.loadTexture(imageFileName_tp);
616             }
617 
618             if (options["scale9Width"] !== undefined && options["scale9Height"] !== undefined) {
619                 var swf = options["scale9Width"];
620                 var shf = options["scale9Height"];
621                 imageView.setSize(cc.size(swf, shf));
622             }
623 
624             var cx = options["capInsetsX"];
625             var cy = options["capInsetsY"];
626             var cw = options["capInsetsWidth"];
627             var ch = options["capInsetsHeight"];
628             imageView.setCapInsets(cc.rect(cx, cy, cw, ch));
629 
630         }
631         else {
632             if (useMergedTexture) {
633                 imageView.loadTexture(imageFileName, ccui.Widget.PLIST_TEXTURE);
634             }
635             else {
636                 imageView.loadTexture(imageFileName_tp);
637             }
638         }
639         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
640     },
641 
642     /**
643      * Sets ccui.Text's properties from json object.
644      * @param {ccui.Text} widget
645      * @param {Object} options json dictionary
646      */
647     setPropsForLabelFromJsonDictionary: function (widget, options) {
648         this.setPropsForWidgetFromJsonDictionary(widget, options);
649         var label = widget;
650         var touchScaleChangeAble = options["touchScaleEnable"];
651         label.setTouchScaleChangeEnabled(touchScaleChangeAble);
652         var text = options["text"];
653         label.setString(text);
654         if (options["fontSize"] !== undefined) {
655             label.setFontSize(options["fontSize"]);
656         }
657         if (options["fontName"] !== undefined) {
658             label.setFontName(options["fontName"]);
659         }
660         if (options["areaWidth"] !== undefined && options["areaHeight"] !== undefined) {
661             var size = cc.size(options["areaWidth"], options["areaHeight"]);
662             label.setTextAreaSize(size);
663         }
664         if (options["hAlignment"]) {
665             label.setTextHorizontalAlignment(options["hAlignment"]);
666         }
667         if (options["vAlignment"]) {
668             label.setTextVerticalAlignment(options["vAlignment"]);
669         }
670         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
671     },
672 
673     /**
674      * Sets ccui.TextAtlas' properties from json object.
675      * @param {ccui.TextAtlas} widget
676      * @param {Object} options
677      */
678     setPropsForLabelAtlasFromJsonDictionary: function (widget, options) {
679         this.setPropsForWidgetFromJsonDictionary(widget, options);
680         var labelAtlas = widget;
681         var sv = (options["stringValue"] !== undefined);
682         var cmf = (options["charMapFile"] !== undefined);
683         var iw = (options["itemWidth"] !== undefined);
684         var ih = (options["itemHeight"] !== undefined);
685         var scm = (options["startCharMap"] !== undefined);
686         if (sv && cmf && iw && ih && scm && options["charMapFile"]) {
687             var cmft = options["charMapFile"];
688             var cmf_tp = this._filePath + cmft;
689             labelAtlas.setProperty(options["stringValue"], cmf_tp, options["itemWidth"], options["itemHeight"], options["startCharMap"]);
690         }
691         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
692     },
693 
694     /**
695      * Sets ccui.Layout's properties from json object.
696      * @param {ccui.Layout} widget
697      * @param {Object} options
698      */
699     setPropsForLayoutFromJsonDictionary: function (widget, options) {
700         this.setPropsForWidgetFromJsonDictionary(widget, options);
701         var containerWidget = widget;
702         if (!(containerWidget instanceof ccui.ScrollView) && !(containerWidget instanceof ccui.ListView)) {
703             containerWidget.setClippingEnabled(options["clipAble"]);
704         }
705         var panel = widget;
706         var backGroundScale9Enable = options["backGroundScale9Enable"];
707         panel.setBackGroundImageScale9Enabled(backGroundScale9Enable);
708         var cr = options["bgColorR"];
709         var cg = options["bgColorG"];
710         var cb = options["bgColorB"];
711 
712         var scr = options["bgStartColorR"];
713         var scg = options["bgStartColorG"];
714         var scb = options["bgStartColorB"];
715 
716         var ecr = options["bgEndColorR"];
717         var ecg = options["bgEndColorG"];
718         var ecb = options["bgEndColorB"];
719 
720         var bgcv1 = options["vectorX"];
721         var bgcv2 = options["vectorY"];
722         panel.setBackGroundColorVector(cc.p(bgcv1, bgcv2));
723 
724         var co = options["bgColorOpacity"];
725 
726         var colorType = options["colorType"];
727         panel.setBackGroundColorType(colorType);
728         panel.setBackGroundColor(cc.color(scr, scg, scb), cc.color(ecr, ecg, ecb));
729         panel.setBackGroundColor(cc.color(cr, cg, cb));
730         panel.setBackGroundColorOpacity(co);
731 
732         var imageFileName = options["backGroundImage"];
733         var imageFileName_tp = imageFileName ? this._filePath + imageFileName : null;
734         var useMergedTexture = options["useMergedTexture"];
735         if (useMergedTexture) {
736             panel.setBackGroundImage(imageFileName, ccui.Widget.PLIST_TEXTURE);
737         }
738         else {
739             panel.setBackGroundImage(imageFileName_tp);
740         }
741         if (backGroundScale9Enable) {
742             var cx = options["capInsetsX"];
743             var cy = options["capInsetsY"];
744             var cw = options["capInsetsWidth"];
745             var ch = options["capInsetsHeight"];
746             panel.setBackGroundImageCapInsets(cc.rect(cx, cy, cw, ch));
747         }
748         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
749     },
750 
751     /**
752      * Sets ccui.ScrollView's properties from json dictionary.
753      * @param {ccui.ScrollView} widget
754      * @param {Object} options json dictionary.
755      */
756     setPropsForScrollViewFromJsonDictionary: function (widget, options) {
757         this.setPropsForLayoutFromJsonDictionary(widget, options);
758         var scrollView = widget;
759         var innerWidth = options["innerWidth"];
760         var innerHeight = options["innerHeight"];
761         scrollView.setInnerContainerSize(cc.size(innerWidth, innerHeight));
762         var direction = options["direction"];
763         scrollView.setDirection(direction);
764         scrollView.setBounceEnabled(options["bounceEnable"]);
765         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
766     },
767 
768     /**
769      * Sets the container's properties from json dictionary.
770      * @param {ccui.Widget} widget
771      * @param {Object} options json dictionary.
772      */
773     setPropsForContainerWidgetFromJsonDictionary: function (widget, options) {
774         this.setPropsForWidgetFromJsonDictionary(widget, options);
775         var containerWidget = widget;
776         if (containerWidget instanceof ccui.ScrollView ||
777             containerWidget instanceof ccui.ListView) {
778             containerWidget.setClippingEnabled(options["clipAble"]);
779         }
780         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
781     },
782 
783     /**
784      * Sets ccui.Slider's properties from json dictionary.
785      * @param {ccui.Slider} widget
786      * @param {Object} options json dictionary.
787      */
788     setPropsForSliderFromJsonDictionary: function (widget, options) {
789         this.setPropsForWidgetFromJsonDictionary(widget, options);
790         var slider = widget;
791 
792         var barTextureScale9Enable = options["barTextureScale9Enable"] || false;
793         slider.setScale9Enabled(barTextureScale9Enable);
794         var barLength = options["length"];
795         var useMergedTexture = options["useMergedTexture"];
796         var bt = (options["barFileName"] !== undefined);
797         if (bt) {
798             if (barTextureScale9Enable) {
799                 var imageFileName = options["barFileName"];
800                 var imageFileName_tp = imageFileName ? this._filePath + imageFileName : null;
801                 if (useMergedTexture) {
802                     slider.loadBarTexture(imageFileName, ccui.Widget.PLIST_TEXTURE);
803                 } else {
804                     slider.loadBarTexture(imageFileName_tp);
805                 }
806                 slider.setSize(cc.size(barLength, slider.getContentSize().height));
807             } else {
808                 var imageFileName = options["barFileName"];
809                 var imageFileName_tp = imageFileName ? this._filePath + imageFileName : null;
810                 if (useMergedTexture) {
811                     slider.loadBarTexture(imageFileName, ccui.Widget.PLIST_TEXTURE);
812                 } else {
813                     slider.loadBarTexture(imageFileName_tp);
814                 }
815             }
816         }
817 
818         var normalFileName = options["ballNormal"];
819         var pressedFileName = options["ballPressed"];
820         var disabledFileName = options["ballDisabled"];
821 
822         var normalFileName_tp = normalFileName ? this._filePath + normalFileName : null;
823         var pressedFileName_tp = pressedFileName ? this._filePath + pressedFileName : null;
824         var disabledFileName_tp = disabledFileName ? this._filePath + disabledFileName : null;
825         if (useMergedTexture) {
826             slider.loadSlidBallTextures(normalFileName, pressedFileName, disabledFileName, ccui.Widget.PLIST_TEXTURE);
827         } else {
828             slider.loadSlidBallTextures(normalFileName_tp, pressedFileName_tp, disabledFileName_tp);
829         }
830         slider.setPercent(options["percent"]);
831 
832         var imageFileName = options["progressBarFileName"];
833         var imageFileName_tp = imageFileName ? this._filePath + imageFileName : null;
834         if (useMergedTexture) {
835             slider.loadProgressBarTexture(imageFileName, ccui.Widget.PLIST_TEXTURE);
836         } else {
837             slider.loadProgressBarTexture(imageFileName_tp);
838         }
839         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
840     },
841 
842     /**
843      * Sets ccui.TextField's properties from json object.
844      * @param {ccui.TextField} widget
845      * @param {Object} options
846      */
847     setPropsForTextAreaFromJsonDictionary: function (widget, options) {
848         this.setPropsForWidgetFromJsonDictionary(widget, options);
849         var textArea = widget;
850         textArea.setString(options["text"]);
851         if (options["fontSize"] !== undefined) {
852             textArea.setFontSize(options["fontSize"]);
853         }
854         var cr = options["colorR"];
855         var cg = options["colorG"];
856         var cb = options["colorB"];
857         textArea.setColor(cc.color((cr == null) ? 255 : cr, (cg == null) ? 255 : cg, (cb == null) ? 255 : cb));
858         textArea.setFontName(options["fontName"]);
859         if (options["areaWidth"] !== undefined && options["areaHeight"] !== undefined) {
860             var size = cc.size(options["areaWidth"], options["areaHeight"]);
861             textArea.setTextAreaSize(size);
862         }
863         if (options["hAlignment"]) {
864             textArea.setTextHorizontalAlignment(options["hAlignment"]);
865         }
866         if (options["vAlignment"]) {
867             textArea.setTextVerticalAlignment(options["vAlignment"]);
868         }
869         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
870     },
871 
872     /**
873      * Sets ccui.Button's text properties from json dictionary.
874      * @param {ccui.Button} widget
875      * @param {Object} options
876      */
877     setPropsForTextButtonFromJsonDictionary: function (widget, options) {
878         this.setPropsForButtonFromJsonDictionary(widget, options);
879 
880         var textButton = widget;
881         textButton.setTitleText(options["text"] || "");
882         var cri = options["textColorR"] !== undefined ? options["textColorR"] : 255;
883         var cgi = options["textColorG"] !== undefined ? options["textColorG"] : 255;
884         var cbi = options["textColorB"] !== undefined ? options["textColorB"] : 255;
885         textButton.setTitleColor(cc.color(cri, cgi, cbi));
886         if (options["fontSize"] !== undefined)
887             textButton.setTitleFontSize(options["fontSize"]);
888         if (options["fontName"] !== undefined)
889             textButton.setTitleFontName(options["fontName"]);
890         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
891     },
892 
893     /**
894      * Sets ccui.TextField's properties from json dictionary.
895      * @param {ccui.TextField} widget
896      * @param {Object} options json dictionary
897      */
898     setPropsForTextFieldFromJsonDictionary: function (widget, options) {
899         this.setPropsForWidgetFromJsonDictionary(widget, options);
900         var textField = widget;
901         if (options["placeHolder"] !== undefined) {
902             textField.setPlaceHolder(options["placeHolder"]);
903         }
904         textField.setString(options["text"]);
905         if (options["fontSize"] !== undefined) {
906             textField.setFontSize(options["fontSize"]);
907         }
908         if (options["fontName"] !== undefined) {
909             textField.setFontName(options["fontName"]);
910         }
911         if (options["touchSizeWidth"] !== undefined && options["touchSizeHeight"] !== undefined) {
912             textField.setTouchSize(cc.size(options["touchSizeWidth"], options["touchSizeHeight"]));
913         }
914 
915         var dw = options["width"];
916         var dh = options["height"];
917         if (dw > 0.0 || dh > 0.0) {
918             //textField.setSize(CCSizeMake(dw, dh));
919         }
920         var maxLengthEnable = options["maxLengthEnable"];
921         textField.setMaxLengthEnabled(maxLengthEnable);
922 
923         if (maxLengthEnable) {
924             var maxLength = options["maxLength"];
925             textField.setMaxLength(maxLength);
926         }
927         var passwordEnable = options["passwordEnable"];
928         textField.setPasswordEnabled(passwordEnable);
929         if (passwordEnable) {
930             textField.setPasswordStyleText(options["passwordStyleText"]);
931         }
932         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
933     },
934 
935     /**
936      * Sets ccui.LoadingBar's properties from json dictionary.
937      * @param {ccui.LoadingBar} widget
938      * @param {Object} options json dictionary
939      */
940     setPropsForLoadingBarFromJsonDictionary: function (widget, options) {
941         this.setPropsForWidgetFromJsonDictionary(widget, options);
942         var loadingBar = widget;
943         var useMergedTexture = options["useMergedTexture"];
944         var imageFileName = options["texture"];
945         var imageFileName_tp = imageFileName ? this._filePath + imageFileName : null;
946         if (useMergedTexture) {
947             loadingBar.loadTexture(imageFileName, ccui.Widget.PLIST_TEXTURE);
948         } else {
949             loadingBar.loadTexture(imageFileName_tp);
950         }
951         loadingBar.setDirection(options["direction"]);
952         loadingBar.setPercent(options["percent"]);
953         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
954     },
955 
956     /**
957      * Sets ccui.ListView's properties from json dictionary.
958      * @param {ccui.ListView} widget
959      * @param {Object} options json dictionary
960      */
961     setPropsForListViewFromJsonDictionary: function (widget, options) {
962         this.setPropsForLayoutFromJsonDictionary(widget, options);
963     },
964 
965     /**
966      * Sets ccui.PageView's properties from json dictionary.
967      * @param {ccui.PageView} widget
968      * @param {Object} options json dictionary
969      */
970     setPropsForPageViewFromJsonDictionary: function (widget, options) {
971         this.setPropsForLayoutFromJsonDictionary(widget, options);
972     },
973 
974     /**
975      * Sets ccui.TextBMFont's properties from json dictionary.
976      * @param {ccui.TextBMFont} widget
977      * @param {Object} options json dictionary
978      */
979     setPropsForLabelBMFontFromJsonDictionary: function (widget, options) {
980         this.setPropsForWidgetFromJsonDictionary(widget, options);
981         var labelBMFont = widget;
982         var cmft = options["fileName"];
983         var cmf_tp = this._filePath + cmft;
984         labelBMFont.setFntFile(cmf_tp);
985         var text = options["text"];
986         labelBMFont.setString(text);
987         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
988     }
989 });
990 
991 /**
992  * The widget properties reader to parse Cocostudio exported file v1.0 higher.
993  * @class
994  * @extends ccs.WidgetPropertiesReader
995  */
996 ccs.WidgetPropertiesReader0300 = ccs.WidgetPropertiesReader.extend(/** @lends ccs.WidgetPropertiesReader0300# */{
997     /**
998      * Creates widget by json object.
999      * @param {Object} jsonDict json dictionary
1000      * @param {String} fullPath
1001      * @param {String} fileName
1002      * @returns {ccui.Widget}
1003      */
1004     createWidget: function (jsonDict, fullPath, fileName) {
1005         this._filePath = fullPath == "" ? fullPath : cc.path.join(fullPath, "/");
1006         var textures = jsonDict["textures"];
1007         for (var i = 0; i < textures.length; i++) {
1008             var file = textures[i];
1009             var tp = fullPath;
1010             tp += file;
1011             cc.spriteFrameCache.addSpriteFrames(tp);
1012         }
1013         var fileDesignWidth = jsonDict["designWidth"];
1014         var fileDesignHeight = jsonDict["designHeight"];
1015         if (fileDesignWidth <= 0 || fileDesignHeight <= 0) {
1016             cc.log("Read design size error!");
1017             var winSize = cc.director.getWinSize();
1018             ccs.uiReader.storeFileDesignSize(fileName, winSize);
1019         } else
1020             ccs.uiReader.storeFileDesignSize(fileName, cc.size(fileDesignWidth, fileDesignHeight));
1021         var widgetTree = jsonDict["widgetTree"];
1022         var widget = this.widgetFromJsonDictionary(widgetTree);
1023 
1024         var size = widget.getContentSize();
1025         if (size.width == 0 && size.height == 0)
1026             widget.setSize(cc.size(fileDesignWidth, fileDesignHeight));
1027 
1028         var actions = jsonDict["animation"];
1029         ccs.actionManager.initWithDictionary(fileName, actions, widget);
1030 
1031         widgetTree = null;
1032         actions = null;
1033         return widget;
1034     },
1035 
1036     /**
1037      * Sets widget's foundation properties from json dictionary.
1038      * @param {Object} reader widget reader
1039      * @param {ccui.Widget} widget
1040      * @param {Object} options json dictionary
1041      */
1042     setPropsForAllWidgetFromJsonDictionary: function(reader, widget, options){
1043         if(reader && reader.setPropsFromJsonDictionary)
1044             reader.setPropsFromJsonDictionary(widget, options);
1045     },
1046 
1047     /**
1048      * Sets widget's custom properties from json dictionary
1049      * @param {String} classType class type
1050      * @param {ccui.Widget} widget
1051      * @param {Object} customOptions
1052      */
1053     setPropsForAllCustomWidgetFromJsonDictionary: function(classType, widget, customOptions){
1054         var guiReader = ccs.uiReader;
1055         var object_map = guiReader.getParseObjectMap();
1056         var object = object_map[classType];
1057 
1058         var selector_map = guiReader.getParseCallBackMap();
1059         var selector = selector_map[classType];
1060 
1061         if (object && selector)
1062             selector.call(object, classType, widget, customOptions);
1063     },
1064 
1065     /**
1066      * Creates a widget from json dictionary.
1067      * @param {Object} data json data
1068      * @returns {ccui.Widget}
1069      */
1070     widgetFromJsonDictionary: function (data) {
1071         var classname = data["classname"];
1072         var uiOptions = data["options"];
1073         var widget = this._createGUI(classname);
1074 
1075         var readerName = this._getWidgetReaderClassName(classname);
1076         var reader = this._createWidgetReaderProtocol(readerName);
1077 
1078         if (reader){
1079             // widget parse with widget reader
1080             this.setPropsForAllWidgetFromJsonDictionary(reader, widget, uiOptions);
1081         } else {
1082             readerName = this._getWidgetReaderClassNameFromWidget(widget);
1083 
1084             reader = ccs.objectFactory.createObject(readerName);
1085 
1086             if (reader && widget) {
1087                 this.setPropsForAllWidgetFromJsonDictionary(reader, widget, uiOptions);
1088 
1089                 // 2nd., custom widget parse with custom reader
1090                 var customProperty = uiOptions["customProperty"];
1091                 var customJsonDict = JSON.parse(customProperty);
1092                 this.setPropsForAllCustomWidgetFromJsonDictionary(classname, widget, customJsonDict);
1093             }else{
1094                 cc.log("Widget or WidgetReader doesn't exists!!!  Please check your json file.");
1095             }
1096 
1097         }
1098 
1099         var childrenItem = data["children"];
1100         for(var i=0; i<childrenItem.length; i++){
1101             var child = this.widgetFromJsonDictionary(childrenItem[i]);
1102             if(child){
1103                 if(widget instanceof ccui.PageView)
1104                     widget.addPage(child);
1105                 else {
1106                     if(widget instanceof ccui.ListView){
1107                         widget.pushBackCustomItem(child);
1108                     } else {
1109                         if(!(widget instanceof ccui.Layout)) {
1110                             if(child.getPositionType() == ccui.Widget.POSITION_PERCENT) {
1111                                 var position = child.getPositionPercent();
1112                                 var anchor = widget.getAnchorPoint();
1113                                 child.setPositionPercent(cc.p(position.x + anchor.x, position.y + anchor.y));
1114                             }
1115                             var AnchorPointIn = widget.getAnchorPointInPoints();
1116                             child.setPosition(cc.p(child.getPositionX() + AnchorPointIn.x, child.getPositionY() + AnchorPointIn.y));
1117                         }
1118                         widget.addChild(child);
1119                     }
1120                 }
1121             }
1122         }
1123         return widget;
1124     },
1125 
1126     /**
1127      * Sets widget's foundation properties from json dictionary.
1128      * @param {ccui.Widget} widget
1129      * @param {Object} options json dictionary
1130      */
1131     setPropsForWidgetFromJsonDictionary: function (widget, options) {
1132         var name = options["name"];
1133         var widgetName = name ? name : "default";
1134         widget.setName(widgetName);
1135 
1136         if (options["ignoreSize"] !== undefined)
1137             widget.ignoreContentAdaptWithSize(options["ignoreSize"]);
1138 
1139         widget.setSizeType(options["sizeType"]);
1140         widget.setPositionType(options["positionType"]);
1141 
1142         widget.setSizePercent(cc.p(options["sizePercentX"], options["sizePercentY"]));
1143         widget.setPositionPercent(cc.p(options["positionPercentX"], options["positionPercentY"]));
1144 
1145         var w = options["width"];
1146         var h = options["height"];
1147         widget.setSize(cc.size(w, h));
1148 
1149         widget.setTag(options["tag"]);
1150         widget.setActionTag(options["actiontag"]);
1151         widget.setTouchEnabled(options["touchAble"]);
1152 
1153         var x = options["x"];
1154         var y = options["y"];
1155         widget.setPosition(cc.p(x, y));
1156 
1157         if (options["scaleX"] !== undefined)
1158             widget.setScaleX(options["scaleX"]);
1159         if (options["scaleY"] !== undefined)
1160             widget.setScaleY(options["scaleY"]);
1161         if (options["rotation"] !== undefined)
1162             widget.setRotation(options["rotation"]);
1163         if (options["visible"] !== undefined)
1164             widget.setVisible(options["visible"]);
1165 
1166         widget.setLocalZOrder(options["ZOrder"]);
1167         var layoutParameterDic = options["layoutParameter"];
1168         if (layoutParameterDic) {
1169             var paramType = layoutParameterDic["type"];
1170             var parameter;
1171             switch (paramType) {
1172                 case 0:
1173                     break;
1174                 case 1:
1175                     parameter = ccui.LinearLayoutParameter.create();
1176                     var gravity = layoutParameterDic["gravity"];
1177                     parameter.setGravity(gravity);
1178                     break;
1179                 case 2:
1180                     parameter = ccui.RelativeLayoutParameter.create();
1181                     var relativeName = layoutParameterDic["relativeName"];
1182                     parameter.setRelativeName(relativeName);
1183                     var relativeToName = layoutParameterDic["relativeToName"];
1184                     parameter.setRelativeToWidgetName(relativeToName);
1185                     parameter.setAlign(layoutParameterDic["align"]);
1186                     break;
1187                 default:
1188                     break;
1189             }
1190             var mgl = layoutParameterDic["marginLeft"];
1191             var mgt = layoutParameterDic["marginTop"];
1192             var mgr = layoutParameterDic["marginRight"];
1193             var mgb = layoutParameterDic["marginDown"];
1194             parameter.setMargin(new ccui.Margin(mgl, mgt, mgr, mgb));
1195             widget.setLayoutParameter(parameter);
1196         }
1197     },
1198 
1199     /**
1200      * Sets widget's color, anchor point, flipped properties from json dictionary.
1201      * @param {ccui.Widget} widget
1202      * @param {Object} options json dictionary
1203      */
1204     setColorPropsForWidgetFromJsonDictionary: function (widget, options) {
1205         if (options["opacity"] !== undefined) {
1206             widget.setOpacity(options["opacity"]);
1207         }
1208         var colorR = options["colorR"] !== undefined ? options["colorR"] : 255;
1209         var colorG = options["colorG"] !== undefined ? options["colorG"] : 255;
1210         var colorB = options["colorB"] !== undefined ? options["colorB"] : 255;
1211         widget.setColor(cc.color(colorR, colorG, colorB));
1212         var apx = options["anchorPointX"] !== undefined ? options["anchorPointX"] : ((widget.getWidgetType() == ccui.Widget.TYPE_WIDGET) ? 0.5 : 0);
1213         var apy = options["anchorPointY"] !== undefined ? options["anchorPointY"] : ((widget.getWidgetType() == ccui.Widget.TYPE_WIDGET) ? 0.5 : 0);
1214         widget.setAnchorPoint(apx, apy);
1215         var flipX = options["flipX"];
1216         var flipY = options["flipY"];
1217         widget.setFlippedX(flipX);
1218         widget.setFlippedY(flipY);
1219     },
1220 
1221     /**
1222      * Sets ccui.Button's properties from json dictionary.
1223      * @param {ccui.Button} widget
1224      * @param {Object} options json dictionary
1225      */
1226     setPropsForButtonFromJsonDictionary: function (widget, options) {
1227         this.setPropsForWidgetFromJsonDictionary(widget, options);
1228         var button = widget;
1229         var scale9Enable = options["scale9Enable"];
1230         button.setScale9Enabled(scale9Enable);
1231 
1232         var normalDic = options["normalData"];
1233         var normalType = normalDic["resourceType"];
1234         switch (normalType) {
1235             case 0:
1236                 var normalFileName = normalDic["path"];
1237                 var normalFileName_tp = normalFileName ? this._filePath + normalFileName : null;
1238                 button.loadTextureNormal(normalFileName_tp);
1239                 break;
1240             case 1:
1241                 var normalFileName = normalDic["path"];
1242                 button.loadTextureNormal(normalFileName, ccui.Widget.PLIST_TEXTURE);
1243                 break;
1244             default:
1245                 break;
1246         }
1247         normalDic = null;
1248         var pressedDic = options["pressedData"];
1249         var pressedType = pressedDic["resourceType"];
1250         switch (pressedType) {
1251             case 0:
1252                 var pressedFileName = pressedDic["path"];
1253                 var pressedFileName_tp = pressedFileName ? this._filePath + pressedFileName : null;
1254                 button.loadTexturePressed(pressedFileName_tp);
1255                 break;
1256             case 1:
1257                 var pressedFileName = pressedDic["path"];
1258                 button.loadTexturePressed(pressedFileName, ccui.Widget.PLIST_TEXTURE);
1259                 break;
1260             default:
1261                 break;
1262         }
1263         pressedDic = null;
1264         var disabledDic = options["disabledData"];
1265         var disabledType = disabledDic["resourceType"];
1266         switch (disabledType) {
1267             case 0:
1268                 var disabledFileName = disabledDic["path"];
1269                 var disabledFileName_tp = disabledFileName ? this._filePath + disabledFileName : null;
1270                 button.loadTextureDisabled(disabledFileName_tp);
1271                 break;
1272             case 1:
1273                 var disabledFileName = disabledDic["path"];
1274                 button.loadTextureDisabled(disabledFileName, ccui.Widget.PLIST_TEXTURE);
1275                 break;
1276             default:
1277                 break;
1278         }
1279         disabledDic = null;
1280         if (scale9Enable) {
1281             var cx = options["capInsetsX"];
1282             var cy = options["capInsetsY"];
1283             var cw = options["capInsetsWidth"];
1284             var ch = options["capInsetsHeight"];
1285 
1286             button.setCapInsets(cc.rect(cx, cy, cw, ch));
1287             if (options["scale9Width"] !== undefined && options["scale9Height"] !== undefined) {
1288                 var swf = options["scale9Width"];
1289                 var shf = options["scale9Height"];
1290                 button.setSize(cc.size(swf, shf));
1291             }
1292         }
1293         if (options["text"] !== undefined) {
1294             var text = options["text"] || "";
1295             if (text)
1296                 button.setTitleText(text);
1297         }
1298         if (options["fontSize"] !== undefined) {
1299             button.setTitleFontSize(options["fontSize"]);
1300         }
1301         if (options["fontName"] !== undefined) {
1302             button.setTitleFontName(options["fontName"]);
1303         }
1304         var cr = options["textColorR"] !== undefined ? options["textColorR"] : 255;
1305         var cg = options["textColorG"] !== undefined ? options["textColorG"] : 255;
1306         var cb = options["textColorB"] !== undefined ? options["textColorB"] : 255;
1307         var tc = cc.color(cr, cg, cb);
1308         button.setTitleColor(tc);
1309         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1310     },
1311 
1312     /**
1313      * Sets ccui.CheckBox's properties from json dictionary.
1314      * @param {ccui.CheckBox} widget
1315      * @param {Object} options json dictionary
1316      */
1317     setPropsForCheckBoxFromJsonDictionary: function (widget, options) {
1318         this.setPropsForWidgetFromJsonDictionary(widget, options);
1319         var checkBox = widget;
1320         var backGroundDic = options["backGroundBoxData"];
1321         var backGroundType = backGroundDic["resourceType"];
1322         switch (backGroundType) {
1323             case 0:
1324                 var backGroundFileName = backGroundDic["path"];
1325                 var backGroundFileName_tp = backGroundFileName ? this._filePath + backGroundFileName : null;
1326                 checkBox.loadTextureBackGround(backGroundFileName_tp);
1327                 break;
1328             case 1:
1329                 var backGroundFileName = backGroundDic["path"];
1330                 checkBox.loadTextureBackGround(backGroundFileName, ccui.Widget.PLIST_TEXTURE);
1331                 break;
1332             default:
1333                 break;
1334         }
1335         backGroundDic = null;
1336         var backGroundSelectedDic = options["backGroundBoxSelectedData"];
1337         var backGroundSelectedType = backGroundSelectedDic["resourceType"];
1338         switch (backGroundSelectedType) {
1339             case 0:
1340                 var backGroundSelectedFileName = backGroundSelectedDic["path"];
1341                 var backGroundSelectedFileName_tp = backGroundSelectedFileName ? this._filePath + backGroundSelectedFileName : null;
1342                 checkBox.loadTextureBackGroundSelected(backGroundSelectedFileName_tp);
1343                 break;
1344             case 1:
1345                 var backGroundSelectedFileName = backGroundSelectedDic["path"];
1346                 checkBox.loadTextureBackGroundSelected(backGroundSelectedFileName, ccui.Widget.PLIST_TEXTURE);
1347                 break;
1348             default:
1349                 break;
1350         }
1351         backGroundSelectedDic = null;
1352 
1353         var frontCrossDic = options["frontCrossData"];
1354         var frontCrossType = frontCrossDic["resourceType"];
1355         switch (frontCrossType) {
1356             case 0:
1357                 var frontCrossFileName = frontCrossDic["path"];
1358                 var frontCrossFileName_tp = frontCrossFileName ? this._filePath + frontCrossFileName : null;
1359                 checkBox.loadTextureFrontCross(frontCrossFileName_tp);
1360                 break;
1361             case 1:
1362                 var frontCrossFileName = frontCrossDic["path"];
1363                 checkBox.loadTextureFrontCross(frontCrossFileName, ccui.Widget.PLIST_TEXTURE);
1364                 break;
1365             default:
1366                 break;
1367         }
1368         frontCrossDic = null;
1369 
1370         var backGroundDisabledDic = options["backGroundBoxDisabledData"];
1371         var backGroundDisabledType = backGroundDisabledDic["resourceType"];
1372         switch (backGroundDisabledType) {
1373             case 0:
1374                 var backGroundDisabledFileName = backGroundDisabledDic["path"];
1375                 var backGroundDisabledFileName_tp = backGroundDisabledFileName ? this._filePath + backGroundDisabledFileName : null;
1376                 checkBox.loadTextureBackGroundDisabled(backGroundDisabledFileName_tp);
1377                 break;
1378             case 1:
1379                 var backGroundDisabledFileName = backGroundDisabledDic["path"];
1380                 checkBox.loadTextureBackGroundDisabled(backGroundDisabledFileName, ccui.Widget.PLIST_TEXTURE);
1381                 break;
1382             default:
1383                 break;
1384         }
1385         backGroundDisabledDic = null;
1386 
1387         var frontCrossDisabledDic = options["frontCrossDisabledData"];
1388         var frontCrossDisabledType = frontCrossDisabledDic["resourceType"];
1389         switch (frontCrossDisabledType) {
1390             case 0:
1391                 var frontCrossDisabledFileName = options["path"];
1392                 var frontCrossDisabledFileName_tp = frontCrossDisabledFileName ? this._filePath + frontCrossDisabledFileName : null;
1393                 checkBox.loadTextureFrontCrossDisabled(frontCrossDisabledFileName_tp);
1394                 break;
1395             case 1:
1396                 var frontCrossDisabledFileName = options["path"];
1397                 checkBox.loadTextureFrontCrossDisabled(frontCrossDisabledFileName, ccui.Widget.PLIST_TEXTURE);
1398                 break;
1399             default:
1400                 break;
1401         }
1402         frontCrossDisabledDic = null;
1403 
1404         var selectedState = options["selectedState"] || false;
1405         widget.setSelectedState(selectedState);
1406         checkBox.setSelectedState(options, "selectedState");
1407         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1408     },
1409 
1410     /**
1411      * Sets ccui.ImageView's properties from json dictionary.
1412      * @param {ccui.ImageView} widget
1413      * @param {Object} options json dictionary
1414      */
1415     setPropsForImageViewFromJsonDictionary: function (widget, options) {
1416         this.setPropsForWidgetFromJsonDictionary(widget, options);
1417 
1418         var imageView = widget;
1419 
1420         var imageFileNameDic = options["fileNameData"];
1421         var imageFileNameType = imageFileNameDic["resourceType"];
1422         switch (imageFileNameType) {
1423             case 0:
1424                 var tp_i = this._filePath;
1425                 var imageFileName = imageFileNameDic["path"];
1426                 var imageFileName_tp = null;
1427                 if (imageFileName) {
1428                     imageFileName_tp = tp_i + imageFileName;
1429                     imageView.loadTexture(imageFileName_tp);
1430                 }
1431                 break;
1432             case 1:
1433                 var imageFileName = imageFileNameDic["path"];
1434                 imageView.loadTexture(imageFileName, ccui.Widget.PLIST_TEXTURE);
1435                 break;
1436             default:
1437                 break;
1438         }
1439         imageFileNameDic = null;
1440 
1441         var scale9Enable = options["scale9Enable"] || false;
1442         imageView.setScale9Enabled(scale9Enable);
1443 
1444         if (scale9Enable) {
1445             if (options["scale9Width"] !== undefined && options["scale9Height"] !== undefined) {
1446                 var swf = options["scale9Width"];
1447                 var shf = options["scale9Height"];
1448                 imageView.setSize(cc.size(swf, shf));
1449             }
1450 
1451             var cx = options["capInsetsX"];
1452             var cy = options["capInsetsY"];
1453             var cw = options["capInsetsWidth"];
1454             var ch = options["capInsetsHeight"];
1455 
1456             imageView.setCapInsets(cc.rect(cx, cy, cw, ch));
1457 
1458         }
1459         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1460     },
1461 
1462     /**
1463      * Sets ccui.Text's properties from json dictionary.
1464      * @param {ccui.Text} widget
1465      * @param {Object} options json dictionary
1466      */
1467     setPropsForLabelFromJsonDictionary: function (widget, options) {
1468         this.setPropsForWidgetFromJsonDictionary(widget, options);
1469         var label = widget;
1470         var touchScaleChangeAble = options["touchScaleEnable"];
1471         label.setTouchScaleChangeEnabled(touchScaleChangeAble);
1472         var text = options["text"];
1473 
1474         label.setString(text);
1475         if (options["fontSize"] !== undefined) {
1476             label.setFontSize(options["fontSize"]);
1477         }
1478         if (options["fontName"] !== undefined) {
1479             label.setFontName(options["fontName"]);
1480         }
1481         if (options["areaWidth"] !== undefined && options["areaHeight"] !== undefined) {
1482             var size = cc.size(options["areaWidth"], options["areaHeight"]);
1483             label.setTextAreaSize(size);
1484         }
1485         if (options["hAlignment"]) {
1486             label.setTextHorizontalAlignment(options["hAlignment"]);
1487         }
1488         if (options["vAlignment"]) {
1489             label.setTextVerticalAlignment(options["vAlignment"]);
1490         }
1491         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1492     },
1493 
1494     /**
1495      * Sets ccui.TextAtlas's properties from json dictionary.
1496      * @param {ccui.TextAtlas} widget
1497      * @param {Object} options json dictionary
1498      */
1499     setPropsForLabelAtlasFromJsonDictionary: function (widget, options) {
1500         this.setPropsForWidgetFromJsonDictionary(widget, options);
1501         var labelAtlas = widget;
1502         var sv = (options["stringValue"] !== undefined);
1503         var cmf = (options["charMapFile"] !== undefined);
1504         var iw = (options["itemWidth"] !== undefined);
1505         var ih = (options["itemHeight"] !== undefined);
1506         var scm = (options["startCharMap"] !== undefined);
1507         if (sv && cmf && iw && ih && scm) {
1508 
1509             var cmftDic = options["charMapFileData"];
1510             var cmfType = cmftDic["resourceType"];
1511             switch (cmfType) {
1512                 case 0:
1513                     var cmfPath = cmftDic["path"];
1514                     var cmf_tp = this._filePath + cmfPath;
1515                     labelAtlas.setProperty(options["stringValue"], cmf_tp, options["itemWidth"], options["itemHeight"], options["startCharMap"]);
1516                     break;
1517                 case 1:
1518                     cc.log("Wrong res type of LabelAtlas!");
1519                     break;
1520                 default:
1521                     break;
1522             }
1523             cmftDic = null;
1524         }
1525         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1526     },
1527 
1528     /**
1529      * Sets ccui.Layout's properties from json dictionary.
1530      * @param {ccui.Layout} widget
1531      * @param {Object} options json dictionary
1532      */
1533     setPropsForLayoutFromJsonDictionary: function (widget, options) {
1534         this.setPropsForWidgetFromJsonDictionary(widget, options);
1535         var panel = widget;
1536         if (!(panel instanceof ccui.ScrollView) && !(panel instanceof ccui.ListView)) {
1537             panel.setClippingEnabled(options["clipAble"]);
1538         }
1539         var backGroundScale9Enable = options["backGroundScale9Enable"];
1540         panel.setBackGroundImageScale9Enabled(backGroundScale9Enable);
1541         var cr = options["bgColorR"];
1542         var cg = options["bgColorG"];
1543         var cb = options["bgColorB"];
1544 
1545         var scr = options["bgStartColorR"];
1546         var scg = options["bgStartColorG"]
1547         var scb = options["bgStartColorB"];
1548 
1549         var ecr = options["bgEndColorR"];
1550         var ecg = options["bgEndColorG"];
1551         var ecb = options["bgEndColorB"];
1552 
1553         var bgcv1 = options["vectorX"];
1554         var bgcv2 = options["vectorY"];
1555         panel.setBackGroundColorVector(cc.p(bgcv1, bgcv2));
1556 
1557         var co = options["bgColorOpacity"];
1558 
1559         var colorType = options["colorType"];
1560         panel.setBackGroundColorType(colorType);
1561         panel.setBackGroundColor(cc.color(scr, scg, scb), cc.color(ecr, ecg, ecb));
1562         panel.setBackGroundColor(cc.color(cr, cg, cb));
1563         panel.setBackGroundColorOpacity(co);
1564 
1565 
1566         var imageFileNameDic = options["backGroundImageData"] || {};
1567         var imageFileNameType = imageFileNameDic["resourceType"];
1568         switch (imageFileNameType) {
1569             case 0:
1570                 var imageFileName = imageFileNameDic["path"];
1571                 var imageFileName_tp = imageFileName ? this._filePath + imageFileName : null;
1572                 panel.setBackGroundImage(imageFileName_tp);
1573                 break;
1574             case 1:
1575                 var imageFileName = imageFileNameDic["path"];
1576                 panel.setBackGroundImage(imageFileName, ccui.Widget.PLIST_TEXTURE);
1577                 break;
1578             default:
1579                 break;
1580         }
1581         imageFileNameDic = null;
1582 
1583         if (backGroundScale9Enable) {
1584             var cx = options["capInsetsX"];
1585             var cy = options["capInsetsY"];
1586             var cw = options["capInsetsWidth"];
1587             var ch = options["capInsetsHeight"];
1588             panel.setBackGroundImageCapInsets(cc.rect(cx, cy, cw, ch));
1589         }
1590         panel.setLayoutType(options["layoutType"]);
1591         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1592     },
1593 
1594     /**
1595      * Sets ccui.ScrollView's properties from json dictionary.
1596      * @param {ccui.ScrollView} widget
1597      * @param {Object} options json dictionary
1598      */
1599     setPropsForScrollViewFromJsonDictionary: function (widget, options) {
1600         this.setPropsForLayoutFromJsonDictionary(widget, options);
1601         var scrollView = widget;
1602         var innerWidth = options["innerWidth"];
1603         var innerHeight = options["innerHeight"];
1604         scrollView.setInnerContainerSize(cc.size(innerWidth, innerHeight));
1605         var direction = options["direction"];
1606         scrollView.setDirection(direction);
1607         scrollView.setBounceEnabled(options["bounceEnable"]);
1608         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1609     },
1610 
1611     /**
1612      * Sets ccui.Slider's properties from json dictionary.
1613      * @param {ccui.Slider} widget
1614      * @param {Object} options json dictionary
1615      */
1616     setPropsForSliderFromJsonDictionary: function (widget, options) {
1617         this.setPropsForWidgetFromJsonDictionary(widget, options);
1618         var slider = widget;
1619 
1620         var barTextureScale9Enable = options["barTextureScale9Enable"] || false;
1621         slider.setScale9Enabled(barTextureScale9Enable);
1622         var barLength = options["length"];
1623         var bt = (options["barFileName"] !== undefined);
1624         if (bt) {
1625             if (barTextureScale9Enable) {
1626                 var imageFileNameDic = options["barFileNameData"];
1627                 var imageFileType = imageFileNameDic["resourceType"];
1628                 switch (imageFileType) {
1629                     case 0:
1630                         var imageFileName = imageFileNameDic["path"];
1631                         var imageFileName_tp = imageFileName ? this._filePath + imageFileName : null;
1632                         slider.loadBarTexture(imageFileName_tp);
1633                         break;
1634                     case 1:
1635                         var imageFileName = imageFileNameDic["path"];
1636                         slider.loadBarTexture(imageFileName, ccui.Widget.PLIST_TEXTURE);
1637                         break;
1638                     default:
1639                         break;
1640                 }
1641 
1642                 slider.setSize(cc.size(barLength, slider.getContentSize().height));
1643                 imageFileNameDic = null;
1644             }
1645             else {
1646                 var imageFileNameDic = options["barFileNameData"];
1647                 var imageFileType = imageFileNameDic["resourceType"];
1648                 switch (imageFileType) {
1649                     case 0:
1650                         var imageFileName = imageFileNameDic["path"];
1651                         var imageFileName_tp = imageFileName ? this._filePath + imageFileName : null;
1652                         slider.loadBarTexture(imageFileName_tp);
1653                         break;
1654                     case 1:
1655                         var imageFileName = imageFileNameDic["path"];
1656                         slider.loadBarTexture(imageFileName, ccui.Widget.PLIST_TEXTURE);
1657                         break;
1658                     default:
1659                         break;
1660                 }
1661                 imageFileNameDic = null;
1662             }
1663         }
1664 
1665         var normalDic = options["ballNormalData"];
1666         var normalType = normalDic["resourceType"];
1667         switch (normalType) {
1668             case 0:
1669                 var normalFileName = normalDic["path"];
1670                 var normalFileName_tp = normalFileName ? this._filePath + normalFileName : null;
1671                 slider.loadSlidBallTextureNormal(normalFileName_tp);
1672                 break;
1673             case 1:
1674                 var normalFileName = normalDic["path"];
1675                 slider.loadSlidBallTextureNormal(normalFileName, ccui.Widget.PLIST_TEXTURE);
1676                 break;
1677             default:
1678                 break;
1679         }
1680         normalDic = null;
1681 
1682         var pressedDic = options["ballPressedData"];
1683         var pressedType = pressedDic["resourceType"];
1684         switch (pressedType) {
1685             case 0:
1686                 var pressedFileName = pressedDic["path"];
1687                 var pressedFileName_tp = pressedFileName ? this._filePath + pressedFileName : null;
1688                 slider.loadSlidBallTexturePressed(pressedFileName_tp);
1689                 break;
1690             case 1:
1691                 var pressedFileName = pressedDic["path"];
1692                 slider.loadSlidBallTexturePressed(pressedFileName, ccui.Widget.PLIST_TEXTURE);
1693                 break;
1694             default:
1695                 break;
1696         }
1697         pressedDic = null;
1698 
1699         var disabledDic = options["ballDisabledData"];
1700         var disabledType = disabledDic["resourceType"];
1701         switch (disabledType) {
1702             case 0:
1703                 var disabledFileName = disabledDic["path"];
1704                 var disabledFileName_tp = disabledFileName ? this._filePath + disabledFileName : null;
1705                 slider.loadSlidBallTextureDisabled(disabledFileName_tp);
1706                 break;
1707             case 1:
1708                 var disabledFileName = disabledDic["path"];
1709                 slider.loadSlidBallTextureDisabled(disabledFileName, ccui.Widget.PLIST_TEXTURE);
1710                 break;
1711             default:
1712                 break;
1713         }
1714         disabledDic = null;
1715 
1716         var progressBarDic = options["progressBarData"];
1717         var progressBarType = progressBarDic["resourceType"];
1718         switch (progressBarType) {
1719             case 0:
1720                 var imageFileName = progressBarDic["path"];
1721                 var imageFileName_tp = imageFileName ? this._filePath + imageFileName : null;
1722                 slider.loadProgressBarTexture(imageFileName_tp);
1723                 break;
1724             case 1:
1725                 var imageFileName = progressBarDic["path"];
1726                 slider.loadProgressBarTexture(imageFileName, ccui.Widget.PLIST_TEXTURE);
1727                 break;
1728             default:
1729                 break;
1730         }
1731         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1732 
1733         slider.setPercent(options["percent"]);
1734     },
1735 
1736     /**
1737      * Sets ccui.TextField's properties from json dictionary.
1738      * @param {ccui.TextField} widget
1739      * @param {Object} options json dictionary
1740      */
1741     setPropsForTextAreaFromJsonDictionary: function (widget, options) {
1742         this.setPropsForWidgetFromJsonDictionary(widget, options);
1743         var textArea = widget;
1744         textArea.setString(options["text"]);
1745         if (options["fontSize"] !== undefined)
1746             textArea.setFontSize(options["fontSize"]);
1747         var cr = options["colorR"];
1748         var cg = options["colorG"];
1749         var cb = options["colorB"];
1750         textArea.setColor(cc.color((cr==null)?255:cr, (cg==null)?255:cg, (cb==null)?255:cb));
1751         textArea.setFontName(options["fontName"]);
1752         if (options["areaWidth"] !== undefined && options["areaHeight"] !== undefined) {
1753             var size = cc.size(options["areaWidth"], options["areaHeight"]);
1754             textArea.setTextAreaSize(size);
1755         }
1756         if (options["hAlignment"])
1757             textArea.setTextHorizontalAlignment(options["hAlignment"]);
1758         if (options["vAlignment"])
1759             textArea.setTextVerticalAlignment(options["vAlignment"]);
1760         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1761     },
1762 
1763     /**
1764      * Sets ccui.Button's text properties from json dictionary.
1765      * @param {ccui.Button} widget
1766      * @param {Object} options json dictionary
1767      */
1768     setPropsForTextButtonFromJsonDictionary: function (widget, options) {
1769         this.setPropsForButtonFromJsonDictionary(widget, options);
1770 
1771         var textButton = widget;
1772         textButton.setTitleText(options["text"] || "");
1773         var cri = options["textColorR"] !== undefined ? options["textColorR"] : 255;
1774         var cgi = options["textColorG"] !== undefined ? options["textColorG"] : 255;
1775         var cbi = options["textColorB"] !== undefined ? options["textColorB"] : 255;
1776         textButton.setTitleColor(cc.color(cri, cgi, cbi));
1777         if (options["fontSize"] !== undefined)
1778             textButton.setTitleFontSize(options["fontSize"]);
1779         if (options["fontName"] !== undefined)
1780             textButton.setTitleFontName(options["fontName"]);
1781         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1782     },
1783 
1784     /**
1785      * Sets ccui.TextField's text properties from json dictionary.
1786      * @param {ccui.TextField} widget
1787      * @param {Object} options json dictionary
1788      */
1789     setPropsForTextFieldFromJsonDictionary: function (widget, options) {
1790         this.setPropsForWidgetFromJsonDictionary(widget, options);
1791         var textField = widget;
1792         if (options["placeHolder"] !== undefined) {
1793             textField.setPlaceHolder(options["placeHolder"]);
1794         }
1795         textField.setString(options["text"]);
1796         if (options["fontSize"] !== undefined) {
1797             textField.setFontSize(options["fontSize"]);
1798         }
1799         if (options["fontName"] !== undefined) {
1800             textField.setFontName(options["fontName"]);
1801         }
1802         if (options["touchSizeWidth"] !== undefined && options["touchSizeHeight"] !== undefined) {
1803             textField.setTouchSize(cc.size(options["touchSizeWidth"], options["touchSizeHeight"]));
1804         }
1805 
1806         var dw = options["width"];
1807         var dh = options["height"];
1808         if (dw > 0.0 || dh > 0.0) {
1809             //textField.setSize(CCSizeMake(dw, dh));
1810         }
1811         var maxLengthEnable = options["maxLengthEnable"];
1812         textField.setMaxLengthEnabled(maxLengthEnable);
1813 
1814         if (maxLengthEnable) {
1815             var maxLength = options["maxLength"];
1816             textField.setMaxLength(maxLength);
1817         }
1818         var passwordEnable = options["passwordEnable"];
1819         textField.setPasswordEnabled(passwordEnable);
1820         if (passwordEnable) {
1821             textField.setPasswordStyleText(options["passwordStyleText"]);
1822         }
1823         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1824     },
1825 
1826     /**
1827      * Sets ccui.LoadingBar's properties from json dictionary.
1828      * @param {ccui.LoadingBar} widget
1829      * @param {Object} options json dictionary
1830      */
1831     setPropsForLoadingBarFromJsonDictionary: function (widget, options) {
1832         this.setPropsForWidgetFromJsonDictionary(widget, options);
1833         var loadingBar = widget;
1834 
1835         var imageFileNameDic = options["textureData"];
1836         var imageFileNameType = imageFileNameDic["resourceType"];
1837         switch (imageFileNameType) {
1838             case 0:
1839                 var tp_i = this._filePath;
1840                 var imageFileName = imageFileNameDic["path"];
1841                 var imageFileName_tp = null;
1842                 if (imageFileName) {
1843                     imageFileName_tp = tp_i + imageFileName;
1844                     loadingBar.loadTexture(imageFileName_tp);
1845                 }
1846                 break;
1847             case 1:
1848                 var imageFileName = imageFileNameDic["path"];
1849                 loadingBar.loadTexture(imageFileName, ccui.Widget.PLIST_TEXTURE);
1850                 break;
1851             default:
1852                 break;
1853         }
1854         imageFileNameDic = null;
1855 
1856         var scale9Enable = options["scale9Enable"];
1857         loadingBar.setScale9Enabled(scale9Enable);
1858 
1859         if (scale9Enable) {
1860             var cx = options["capInsetsX"];
1861             var cy = options["capInsetsY"];
1862             var cw = options["capInsetsWidth"];
1863             var ch = options["capInsetsHeight"];
1864 
1865             loadingBar.setCapInsets(cc.rect(cx, cy, cw, ch));
1866 
1867             var width = options["width"];
1868             var height = options["height"];
1869             loadingBar.setSize(cc.size(width, height));
1870         }
1871 
1872         loadingBar.setDirection(options["direction"]);
1873         loadingBar.setPercent(options["percent"]);
1874         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1875 
1876     },
1877 
1878     /**
1879      * Sets ccui.ListView's properties from json dictionary.
1880      * @param {ccui.ListView} widget
1881      * @param {Object} options json dictionary
1882      */
1883     setPropsForListViewFromJsonDictionary: function (widget, options) {
1884         this.setPropsForLayoutFromJsonDictionary(widget, options);
1885         var innerWidth = options["innerWidth"] || 0;
1886         var innerHeight = options["innerHeight"] || 0;
1887         widget.setInnerContainerSize(cc.size(innerWidth, innerHeight));
1888         widget.setDirection(options["direction"] || 0);
1889         widget.setGravity(options["gravity"] || 0);
1890         widget.setItemsMargin(options["itemMargin"] || 0);
1891     },
1892 
1893     /**
1894      * Sets ccui.PageView's properties from json dictionary.
1895      * @param {ccui.PageView} widget
1896      * @param {Object} options json dictionary
1897      */
1898     setPropsForPageViewFromJsonDictionary: function (widget, options) {
1899         this.setPropsForLayoutFromJsonDictionary(widget, options);
1900     },
1901 
1902     /**
1903      * Sets ccui.TextBMFont's properties from json dictionary.
1904      * @param {ccui.TextBMFont} widget
1905      * @param {Object} options json dictionary
1906      */
1907     setPropsForLabelBMFontFromJsonDictionary: function (widget, options) {
1908         this.setPropsForWidgetFromJsonDictionary(widget, options);
1909 
1910         var labelBMFont = widget;
1911 
1912         var cmftDic = options["fileNameData"];
1913         var cmfType = cmftDic["resourceType"];
1914         switch (cmfType) {
1915             case 0:
1916                 var cmfPath = cmftDic["path"];
1917                 var cmf_tp = this._filePath + cmfPath;
1918                 labelBMFont.setFntFile(cmf_tp);
1919                 break;
1920             case 1:
1921                 cc.log("Wrong res type of LabelAtlas!");
1922                 break;
1923             default:
1924                 break;
1925         }
1926         cmftDic = null;
1927 
1928         var text = options["text"];
1929         labelBMFont.setString(text);
1930 
1931         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1932     }
1933 });
1934