1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* DreemGL is a collaboration between Teeming Society & Samsung Electronics, sponsored by Samsung and others.
   Copyright 2015-2016 Teeming Society. Licensed under the Apache License, Version 2.0 (the "License"); You may not use this file except in compliance with the License.
   You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing,
   software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and limitations under the License.*/


define.class(function(require, $ui$, foldcontainer, view, label, scrollbar, textbox, $widgets$, propeditor){
// The property viewer allows for the visual inspection and manipulation of properties on DreemGL objects

        this.attributes = {

                // The target who's properties to view.  Can be either a DreemGL object or a named reference to one.
                target:Config({type:Object, value:""}),
                // Shows properties for unknown property types
                showunknown:Config({type:boolean, value:false}),

                // internal, Callback used by the property editor to actually set properties.
                callback:Config({type:Function})
        };

        this.borderwidth = 0;
        this.flexdirection= "column";
        this.margin = 0;
        this.clearcolor = "#4e4e4e";
        this.padding = 0;
        this.bgcolor = NaN;

        this.uppercaseFirst = function (inp) {
                if (!inp || inp.length == 0) return inp;
                return inp.charAt(0).toUpperCase() + inp.slice(1);
        };

        this.render = function(){
                var c = this.target;
                if (typeof(this.target) === 'string') {
                        c = this.find(this.target);
                }

                if (!c) return [];

                var res = [];
                var keysgroups = {};

        for (var key in c._attributes) {
                        var attr = c._attributes[key];

                        var typename = "NONE";
                        var meta = attr.meta;

                        if (attr.type) {
                                typename = attr.type.name;
                                if (attr.type.meta) {
                                        meta = attr.type.meta;
                                }
                        }

                        if (key == "layout") {
                                meta = "hidden";
                        }

                        if (typename != "NONE" && typename != "Event" && meta != "hidden") {
                                if (!keysgroups[attr.group]) keysgroups[attr.group] = [];
                                keysgroups[attr.group].push(key);
                        }
                }

                for(var group in keysgroups){
                        var groupcontent = [];

                        keys = keysgroups[group];

                        keys.sort();

                        for(var i = 0 ;i<keys.length;i++){
                                var key = keys[i];
                                var thevalue = c["_"+key];
                                var attr = c._attributes[key];
                                var props = {
                                        target:this.target,
                                        value:thevalue,
                                        property:attr,
                                        propertyname: key,
                                        fontsize:this.fontsize,
                                        showunknown:this.showunknown
                                };

                                if (this.callback) {
                                        props.callback = this.callback;
                                }
                                groupcontent.push(propeditor(props))
                        }

                        res.push(
                                foldcontainer({
                                                collapsed: true,
                                                basecolor:this.clearcolor,
                                                autogradient: false,
                                                icon:undefined,
                                                title: this.uppercaseFirst(group),
                                                bordercolor:"#565656",
                                                fontsize:this.fontsize
                                        },
                                        view({
                                                        flexdirection:"column",
                                                        flex:1,
                                                        margin:0,
                                                        padding:0,
                                                        bgcolor:NaN
                                                },
                                                groupcontent
                                        )
                                )
                        );

                        res[res.length-1].collapsed = function(){
                                window.mydbg = 1
                        }
                }
                return res;
        };

        var propviewer = this.constructor;
        this.constructor.examples = {
                Usage: function () {
                        return [
                                label({height:30, width:300,
                                        name:"inspectable",
                                        text:"Inspect me below!",
                                        fgcolor:'red',
                                        bordercolor:'pink',
                                        borderwidth:3}),
                                propviewer({y:40, width:300, height:700, target:"inspectable", overflow:"scroll"})
                        ]
                }
        }

});