Skip to content

Commit

Permalink
Button code working and mostly cleaned up.
Browse files Browse the repository at this point in the history
Ready for merge into main branch.
  • Loading branch information
bvds committed May 21, 2010
1 parent 4be68b4 commit 2867840
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 70 deletions.
5 changes: 2 additions & 3 deletions web-UI/andes/Combo.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,9 @@ andes.buttonCombo = dojox.drawing.util.oo.declare(
},
{
type:"andes.buttonCombo",
// BvdS: is this ever used?
onChangeData: function(/*Object*/ stencil){
if (stencil.mod == true) { console.log("------------mod, no save to server", stencil.mod);};
console.log("--------------on change combo", stencil.id);
if (stencil.mod == true) { console.log("------------button mod, no save to server", stencil.mod);};
console.log("--------------on change button combo", stencil.id);
// summary:
// Stub - fires on change of dimensional
// properties or a text change of the master
Expand Down
56 changes: 23 additions & 33 deletions web-UI/andes/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,7 @@ dojo.provide("andes.convert");
id:o.id,
type:o.type,
itemType:o.items[0].type,
items:dojo.map(o.items, function(x){
// BvdS: Might be auto-generated later, so generating
// id here might not be necessary.
// Maybe better to generate this on server?
x.id=x.id||(o.id+"Part"+(x.value||"0"));
return andes.convert.andesToDrawing(x);
}),
items:dojo.map(o.items,andes.convert.andesToDrawing),
checked: o.checked || []
}
return obj;
Expand All @@ -80,8 +74,10 @@ dojo.provide("andes.convert");
enabled:o.mode!="locked"
};

// BvdS: fix up if logic here
if(o.type!="vector" && o.type!="line" && o.type!="axes" && o.type!="ellipse" && o.type!="checkbox" && o.type!="radio" && o.type!="done"){
var buttonWidth;
// o.type can be: statement, graphics, radio, done, checkbox, axes, ellipse,
// vector, equation, line, rectangle
if(o.type=="statement" || o.type=="equation" || o.type=="graphics" || o.type=="rectangle"){
obj.data.width = o.width;
obj.data.height = o.height;

Expand All @@ -93,32 +89,24 @@ dojo.provide("andes.convert");
ry:o.height/2
}
}else if(o.type=="radio"){
buttonWidth=andes.defaults.button.radioButtonRadius;
obj.buttonType=o.type;
obj.data.width = 20;
obj.data.height = 20;
obj.data={
cx:o.x + 0.5*buttonWidth,
cy:o.y + 0.5*buttonWidth,
rx:0.5*buttonWidth,
ry:0.5*buttonWidth
// x:o.x, y:o.y, height:20, width:40
};
obj.value = o.value;
obj.icon={
type:"ellipse",
borderWidth:1,
cx:50,
cy:50,
rx:20,
ry:20
}
}else if(o.type=="checkbox"){
buttonWidth=andes.defaults.button.checkboxWidth;
obj.buttonType=o.type;
obj.data.width = 20;
obj.data.height = 20;
obj.data.width = checkboxWidth;
obj.data.height = checkboxWidth;
obj.value = o.value;
obj.icon={
type:"rect",
borderWidth:1,
x:10,
y:10,
width:40,
height:40
};
}else if(o.type=="done"){
buttonWidth=o.label.length*10; // should be determined by actual drawn width
obj.buttonType=o.type;
obj.data.width = 40;
obj.data.height = 20;
Expand All @@ -128,21 +116,23 @@ dojo.provide("andes.convert");
};
}else if(o.type=="vector"){
//in case of zero vector
if(o.radius == 0) {obj.data.radius = 0; obj.data.angle = 1; } else { obj.data.radius = o.radius; obj.data.angle = o.angle; }
if(o.radius == 0) {obj.data.radius = 0; obj.data.angle = 1; } else { obj.data.radius = o.radius; obj.data.angle = o.angle; }

}else{
//line, axes
}else if(o.type=="line" || o.type=="axes"){
obj.data.radius = o.radius || 0;
obj.data.angle = o.angle;
}else{
console.warn("Unrecognized type ",o.type);
}

if(o.type=="statement" && o.mode=="locked"){
obj.stencilType = "text";
}

if(o.type=="done" || o.type=="checkbox" || o.type=="radio"){
obj.statement = {
data:{
x:o.x+40, // BvdS: to the right of the button, need actual button width
x:o.x+buttonWidth,
y:o.y,
text:o.text
//width:"auto"- for cases where the text is "" width:auto makes init fail
Expand Down
2 changes: 2 additions & 0 deletions web-UI/andes/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ dojo.provide("andes.defaults");
// BvdS: I thought andes.defaults is supposed to override of dojox.drawing.defaults
// Why does dojox.drawing.defaults.button not show up if following is not included?
button:{
radioButtonRadius:15,
checkboxWidth:20,
norm:{
"color": "#cccccc",
"fill": {
Expand Down
66 changes: 51 additions & 15 deletions web-UI/andes/drawing.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,37 @@ dojo.provide("andes.drawing");
}
},

addUI: function(/* group of objects */group){
addGroup: function(/* group of objects */group){
// Taken from add(...) below.
items[group.id] = group;

dojo.forEach(group.items,function(item){
dojo.connect(item.master,"onClick",this,function(item){

// Handle button clicks; don't do anything for done button.
if(item.buttonType == "checkbox"){
if(item.selected) {
var pos=item.group.checked.indexOf(item.value);
item.group.checked.splice(pos,1);
item.deselect();
}else{
item.group.checked.push(item.value);
item.select();
}
}else if(item.buttonType == "radio"){
item.group.checked=[item.value];
var myId=item.id
dojo.forEach(item.buttons,function(button){
if(button.id == myId){
if(!button.selected){button.select();}
}else{
// deselect all other buttons in group
if(button.selected){button.deselect();}
}
});
}

// Send result to server
var data = andes.convert.drawingToAndes(group, "modify-object");
// BvdS: Why doesn't this.save() work?
andes.drawing.save(data);
Expand Down Expand Up @@ -227,6 +252,8 @@ dojo.provide("andes.drawing");
var o = andes.convert.andesToDrawing(obj);

var t = o.stencilType;
// o.stencilType includes: text, image, line, rect, ellipse, vector
// textBlock (equation & statement), axes
if(t=="vector" || t=="line" || t=="ellipse" || t=="rect"){

// prevent adding items via onRenderStencil
Expand All @@ -247,21 +274,22 @@ dojo.provide("andes.drawing");
items[master.id] = master; //master;
return {master: master, statement:statement};
});
console.log("constructing button group, butt=",butt);
// Back pointer to other buttons in group, for deselection
// of radio buttons.
var buttOnly = dojo.map(butt,function(x){return x.master;});
dojo.forEach(butt,function(x){x.master.buttons=buttOnly;});

var buttonCombo=new andes.buttonCombo(butt,o.id);
buttonCombo.group=o;
this.addUI(buttonCombo);

// BvdS: logic needs fixing, need to find out real categories.
}else if(t=="image" ||t=="statement" || t=="equation" || t=="axes" || t=="text") { // image, statement, equation, axes
this.addGroup(buttonCombo);
}else{
// including: textBlock, axes ...
var item = _drawing.addStencil(o.stencilType, o);
var ID = item.id;
ID = ID.indexOf("TextBlock");
if(item.stencilType=='textBlock' && ID!=-1) item.util.uid(item.type);
item.andesType = obj.type; // to tell between equation and statement
this.add(item);
}else{
console.warn("No valid type or stencilType for ",o);
}

}else if(obj.action=="modify-object"){
Expand Down Expand Up @@ -329,31 +357,39 @@ dojo.provide("andes.drawing");
y:obj["y-statement"]
});
}

if(obj.type=='vector' || obj.type=='line'){

items[obj.id].master.attr({
angle:obj.angle,
radius:obj.radius
});
}
if(obj.type=="axes"){
}else if(obj.type=="axes"){
items[obj.id].attr({
angle:obj.angle,
radius:obj.radius
});
}
if(obj.type=="ellipse" || obj.type=='rectangle'){
}else if(obj.type=="ellipse" || obj.type=='rectangle'){
items[obj.id].master.attr({
height:obj.height,
width:obj.width
});
}else if(obj.type=="button" && obj.checked){ // checked is optional
items[obj.id].checked=obj.checked;
dojo.forEach(items[obj.id].items,function(pair){
if(obj.checked.indexOf(pair.master.value)!=-1){
pair.master.select();
}else{
pair.master.deselect();
}
});
}

// text
if(items[obj.id].isText==true && obj.text) { items[obj.id].attr({text:obj.text});};
if(obj.text && items[obj.id].type == "andes.Combo") {
/*items[obj.id].master.attr({
label:obj.text
});*/
label:obj.text
});*/
var text = obj.text==" "? obj.symbol : obj.text;
items[obj.id].textEdit(text);
};
Expand Down
41 changes: 22 additions & 19 deletions web-UI/dojox/drawing/ui/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,36 @@ dojox.drawing.ui.Button = dojox.drawing.util.oo.declare(
options.subShape = true;
dojo.mixin(this, options);
//console.log(" button:", this);
this.width = options.data.width;
this.height = options.data.height;
this.width = options.data.width || options.data.rx*2;
this.height = options.data.height || options.data.ry*2;
this.y = options.data.y || options.data.cy - options.data.ry;
//
this.id = this.id || this.util.uid(this.type);
this.util.attr(this.container, "id", this.id);

if(this.callback){
this.hitched = dojo.hitch(this.scope || window, this.callback, this);
}

this.shape = new dojox.drawing.stencil.Rect(options);
// Rectangle itself must be "ui" for radio buttons to work.
// This is a work-around for messy code associated with drawingType;
// see http://www.andestutor.org/bugzilla/show_bug.cgi?id=1745
options.drawingType="ui";
// Choose between rectangle and ellipse based on options
if(options.data.width && options.data.height){
this.shape = new dojox.drawing.stencil.Rect(options);
}else{
this.shape = new dojox.drawing.stencil.Ellipse(options);
}

var setGrad = function(s, p, v){
dojo.forEach(["norm", "over", "down", "selected"], function(nm){
s[nm].fill[p] = v;
});
};
// for button backs, not for icons
setGrad(this.style.button, "y2", this.data.height + this.data.y);
setGrad(this.style.button, "y1", this.data.y);
setGrad(this.style.button, "y2", this.height + this.y);
setGrad(this.style.button, "y1", this.y);

if(options.icon && !options.icon.text){
var constr = this.drawing.getConstructor(options.icon.type);
Expand All @@ -44,15 +55,15 @@ dojox.drawing.ui.Button = dojox.drawing.util.oo.declare(
}
this.icon = new constr(o);
//console.log(" button:", this.toolType, this.style.button.icon)
}else if(options.text || options.icon.text){
}else if(options.text || (options.icon && options.icon.text)){
//console.warn("button text:", options.text || options.icon.text)
o = this.makeOptions(options.text || options.icon.text);
o.data.color = this.style.button.icon.norm.color; //= o.data.fill;
this.style.button.icon.selected.color = this.style.button.icon.selected.fill;
this.icon = new dojox.drawing.stencil.Text(o);
this.icon.attr({
height: this.icon._lineHeight,
y:((this.data.height-this.icon._lineHeight)/2)+this.data.y
y:((this.height-this.icon._lineHeight)/2)+this.y
});
}

Expand All @@ -75,14 +86,6 @@ dojox.drawing.ui.Button = dojox.drawing.util.oo.declare(
// Stub to connect. Event is 'this'
// Alternatively can pass in a scope and a callback
// on creation.
console.log("button clicked type=",this.buttonType,this);
if(this.type == "checkbox"){
if(this.selected) {
this.deselect();
} else {
this.select();
}
}
},

makeOptions: function(/*Object*/d, /*Float*/s){
Expand Down Expand Up @@ -161,13 +164,13 @@ dojox.drawing.ui.Button = dojox.drawing.util.oo.declare(
// moveTo.. methods.
select: function(){
this.selected = true;
this.icon.attr(this.style.button.icon.selected);
if(this.icon){this.icon.attr(this.style.button.icon.selected);}
this._change(this.style.button.selected);
this.shape.shadow && this.shape.shadow.hide();
},
deselect: function(){
this.selected = false;
this.icon.attr(this.style.button.icon.norm);
if(this.icon){this.icon.attr(this.style.button.icon.norm);}
this.shape.shadow && this.shape.shadow.show();
this._change(this.style.button.norm);

Expand All @@ -176,7 +179,7 @@ dojox.drawing.ui.Button = dojox.drawing.util.oo.declare(
_change: function(/*Object*/sty){
this.shape.attr(sty);
this.shape.shadow && this.shape.shadow.container.moveToBack();
this.icon.shape.moveToFront();
if(this.icon){this.icon.shape.moveToFront();};

},
onOver: function(){
Expand All @@ -201,7 +204,7 @@ dojox.drawing.ui.Button = dojox.drawing.util.oo.declare(
this.onClick(this);
},
attr: function(options){
this.icon.attr(options);
if(this.icon){this.icon.attr(options);}
}
}

Expand Down

0 comments on commit 2867840

Please sign in to comment.