Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

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