/***** * * Button.js * * Copyright 2001, Kevin Lindsey * *****/ /***** * * globals * *****/ Button.VERSION = 1.0; Button.buttons = new Array(); /***** * * constructor * *****/ function Button(x, y, callback, up_id, down_id, parent) { this.x = x; this.y = y; this.callback = callback; this.parent = parent; this.selected = false; this.up = null; this.down = null; this.make_button(up_id, down_id); Button.buttons[Button.buttons.length] = this; } /***** * * make_button * *****/ Button.prototype.make_button = function(up_id, down_id) { var trans = "translate(" + this.x + "," + this.y + ")"; var button; button = svgDocument.getElementById(up_id).cloneNode(true); button.setAttributeNS(null, "transform", trans); button.addEventListener("mousedown", this, false); this.up = button; button = svgDocument.getElementById(down_id).cloneNode(true); button.setAttributeNS(null, "transform", trans); button.setAttributeNS(null, "display", "none"); button.addEventListener("mousedown", this, false); this.down = button; this.parent.appendChild( this.up ); this.parent.appendChild( this.down ); } /***** * * set_select * *****/ Button.prototype.set_select = function(state) { var current = this.selected; if ( current != state ) { if ( state == true ) { this.up.setAttributeNS(null, "display", "none"); this.down.setAttributeNS(null, "display", "inline"); } else { this.up.setAttributeNS(null, "display", "inline"); this.down.setAttributeNS(null, "display", "none"); } this.selected = state; } } /***** * * handleEvent * *****/ Button.prototype.handleEvent = function(e) { var type = e.type; if ( this[type] != null ) this[type](e); }; /***** * * mousedown * *****/ Button.prototype.mousedown = function(e) { if ( this.callback ) this.callback(this); }; /***** * * unload * *****/ Button.prototype.unload = function() { this.down.removeEventListener("mousedown", this, false); this.up.removeEventListener("mousedown", this, false); } /***** * * Radio.js * *****/ /***** * * constructeur * *****/ function Radio(x, y, size, callback, up_id, down_id, parent) { this.x=x; this.y=y; this.size=size; this.callback=callback; this.up_id=up_id; this.down_id=down_id; this.parent=parent; this.current=null; } /***** * * addButton * *****/ Radio.prototype.add = function(label, id) { var button = new Button(this.x, this.y, this.select, this.up_id, this.down_id, this.parent); if (this.selected==null) { this.current=button; button.set_select(true); this.callback(id); } alert(this.current); button.id=id; var data = svgDocument.createTextNode(label); var text = svgDocument.createElementNS(svgns, "text"); text.setAttributeNS(null, "x", this.x+this.size); text.setAttributeNS(null, "y", this.y); text.setAttributeNS(null, "fill", "black"); text.appendChild(data); svgDocument.documentElement.appendChild(text); this.y += this.size; } Radio.prototype.select = function(button) { alert(this.current); this.current.set_select(false); button.set_select(true); this.current=button; this.callback(button.id); }