Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1318 Rev 1422
1
/*
1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
3
	All Rights Reserved.
4
 
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
9
*/
-
 
10
 
-
 
11
 
10
 
12
 
11
dojo.provide("dojo.widget.SvgButton");
13
dojo.provide("dojo.widget.SvgButton");
12
dojo.require("dojo.experimental");
14
dojo.require("dojo.experimental");
13
dojo.experimental("dojo.widget.SvgButton");
15
dojo.experimental("dojo.widget.SvgButton");
14
dojo.widget.SvgButton = function () {
16
dojo.widget.SvgButton = function () {
15
	dojo.widget.DomButton.call(this);
17
	dojo.widget.DomButton.call(this);
16
	dojo.widget.SvgWidget.call(this);
18
	dojo.widget.SvgWidget.call(this);
17
	this.onFoo = function () {
19
	this.onFoo = function () {
18
		alert("bar");
20
		alert("bar");
19
	};
21
	};
20
	this.label = "huzzah!";
22
	this.label = "huzzah!";
21
	this.setLabel = function (x, y, textSize, label, shape) {
23
	this.setLabel = function (x, y, textSize, label, shape) {
22
		var coords = dojo.widget.SvgButton.prototype.coordinates(x, y, textSize, label, shape);
24
		var coords = dojo.widget.SvgButton.prototype.coordinates(x, y, textSize, label, shape);
23
		var textString = "";
25
		var textString = "";
24
		switch (shape) {
26
		switch (shape) {
25
		  case "ellipse":
27
		  case "ellipse":
26
			textString = "<text x='" + coords[6] + "' y='" + coords[7] + "'>" + label + "</text>";
28
			textString = "<text x='" + coords[6] + "' y='" + coords[7] + "'>" + label + "</text>";
27
			break;
29
			break;
28
		  case "rectangle":
30
		  case "rectangle":
29
			textString = "";
31
			textString = "";
30
			break;
32
			break;
31
		  case "circle":
33
		  case "circle":
32
			textString = "";
34
			textString = "";
33
			break;
35
			break;
34
		}
36
		}
35
		return textString;
37
		return textString;
36
	};
38
	};
37
	this.fillInTemplate = function (x, y, textSize, label, shape) {
39
	this.fillInTemplate = function (x, y, textSize, label, shape) {
38
		this.textSize = textSize || 12;
40
		this.textSize = textSize || 12;
39
		this.label = label;
41
		this.label = label;
40
		var textWidth = this.label.length * this.textSize;
42
		var textWidth = this.label.length * this.textSize;
41
	};
43
	};
42
};
44
};
43
dojo.inherits(dojo.widget.SvgButton, dojo.widget.DomButton);
45
dojo.inherits(dojo.widget.SvgButton, dojo.widget.DomButton);
44
dojo.widget.SvgButton.prototype.shapeString = function (x, y, textSize, label, shape) {
46
dojo.widget.SvgButton.prototype.shapeString = function (x, y, textSize, label, shape) {
45
	switch (shape) {
47
	switch (shape) {
46
	  case "ellipse":
48
	  case "ellipse":
47
		var coords = dojo.widget.SvgButton.prototype.coordinates(x, y, textSize, label, shape);
49
		var coords = dojo.widget.SvgButton.prototype.coordinates(x, y, textSize, label, shape);
48
		return "<ellipse cx='" + coords[4] + "' cy='" + coords[5] + "' rx='" + coords[2] + "' ry='" + coords[3] + "'/>";
50
		return "<ellipse cx='" + coords[4] + "' cy='" + coords[5] + "' rx='" + coords[2] + "' ry='" + coords[3] + "'/>";
49
		break;
51
		break;
50
	  case "rect":
52
	  case "rect":
51
		return "";
53
		return "";
52
		break;
54
		break;
53
	  case "circle":
55
	  case "circle":
54
		return "";
56
		return "";
55
		break;
57
		break;
56
	}
58
	}
57
};
59
};
58
dojo.widget.SvgButton.prototype.coordinates = function (x, y, textSize, label, shape) {
60
dojo.widget.SvgButton.prototype.coordinates = function (x, y, textSize, label, shape) {
59
	switch (shape) {
61
	switch (shape) {
60
	  case "ellipse":
62
	  case "ellipse":
61
		var buttonWidth = label.length * textSize;
63
		var buttonWidth = label.length * textSize;
62
		var buttonHeight = textSize * 2.5;
64
		var buttonHeight = textSize * 2.5;
63
		var rx = buttonWidth / 2;
65
		var rx = buttonWidth / 2;
64
		var ry = buttonHeight / 2;
66
		var ry = buttonHeight / 2;
65
		var cx = rx + x;
67
		var cx = rx + x;
66
		var cy = ry + y;
68
		var cy = ry + y;
67
		var textX = cx - rx * textSize / 25;
69
		var textX = cx - rx * textSize / 25;
68
		var textY = cy * 1.1;
70
		var textY = cy * 1.1;
69
		return [buttonWidth, buttonHeight, rx, ry, cx, cy, textX, textY];
71
		return [buttonWidth, buttonHeight, rx, ry, cx, cy, textX, textY];
70
		break;
72
		break;
71
	  case "rectangle":
73
	  case "rectangle":
72
		return "";
74
		return "";
73
		break;
75
		break;
74
	  case "circle":
76
	  case "circle":
75
		return "";
77
		return "";
76
		break;
78
		break;
77
	}
79
	}
78
};
80
};
79
dojo.widget.SvgButton.prototype.labelString = function (x, y, textSize, label, shape) {
81
dojo.widget.SvgButton.prototype.labelString = function (x, y, textSize, label, shape) {
80
	var textString = "";
82
	var textString = "";
81
	var coords = dojo.widget.SvgButton.prototype.coordinates(x, y, textSize, label, shape);
83
	var coords = dojo.widget.SvgButton.prototype.coordinates(x, y, textSize, label, shape);
82
	switch (shape) {
84
	switch (shape) {
83
	  case "ellipse":
85
	  case "ellipse":
84
		textString = "<text x='" + coords[6] + "' y='" + coords[7] + "'>" + label + "</text>";
86
		textString = "<text x='" + coords[6] + "' y='" + coords[7] + "'>" + label + "</text>";
85
		break;
87
		break;
86
	  case "rectangle":
88
	  case "rectangle":
87
		textString = "";
89
		textString = "";
88
		break;
90
		break;
89
	  case "circle":
91
	  case "circle":
90
		textString = "";
92
		textString = "";
91
		break;
93
		break;
92
	}
94
	}
93
	return textString;
95
	return textString;
94
};
96
};
95
dojo.widget.SvgButton.prototype.templateString = function (x, y, textSize, label, shape) {
97
dojo.widget.SvgButton.prototype.templateString = function (x, y, textSize, label, shape) {
96
	return "<g class='dojoButton' dojoAttachEvent='onClick; onMouseMove: onFoo;' dojoAttachPoint='labelNode'>" + dojo.widgets.SVGButton.prototype.shapeString(x, y, textSize, label, shape) + dojo.widget.SVGButton.prototype.labelString(x, y, textSize, label, shape) + "</g>";
98
	return "<g class='dojoButton' dojoAttachEvent='onClick; onMouseMove: onFoo;' dojoAttachPoint='labelNode'>" + dojo.widgets.SVGButton.prototype.shapeString(x, y, textSize, label, shape) + dojo.widget.SVGButton.prototype.labelString(x, y, textSize, label, shape) + "</g>";
97
};
99
};
98
 
100