You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-commits@incubator.apache.org by jm...@apache.org on 2006/09/03 22:42:18 UTC

svn commit: r439862 - in /incubator/xap/trunk/src/xap/widgets: BaseWidget.js Button.js Checkbox.js Label.js RadioButton.js

Author: jmargaris
Date: Sun Sep  3 15:42:18 2006
New Revision: 439862

URL: http://svn.apache.org/viewvc?view=rev&rev=439862
Log:
new button, label, radioButton and checkBox widgets

Added:
    incubator/xap/trunk/src/xap/widgets/BaseWidget.js   (with props)
    incubator/xap/trunk/src/xap/widgets/Button.js   (with props)
    incubator/xap/trunk/src/xap/widgets/Checkbox.js   (with props)
    incubator/xap/trunk/src/xap/widgets/Label.js   (with props)
    incubator/xap/trunk/src/xap/widgets/RadioButton.js   (with props)

Added: incubator/xap/trunk/src/xap/widgets/BaseWidget.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/widgets/BaseWidget.js?view=auto&rev=439862
==============================================================================
--- incubator/xap/trunk/src/xap/widgets/BaseWidget.js (added)
+++ incubator/xap/trunk/src/xap/widgets/BaseWidget.js Sun Sep  3 15:42:18 2006
@@ -0,0 +1,49 @@
+/*
+ * Copyright  2006 The Apache Software Foundation.
+ *
+ *  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.
+ *
+ */
+ 
+
+
+Xap.provide("xap.widgets.BaseWidget");
+
+
+
+xap.widgets.BaseWidget = function() {
+	
+	this._rootDomNode = document.createElement('div');
+	
+}
+
+/*
+xap.widgets.BaseWidget.prototype.setX = function(x) {
+	this._rootDomNode.style.top = x;
+}
+
+
+xap.widgets.BaseWidget.prototype.setY = function(y) {
+	this._rootDomNode.style.left = y;
+}
+
+xap.widgets.BaseWidget.prototype.setWidth = function(w) {
+	this._rootDomNode.style.width = w;
+}
+
+
+xap.widgets.BaseWidget.prototype.setHeight = function(h) {
+	this._rootDomNode.style.height = h;
+}
+*/
+

Propchange: incubator/xap/trunk/src/xap/widgets/BaseWidget.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/xap/trunk/src/xap/widgets/Button.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/widgets/Button.js?view=auto&rev=439862
==============================================================================
--- incubator/xap/trunk/src/xap/widgets/Button.js (added)
+++ incubator/xap/trunk/src/xap/widgets/Button.js Sun Sep  3 15:42:18 2006
@@ -0,0 +1,71 @@
+/*
+ * Copyright  2006 The Apache Software Foundation.
+ *
+ *  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.
+ *
+ */
+ 
+
+Xap.provide("xap.widgets.Button");
+Xap.require("xap.widgets.Label");
+
+
+
+xap.widgets.Button = function() {
+	
+	xap.widgets.Label.call(this);
+	
+	
+	var root = this._rootDomNode;
+	
+	var onsetBorder = '2px solid #555';
+	var offsetBorder = '2px solid #ccc';
+	
+	
+	var styleMouseDown = function() {
+		root.style.borderTop = onsetBorder;
+		root.style.borderLeft = onsetBorder;
+		root.style.borderBottom = offsetBorder;
+		root.style.borderRight = offsetBorder;	
+	}
+	
+	var styleMouseUp = function() {
+		root.style.borderTop = offsetBorder;
+		root.style.borderLeft = offsetBorder;
+		root.style.borderBottom = onsetBorder;
+		root.style.borderRight = onsetBorder;			
+	}
+		
+	styleMouseUp();
+	root.style.cursor = 'default';
+
+	
+  this._rootDomNode.onmouseup = styleMouseUp;
+  this._rootDomNode.onmousedown = styleMouseDown;	
+	
+	
+
+
+}
+
+
+xap.widgets.Button.prototype = new xap.widgets.Label();
+
+
+xap.widgets.Button.prototype.setOnClick = function(obj, fn, param) {
+  this._rootDomNode.onclick = function() {
+		obj[fn] && obj[fn](param);
+	}
+	
+}
+

Propchange: incubator/xap/trunk/src/xap/widgets/Button.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/xap/trunk/src/xap/widgets/Checkbox.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/widgets/Checkbox.js?view=auto&rev=439862
==============================================================================
--- incubator/xap/trunk/src/xap/widgets/Checkbox.js (added)
+++ incubator/xap/trunk/src/xap/widgets/Checkbox.js Sun Sep  3 15:42:18 2006
@@ -0,0 +1,57 @@
+/*
+ * Copyright  2006 The Apache Software Foundation.
+ *
+ *  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.
+ *
+ */
+ 
+
+Xap.provide("xap.widgets.Checkbox");
+Xap.require("xap.widgets.Label");
+
+
+
+xap.widgets.Checkbox = function(text) {
+	
+	xap.widgets.Label.call(this);
+	
+	this.img.srcON = '../../css/tree_folderopen.gif'; /* should change to xapContext */
+	this.img.srcOFF = '../../css/tree_folderclosed.gif'; /* should change to xapContext */
+	this.img.srcToggle = this.img.srcOFF;	
+	this.img.style.display = '';
+	
+	this.setTextPlacementHorizontal('right');
+	this.setAlignVertical('center');
+	this.setAlignHorizontal('center');
+  
+	this.setImage(this.img.srcOFF);
+
+	this.img.onclick = function() {
+		this.srcToggle = (this.srcToggle == this.srcOFF) ? this.srcON : this.srcOFF;
+		this.src = this.srcToggle;
+		this.clickobj && this.clickobj[this.clickfn] && this.clickobj[this.clickfn](this.clickparam);
+
+	}
+	
+
+}
+
+xap.widgets.Checkbox.prototype = new xap.widgets.Label();
+
+
+xap.widgets.Checkbox.prototype.setOnClick = function(obj, fn, param) {
+	this.img.clickobj = obj;
+	this.img.clickfn = fn;
+	this.img.clickparam = param;
+}
+

Propchange: incubator/xap/trunk/src/xap/widgets/Checkbox.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/xap/trunk/src/xap/widgets/Label.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/widgets/Label.js?view=auto&rev=439862
==============================================================================
--- incubator/xap/trunk/src/xap/widgets/Label.js (added)
+++ incubator/xap/trunk/src/xap/widgets/Label.js Sun Sep  3 15:42:18 2006
@@ -0,0 +1,160 @@
+/*
+ * Copyright  2006 The Apache Software Foundation.
+ *
+ *  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.
+ *
+ */
+ 
+
+Xap.provide("xap.widgets.Label");
+Xap.require("xap.widgets.BaseWidget");
+
+
+xap.widgets.styleSet = function(el, properties) {
+
+	var style = el.style;
+	
+	for (var i in properties)  {
+		style[i] = properties[i];
+	}
+	
+}
+
+
+xap.widgets.Label = function() {
+	
+	xap.widgets.BaseWidget.call(this);
+	
+	this.table = document.createElement('table');
+	this.td = document.createElement('td');
+	this.br = document.createElement('br');
+	
+	var tbody = document.createElement('tbody');
+	var tr = document.createElement('tr');
+	
+
+	this.table.appendChild(tbody);
+	tbody.appendChild(tr);
+	tr.appendChild(this.td);
+	
+
+	this.span = document.createElement('span');
+	this.img = document.createElement('img');
+	this.img.style.display = 'none';
+	
+	this.td.appendChild(this.span);
+	this.td.appendChild(this.img);
+	
+	this._rootDomNode.appendChild(this.table);
+	
+	xap.widgets.styleSet(this.table, {backgroundColor: '#eee', width:'100%', height: '100%'});	/* to remove */
+	xap.widgets.styleSet(this.td, {backgroundColor: '#eef', width:'100%', height: '100%'});	/* to remove */	
+	
+	xap.widgets.styleSet(this._rootDomNode, {overflow:'hidden', position:'relative', backgroundColor:'gray'}); /* to remove */
+
+}
+
+
+xap.widgets.Label.prototype = new xap.widgets.BaseWidget();
+
+xap.widgets.Label.prototype.setText = function(text) {
+	if (this.span.firstChild) {
+		this.span.firstChild.nodeValue = text;
+	} else {
+		this.span.appendChild(document.createTextNode(text));
+	}
+}
+
+xap.widgets.Label.prototype.setImage = function(imageURL) {	
+  this.img.src = imageURL;
+	this.img.style.display = '';
+}
+
+xap.widgets.Label.prototype.setImageHint = function(text) {	
+
+}
+
+
+xap.widgets.Label.prototype.setAlignHorizontal = function(direction) {
+
+	if (direction == 'left') {
+		xap.widgets.styleSet(this.td, {textAlign: 'left'});
+		return;
+	}
+	
+	if (direction == 'right') {
+		xap.widgets.styleSet(this.td, {textAlign: 'right'});		
+		return;
+	}
+	
+	if (direction == 'center') {
+		xap.widgets.styleSet(this.td, {textAlign: 'center'});
+		return;
+	}	
+	
+}
+
+xap.widgets.Label.prototype.setAlignVertical = function(direction) {
+	if (direction == 'top') {
+		xap.widgets.styleSet(this.td, {verticalAlign: 'top'});		
+		return;
+	}
+	
+	if (direction == 'bottom') {
+		xap.widgets.styleSet(this.td, {verticalAlign: 'bottom'});				
+		return;
+	}
+
+	if (direction == 'center') {
+		xap.widgets.styleSet(this.td, {verticalAlign: 'middle'});				
+		return;
+	}	
+	
+}
+
+xap.widgets.Label.prototype.setTextPlacementHorizontal = function(direction) {
+	
+	if (this.img.style.display != 'none') { /* don't do anything if there is no image */
+	
+		var children = this.td.childNodes;
+		
+		for (var i = 0; i < children.length; i++) {
+			var node = children[i];
+			if (node.nodeType == 1 && node.nodeName == 'br') this.td.removeChild(node);
+		}
+	
+	
+		if (direction == 'left') {
+			this.td.insertBefore(this.span, this.img);
+		}
+		
+		if (direction == 'right') {
+			this.td.insertBefore(this.img, this.span);
+		}
+	}
+}
+
+xap.widgets.Label.prototype.setTextPlacementVertical = function(direction) {
+
+	if (this.img.style.display != 'none') { /* don't do anything if there is no image */
+		if (direction == 'bottom') {
+			this.td.insertBefore(this.img, this.span);
+			this.td.insertBefore(this.br, this.span);
+		}
+		
+		if (direction == 'top') {
+			this.td.insertBefore(this.span, this.img);
+			this.td.insertBefore(this.br, this.img);
+		}
+	}
+}

Propchange: incubator/xap/trunk/src/xap/widgets/Label.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/xap/trunk/src/xap/widgets/RadioButton.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/widgets/RadioButton.js?view=auto&rev=439862
==============================================================================
--- incubator/xap/trunk/src/xap/widgets/RadioButton.js (added)
+++ incubator/xap/trunk/src/xap/widgets/RadioButton.js Sun Sep  3 15:42:18 2006
@@ -0,0 +1,61 @@
+/*
+ * Copyright  2006 The Apache Software Foundation.
+ *
+ *  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.
+ *
+ */
+ 
+
+Xap.provide("xap.widgets.RadioButton");
+Xap.require("xap.widgets.Label");
+
+
+
+xap.widgets.RadioButton = function(text) {
+	
+	xap.widgets.Label.call(this);
+	
+	this.img.srcON = '../../css/tree_folderopen.gif'; /* should change to xapContext */
+	this.img.srcOFF = '../../css/tree_folderclosed.gif'; /* should change to xapContext */
+	this.img.srcToggle = this.img.srcOFF;	
+	this.img.style.display = '';
+	
+	this.setTextPlacementHorizontal('right');
+	this.setAlignVertical('center');
+	this.setAlignHorizontal('center');
+  
+	this.setImage(this.img.srcOFF);
+
+	this.img.onclick = function() {
+		this.srcToggle = (this.srcToggle == this.srcOFF) ? this.srcON : this.srcOFF;
+		this.src = this.srcToggle;
+		this.clickobj && this.clickobj[this.clickfn] && this.clickobj[this.clickfn](this.clickparam);
+
+	}
+	
+
+}
+
+xap.widgets.RadioButton.prototype = new xap.widgets.Label();
+
+
+xap.widgets.RadioButton.prototype.setOnClick = function(obj, fn, param) {
+	this.img.clickobj = obj;
+	this.img.clickfn = fn;
+	this.img.clickparam = param;
+}
+
+xap.widgets.RadioButton.prototype.reset = function() {
+	this.img.srcToggle = this.img.srcOFF;
+  this.setImage(this.img.srcOFF);
+}

Propchange: incubator/xap/trunk/src/xap/widgets/RadioButton.js
------------------------------------------------------------------------------
    svn:eol-style = native