From xap-commits-return-615-apmail-incubator-xap-commits-archive=incubator.apache.org@incubator.apache.org Fri Oct 27 18:49:10 2006 Return-Path: Delivered-To: apmail-incubator-xap-commits-archive@locus.apache.org Received: (qmail 73791 invoked from network); 27 Oct 2006 18:49:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 27 Oct 2006 18:49:09 -0000 Received: (qmail 57802 invoked by uid 500); 27 Oct 2006 18:49:20 -0000 Delivered-To: apmail-incubator-xap-commits-archive@incubator.apache.org Received: (qmail 57788 invoked by uid 500); 27 Oct 2006 18:49:20 -0000 Mailing-List: contact xap-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: xap-dev@incubator.apache.org Delivered-To: mailing list xap-commits@incubator.apache.org Received: (qmail 57779 invoked by uid 99); 27 Oct 2006 18:49:20 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Oct 2006 11:49:20 -0700 X-ASF-Spam-Status: No, hits=0.6 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Oct 2006 11:49:07 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id DECDB1A984D; Fri, 27 Oct 2006 11:48:44 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r468492 [2/2] - in /incubator/xap/trunk: WebContent/examples/widgets/ src/xap/bridges/xap/ src/xap/widgets/ src/xap/widgets/images/ Date: Fri, 27 Oct 2006 18:48:44 -0000 To: xap-commits@incubator.apache.org From: mturyn@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061027184844.DECDB1A984D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: incubator/xap/trunk/src/xap/bridges/xap/LabelBridge.js URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/xap/LabelBridge.js?view=diff&rev=468492&r1=468491&r2=468492 ============================================================================== --- incubator/xap/trunk/src/xap/bridges/xap/LabelBridge.js (original) +++ incubator/xap/trunk/src/xap/bridges/xap/LabelBridge.js Fri Oct 27 11:48:42 2006 @@ -15,7 +15,7 @@ * */ -Xap.provide("xap.bridges.xap.LabelBridge"); +Xap.provide("xap.bridges.xap.LabelBridge"); Xap.require("xap.bridges.basic.AbstractWidgetBridge"); Xap.require("xap.widgets.Label"); @@ -25,45 +25,72 @@ Xap.setupClassAsSubclassOf("xap.bridges.xap.LabelBridge", "xap.bridges.basic.AbstractWidgetBridge"); +xap.bridges.xap.LabelBridge.prototype.obtainPeer = function() { + this.setPeer(new xap.widgets.Label()); +} +xap.bridges.xap.LabelBridge.prototype.getRootDomNode = function() { + return this.getPeer()._rootDomNode; +} -xap.bridges.xap.LabelBridge.prototype.obtainPeer = function() { +xap.bridges.xap.LabelBridge.prototype.getNewAllowedAttributes = function() { + return ["alignHorizontal", "alignVertical", "autoWrap", "enabled", "img", + "imgBackground", "imgDisabled", "imgHeight", "imgWidth", "richText", + "selectable", "text", "textPlacementHorizontal", "textPlacementVertical"]; +} - var labelWidget = new xap.widgets.Label(); - - this._peer = labelWidget; +xap.bridges.xap.LabelBridge.prototype.setAlignHorizontalAttribute = function(alignment) { + this.getPeer().setAlignHorizontal(alignment); +} +xap.bridges.xap.LabelBridge.prototype.setAlignVerticalAttribute = function(alignment) { + this.getPeer().setAlignVertical(alignment); } +xap.bridges.xap.LabelBridge.prototype.setAutoWrapAttribute = function(autoWrap) { + this.getPeer().setAutoWrap(autoWrap); +} -xap.bridges.xap.LabelBridge.prototype.getRootDomNode = function() { - return this._peer._rootDomNode; -} +xap.bridges.xap.LabelBridge.prototype.setEnabledAttribute = function(enabled) { + this.getPeer().setEnabled(enabled); +} -xap.bridges.xap.LabelBridge.prototype.getNewAllowedAttributes = function() { - return ["img","text", "alignVertical", "alignHorizontal", "textPlacementHorizontal", "textPlacementVertical"]; -} +xap.bridges.xap.LabelBridge.prototype.setImgAttribute = function(imgURL) { + this.getPeer().setImg(imgURL); +} -xap.bridges.xap.LabelBridge.prototype.setImgAttribute = function(imgUrl) { - this.getPeer().setImage(imgUrl); +xap.bridges.xap.LabelBridge.prototype.setImgBackgroundAttribute = function(imgURL) { + this.getPeer().setImgBackground(imgURL); } -xap.bridges.xap.LabelBridge.prototype.setTextAttribute = function(text) { - this.getPeer().setText(text); +xap.bridges.xap.LabelBridge.prototype.setImgDisabledAttribute = function(imgURL) { + this.getPeer().setImgDisabled(imgURL); } -xap.bridges.xap.LabelBridge.prototype.setAlignVerticalAttribute = function(alignment) { - this.getPeer().setAlignVertical(alignment); +xap.bridges.xap.LabelBridge.prototype.setImgHeightAttribute = function(imgHeight) { + this.getPeer().setImgHeight(imgHeight); } -xap.bridges.xap.LabelBridge.prototype.setAlignHorizontalAttribute = function(alignment) { - this.getPeer().setAlignHorizontal(alignment); +xap.bridges.xap.LabelBridge.prototype.setImgWidthAttribute = function(imgWidth) { + this.getPeer().setImgWidth(imgWidth); +} + +xap.bridges.xap.LabelBridge.prototype.setRichTextAttribute = function(richText) { + this.getPeer().setRichText(richText); +} + +xap.bridges.xap.LabelBridge.prototype.setSelectableAttribute = function(selectable) { + this.getPeer().setSelectable(selectable); +} + +xap.bridges.xap.LabelBridge.prototype.setTextAttribute = function(text) { + this.getPeer().setText(text); } xap.bridges.xap.LabelBridge.prototype.setTextPlacementHorizontalAttribute = function(alignment) { - this.getPeer().setTextPlacementHorizontal(alignment); + this.getPeer().setTextPlacementHorizontal(alignment); } xap.bridges.xap.LabelBridge.prototype.setTextPlacementVerticalAttribute = function(alignment) { this.getPeer().setTextPlacementVertical(alignment); -} +} \ No newline at end of file Modified: incubator/xap/trunk/src/xap/bridges/xap/RadioButtonBridge.js URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/xap/RadioButtonBridge.js?view=diff&rev=468492&r1=468491&r2=468492 ============================================================================== --- incubator/xap/trunk/src/xap/bridges/xap/RadioButtonBridge.js (original) +++ incubator/xap/trunk/src/xap/bridges/xap/RadioButtonBridge.js Fri Oct 27 11:48:42 2006 @@ -15,7 +15,7 @@ * */ -Xap.provide("xap.bridges.xap.RadioButtonBridge"); +Xap.provide("xap.bridges.xap.RadioButtonBridge"); Xap.require("xap.bridges.xap.ButtonBridge"); Xap.require("xap.widgets.RadioButton"); @@ -26,66 +26,123 @@ Xap.setupClassAsSubclassOf("xap.bridges.xap.RadioButtonBridge", "xap.bridges.xap.ButtonBridge"); xap.bridges.xap.RadioButtonBridge.prototype.obtainPeer = function() { - - this._peer = new xap.widgets.RadioButton( this.getSession()._webappContext); - this.group = this.getElement().getAttribute('group'); - - var session = this.getSession(); + this.setPeer(new xap.widgets.RadioButton()); + this.getPeer().init(this.getSession()._webappContext); + this.group = this.getElement().getAttribute("group"); - if (!session.radioGroup) session.radioGroup = {}; /* create a general radioGroup attribute in the global session */ - if (!session.radioGroup[this.group]) session.radioGroup[this.group] = {}; /* placeholder for the currently clicked radio button for this radio group */ + if (this.group) { + var session = this.getSession(); + if (!session.radioGroup) { + // create a general radioGroup attribute in the global session + session.radioGroup = {}; + } + if (!session.radioGroup[this.group]) { + // placeholder for the currently clicked radio button for this radio group + session.radioGroup[this.group] = {}; + } + } - this._peer.setOnClick(this, 'register', null); + this.getPeer().setOnClick(this, "register", null); } xap.bridges.xap.RadioButtonBridge.prototype.register = function() { + if (this.getPeer().enabled) { + if (this.group) { + var session = this.getSession(); + var radioGroup = session.radioGroup[this.group]; + var activeRadioButton = radioGroup.peer; + + if (!activeRadioButton) { + // act on the current element + this.getPeer().setOn(); + this.writeBackAttribute("selected", "true"); + + radioGroup.peer = this.getPeer(); + radioGroup.relatedElement = this; + + var clientEvent = new xap.session.ClientEvent(this.getElement(), session); + clientEvent.selected = "true"; + // fire onSelect event + this.fireEvent("onSelect", null, null, clientEvent); + // fire onStateChange event. + this.fireEvent("onStateChange", null, null, clientEvent); + } else if (activeRadioButton != this.getPeer()) { + // reset current active radio button for this radio group in the session object + activeRadioButton.setOff(); + // set previous radio button to false + radioGroup.relatedElement.writeBackAttribute("selected", "false"); - var session = this.getSession(); - var radioGroup = session.radioGroup[this.group]; - var activeRadioButton = radioGroup.peer; - - if (activeRadioButton && activeRadioButton != this._peer) { - activeRadioButton.setOff(); /* reset current active radio button for this radio group in the session object */ - radioGroup.relatedElement.writeBackAttribute('selected', 'false'); /* set previous radio button to false */ - - /* act on the current element */ - this._peer.setOn(); - this.writeBackAttribute('selected', 'true'); + // fire onStateChange event on the current element + if (radioGroup.relatedElement.getPeer().enabled) { + var clientEvent = new xap.session.ClientEvent(this.getElement(), session); + clientEvent.selected = "false"; + radioGroup.relatedElement.fireEvent("onStateChange", null, null, clientEvent); + } + + // act on the current element + this.getPeer().setOn(); + this.writeBackAttribute("selected", "true"); + + radioGroup.peer = this.getPeer(); + radioGroup.relatedElement = this; + + var clientEvent = new xap.session.ClientEvent(this.getElement(), session); + clientEvent.selected = "true"; + // fire onSelect event + this.fireEvent("onSelect", null, null, clientEvent); + // fire onStateChange event. + this.fireEvent("onStateChange", null, null, clientEvent); + } + } else { + if (this.getPeer().selected) { + this.getPeer().setOff(); + this.writeBackAttribute("selected", "true"); + } else { + this.getPeer().setOn(); + this.writeBackAttribute("selected", "false"); + } + var clientEvent = new xap.session.ClientEvent(this.getElement(), session); - this.fireEvent('onStateChange', null, null, clientEvent); - - radioGroup.peer = this._peer; - radioGroup.relatedElement = this; - - } - + clientEvent.selected = "true"; + // fire onSelect event + this.fireEvent("onSelect", null, null, clientEvent); + // fire onStateChange event. + this.fireEvent("onStateChange", null, null, clientEvent); + } + } } xap.bridges.xap.RadioButtonBridge.prototype.getNewAllowedAttributes = function() { - return ['text', 'alignVertical', 'alignHorizontal', 'textPlacementHorizontal', 'textPlacementVertical', 'selected']; -} - -xap.bridges.xap.RadioButtonBridge.prototype.setSelectedAttribute = function(value) { - - if (value == 'true') { - var radioGroup = this.getSession().radioGroup[this.group]; - - if (radioGroup && radioGroup.peer && radioGroup.relatedElement) { - radioGroup.peer.setOff(); - radioGroup.relatedElement.writeBackAttribute('selected', 'false'); - } - - this._peer.setOn(); - radioGroup.peer = this._peer; - radioGroup.relatedElement = this; - } - -} - - - - + return ["imgOverSelected", "imgPressedSelected", "imgSelected", "selected"]; +} +xap.bridges.xap.RadioButtonBridge.prototype.setImgOverSelectedAttribute = function(imgOverSelectedURL) { + this.getPeer().setImgOverSelected(imgOverSelectedURL); +} +xap.bridges.xap.RadioButtonBridge.prototype.setImgPressedSelectedAttribute = function(imgPressedSelectedURL) { + this.getPeer().setImgPressedSelected(imgPressedSelectedURL); +} +xap.bridges.xap.RadioButtonBridge.prototype.setImgSelectedAttribute = function(imgSelectedURL) { + this.getPeer().setImgSelected(imgSelectedURL); +} +xap.bridges.xap.RadioButtonBridge.prototype.setSelectedAttribute = function(value) { + if (value == "true") { + if (this.group) { + var radioGroup = this.getSession().radioGroup[this.group]; + + if (radioGroup && radioGroup.peer && radioGroup.relatedElement) { + radioGroup.peer.setOff(); + radioGroup.relatedElement.writeBackAttribute("selected", "false"); + } + radioGroup.peer = this.getPeer(); + radioGroup.relatedElement = this; + } + + this.getPeer().setOn(); + } else { + this.getPeer().setOff(); + } +} \ No newline at end of file Modified: incubator/xap/trunk/src/xap/widgets/Button.js URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/widgets/Button.js?view=diff&rev=468492&r1=468491&r2=468492 ============================================================================== --- incubator/xap/trunk/src/xap/widgets/Button.js (original) +++ incubator/xap/trunk/src/xap/widgets/Button.js Fri Oct 27 11:48:42 2006 @@ -14,43 +14,108 @@ * limitations under the License. * */ - Xap.provide("xap.widgets.Button"); Xap.require("xap.widgets.Label"); - - +Xap.require("dojo.event.*"); xap.widgets.Button = function() { - xap.widgets.Label.call(this); - - - var root = this._rootDomNode; + this.imgOverURL = ""; + this.imgPressedURL = ""; - var styleMouseDown = function() { - root.className = 'buttonDown'; - } - - var styleMouseUp = function() { - root.className = 'buttonUp'; + this.mouseOver = false; + this.mousePressed = false; +} + +Xap.setupClassAsSubclassOf("xap.widgets.Button", "xap.widgets.Label"); + +xap.widgets.Button.prototype.init = function() { + dojo.event.connect(this._rootDomNode, "onmousedown", this, "_onmousedown"); + dojo.event.connect(this._rootDomNode, "onmousedown", this, "_styleMousedown"); + + this.buttonUpClassName = "buttonUp"; + this.buttonDownClassName = "buttonDown"; + + this._rootDomNode.style.cursor = "default"; + this._rootDomNode.className = this.buttonUpClassName; +} + +/** + * Set img URL for mouse over. + * @param imgOverURL the img URL for mouse over. + */ +xap.widgets.Button.prototype.setImgOver = function(imgOverURL) { + this.imgOverURL = imgOverURL; + dojo.event.connect(this._rootDomNode, "onmouseover", this, "_onmouseover"); + dojo.event.connect(this._rootDomNode, "onmouseout", this, "_onmouseout"); +} + +/** + * Set img URL for mouse pressed. + * @param {url} imgPressedURL the img URL for mouse pressed. + */ +xap.widgets.Button.prototype.setImgPressed = function(imgPressedURL) { + this.imgPressedURL = imgPressedURL; + dojo.event.connect(this._rootDomNode, "onmousedown", this, "_onmousedown"); +} + +xap.widgets.Button.prototype._onmouseover = function() { + if (this.enabled) { + this.mouseOver = true; + this._showImg(); } - - styleMouseUp(); - root.style.cursor = 'default'; +} - this._rootDomNode.onmouseup = styleMouseUp; - this._rootDomNode.onmousedown = styleMouseDown; - +xap.widgets.Button.prototype._onmouseout = function() { + if (this.enabled) { + this.mouseOver = false; + this._showImg(); + } } +xap.widgets.Button.prototype._onmousedown = function() { + if (this.enabled) { + if (this.buttonDownClassName) { + this._rootDomNode.className = this.buttonDownClassName; + } + + this.mousePressed = true; + this._showImg(); -xap.widgets.Button.prototype = new xap.widgets.Label(); + dojo.event.connect(document, "onmouseup", this, "_onmouseup"); + } +} + +xap.widgets.Button.prototype._onmouseup = function() { + if (this.enabled) { + if (this.buttonUpClassName) { + this._rootDomNode.className = this.buttonUpClassName; + } + this.mousePressed = false; + this._showImg(); -xap.widgets.Button.prototype.setOnClick = function(obj, fn, param) { - this._rootDomNode.onclick = function() { - obj[fn] && obj[fn](param); + dojo.event.disconnect(document, "onmouseup", this, "_onmouseup"); } } + +/** + * Get proper img URL for display. + */ +xap.widgets.Button.prototype._getProperImgURL = function() { + imgURL = ""; + + if (this.enabled) { + if (this.mousePressed && this.imgPressedURL != "") { + imgURL = this.imgPressedURL; + } else if (this.mouseOver && this.imgOverURL != "") { + imgURL = this.imgOverURL; + } + } else { + imgURL = this.imgDisabledURL; + } + + return (imgURL == "") ? this.imgURL : imgURL; +} \ No newline at end of file Modified: incubator/xap/trunk/src/xap/widgets/Checkbox.js URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/widgets/Checkbox.js?view=diff&rev=468492&r1=468491&r2=468492 ============================================================================== --- incubator/xap/trunk/src/xap/widgets/Checkbox.js (original) +++ incubator/xap/trunk/src/xap/widgets/Checkbox.js Fri Oct 27 11:48:42 2006 @@ -13,64 +13,23 @@ * 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.require("xap.widgets.RadioButton"); +Xap.require("dojo.event.*"); - - -xap.widgets.Checkbox = function(appContext) { - - xap.widgets.Label.call(this); - - this.img.srcON = appContext + 'src/xap/widgets/images/checkbox_on.gif'; - this.img.srcOFF = appContext + 'src/xap/widgets/images/checkbox_off.gif'; - this.img.srcToggle = this.img.srcOFF; - this.img.style.display = ''; - - this.setTextPlacementHorizontal('right'); - this.setAlignVertical('center'); - this.setAlignHorizontal('center'); - this.setOff(); - - var parent = this; - - this.img.onclick = function() { - (this.srcToggle == this.srcOFF) ? parent.setOn() : parent.setOff(); - 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; -} - - -xap.widgets.Checkbox.prototype.setOn = function() { - this.setImage(this.img.srcON); - this.img.srcToggle = this.img.srcON; - this.selected = 'true'; -} - -xap.widgets.Checkbox.prototype.setOff = function() { - this.setImage(this.img.srcOFF); - this.img.srcToggle = this.img.srcOFF; - this.selected = 'false'; -} - -xap.widgets.Checkbox.prototype.getSelected = function() { - return this.selected; +xap.widgets.Checkbox = function() { + xap.widgets.RadioButton.call(this); } +Xap.setupClassAsSubclassOf("xap.widgets.Checkbox", "xap.widgets.RadioButton"); +xap.widgets.Checkbox.prototype.init = function(appContext) { + this.img.srcON = appContext + "src/xap/widgets/images/checkbox_on.gif"; + this.img.srcOFF = appContext + "src/xap/widgets/images/checkbox_off.gif"; + this.img.srcONDisabled = appContext + "src/xap/widgets/images/checkbox_on_disabled.gif"; + this.img.srcOFFDisabled = appContext + "src/xap/widgets/images/checkbox_off_disabled.gif"; + this.setOff(); +} \ No newline at end of file Modified: incubator/xap/trunk/src/xap/widgets/Label.js URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/widgets/Label.js?view=diff&rev=468492&r1=468491&r2=468492 ============================================================================== --- incubator/xap/trunk/src/xap/widgets/Label.js (original) +++ incubator/xap/trunk/src/xap/widgets/Label.js Fri Oct 27 11:48:42 2006 @@ -15,150 +15,265 @@ * */ +/** + * @fileoverview This class represents a label widget. + * @author James Margaris, Yong Wang + * @version 0.1 + */ 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'); + // create label structure + this.table = document.createElement("table"); this.table.cellPadding = "0px"; this.table.cellSpacing = "0px"; - this.td = document.createElement('td'); - this.td.style.whiteSpace = "nowrap"; - this.br = document.createElement('br'); - - var tbody = document.createElement('tbody'); - var tr = document.createElement('tr'); - - + 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.span = document.createElement("span"); + this.img = document.createElement("img"); + this.img.style.display = "none"; + this.td.appendChild(this.img); - + this.td.appendChild(this.span); + this._rootDomNode.appendChild(this.table); - this._rootDomNode.style.padding="2px"; - - xap.widgets.styleSet(this.table, {width:'100%', height: '100%'}); - xap.widgets.styleSet(this.td, {width:'100%', height: '100%'}); - - xap.widgets.styleSet(this._rootDomNode, {overflow:'hidden', position:'relative'}); + this._rootDomNode.style.padding = "2px"; + + xap.widgets.styleSet(this.table, {width:"100%", height: "100%"}); + xap.widgets.styleSet(this.td, {width:"100%", height: "100%"}); + xap.widgets.styleSet(this._rootDomNode, {overflow:"hidden", position:"relative"}); + + this.enabled = true; + this.text = ""; + this.imgURL = ""; + this.imgDisabledURL = ""; + this.richText = "false"; + this.textPlacementVertical = ""; + this.textPlacementHorizontal = ""; + + this.setSelectable("false"); + this.setEnabled("true"); + this.setAutoWrap("false"); } +Xap.setupClassAsSubclassOf("xap.widgets.Label", "xap.widgets.BaseWidget"); -xap.widgets.Label.prototype = new xap.widgets.BaseWidget(); +xap.widgets.styleSet = function(el, properties) { + var style = el.style; + for (var i in properties) { + style[i] = properties[i]; + } +} + +/** + * Set label text attribute. + * @param {string} text the value of the text attribute. + */ xap.widgets.Label.prototype.setText = function(text) { - if (this.span.firstChild) { - this.span.firstChild.nodeValue = text; - } else { - this.span.appendChild(document.createTextNode(text)); + this.text = text; + this._showText(); +} + +/** + * Set "richText" attribute for the label. + * @param {boolean} richText if true, the label will show richText, otherwise not. + */ +xap.widgets.Label.prototype.setRichText = function(richText) { + if (this.richText != richText) { + this.richText = richText; + this._showText(); } } -xap.widgets.Label.prototype.setImage = function(imageURL) { - this.img.src = imageURL; - this.img.style.display = ''; +/** + * Show the proper text based on value of richText. + */ +xap.widgets.Label.prototype._showText = function() { + // give it proper text placement + if (this.img.style.display != "none") { + if (this.textPlacementHorizontal == "left" || this.textPlacementHorizontal == "right") { + 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 (this.textPlacementHorizontal == "left") { + this.td.insertBefore(this.span, this.img); + } else if(this.textPlacementHorizontal == "right") { + this.td.insertBefore(this.img, this.span); + } + } + + if (this.textPlacementVertical == "bottom") { + this.td.insertBefore(this.img, this.span); + this.td.insertBefore(this.br, this.span); + } else if (this.textPlacementVertical == "top") { + this.td.insertBefore(this.span, this.img); + this.td.insertBefore(this.br, this.img); + } + } + + this.span.innerHTML = ""; + + if (this.richText == "true") { + this.span.innerHTML = this.text; + } else { + this.span.appendChild(document.createTextNode(this.text)); + } } -xap.widgets.Label.prototype.setImageHint = function(text) { +/** + * Set img URL. + * @param {string} imgURL the img URL. + */ +xap.widgets.Label.prototype.setImg = function(imgURL) { + this.imgURL = imgURL; + this._showImg(); +} +/** + * Set disabled img URL. + * @param {string} imgDisabledURL the disabled img URL. + */ +xap.widgets.Label.prototype.setImgDisabled = function(imgDisabledURL) { + this.imgDisabledURL = imgDisabledURL; + this._showImg(); } +xap.widgets.Label.prototype.setImgHint = function(text) { + // TODO: implement later +} xap.widgets.Label.prototype.setAlignHorizontal = function(direction) { - - if (direction == 'left') { - xap.widgets.styleSet(this.td, {textAlign: 'left'}); - return; + if (direction == "left" || direction == "right" || direction == "center") { + eval("xap.widgets.styleSet(this.td, {textAlign: \"" + direction + "\"})"); } - - 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 == "top" || direction == "bottom" || direction == "center") { + direction = direction == "center" ? "middle" : direction; + eval("xap.widgets.styleSet(this.td, {verticalAlign: \"" + direction + "\"})"); } - - if (direction == 'bottom') { - xap.widgets.styleSet(this.td, {verticalAlign: 'bottom'}); - return; +} + +xap.widgets.Label.prototype.setTextPlacementHorizontal = function(direction) { + this.textPlacementHorizontal = direction; + this._showText(); +} + +xap.widgets.Label.prototype.setTextPlacementVertical = function(direction) { + this.textPlacementVertical = direction; + this._showText(); +} + +/** + * Set autoWrap attribute. + * @param {boolean} autoWrap if true, the text will be wrapped when necessary, otherwise, no wrap. + */ +xap.widgets.Label.prototype.setAutoWrap = function(autoWrap) { + if (autoWrap == "true") { + xap.widgets.styleSet(this.td, {whiteSpace: "normal"}); + } else { + xap.widgets.styleSet(this.td, {whiteSpace: "nowrap"}); } +} - if (direction == 'center') { - xap.widgets.styleSet(this.td, {verticalAlign: 'middle'}); - return; - } - +/** + * Set the URL for img background. Note that the background-repeat value is "repeat" by default. + * @param {string} backgroundImgURL the background img URL. + */ +xap.widgets.Label.prototype.setImgBackground = function(backgroundImgURL) { + xap.widgets.styleSet(this.table, {backgroundImage: "url(" + backgroundImgURL + ")", backgroundRepeat: "repeat"}); } -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); - } +/** + * Set the height for the img. + * @param {int} imgHeight the height of the img. + */ +xap.widgets.Label.prototype.setImgHeight = function(imgHeight) { + this.img.height = imgHeight; +} + +/** + * Set the width for the img. + * @param {int} imgWidth the width. + */ +xap.widgets.Label.prototype.setImgWidth = function(imgWidth) { + this.img.width = imgWidth; +} + +var a = 0; +/** + * Set "selectable" attribute for the label. The default value is false. + * @param {boolean} seletable if true, user can select the label, otherwise user cannot. + */ +xap.widgets.Label.prototype.setSelectable = function(selectable) { + if (selectable == "true") { + this.td.onmousedown = null; + this.td.onselectstart = null; + } else { + this.td.onmousedown = function() {return false;}; + this.td.onselectstart = function() {return false;}; } } -xap.widgets.Label.prototype.setTextPlacementVertical = function(direction) { +/** + * Set "enabled" attribute for the label. + * @param {boolean} enabled if true the label is enabled, otherwise it is disabled. + */ +xap.widgets.Label.prototype.setEnabled = function(enabled) { + this.enabled = enabled == "true"; + this._showImg(); +} - 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); +/** + * Show proper img for the label based on its state of enabled/disabled. + */ +xap.widgets.Label.prototype._showImg = function() { + imgURL = this._getProperImgURL(); + + if (imgURL != this.img.src) { + if (imgURL != "") { + this.img.src = imgURL; + this.img.style.display = ""; + + this._showText(); + } else { + this.img.style.display = "none"; } } } + +/** + * Get proper img URL for display. + */ +xap.widgets.Label.prototype._getProperImgURL = function() { + imgURL = ""; + + if (!this.enabled && this.imgDisabledURL != "") { + imgURL = this.imgDisabledURL; + } else if (this.imgURL != "") { + imgURL = this.imgURL; + } + + return imgURL; +} \ No newline at end of file Modified: incubator/xap/trunk/src/xap/widgets/RadioButton.js URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/widgets/RadioButton.js?view=diff&rev=468492&r1=468491&r2=468492 ============================================================================== --- incubator/xap/trunk/src/xap/widgets/RadioButton.js (original) +++ incubator/xap/trunk/src/xap/widgets/RadioButton.js Fri Oct 27 11:48:42 2006 @@ -13,34 +13,41 @@ * 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.require("xap.widgets.Button"); +Xap.require("dojo.event.*"); -xap.widgets.RadioButton = function(appContext) { - - xap.widgets.Label.call(this); - - this.img.srcON = appContext + 'src/xap/widgets/images/radio_on.gif'; - this.img.srcOFF = appContext + 'src/xap/widgets/images/radio_off.gif'; - this.img.srcToggle = this.img.srcOFF; - this.img.style.display = ''; - - this.setTextPlacementHorizontal('right'); - this.setAlignVertical('center'); - this.setAlignHorizontal('center'); - - this.setOff(); +xap.widgets.RadioButton = function() { + xap.widgets.Button.call(this); + + this.img.style.display = ""; + + this.setTextPlacementHorizontal("right"); + this.setAlignVertical("center"); + this.setAlignHorizontal("center"); this.img.onclick = function() { this.clickobj && this.clickobj[this.clickfn] && this.clickobj[this.clickfn](this.clickparam); } - + + this.selected = false; + this.imgSelectedURL = ""; + this.imgPressedSelectedURL = ""; + this.imgOverSelectedURL = ""; } -xap.widgets.RadioButton.prototype = new xap.widgets.Label(); +Xap.setupClassAsSubclassOf("xap.widgets.RadioButton", "xap.widgets.Button"); + +xap.widgets.RadioButton.prototype.init = function(appContext) { + this.img.srcON = appContext + "src/xap/widgets/images/radio_on.gif"; + this.img.srcOFF = appContext + "src/xap/widgets/images/radio_off.gif"; + this.img.srcONDisabled = appContext + "src/xap/widgets/images/radio_on_disabled.gif"; + this.img.srcOFFDisabled = appContext + "src/xap/widgets/images/radio_off_disabled.gif"; + + this.setOff(); +} xap.widgets.RadioButton.prototype.setOnClick = function(obj, fn, param) { this.img.clickobj = obj; @@ -49,17 +56,76 @@ } xap.widgets.RadioButton.prototype.setOn = function() { - this.setImage(this.img.srcON); - this.img.srcToggle = this.img.srcON; - this.selected = 'true'; + this.selected = true; + this._showImg(); } xap.widgets.RadioButton.prototype.setOff = function() { - this.setImage(this.img.srcOFF); - this.img.srcToggle = this.img.srcOFF; - this.selected = 'false'; + this.selected = false; + this._showImg(); } xap.widgets.RadioButton.prototype.getSelected = function() { - return this.selected; + return this.selected; +} + +xap.widgets.RadioButton.prototype.setImgSelected = function(imgSelectedURL) { + this.imgSelectedURL = imgSelectedURL; + this._showImg(); } + +xap.widgets.RadioButton.prototype.setImgOverSelected = function(imgOverSelectedURL) { + this.imgOverSelectedURL = imgOverSelectedURL; + dojo.event.connect(this._rootDomNode, "onmouseover", this, "_onmouseover"); + dojo.event.connect(this._rootDomNode, "onmouseout", this, "_onmouseout"); +} + +xap.widgets.RadioButton.prototype.setImgPressedSelected = function(imgPressedSelectedURL) { + this.imgPressedSelectedURL = imgPressedSelectedURL; + dojo.event.connect(this._rootDomNode, "onmousedown", this, "_onmousedown"); +} + +xap.widgets.RadioButton.prototype._getProperImgURL = function () { + imgURL = ""; + if (this.enabled) { + if (this.selected) { + if (this.mousePressed && this.imgPressedSelectedURL != "") { + imgURL = this.imgPressedSelectedURL; + } else if (this.mouseOver && this.imgOverSelectedURL != "") { + imgURL = this.imgOverSelectedURL; + } else if (this.imgSelectedURL != "") { + imgURL = this.imgSelectedURL; + } + } + + if (imgURL == "") { + if (this.mousePressed && this.imgPressedURL != "") { + imgURL = this.imgPressedURL; + } else if (this.mouseOver && this.imgOverURL != "") { + imgURL = this.imgOverURL; + } else if (this.imgURL != "") { + imgURL = this.imgURL; + } + } + } else { + if (this.imgDisabledURL != "") { + imgURL = this.imgDisabledURL; + } else if (this.imgURL != "") { + imgURL = this.imgURL; + } else if (this.selected && this.img.srcONDisabled != "") { + imgURL = this.img.srcONDisabled; + } else if (!this.selected && this.img.srcOFFDisabled != "") { + imgURL = this.img.srcOFFDisabled; + } + } + + if (imgURL == "") { + if (this.selected) { + imgURL = this.img.srcON; + } else { + imgURL = this.img.srcOFF; + } + } + + return imgURL; +} \ No newline at end of file Modified: incubator/xap/trunk/src/xap/widgets/images/checkbox_off.gif URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/widgets/images/checkbox_off.gif?view=diff&rev=468492&r1=468491&r2=468492 ============================================================================== Binary files - no diff available. Added: incubator/xap/trunk/src/xap/widgets/images/checkbox_off_disabled.gif URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/widgets/images/checkbox_off_disabled.gif?view=auto&rev=468492 ============================================================================== Binary file - no diff available. Propchange: incubator/xap/trunk/src/xap/widgets/images/checkbox_off_disabled.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: incubator/xap/trunk/src/xap/widgets/images/checkbox_on_disabled.gif URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/widgets/images/checkbox_on_disabled.gif?view=auto&rev=468492 ============================================================================== Binary file - no diff available. Propchange: incubator/xap/trunk/src/xap/widgets/images/checkbox_on_disabled.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: incubator/xap/trunk/src/xap/widgets/images/radio_off_disabled.gif URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/widgets/images/radio_off_disabled.gif?view=auto&rev=468492 ============================================================================== Binary file - no diff available. Propchange: incubator/xap/trunk/src/xap/widgets/images/radio_off_disabled.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: incubator/xap/trunk/src/xap/widgets/images/radio_on_disabled.gif URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/widgets/images/radio_on_disabled.gif?view=auto&rev=468492 ============================================================================== Binary file - no diff available. Propchange: incubator/xap/trunk/src/xap/widgets/images/radio_on_disabled.gif ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream