You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by jk...@apache.org on 2006/10/07 20:22:39 UTC
svn commit: r453979 [2/8] - in
/tapestry/tapestry4/trunk/tapestry-framework/src/js: dojo/ dojo/src/
dojo/src/collections/ dojo/src/data/ dojo/src/data/csv/ dojo/src/date/
dojo/src/debug/ dojo/src/event/ dojo/src/gfx/ dojo/src/html/ dojo/src/i18n/
dojo/...
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/date/format.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/date/format.js?view=diff&rev=453979&r1=453978&r2=453979
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/date/format.js (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/date/format.js Sat Oct 7 11:22:33 2006
@@ -51,6 +51,7 @@
// selector- choice of timeOnly,dateOnly (default: date and time)
// formatLength- choice of long, short, medium or full (plus any custom additions). Defaults to 'full'
// datePattern,timePattern- override pattern with this string
+// am,pm- override strings for am/pm in times
// locale- override the locale used to determine formatting rules
//
@@ -60,7 +61,7 @@
}
// Format a pattern without literals
- function formatPattern(dateObject, pattern) {
+ function formatPattern(dateObject, pattern){
return pattern.replace(/[a-zA-Z]+/g, function(match){
var s;
var c = match.charAt(0);
@@ -215,7 +216,7 @@
s = "?";
break;
default:
- dojo.raise("dojo.date.parse: invalid format: "+pattern);
+ dojo.raise("dojo.date.format: invalid pattern char: "+pattern);
}
if(pad){ s = dojo.string.pad(s, l); }
return s;
@@ -229,11 +230,11 @@
var info = dojo.date._getGregorianBundle(locale);
var str = [];
var sauce = dojo.lang.curry(this, formatPattern, dateObject);
- if (options.selector != "timeOnly") {
+ if(options.selector != "timeOnly"){
var datePattern = options.datePattern || info["dateFormat-"+formatLength];
if(datePattern){str.push(_processPattern(datePattern, sauce));}
}
- if (options.selector != "dateOnly") {
+ if(options.selector != "dateOnly"){
var timePattern = options.timePattern || info["timeFormat-"+formatLength];
if(timePattern){str.push(_processPattern(timePattern, sauce));}
}
@@ -264,6 +265,7 @@
// selector- choice of timeOnly, dateOnly, dateTime (default: dateOnly)
// formatLength- choice of long, short, medium or full (plus any custom additions). Defaults to 'full'
// datePattern,timePattern- override pattern with this string
+// am,pm- override strings for am/pm in times
// locale- override the locale used to determine formatting rules
// strict- strict parsing, off by default
//
@@ -277,15 +279,14 @@
var timePattern = options.timePattern || info["timeFormat-" + formatLength];
var pattern;
- options.selector = options.selector.toLowerCase();
- if (options.selector == 'dateonly') {
+ if(options.selector == 'dateOnly'){
pattern = datePattern;
}
- else if (options.selector == 'timeonly') {
+ else if(options.selector == 'timeOnly'){
pattern = timePattern;
- } else if (options.selector == 'datetime') {
+ }else if(options.selector == 'dateTime'){
pattern = datePattern + ' ' + timePattern; //TODO: use locale-specific pattern to assemble date + time
- } else {
+ }else{
var msg = "dojo.date.parse: Unknown selector param passed: '" + options.selector + "'.";
msg += " Defaulting to date pattern.";
dojo.debug(msg);
@@ -316,7 +317,7 @@
//interpret year literally, so '5' would be 5 A.D.
result.setFullYear(v);
expected.year = v;
- } else {
+ }else{
if(v<100){
v = Number(v);
//choose century to apply, according to a sliding window
@@ -328,7 +329,7 @@
var num = (v < cutoff) ? century + v : century - 100 + v;
result.setFullYear(num);
expected.year = num;
- } else {
+ }else{
//we expected 2 digits and got more...
if(options.strict){
return null;
@@ -349,22 +350,22 @@
v = v.toLowerCase();
}
var months = info['months-format-' + widthList[l-3]].concat();
- for (var j=0; j<months.length; j++) {
- if (!options.strict) {
+ for (var j=0; j<months.length; j++){
+ if(!options.strict){
//Case-insensitive
months[j] = months[j].toLowerCase();
}
- if (v == months[j]) {
+ if(v == months[j]){
result.setMonth(j);
expected.month = j;
break;
}
}
- if (j==months.length) {
+ if(j==months.length){
dojo.debug("dojo.date.parse: Could not parse month name: '" + v + "'.");
return null;
}
- } else {
+ }else{
result.setMonth(v-1);
expected.month = v-1;
}
@@ -376,19 +377,19 @@
v = v.toLowerCase();
}
var days = info['days-format-' + widthList[l-3]].concat();
- for (var j=0; j<days.length; j++) {
- if (!options.strict) {
+ for (var j=0; j<days.length; j++){
+ if(!options.strict){
//Case-insensitive
days[j] = days[j].toLowerCase();
}
- if (v == days[j]) {
+ if(v == days[j]){
//TODO: not sure what to actually do with this input,
//in terms of setting something on the Date obj...?
//without more context, can't affect the actual date
break;
}
}
- if (j==days.length) {
+ if(j==days.length){
dojo.debug("dojo.date.parse: Could not parse weekday name: '" + v + "'.");
return null;
}
@@ -398,39 +399,38 @@
expected.date = v;
break;
case 'a': //am/pm
- var am = info.am;
- var pm = info.pm;
- if (!options.strict) {
+ var am = options.am || info.am;
+ var pm = options.pm || info.pm;
+ if(!options.strict){
v = v.replace(/\./g,'').toLowerCase();
am = am.replace(/\./g,'').toLowerCase();
pm = pm.replace(/\./g,'').toLowerCase();
}
- if (options.strict && v != am && v != pm) {
+ if(options.strict && v != am && v != pm){
dojo.debug("dojo.date.parse: Could not parse am/pm part.");
return null;
}
var hours = result.getHours();
- if (v == pm && hours < 12) {
+ if(v == pm && hours < 12){
result.setHours(hours + 12); //e.g., 3pm -> 15
- } else if (v == am && hours == 12) {
+ } else if(v == am && hours == 12){
result.setHours(0); //12am -> 0
}
break;
+ case 'K': //hour (1-24)
+ if(v==24){v=0;}
+ // fallthrough...
case 'h': //hour (1-12)
- //in the 12-hour case, adjusting for am/pm requires the 'a' part
- //which for now we will assume always comes after the 'h' part
- result.setHours(v);
- break;
case 'H': //hour (0-23)
- result.setHours(v);
- break;
case 'k': //hour (0-11)
- ++v; //adjust to the 1-12 input that js setHours() expects
- //also see 12-hour case comment in the 'h' case above
- result.setHours(v);
- break;
- case 'K': //hour (1-24)
- --v; // js setHours() range is 0 to 23
+ //TODO: strict bounds checking, padding
+ if(v>23){
+ dojo.debug("dojo.date.parse: Illegal hours value");
+ return null;
+ }
+
+ //in the 12-hour case, adjusting for am/pm requires the 'a' part
+ //which for now we will assume always comes after the 'h' part
result.setHours(v);
break;
case 'm': //minutes
@@ -439,21 +439,24 @@
case 's': //seconds
result.setSeconds(v);
break;
+ case 'S': //milliseconds
+ result.setMilliseconds(v);
+ break;
default:
- dojo.unimplemented("incomplete parse algorithm: " + grp.charAt(0));
+ dojo.unimplemented("dojo.date.parse: unsupported pattern char=" + grp.charAt(0));
}
}
//validate parse date fields versus input date fields
- if (expected.year && result.getFullYear() != expected.year) {
+ if(expected.year && result.getFullYear() != expected.year){
dojo.debug("Parsed year: '" + result.getFullYear() + "' did not match input year: '" + expected.year + "'.");
return null;
}
- if (expected.month && result.getMonth() != expected.month) {
+ if(expected.month && result.getMonth() != expected.month){
dojo.debug("Parsed month: '" + result.getMonth() + "' did not match input month: '" + expected.month + "'.");
return null;
}
- if (expected.date && result.getDate() != expected.date) {
+ if(expected.date && result.getDate() != expected.date){
dojo.debug("Parsed day of month: '" + result.getDate() + "' did not match input day of month: '" + expected.date + "'.");
return null;
}
@@ -488,8 +491,9 @@
return applyAll(chunks.join(''));
}
-function _buildDateTimeRE(groups, info, options, pattern) {
+function _buildDateTimeRE(groups, info, options, pattern){
return pattern.replace(/[a-zA-Z]+/g, function(match){
+ // Build a simple regexp without parenthesis, which would ruin the match list
var s;
var c = match.charAt(0);
var l = match.length;
@@ -514,17 +518,17 @@
break;
case 'm':
case 's':
- s = '\\d{2}';
+ s = '[0-5]\\d';
break;
case 'S':
- s = '\\d+';
+ s = '\\d{1,3}';
break;
case 'a':
- var am = info.am || 'AM';
- var pm = info.pm || 'PM';
- if (options.strict) {
+ var am = options.am || info.am || 'AM';
+ var pm = options.pm || info.pm || 'PM';
+ if(options.strict){
s = am + '|' + pm;
- } else {
+ }else{
s = am;
s += (am != am.toLowerCase()) ? '|' + am.toLowerCase() : '';
s += '|';
@@ -537,6 +541,7 @@
if(groups){ groups.push(match); }
+//FIXME: replace whitespace within final regexp with more flexible whitespace match instead?
//tolerate whitespace
return '\\s*(' + s + ')\\s*';
});
@@ -545,7 +550,7 @@
//TODO: try to common strftime and format code somehow?
-dojo.date.strftime = function (/*Date*/dateObject, /*String*/format, /*String?*/locale) {
+dojo.date.strftime = function(/*Date*/dateObject, /*String*/format, /*String?*/locale){
//
// summary:
// Formats the date object using the specifications of the POSIX strftime function
@@ -555,14 +560,14 @@
// zero pad
var padChar = null;
- function _(s, n) {
+ function _(s, n){
return dojo.string.pad(s, n || 2, padChar || "0");
}
var info = dojo.date._getGregorianBundle(locale);
- function $ (property) {
- switch (property) {
+ function $(property){
+ switch (property){
case "a": // abbreviated weekday name according to the current locale
return dojo.date.getDayShortName(dateObject, locale);
@@ -592,12 +597,12 @@
case "e": // day of the month as a decimal number, a single digit is
// preceded by a space (range ' 1' to '31')
- if (padChar == null) { padChar = " "; }
+ if(padChar == null){ padChar = " "; }
return _(dateObject.getDate());
case "f": // month as a decimal number, a single digit is
// preceded by a space (range ' 1' to '12')
- if (padChar == null) { padChar = " "; }
+ if(padChar == null){ padChar = " "; }
return _(dateObject.getMonth()+1);
case "g": // like %G, but without the century.
@@ -720,7 +725,7 @@
var i = 0;
var index = 0;
var switchCase = null;
- while ((index = format.indexOf("%", i)) != -1) {
+ while ((index = format.indexOf("%", i)) != -1){
string += format.substring(i, index++);
// inspect modifier flag
@@ -743,7 +748,7 @@
// toggle case if a flag is set
var property = $(format.charAt(index++));
- switch (switchCase) {
+ switch (switchCase){
case "upper":
property = property.toUpperCase();
break;
@@ -755,7 +760,7 @@
var swapString = '';
var j = 0;
var ch = '';
- while (j < property.length) {
+ while (j < property.length){
ch = property.charAt(j);
swapString += (ch == compareString.charAt(j)) ?
ch.toUpperCase() : ch.toLowerCase();
@@ -773,12 +778,12 @@
}
string += format.substring(i);
- return string;
+ return string; // String
};
(function(){
var _customFormats = [];
-dojo.date.addCustomFormats = function(packageName, bundleName){
+dojo.date.addCustomFormats = function(/*String*/packageName, /*String*/bundleName){
//
// summary:
// Add a reference to a bundle containing localized custom formats to be
@@ -794,13 +799,13 @@
_customFormats.push({pkg:packageName,name:bundleName});
};
-dojo.date._getGregorianBundle = function(locale){
+dojo.date._getGregorianBundle = function(/*String*/locale){
var gregorian = {};
dojo.lang.forEach(_customFormats, function(desc){
var bundle = dojo.i18n.getLocalization(desc.pkg, desc.name, locale);
gregorian = dojo.lang.mixin(gregorian, bundle);
}, this);
- return gregorian;
+ return gregorian; /*Object*/
};
})();
@@ -820,7 +825,7 @@
var label;
var lookup = dojo.date._getGregorianBundle(locale);
var props = [item, use, type];
- if (use == 'standAlone') {
+ if(use == 'standAlone'){
label = lookup[props.join('-')];
}
props[1] = 'format';
@@ -852,11 +857,9 @@
};
//FIXME: not localized
-dojo.date.toRelativeString = function(date) {
+dojo.date.toRelativeString = function(/*Date*/dateObject){
// summary:
-// Returns a string of the date relative to the current date. Note: this is not localized yet. English only.
-//
-// date: a Date object
+// Returns an description in English of the date relative to the current date. Note: this is not localized yet. English only.
//
// description: Example returns:
// - "1 minute ago"
@@ -865,54 +868,55 @@
// - "2 days ago"
var now = new Date();
- var diff = (now - date) / 1000;
+ var diff = (now - dateObject) / 1000;
var end = " ago";
var future = false;
- if(diff < 0) {
+ if(diff < 0){
future = true;
end = " from now";
diff = -diff;
}
- if(diff < 60) {
+ if(diff < 60){
diff = Math.round(diff);
return diff + " second" + (diff == 1 ? "" : "s") + end;
}
- if(diff < 60*60) {
+ if(diff < 60*60){
diff = Math.round(diff/60);
return diff + " minute" + (diff == 1 ? "" : "s") + end;
}
- if(diff < 60*60*24) {
+ if(diff < 60*60*24){
diff = Math.round(diff/3600);
return diff + " hour" + (diff == 1 ? "" : "s") + end;
}
- if(diff < 60*60*24*7) {
+ if(diff < 60*60*24*7){
diff = Math.round(diff/(3600*24));
- if(diff == 1) {
+ if(diff == 1){
return future ? "Tomorrow" : "Yesterday";
- } else {
+ }else{
return diff + " days" + end;
}
}
- return dojo.date.toShortDateString(date);
+ return dojo.date.format(dateObject); // String
};
//FIXME: SQL methods can probably be moved to a different module without i18n deps
-dojo.date.toSql = function(date, noTime) {
+dojo.date.toSql = function(/*Date*/dateObject, /*Boolean?*/noTime){
// summary:
-// Convert a Date to a SQL string, optionally ignoring the HH:MM:SS portion of the Date
+// Convert a Date to a SQL string
+// noTime: whether to ignore the time portion of the Date. Defaults to false.
- return dojo.date.strftime(date, "%F" + !noTime ? " %T" : "");
+ return dojo.date.strftime(dateObject, "%F" + !noTime ? " %T" : ""); // String
};
-dojo.date.fromSql = function(sqlDate) {
+dojo.date.fromSql = function(/*String*/sqlDate){
// summary:
// Convert a SQL date string to a JavaScript Date object
var parts = sqlDate.split(/[\- :]/g);
- while(parts.length < 6) {
+ while(parts.length < 6){
parts.push(0);
}
- return new Date(parts[0], (parseInt(parts[1],10)-1), parts[2], parts[3], parts[4], parts[5]);
+ return new Date(parts[0], (parseInt(parts[1],10)-1), parts[2], parts[3], parts[4], parts[5]); // Date
};
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/date/serialize.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/date/serialize.js?view=diff&rev=453979&r1=453978&r2=453979
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/date/serialize.js (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/date/serialize.js Sat Oct 7 11:22:33 2006
@@ -15,74 +15,76 @@
/* ISO 8601 Functions
*********************/
-dojo.date.setIso8601 = function (dateObject, formattedString){
+dojo.date.setIso8601 = function(/*Date*/dateObject, /*String*/formattedString){
+ // summary: sets a Date object based on an ISO 8601 formatted string (uses date and time)
var comps = (formattedString.indexOf("T") == -1) ? formattedString.split(" ") : formattedString.split("T");
dateObject = dojo.date.setIso8601Date(dateObject, comps[0]);
- if (comps.length == 2) { dateObject = dojo.date.setIso8601Time(dateObject, comps[1]); }
+ if(comps.length == 2){ dateObject = dojo.date.setIso8601Time(dateObject, comps[1]); }
return dateObject; /* Date or null */
};
-dojo.date.fromIso8601 = function (formattedString) {
+dojo.date.fromIso8601 = function(/*String*/formattedString){
+ // summary: returns a Date object based on an ISO 8601 formatted string (uses date and time)
return dojo.date.setIso8601(new Date(0, 0), formattedString);
};
-
-dojo.date.setIso8601Date = function (dateObject, formattedString) {
+dojo.date.setIso8601Date = function(/*String*/dateObject, /*String*/formattedString){
+ // summary: sets a Date object based on an ISO 8601 formatted string (date only)
var regexp = "^([0-9]{4})((-?([0-9]{2})(-?([0-9]{2}))?)|" +
"(-?([0-9]{3}))|(-?W([0-9]{2})(-?([1-7]))?))?$";
var d = formattedString.match(new RegExp(regexp));
- if(!d) {
+ if(!d){
dojo.debug("invalid date string: " + formattedString);
- return null;
+ return null; // null
}
var year = d[1];
var month = d[4];
var date = d[6];
var dayofyear = d[8];
var week = d[10];
- var dayofweek = (d[12]) ? d[12] : 1;
+ var dayofweek = d[12] ? d[12] : 1;
dateObject.setFullYear(year);
-
- if (dayofyear) {
+
+ if(dayofyear){
dateObject.setMonth(0);
dateObject.setDate(Number(dayofyear));
}
- else if (week) {
+ else if(week){
dateObject.setMonth(0);
dateObject.setDate(1);
var gd = dateObject.getDay();
- var day = (gd) ? gd : 7;
+ var day = gd ? gd : 7;
var offset = Number(dayofweek) + (7 * Number(week));
- if (day <= 4) { dateObject.setDate(offset + 1 - day); }
- else { dateObject.setDate(offset + 8 - day); }
- } else {
- if (month) {
+ if(day <= 4){ dateObject.setDate(offset + 1 - day); }
+ else{ dateObject.setDate(offset + 8 - day); }
+ } else{
+ if(month){
dateObject.setDate(1);
dateObject.setMonth(month - 1);
}
- if (date) { dateObject.setDate(date); }
+ if(date){ dateObject.setDate(date); }
}
- return dateObject;
+ return dateObject; // Date
};
-dojo.date.fromIso8601Date = function (formattedString) {
+dojo.date.fromIso8601Date = function(/*String*/formattedString){
+ // summary: returns a Date object based on an ISO 8601 formatted string (date only)
return dojo.date.setIso8601Date(new Date(0, 0), formattedString);
};
+dojo.date.setIso8601Time = function(/*Date*/dateObject, /*String*/formattedString){
+ // summary: sets a Date object based on an ISO 8601 formatted string (time only)
-
-
-dojo.date.setIso8601Time = function (dateObject, formattedString) {
// first strip timezone info from the end
var timezone = "Z|(([-+])([0-9]{2})(:?([0-9]{2}))?)$";
var d = formattedString.match(new RegExp(timezone));
var offset = 0; // local time if no tz info
- if (d) {
- if (d[0] != 'Z') {
+ if(d){
+ if(d[0] != 'Z'){
offset = (Number(d[3]) * 60) + Number(d[5]);
offset *= ((d[2] == '-') ? 1 : -1);
}
@@ -93,9 +95,9 @@
// then work out the time
var regexp = "^([0-9]{2})(:?([0-9]{2})(:?([0-9]{2})(\.([0-9]+))?)?)?$";
d = formattedString.match(new RegExp(regexp));
- if(!d) {
+ if(!d){
dojo.debug("invalid time string: " + formattedString);
- return null;
+ return null; // null
}
var hours = d[1];
var mins = Number((d[3]) ? d[3] : 0);
@@ -107,13 +109,14 @@
dateObject.setSeconds(secs);
dateObject.setMilliseconds(ms);
- if (offset !== 0) {
+ if(offset !== 0){
dateObject.setTime(dateObject.getTime() + offset * 60000);
}
- return dateObject;
+ return dateObject; // Date
};
-dojo.date.fromIso8601Time = function (formattedString) {
+dojo.date.fromIso8601Time = function(/*String*/formattedString){
+ // summary: returns a Date object based on an ISO 8601 formatted string (date only)
return dojo.date.setIso8601Time(new Date(0, 0), formattedString);
};
@@ -121,7 +124,7 @@
/* RFC-3339 Date Functions
*************************/
-dojo.date.toRfc3339 = function(/*Date?*/dateObject, /*String?*/selector) {
+dojo.date.toRfc3339 = function(/*Date?*/dateObject, /*String?*/selector){
// summary:
// Format a JavaScript Date object as a string according to RFC 3339
//
@@ -133,17 +136,17 @@
// Date and time will be formatted by default.
//FIXME: tolerate Number, string input?
- if(!dateObject) {
+ if(!dateObject){
dateObject = new Date();
}
var _ = dojo.string.pad;
var formattedDate = [];
- if (selector != "timeOnly"){
+ if(selector != "timeOnly"){
var date = [_(dateObject.getFullYear(),4), _(dateObject.getMonth()+1,2), _(dateObject.getDate(),2)].join('-');
formattedDate.push(date);
}
- if (selector != "dateOnly"){
+ if(selector != "dateOnly"){
var time = [_(dateObject.getHours(),2), _(dateObject.getMinutes(),2), _(dateObject.getSeconds(),2)].join(':');
var timezoneOffset = dateObject.getTimezoneOffset();
time += (timezoneOffset > 0 ? "-" : "+") +
@@ -154,7 +157,7 @@
return formattedDate.join('T'); // String
};
-dojo.date.fromRfc3339 = function(/*String*/rfcDate) {
+dojo.date.fromRfc3339 = function(/*String*/rfcDate){
// summary:
// Create a JavaScript Date object from a string formatted according to RFC 3339
//
@@ -164,7 +167,7 @@
// backwards compatible support for use of "any" instead of just not
// including the time
- if(rfcDate.indexOf("Tany")!=-1) {
+ if(rfcDate.indexOf("Tany")!=-1){
rfcDate = rfcDate.replace("Tany","");
}
var dateObject = new Date();
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/date/supplemental.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/date/supplemental.js?view=diff&rev=453979&r1=453978&r2=453979
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/date/supplemental.js (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/date/supplemental.js Sat Oct 7 11:22:33 2006
@@ -11,7 +11,8 @@
dojo.provide("dojo.date.supplemental");
dojo.date.getFirstDayOfWeek = function(/*String?*/locale){
-// summary:
+// summary: Returns a zero-based index for first day of the week
+// description:
// Returns a zero-based index for first day of the week, as used by the local (Gregorian) calendar.
// e.g. Sunday (returns 0), or Monday (returns 1)
@@ -34,8 +35,10 @@
};
dojo.date.getWeekend = function(/*String?*/locale){
-// summary:
-// Returns a hash containing the start and end of the weekend in the locale, or by default in the user's locale.
+// summary: Returns a hash containing the start and end days of the weekend
+// description:
+// Returns a hash containing the start and end days of the weekend according to local custom using locale,
+// or by default in the user's locale.
// e.g. {start:6, end:0}
// from http://www.unicode.org/cldr/data/common/supplemental/supplementalData.xml:supplementalData/weekData/weekend{Start,End}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/debug/console.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/debug/console.js?view=diff&rev=453979&r1=453978&r2=453979
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/debug/console.js (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/debug/console.js Sat Oct 7 11:22:33 2006
@@ -9,6 +9,8 @@
*/
dojo.provide("dojo.debug.console");
+dojo.require("dojo.logging.ConsoleLogger");
+
// summary:
// Console logger, for use with FireFox Firebug, Safari and Opera's consoles.
// description:
@@ -22,7 +24,7 @@
if (console.info != null) {
// using a later version of Firebug -- lots of fun stuff!
- dojo.debug = function() {
+ dojo.hostenv.println = function() {
// summary: Write all of the arguments to the Firebug console
// description: Uses console.info() so that the (i) icon prints next to the debug line
// rather than munging the arguments by adding "DEBUG:" in front of them.
@@ -30,7 +32,8 @@
if (!djConfig.isDebug) { return; }
console.info.apply(console, arguments);
}
- dojo.debugDeep = dojo.debug;
+ dojo.debug=dojo.hostenv.println;
+ dojo.debugDeep = dojo.debug;
dojo.debugShallow = function(/*Object*/ obj, /*Boolean?*/showMethods, /*Boolean?*/sort) {
// summary: Write first-level properties of obj to the console.
@@ -86,16 +89,16 @@
// which is nice for a DOM element, etc
return dojo.debug(obj.constructor + ": ", obj);
}
-
+
} else if (console.log != null) {
// using Safari or an old version of Firebug
-
- dojo.debug = function() {
+ dojo.hostenv.println=function() {
if (!djConfig.isDebug) { return ; }
// make sure we're only writing a single string to Safari's console
var args = dojo.lang.toArray(arguments);
console.log("DEBUG: " + args.join(" "));
}
+ dojo.debug=dojo.hostenv.println;
} else {
// not supported
dojo.debug("dojo.debug.console requires Firebug > 0.4");
@@ -105,10 +108,8 @@
if (opera && opera.postError) {
dojo.hostenv.println=opera.postError;
// summary: hook debugging up to Opera's postError routine
-
} else {
dojo.debug("dojo.debug.Opera requires Opera > 8.0");
-
}
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/event/common.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/event/common.js?view=diff&rev=453979&r1=453978&r2=453979
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/event/common.js (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/event/common.js Sat Oct 7 11:22:33 2006
@@ -30,7 +30,7 @@
// TODO: more resiliency for 4+ arguments to connect()
dojo.event = new function(){
- this.canTimeout = dojo.lang.isFunction(dj_global["setTimeout"])||dojo.lang.isAlien(dj_global["setTimeout"]);
+ this._canTimeout = dojo.lang.isFunction(dj_global["setTimeout"])||dojo.lang.isAlien(dj_global["setTimeout"]);
// FIXME: where should we put this method (not here!)?
function interpolateArgs(args, searchForNames){
@@ -181,10 +181,104 @@
return ao;
}
- this.connect = function(){
+ this.connect = function(/*...*/){
// summary:
- // dojo.event.connect is the glue that holds most Dojo-based
- // applications together.
+ // dojo.event.connect is the glue that holds most Dojo-based
+ // applications together. Most combinations of arguments are
+ // supported, with the connect() method attempting to disambiguate
+ // the implied types of positional parameters. The following will
+ // all work:
+ // dojo.event.connect("globalFunctionName1", "globalFunctionName2");
+ // dojo.event.connect(functionReference1, functionReference2);
+ // dojo.event.connect("globalFunctionName1", functionReference2);
+ // dojo.event.connect(functionReference1, "globalFunctionName2");
+ // dojo.event.connect(scope1, "functionName1", "globalFunctionName2");
+ // dojo.event.connect("globalFunctionName1", scope2, "functionName2");
+ // dojo.event.connect(scope1, "functionName1", scope2, "functionName2");
+ // dojo.event.connect("after", scope1, "functionName1", scope2, "functionName2");
+ // dojo.event.connect("before", scope1, "functionName1", scope2, "functionName2");
+ // dojo.event.connect("around", scope1, "functionName1",
+ // scope2, "functionName2",
+ // aroundFunctionReference);
+ // dojo.event.connect("around", scope1, "functionName1",
+ // scope2, "functionName2",
+ // scope3, "aroundFunctionName");
+ // dojo.event.connect("before-around", scope1, "functionName1",
+ // scope2, "functionName2",
+ // aroundFunctionReference);
+ // dojo.event.connect("after-around", scope1, "functionName1",
+ // scope2, "functionName2",
+ // aroundFunctionReference);
+ // dojo.event.connect("after-around", scope1, "functionName1",
+ // scope2, "functionName2",
+ // scope3, "aroundFunctionName");
+ // dojo.event.connect("around", scope1, "functionName1",
+ // scope2, "functionName2",
+ // scope3, "aroundFunctionName", true, 30);
+ // dojo.event.connect("around", scope1, "functionName1",
+ // scope2, "functionName2",
+ // scope3, "aroundFunctionName", null, null, 10);
+ // adviceType:
+ // Optional. String. One of "before", "after", "around",
+ // "before-around", or "after-around". FIXME
+ // srcObj:
+ // the scope in which to locate/execute the named srcFunc. Along
+ // with srcFunc, this creates a way to dereference the function to
+ // call. So if the function in question is "foo.bar", the
+ // srcObj/srcFunc pair would be foo and "bar", where "bar" is a
+ // string and foo is an object reference.
+ // srcFunc:
+ // the name of the function to connect to. When it is executed,
+ // the listener being registered with this call will be called.
+ // The adviceType defines the call order between the source and
+ // the target functions.
+ // adviceObj:
+ // the scope in which to locate/execute the named adviceFunc.
+ // adviceFunc:
+ // the name of the function being conected to srcObj.srcFunc
+ // aroundObj:
+ // the scope in which to locate/execute the named aroundFunc.
+ // aroundFunc:
+ // the name of, or a reference to, the function that will be used
+ // to mediate the advice call. Around advice requires a special
+ // unary function that will be passed a "MethodInvocation" object.
+ // These objects have several important properties, namely:
+ // - args
+ // a mutable array of arguments to be passed into the
+ // wrapped function
+ // - proceed
+ // a function that "continues" the invocation. The result
+ // of this function is the return of the wrapped function.
+ // You can then manipulate this return before passing it
+ // back out (or take further action based on it).
+ // once:
+ // boolean that determines whether or not this connect() will
+ // create a new connection if an identical connect() has already
+ // been made. Defaults to "false".
+ // delay:
+ // an optional delay (in ms), as an integer, for dispatch of a
+ // listener after the source has been fired.
+ // rate:
+ // an optional rate throttling parameter (integer, in ms). When
+ // specified, this particular connection will not fire more than
+ // once in the interval specified by the rate
+ // adviceMsg:
+ // boolean. Should the listener have all the parameters passed in
+ // as a single argument?
+
+ /*
+ ao.adviceType = args[0];
+ ao.srcObj = args[1];
+ ao.srcFunc = args[2];
+ ao.adviceObj = args[3]
+ ao.adviceFunc = args[4];
+ ao.aroundObj = args[5];
+ ao.aroundFunc = args[6];
+ ao.once = args[7];
+ ao.delay = args[8];
+ ao.rate = args[9];
+ ao.adviceMsg = args[10];
+ */
if(arguments.length == 1){
var ao = arguments[0];
}else{
@@ -198,6 +292,7 @@
ao.srcFunc = "onkeypress";
}
+
if(dojo.lang.isArray(ao.srcObj) && ao.srcObj!=""){
var tmpAO = {};
for(var x in ao){
@@ -225,11 +320,21 @@
mjp.kwAddAdvice(ao);
- return mjp; // advanced users might want to fsck w/ the join point
- // manually
+ // advanced users might want to fsck w/ the join point manually
+ return mjp; // a MethodJoinPoint object
}
- this.log = function(a1, a2){
+ this.log = function(/*object or funcName*/ a1, /*funcName*/ a2){
+ // summary:
+ // a function that will wrap and log all calls to the specified
+ // a1.a2() function. If only a1 is passed, it'll be used as a
+ // function or function name on the global context. Logging will
+ // be sent to dojo.debug
+ // a1:
+ // if a2 is passed, this should be an object. If not, it can be a
+ // function or function name.
+ // a2:
+ // a function name
var kwArgs;
if((arguments.length == 1)&&(typeof a1 == "object")){
kwArgs = a1;
@@ -250,21 +355,30 @@
}
this.connectBefore = function(){
+ // summary:
+ // takes the same parameters as dojo.event.connect(), except that
+ // the advice type will always be "before"
var args = ["before"];
for(var i = 0; i < arguments.length; i++){ args.push(arguments[i]); }
- return this.connect.apply(this, args);
+ return this.connect.apply(this, args); // a MethodJoinPoint object
}
this.connectAround = function(){
+ // summary:
+ // takes the same parameters as dojo.event.connect(), except that
+ // the advice type will always be "around"
var args = ["around"];
for(var i = 0; i < arguments.length; i++){ args.push(arguments[i]); }
- return this.connect.apply(this, args);
+ return this.connect.apply(this, args); // a MethodJoinPoint object
}
this.connectOnce = function(){
+ // summary:
+ // takes the same parameters as dojo.event.connect(), except that
+ // the "once" flag will always be set to "true"
var ao = interpolateArgs(arguments, true);
ao.once = true;
- return this.connect(ao);
+ return this.connect(ao); // a MethodJoinPoint object
}
this._kwConnectImpl = function(kwArgs, disconnect){
@@ -279,25 +393,46 @@
var tmpName = dojo.lang.nameAnonFunc(kwArgs.adviceFunc, kwArgs.adviceObj, true);
kwArgs.adviceFunc = tmpName;
}
- return dojo.event[fn]( (kwArgs["type"]||kwArgs["adviceType"]||"after"),
- kwArgs["srcObj"]||dj_global,
- kwArgs["srcFunc"],
- kwArgs["adviceObj"]||kwArgs["targetObj"]||dj_global,
- kwArgs["adviceFunc"]||kwArgs["targetFunc"],
- kwArgs["aroundObj"],
- kwArgs["aroundFunc"],
- kwArgs["once"],
- kwArgs["delay"],
- kwArgs["rate"],
- kwArgs["adviceMsg"]||false );
+ kwArgs.srcObj = kwArgs["srcObj"]||dj_global;
+ kwArgs.adviceObj = kwArgs["adviceObj"]||kwArgs["targetObj"]||dj_global;
+ kwArgs.adviceFunc = kwArgs["adviceFunc"]||kwArgs["targetFunc"];
+ // pass kwargs to avoid unrolling/repacking
+ return dojo.event[fn](kwArgs);
}
- this.kwConnect = function(kwArgs){
- return this._kwConnectImpl(kwArgs, false);
+ this.kwConnect = function(/*Object*/ kwArgs){
+ // summary:
+ // A version of dojo.event.connect() that takes a map of named
+ // parameters instead of the positional parameters that
+ // dojo.event.connect() uses. For many advanced connection types,
+ // this can be a much more readable (and potentially faster)
+ // alternative.
+ // kwArgs:
+ // An object that can have the following properties:
+ // - adviceType
+ // - srcObj
+ // - srcFunc
+ // - adviceObj
+ // - adviceFunc
+ // - aroundObj
+ // - aroundFunc
+ // - once
+ // - delay
+ // - rate
+ // - adviceMsg
+ // As with connect, only srcFunc and adviceFunc are generally
+ // required
+
+ return this._kwConnectImpl(kwArgs, false); // a MethodJoinPoint object
}
this.disconnect = function(){
+ // summary:
+ // Takes the same parameters as dojo.event.connect() but destroys
+ // an existing connection instead of building a new one. For
+ // multiple identical connections, multiple disconnect() calls
+ // will unroll one each time it's called.
if(arguments.length == 1){
var ao = arguments[0];
}else{
@@ -312,20 +447,36 @@
ao.srcFunc = "onkeypress";
}
var mjp = dojo.event.MethodJoinPoint.getForMethod(ao.srcObj, ao.srcFunc);
- return mjp.removeAdvice(ao.adviceObj, ao.adviceFunc, ao.adviceType, ao.once);
+ return mjp.removeAdvice(ao.adviceObj, ao.adviceFunc, ao.adviceType, ao.once); // a MethodJoinPoint object
}
this.kwDisconnect = function(kwArgs){
+ // summary:
+ // Takes the same parameters as dojo.event.kwConnect() but
+ // destroys an existing connection instead of building a new one.
return this._kwConnectImpl(kwArgs, true);
}
}
// exactly one of these is created whenever a method with a joint point is run,
// if there is at least one 'around' advice.
-dojo.event.MethodInvocation = function(join_point, obj, args){
+dojo.event.MethodInvocation = function(/*dojo.event.MethodJoinPoint*/join_point, /*Object*/obj, /*Array*/args){
+ // summary:
+ // a class the models the call into a function. This is used under the
+ // covers for all method invocations on both ends of a
+ // connect()-wrapped function dispatch. This allows us to "pickle"
+ // calls, such as in the case of around advice.
+ // join_point:
+ // a dojo.event.MethodJoinPoint object that represents a connection
+ // obj:
+ // the scope the call will execute in
+ // args:
+ // an array of parameters that will get passed to the callee
this.jp_ = join_point;
this.object = obj;
this.args = [];
+ // make sure we don't lock into a mutable object which can change under us.
+ // It's ok if the individual items change, though.
for(var x=0; x<args.length; x++){
this.args[x] = args[x];
}
@@ -334,6 +485,9 @@
}
dojo.event.MethodInvocation.prototype.proceed = function(){
+ // summary:
+ // proceed with the method call that's represented by this invocation
+ // object
this.around_index++;
if(this.around_index >= this.jp_.around.length){
return this.jp_.object[this.jp_.methodname].apply(this.jp_.object, this.args);
@@ -347,32 +501,39 @@
}
-dojo.event.MethodJoinPoint = function(obj, methname){
+dojo.event.MethodJoinPoint = function(/*Object*/obj, /*String*/funcName){
this.object = obj||dj_global;
- this.methodname = methname;
- this.methodfunc = this.object[methname];
+ this.methodname = funcName;
+ this.methodfunc = this.object[funcName];
this.squelch = false;
- this.before = [];
- this.after = [];
- this.around = [];
+ // this.before = [];
+ // this.after = [];
+ // this.around = [];
}
-dojo.event.MethodJoinPoint.getForMethod = function(obj, methname){
- // if(!(methname in obj)){
+dojo.event.MethodJoinPoint.getForMethod = function(/*Object*/obj, /*String*/funcName){
+ // summary:
+ // "static" class function for returning a MethodJoinPoint from a
+ // scoped function. If one doesn't exist, one is created.
+ // obj:
+ // the scope to search for the function in
+ // funcName:
+ // the name of the function to return a MethodJoinPoint for
if(!obj){ obj = dj_global; }
- if(!obj[methname]){
+ if(!obj[funcName]){
// supply a do-nothing method implementation
- obj[methname] = function(){};
- if(!obj[methname]){
+ obj[funcName] = function(){};
+ if(!obj[funcName]){
// e.g. cannot add to inbuilt objects in IE6
- dojo.raise("Cannot set do-nothing method on that object "+methname);
+ dojo.raise("Cannot set do-nothing method on that object "+funcName);
}
- }else if((!dojo.lang.isFunction(obj[methname]))&&(!dojo.lang.isAlien(obj[methname]))){
- return null; // FIXME: should we throw an exception here instead?
- }
- // we hide our joinpoint instance in obj[methname + '$joinpoint']
- var jpname = methname + "$joinpoint";
- var jpfuncname = methname + "$joinpoint$method";
+ }else if((!dojo.lang.isFunction(obj[funcName]))&&(!dojo.lang.isAlien(obj[funcName]))){
+ // FIXME: should we throw an exception here instead?
+ return null;
+ }
+ // we hide our joinpoint instance in obj[funcName + '$joinpoint']
+ var jpname = funcName + "$joinpoint";
+ var jpfuncname = funcName + "$joinpoint$method";
var joinpoint = obj[jpname];
if(!joinpoint){
var isNode = false;
@@ -381,14 +542,14 @@
(obj["nodeType"])||
(obj["addEventListener"]) ){
isNode = true;
- dojo.event.browser.addClobberNodeAttrs(obj, [jpname, jpfuncname, methname]);
+ dojo.event.browser.addClobberNodeAttrs(obj, [jpname, jpfuncname, funcName]);
}
}
- var origArity = obj[methname].length;
- obj[jpfuncname] = obj[methname];
- // joinpoint = obj[jpname] = new dojo.event.MethodJoinPoint(obj, methname);
+ var origArity = obj[funcName].length;
+ obj[jpfuncname] = obj[funcName];
+ // joinpoint = obj[jpname] = new dojo.event.MethodJoinPoint(obj, funcName);
joinpoint = obj[jpname] = new dojo.event.MethodJoinPoint(obj, jpfuncname);
- obj[methname] = function(){
+ obj[funcName] = function(){
var args = [];
if((isNode)&&(!arguments.length)){
@@ -422,13 +583,16 @@
// return joinpoint.run.apply(joinpoint, arguments);
return joinpoint.run.apply(joinpoint, args);
}
- obj[methname].__preJoinArity = origArity;
+ obj[funcName].__preJoinArity = origArity;
}
- return joinpoint;
+ return joinpoint; // dojo.event.MethodJoinPoint
}
dojo.lang.extend(dojo.event.MethodJoinPoint, {
unintercept: function(){
+ // summary:
+ // destroy the connection to all listeners that may have been
+ // registered on this joinpoint
this.object[this.methodname] = this.methodfunc;
this.before = [];
this.after = [];
@@ -438,6 +602,10 @@
disconnect: dojo.lang.forward("unintercept"),
run: function(){
+ // summary:
+ // execute the connection represented by this join point. The
+ // arguments passed to run() will be passed to the function and
+ // its listeners.
var obj = this.object||dj_global;
var args = arguments;
@@ -483,7 +651,7 @@
var cur = new Date();
var timerSet = false;
if((marr["last"])&&((cur-marr.last)<=rate)){
- if(dojo.event.canTimeout){
+ if(dojo.event._canTimeout){
if(marr["delayTimer"]){
clearTimeout(marr.delayTimer);
}
@@ -541,14 +709,14 @@
}
}
- if(this.before.length>0){
+ if((this["before"])&&(this.before.length>0)){
// pass a cloned array, if this event disconnects this event forEach on this.before wont work
dojo.lang.forEach(this.before.concat(new Array()), unRollSquelch);
}
var result;
try{
- if(this.around.length>0){
+ if((this["around"])&&(this.around.length>0)){
var mi = new dojo.event.MethodInvocation(this, obj, args);
result = mi.proceed();
}else if(this.methodfunc){
@@ -556,7 +724,7 @@
}
}catch(e){ if(!this.squelch){ dojo.raise(e); } }
- if(this.after.length>0){
+ if((this["after"])&&(this.after.length>0)){
// see comment on this.before above
dojo.lang.forEach(this.after.concat(new Array()), unRollSquelch);
}
@@ -564,18 +732,23 @@
return (this.methodfunc) ? result : null;
},
- getArr: function(kind){
- var arr = this.after;
+ getArr: function(/*String*/kind){
+ // summary: return a list of listeners of the past "kind"
+ // kind:
+ // can be one of: "before", "after", "around", "before-around", or
+ // "after-around"
+ var type = "after";
// FIXME: we should be able to do this through props or Array.in()
if((typeof kind == "string")&&(kind.indexOf("before")!=-1)){
- arr = this.before;
+ type = "before";
}else if(kind=="around"){
- arr = this.around;
+ type = "around";
}
- return arr;
+ if(!this[type]){ this[type] = []; }
+ return this[type]; // Array
},
- kwAddAdvice: function(args){
+ kwAddAdvice: function(/*Object*/args){
this.addAdvice( args["adviceObj"], args["adviceFunc"],
args["aroundObj"], args["aroundFunc"],
args["adviceType"], args["precedence"],
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/event/topic.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/event/topic.js?view=diff&rev=453979&r1=453978&r2=453979
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/event/topic.js (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/event/topic.js Sat Oct 7 11:22:33 2006
@@ -14,39 +14,93 @@
dojo.event.topic = new function(){
this.topics = {};
- this.getTopic = function(topicName){
- if(!this.topics[topicName]){
- this.topics[topicName] = new this.TopicImpl(topicName);
+ this.getTopic = function(/*String*/topic){
+ // summary:
+ // returns a topic implementation object of type
+ // dojo.event.topic.TopicImpl
+ // topic:
+ // a unique, opaque string that names the topic
+ if(!this.topics[topic]){
+ this.topics[topic] = new this.TopicImpl(topic);
}
- return this.topics[topicName];
+ return this.topics[topic]; // a dojo.event.topic.TopicImpl object
}
- this.registerPublisher = function(topic, obj, funcName){
+ this.registerPublisher = function(/*String*/topic, /*Object*/obj, /*String*/funcName){
+ // summary:
+ // registers a function as a publisher on a topic. Subsequent
+ // calls to the function will cause a publish event on the topic
+ // with the arguments passed to the function passed to registered
+ // listeners.
+ // topic:
+ // a unique, opaque string that names the topic
+ // obj:
+ // the scope to locate the function in
+ // funcName:
+ // the name of the function to register
var topic = this.getTopic(topic);
topic.registerPublisher(obj, funcName);
}
- this.subscribe = function(topic, obj, funcName){
+ this.subscribe = function(/*String*/topic, /*Object*/obj, /*String*/funcName){
+ // summary:
+ // susbscribes the function to the topic. Subsequent events
+ // dispached to the topic will create a function call for the
+ // obj.funcName() function.
+ // topic:
+ // a unique, opaque string that names the topic
+ // obj:
+ // the scope to locate the function in
+ // funcName:
+ // the name of the function to being registered as a listener
var topic = this.getTopic(topic);
topic.subscribe(obj, funcName);
}
- this.unsubscribe = function(topic, obj, funcName){
+ this.unsubscribe = function(/*String*/topic, /*Object*/obj, /*String*/funcName){
+ // summary:
+ // unsubscribes the obj.funcName() from the topic
+ // topic:
+ // a unique, opaque string that names the topic
+ // obj:
+ // the scope to locate the function in
+ // funcName:
+ // the name of the function to being unregistered as a listener
var topic = this.getTopic(topic);
topic.unsubscribe(obj, funcName);
}
- this.destroy = function(topic){
+ this.destroy = function(/*String*/topic){
+ // summary:
+ // destroys the topic and unregisters all listeners
+ // topic:
+ // a unique, opaque string that names the topic
this.getTopic(topic).destroy();
delete this.topics[topic];
}
- this.publishApply = function(topic, args){
+ this.publishApply = function(/*String*/topic, /*Array*/args){
+ // summary:
+ // dispatches an event to the topic using the args array as the
+ // source for the call arguments to each listener. This is similar
+ // to JavaScript's built-in Function.apply()
+ // topic:
+ // a unique, opaque string that names the topic
+ // args:
+ // the arguments to be passed into listeners of the topic
var topic = this.getTopic(topic);
topic.sendMessage.apply(topic, args);
}
- this.publish = function(topic, message){
+ this.publish = function(/*String*/topic, /*Object*/message){
+ // summary:
+ // manually "publish" to the passed topic
+ // topic:
+ // a unique, opaque string that names the topic
+ // message:
+ // can be an array of parameters (similar to publishApply), or
+ // will be treated as one of many arguments to be passed along in
+ // a "flat" unrolling
var topic = this.getTopic(topic);
// if message is an array, we treat it as a set of arguments,
// otherwise, we just pass on the arguments passed in as-is
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/gfx/common.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/gfx/common.js?view=diff&rev=453979&r1=453978&r2=453979
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/gfx/common.js (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/gfx/common.js Sat Oct 7 11:22:33 2006
@@ -18,10 +18,10 @@
//dojo.gfx.defaultRenderer.init();
dojo.lang.mixin(dojo.gfx, {
- defaultPath: {type: "path", path: "", absolute: true},
+ defaultPath: {type: "path", path: ""},
defaultPolyline: {type: "polyline", points: []},
defaultRect: {type: "rect", x: 0, y: 0, width: 100, height: 100, r: 0},
- defaultEllipse: {type: "ellipse", cx: 0, cy: 0, rx: 100, ry: 200},
+ defaultEllipse: {type: "ellipse", cx: 0, cy: 0, rx: 200, ry: 100},
defaultCircle: {type: "circle", cx: 0, cy: 0, r: 100},
defaultLine: {type: "line", x1: 0, y1: 0, x2: 100, y2: 100},
defaultImage: {type: "image", width: 0, height: 0, src: ""},
@@ -56,167 +56,29 @@
}
}
return result;
- }
-});
-
-// this is a Shape object, which knows how to apply graphical attributes and a transformation
-dojo.gfx.Shape = function(){
- // underlying node
- this.rawNode = null;
- // abstract shape object
- this.shape = null;
- // transformation matrix
- this.matrix = null;
- // graphical attributes
- this.fillStyle = null;
- this.strokeStyle = null;
- // virtual group structure
- this.parent = null;
- this.parentMatrix = null;
-};
-
-dojo.lang.extend(dojo.gfx.Shape, {
- // trivial getters
- getNode: function(){ return this.rawNode; },
- getShape: function(){ return this.shape; },
- getTransform: function(){ return this.matrix; },
- getFill: function(){ return this.fillStyle; },
- getStroke: function(){ return this.strokeStyle; },
- getParent: function(){ return this.parent; },
-
- getEventSource: function(){ return this.rawNode; },
-
- // empty settings
- setShape: function(shape) { return this; }, // ignore
- setStroke: function(stroke){ return this; }, // ignore
- setFill: function(fill) { return this; }, // ignore
-
- // z-index
- moveToFront: function(){ return this; }, // ignore
- moveToBack: function(){ return this; }, // ignore
-
- // apply transformations
- setTransform: function(matrix){
- this.matrix = dojo.gfx.matrix.clone(matrix ? dojo.gfx.matrix.normalize(matrix) : dojo.gfx.identity, true);
- return this._applyTransform();
- },
-
- // apply left & right transformation
- applyRightTransform: function(matrix){
- return matrix ? this.setTransform([this.matrix, matrix]) : this;
- },
- applyLeftTransform: function(matrix){
- return matrix ? this.setTransform([matrix, this.matrix]) : this;
- },
-
- // a shortcut for apply-right
- applyTransform: function(matrix){
- return matrix ? this.setTransform([this.matrix, matrix]) : this;
- },
-
- // virtual group methods
- remove: function(silently){
- if(this.parent){
- this.parent.remove(this, silently);
- }
- return this;
- },
- _setParent: function(parent, matrix){
- this.parent = parent;
- return this._updateParentMatrix(matrix);
- },
- _updateParentMatrix: function(matrix){
- this.parentMatrix = matrix ? dojo.gfx.matrix.clone(matrix) : null;
- return this._applyTransform();
- },
- _getRealMatrix: function(){
- return this.parentMatrix ? new dojo.gfx.matrix.Matrix2D([this.parentMatrix, this.matrix]) : this.matrix;
- }
-});
-
-dojo.declare("dojo.gfx.VirtualGroup", dojo.gfx.Shape, {
- initializer: function() {
- this.children = [];
- },
-
- // group management
- add: function(shape){
- var oldParent = shape.getParent();
- if(oldParent){
- oldParent.remove(shape, true);
- }
- this.children.push(shape);
- return shape._setParent(this, this._getRealMatrix());
},
- remove: function(shape, silently){
- var i = 0;
- for(; i < this.children.length; ++i){
- if(this.children[i] == shape){
- if(silently){
- // skip for now
- }else{
- shape._setParent(null, null);
- }
- this.children.splice(i, 1);
- break;
+ formatNumber: function(x, addSpace){
+ var val = x.toString();
+ if(val.indexOf("e") >= 0){
+ val = x.toFixed(4);
+ }else{
+ var point = val.indexOf(".");
+ if(point >= 0 && val.length - point > 5){
+ val = x.toFixed(4);
}
}
- return this;
- },
-
- // apply transformation
- _applyTransform: function(){
- var matrix = this._getRealMatrix();
- for(var i = 0; i < this.children.length; ++i){
- this.children[i]._updateParentMatrix(matrix);
+ if(x < 0){
+ return val;
}
- return this;
+ return addSpace ? " " + val : val;
}
});
// this is a Surface object
-dojo.gfx.Surface = function(){
- // underlying node
- this.rawNode = null;
-};
-
-dojo.lang.extend(dojo.gfx.Surface, {
- getEventSource: function(){ return this.rawNode; }
-});
-
-// this is a Path shape
-dojo.declare("dojo.gfx.Path", dojo.gfx.Shape, {
- initializer: function(rawNode) {
- this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultPath, true);
- this.lastPos = {x: 0, y: 0};
- this._extraInit(rawNode);
- this.attach(rawNode);
- },
- setAbsoluteMode: function(mode){
- this.shape.absolute = typeof(mode) == "string" ? (mode == "absolute") : mode;
- return this;
- },
- getAbsoluteMode: function(){
- return this.shape.absolute;
- },
- closePath: function(){
- return this._drawTo("z", []);
+dojo.declare("dojo.gfx.Surface", null, {
+ initializer: function(){
+ // underlying node
+ this.rawNode = null;
},
- moveTo: function(x, y){
- this._update(x, y);
- return this._drawTo("m", [x, y]);
- },
- lineTo: function(x, y){
- this._update(x, y);
- return this._drawTo("l", [x, y]);
- },
- curveTo: function(x1, y1, x2, y2, x, y){
- this._update(x, y, x2, y2);
- return this._drawTo("c", [x1, y1, x2, y2, x, y]);
- },
- _2PI: Math.PI * 2,
- // these are meant to be overridden in derived classes
- _extraInit: function(rawNode) {},
- _drawTo: function(action) { return this; },
- _update: function(x, y, x2, y2) {}
+ getEventSource: function(){ return this.rawNode; }
});
Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/gfx/path.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/gfx/path.js?view=auto&rev=453979
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/gfx/path.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/gfx/path.js Sat Oct 7 11:22:33 2006
@@ -0,0 +1,297 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.gfx.path");
+
+dojo.require("dojo.math");
+
+dojo.require("dojo.gfx.shape");
+
+// this is a Path shape
+dojo.declare("dojo.gfx.path.Path", dojo.gfx.Shape, {
+ initializer: function(rawNode){
+ this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultPath, true);
+ this.segments = [];
+ this.absolute = true;
+ this.last = {};
+ this.attach(rawNode);
+ },
+
+ // mode manipulations
+ setAbsoluteMode: function(mode){
+ this.absolute = typeof(mode) == "string" ? (mode == "absolute") : mode;
+ return this;
+ },
+ getAbsoluteMode: function(){
+ return this.absolute;
+ },
+ getBoundingBox: function(){
+ return "l" in this.bbox
+ ? {x: this.bbox.l, y: this.bbox.t,
+ width: this.bbox.r - this.bbox.l,
+ height: this.bbox.b - this.bbox.t}
+ : null;
+ },
+ getLastPosition: function(){
+ return "x" in this.last ? this.last : null;
+ },
+
+ // segment interpretation
+ _updateBBox: function(x, y){
+ // we use {l, b, r, t} representation of a bbox
+ if("l" in this.bbox){
+ if(this.bbox.l > x) this.bbox.l = x;
+ if(this.bbox.r < x) this.bbox.r = x;
+ if(this.bbox.t > y) this.bbox.t = y;
+ if(this.bbox.b < y) this.bbox.b = y;
+ }else{
+ this.bbox = {l: x, b: y, r: x, t: y};
+ }
+ },
+ _updateWithSegment: function(segment){
+ var n = segment.args;
+ var l = n.length;
+ // update internal variables: bbox, absolute, last
+ switch(segment.action){
+ case "M":
+ case "L":
+ case "C":
+ case "S":
+ case "Q":
+ case "T":
+ for(var i = 0; i < l; i += 2){
+ this._updateBBox(this.bbox, n[i], n[i + 1]);
+ }
+ this.last.x = n[l - 2];
+ this.last.y = n[l - 1];
+ this.absolute = true;
+ break;
+ case "H":
+ for(var i = 0; i < l; ++i){
+ this._updateBBox(this.bbox, n[i], this.last.y);
+ }
+ this.last.x = n[l - 1];
+ this.absolute = true;
+ break;
+ case "V":
+ for(var i = 0; i < l; ++i){
+ this._updateBBox(this.bbox, this.last.x, n[i]);
+ }
+ this.last.y = n[l - 1];
+ this.absolute = true;
+ break;
+ case "m":
+ var start = 0;
+ if(!("x" in this.last)){
+ this._updateBBox(this.bbox, this.last.x = n[0], this.last.y = n[1]);
+ start = 2;
+ }
+ for(var i = start; i < l; i += 2){
+ this._updateBBox(this.bbox, this.last.x += n[i], this.last.y += n[i + 1]);
+ }
+ this.absolute = false;
+ break;
+ case "l":
+ case "t":
+ for(var i = 0; i < l; i += 2){
+ this._updateBBox(this.bbox, this.last.x += n[i], this.last.y += n[i + 1]);
+ }
+ this.absolute = false;
+ break;
+ case "h":
+ for(var i = 0; i < l; ++i){
+ this._updateBBox(this.bbox, this.last.x += n[i], this.last.y);
+ }
+ this.absolute = false;
+ break;
+ case "v":
+ for(var i = 0; i < l; ++i){
+ this._updateBBox(this.bbox, this.last.x, this.last.y += n[i]);
+ }
+ this.absolute = false;
+ break;
+ case "c":
+ for(var i = 0; i < l; i += 6){
+ this._updateBBox(this.bbox, this.last.x + n[i], this.last.y + n[i + 1]);
+ this._updateBBox(this.bbox, this.last.x + n[i + 2], this.last.y + n[i + 3]);
+ this._updateBBox(this.bbox, this.last.x += n[i + 4], this.last.y += n[i + 5]);
+ }
+ this.absolute = false;
+ break;
+ case "s":
+ case "q":
+ for(var i = 0; i < l; i += 4){
+ this._updateBBox(this.bbox, this.last.x + n[i], this.last.y + n[i + 1]);
+ this._updateBBox(this.bbox, this.last.x += n[i + 2], this.last.y += n[i + 3]);
+ }
+ this.absolute = false;
+ break;
+ case "A":
+ for(var i = 0; i < l; i += 7){
+ this._updateBBox(this.bbox, n[i + 5], n[i + 6]);
+ }
+ this.last.x = n[l - 2];
+ this.last.y = n[l - 1];
+ this.absolute = true;
+ break;
+ case "a":
+ for(var i = 0; i < l; i += 7){
+ this._updateBBox(this.bbox, this.last.x += n[i + 5], this.last.y += n[i + 6]);
+ }
+ this.absolute = false;
+ break;
+ }
+ // add an SVG path segment
+ var path = [segment.action];
+ for(var i = 0; i < l; ++i){
+ path.push(dojo.gfx.formatNumber(n[i], true));
+ }
+ if(typeof(this.shape.path) == "string"){
+ this.shape.path += path.join("");
+ }else{
+ this.shape.path = this.shape.path.concat(path);
+ }
+ },
+ _validSegments: {m: 2, l: 2, h: 1, v: 1, c: 6, s: 4, q: 4, t: 2, a: 7, z: 0},
+ _pushSegment: function(action, args){
+ var group = this._validSegments[action.toLowerCase()];
+ if(typeof(group) == "number"){
+ if(group){
+ if(args.length >= group){
+ var segment = {action: action, args: args.slice(0, args.length - args.length % group)};
+ this.segments.push(segment);
+ this._updateWithSegment(segment);
+ }
+ }else{
+ var segment = {action: action, args: []};
+ this.segments.push(segment);
+ this._updateWithSegment(segment);
+ }
+ }
+ },
+ _pathRegExp: /([A-Za-z]+)|(\d+(\.\d+)?)|(\.\d+)|(-\d+(\.\d+)?)|(-\.\d+)/g,
+ _collectArgs: function(array, args){
+ for(var i = 0; i < args.length; ++i){
+ var t = args[i];
+ if(typeof(t) == "boolean"){
+ array.push(t ? 1 : 0);
+ }else if(typeof(t) == "number"){
+ array.push(t);
+ }else if(t instanceof Array){
+ this._collectArgs(array, t);
+ }else if("x" in t && "y" in t){
+ array.push(t.x);
+ array.push(t.y);
+ }
+ }
+ },
+
+ // segments
+ moveTo: function(){
+ var args = [];
+ this._collectArgs(args, arguments);
+ this._pushSegment(this.absolute ? "M" : "m", args);
+ return this;
+ },
+ lineTo: function(){
+ var args = [];
+ this._collectArgs(args, arguments);
+ this._pushSegment(this.absolute ? "L" : "l", args);
+ return this;
+ },
+ hLineTo: function(){
+ var args = [];
+ this._collectArgs(args, arguments);
+ this._pushSegment(this.absolute ? "H" : "h", args);
+ return this;
+ },
+ vLineTo: function(){
+ var args = [];
+ this._collectArgs(args, arguments);
+ this._pushSegment(this.absolute ? "V" : "v", args);
+ return this;
+ },
+ curveTo: function(){
+ var args = [];
+ this._collectArgs(args, arguments);
+ this._pushSegment(this.absolute ? "C" : "c", args);
+ return this;
+ },
+ smoothCurveTo: function(){
+ var args = [];
+ this._collectArgs(args, arguments);
+ this._pushSegment(this.absolute ? "S" : "s", args);
+ return this;
+ },
+ qCurveTo: function(){
+ var args = [];
+ this._collectArgs(args, arguments);
+ this._pushSegment(this.absolute ? "Q" : "q", args);
+ return this;
+ },
+ qSmoothCurveTo: function(){
+ var args = [];
+ this._collectArgs(args, arguments);
+ this._pushSegment(this.absolute ? "T" : "t", args);
+ return this;
+ },
+ arcTo: function(){
+ var args = [];
+ this._collectArgs(args, arguments);
+ for(var i = 2; i < args.length; i += 7){
+ args[i] = -args[i];
+ }
+ this._pushSegment(this.absolute ? "A" : "a", args);
+ return this;
+ },
+ closePath: function(){
+ this._pushSegment("Z", []);
+ return this;
+ },
+
+ // setShape
+ _setPath: function(path){
+ var p = path.match(this._pathRegExp);
+ this.segments = [];
+ this.absolute = true;
+ this.bbox = {};
+ this.last = {};
+ if(!p) return;
+ // create segments
+ var action = ""; // current action
+ var args = []; // current arguments
+ for(var i = 0; i < p.length; ++i){
+ var t = p[i];
+ var x = parseFloat(t);
+ if(isNaN(x)){
+ if(action){
+ this._pushSegment(action, args);
+ }
+ args = [];
+ action = t;
+ }else{
+ args.push(x);
+ }
+ }
+ this._pushSegment(action, args);
+ },
+ setShape: function(newShape){
+ this.shape = dojo.gfx.makeParameters(this.shape, typeof(newShape) == "string" ? {path: newShape} : newShape);
+ var path = this.shape.path;
+ // switch to non-updating version of path building
+ this.shape.path = [];
+ this._setPath(path);
+ // switch back to the string path
+ this.shape.path = this.shape.path.join("");
+ return this;
+ },
+
+ _2PI: Math.PI * 2 // useful constant for descendants
+});
Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/gfx/path.js
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/gfx/shape.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/gfx/shape.js?view=auto&rev=453979
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/gfx/shape.js (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/gfx/shape.js Sat Oct 7 11:22:33 2006
@@ -0,0 +1,236 @@
+/*
+ Copyright (c) 2004-2006, The Dojo Foundation
+ All Rights Reserved.
+
+ Licensed under the Academic Free License version 2.1 or above OR the
+ modified BSD license. For more information on Dojo licensing, see:
+
+ http://dojotoolkit.org/community/licensing.shtml
+*/
+
+dojo.provide("dojo.gfx.shape");
+
+dojo.require("dojo.lang.declare");
+
+dojo.require("dojo.gfx.common");
+
+// this is a Shape object, which knows how to apply graphical attributes and a transformation
+dojo.declare("dojo.gfx.Shape", null, {
+
+ initializer: function(){
+ // underlying node
+ this.rawNode = null;
+ // abstract shape object
+ this.shape = null;
+ // transformation matrix
+ this.matrix = null;
+ // graphical attributes
+ this.fillStyle = null;
+ this.strokeStyle = null;
+ // virtual group structure
+ this.parent = null;
+ this.parentMatrix = null;
+ // bounding box
+ this.bbox = null;
+ },
+
+ // trivial getters
+ getNode: function(){ return this.rawNode; },
+ getShape: function(){ return this.shape; },
+ getTransform: function(){ return this.matrix; },
+ getFill: function(){ return this.fillStyle; },
+ getStroke: function(){ return this.strokeStyle; },
+ getParent: function(){ return this.parent; },
+ getBoundingBox: function(){ return this.bbox; },
+ getEventSource: function(){ return this.rawNode; },
+
+ // empty settings
+ setShape: function(shape) { return this; }, // ignore
+ setStroke: function(stroke){ return this; }, // ignore
+ setFill: function(fill) { return this; }, // ignore
+
+ // z-index
+ moveToFront: function(){ return this; }, // ignore
+ moveToBack: function(){ return this; }, // ignore
+
+ // apply transformations
+ setTransform: function(matrix){
+ this.matrix = dojo.gfx.matrix.clone(matrix ? dojo.gfx.matrix.normalize(matrix) : dojo.gfx.identity, true);
+ return this._applyTransform();
+ },
+
+ // apply left & right transformation
+ applyRightTransform: function(matrix){
+ return matrix ? this.setTransform([this.matrix, matrix]) : this;
+ },
+ applyLeftTransform: function(matrix){
+ return matrix ? this.setTransform([matrix, this.matrix]) : this;
+ },
+
+ // a shortcut for apply-right
+ applyTransform: function(matrix){
+ return matrix ? this.setTransform([this.matrix, matrix]) : this;
+ },
+
+ // virtual group methods
+ remove: function(silently){
+ if(this.parent){
+ this.parent.remove(this, silently);
+ }
+ return this;
+ },
+ _setParent: function(parent, matrix){
+ this.parent = parent;
+ return this._updateParentMatrix(matrix);
+ },
+ _updateParentMatrix: function(matrix){
+ this.parentMatrix = matrix ? dojo.gfx.matrix.clone(matrix) : null;
+ return this._applyTransform();
+ },
+ _getRealMatrix: function(){
+ return this.parentMatrix ? new dojo.gfx.matrix.Matrix2D([this.parentMatrix, this.matrix]) : this.matrix;
+ }
+});
+
+dojo.declare("dojo.gfx.shape.VirtualGroup", dojo.gfx.Shape, {
+ initializer: function() {
+ this.children = [];
+ },
+
+ // group management
+ add: function(shape){
+ var oldParent = shape.getParent();
+ if(oldParent){
+ oldParent.remove(shape, true);
+ }
+ this.children.push(shape);
+ return shape._setParent(this, this._getRealMatrix());
+ },
+ remove: function(shape, silently){
+ var i = 0;
+ for(; i < this.children.length; ++i){
+ if(this.children[i] == shape){
+ if(silently){
+ // skip for now
+ }else{
+ shape._setParent(null, null);
+ }
+ this.children.splice(i, 1);
+ break;
+ }
+ }
+ return this;
+ },
+
+ // apply transformation
+ _applyTransform: function(){
+ var matrix = this._getRealMatrix();
+ for(var i = 0; i < this.children.length; ++i){
+ this.children[i]._updateParentMatrix(matrix);
+ }
+ return this;
+ }
+});
+
+dojo.declare("dojo.gfx.shape.Rect", dojo.gfx.Shape, {
+ initializer: function(rawNode) {
+ this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultRect, true);
+ this.attach(rawNode);
+ },
+ getBoundingBox: function(){ return this.shape; }
+});
+
+dojo.declare("dojo.gfx.shape.Ellipse", dojo.gfx.Shape, {
+ initializer: function(rawNode) {
+ this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultEllipse, true);
+ this.attach(rawNode);
+ },
+ getBoundingBox: function(){
+ if(!this.bbox){
+ var shape = this.shape;
+ this.bbox = {x: shape.cx - shape.rx, y: shape.cy - shape.ry,
+ width: 2 * shape.rx, height: 2 * shape.ry};
+ }
+ return this.bbox;
+ }
+});
+
+dojo.declare("dojo.gfx.shape.Circle", dojo.gfx.Shape, {
+ initializer: function(rawNode) {
+ this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultCircle, true);
+ this.attach(rawNode);
+ },
+ getBoundingBox: function(){
+ if(!this.bbox){
+ var shape = this.shape;
+ this.bbox = {x: shape.cx - shape.r, y: shape.cy - shape.r,
+ width: 2 * shape.r, height: 2 * shape.r};
+ }
+ return this.bbox;
+ }
+});
+
+dojo.declare("dojo.gfx.shape.Line", dojo.gfx.Shape, {
+ initializer: function(rawNode) {
+ this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultLine, true);
+ this.attach(rawNode);
+ },
+ getBoundingBox: function(){
+ if(!this.bbox){
+ var shape = this.shape;
+ this.bbox = {
+ x: Math.min(shape.x1, shape.x2),
+ y: Math.min(shape.y1, shape.y2),
+ width: Math.abs(shape.x2 - shape.x1),
+ height: Math.abs(shape.y2 - shape.y1)
+ };
+ }
+ return this.bbox;
+ }
+});
+
+dojo.declare("dojo.gfx.shape.Polyline", dojo.gfx.Shape, {
+ initializer: function(rawNode) {
+ this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultPolyline, true);
+ this.attach(rawNode);
+ },
+ getBoundingBox: function(){
+ if(!this.bbox && this.shape.point.length){
+ var p = this.shape.points;
+ var l = p.length;
+ var bbox = {l: p.x, t: p.y, r: p.x, b: p.y};
+ for(var i = 1; i < l; ++i){
+ if(bbox.l > p.x) bbox.l = p.x;
+ if(bbox.r < p.x) bbox.r = p.x;
+ if(bbox.t > p.y) bbox.t = p.y;
+ if(bbox.b < p.y) bbox.b = p.y;
+ }
+ this.bbox = {
+ x: bbox.l,
+ y: bbox.t,
+ width: bbox.r - bbox.l,
+ height: bbox.b - bbox.t
+ };
+ }
+ return this.bbox;
+ }
+});
+
+dojo.declare("dojo.gfx.shape.Image", dojo.gfx.Shape, {
+ initializer: function(rawNode) {
+ this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultImage, true);
+ this.attach(rawNode);
+ },
+ getBoundingBox: function(){
+ if(!this.bbox){
+ var shape = this.shape;
+ this.bbox = {
+ x: 0,
+ y: 0,
+ width: shape.width,
+ height: shape.height
+ };
+ }
+ return this.bbox;
+ }
+});
Propchange: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/gfx/shape.js
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/gfx/svg.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/gfx/svg.js?view=diff&rev=453979&r1=453978&r2=453979
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/gfx/svg.js (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/src/gfx/svg.js Sat Oct 7 11:22:33 2006
@@ -15,6 +15,8 @@
dojo.require("dojo.gfx.color");
dojo.require("dojo.gfx.common");
+dojo.require("dojo.gfx.shape");
+dojo.require("dojo.gfx.path");
dojo.require("dojo.experimental");
dojo.experimental("dojo.gfx.svg");
@@ -320,13 +322,10 @@
});
dojo.gfx.Group.nodeType = "g";
-dojo.declare("dojo.gfx.Rect", dojo.gfx.Shape, {
- initializer: function(rawNode) {
- this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultRect, true);
- this.attach(rawNode);
- },
+dojo.declare("dojo.gfx.Rect", dojo.gfx.shape.Rect, {
setShape: function(newShape){
this.shape = dojo.gfx.makeParameters(this.shape, newShape);
+ this.bbox = null;
for(var i in this.shape){
if(i != "type" && i != "r"){ this.rawNode.setAttribute(i, this.shape[i]); }
}
@@ -345,35 +344,16 @@
});
dojo.gfx.Rect.nodeType = "rect";
-dojo.declare("dojo.gfx.Ellipse", dojo.gfx.Shape, {
- initializer: function(rawNode) {
- this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultEllipse, true);
- this.attach(rawNode);
- }
-});
+dojo.gfx.Ellipse = dojo.gfx.shape.Ellipse;
dojo.gfx.Ellipse.nodeType = "ellipse";
-dojo.declare("dojo.gfx.Circle", dojo.gfx.Shape, {
- initializer: function(rawNode) {
- this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultCircle, true);
- this.attach(rawNode);
- }
-});
+dojo.gfx.Circle = dojo.gfx.shape.Circle;
dojo.gfx.Circle.nodeType = "circle";
-dojo.declare("dojo.gfx.Line", dojo.gfx.Shape, {
- initializer: function(rawNode) {
- this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultLine, true);
- this.attach(rawNode);
- }
-});
+dojo.gfx.Line = dojo.gfx.shape.Line;
dojo.gfx.Line.nodeType = "line";
-dojo.declare("dojo.gfx.Polyline", dojo.gfx.Shape, {
- initializer: function(rawNode) {
- this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultPolyline, true);
- this.attach(rawNode);
- },
+dojo.declare("dojo.gfx.Polyline", dojo.gfx.shape.Polyline, {
setShape: function(points){
if(points && points instanceof Array){
this.shape = dojo.gfx.makeParameters(this.shape, { points: points });
@@ -383,16 +363,20 @@
}else{
this.shape = dojo.gfx.makeParameters(this.shape, points);
}
- var attr = "";
- for(var i = 0; i< this.shape.points.length; ++i){
- attr += this.shape.points[i].x.toFixed(8) + " " + this.shape.points[i].y.toFixed(8) + " ";
+ this.box = null;
+ var attr = [];
+ var p = this.shape.points;
+ for(var i = 0; i < p.length; ++i){
+ attr.push(p[i].x.toFixed(8));
+ attr.push(p[i].y.toFixed(8));
}
- this.rawNode.setAttribute("points", attr);
+ this.rawNode.setAttribute("points", attr.join(" "));
return this;
}
});
dojo.gfx.Polyline.nodeType = "polyline";
+/*
dojo.lang.extend(dojo.gfx.Path, {
_extraDrawTo: function(action){
this.rawNode.setAttribute("d", this.shape.path);
@@ -455,18 +439,17 @@
}
});
dojo.gfx.Path.nodeType = "path";
+*/
-dojo.declare("dojo.gfx.Image", dojo.gfx.Shape, {
- initializer: function(rawNode) {
- this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultImage, true);
- this.attach(rawNode);
- },
+dojo.declare("dojo.gfx.Image", dojo.gfx.shape.Image, {
setShape: function(newShape){
this.shape = dojo.gfx.makeParameters(this.shape, newShape);
+ this.bbox = null;
+ var rawNode = this.rawNode;
for(var i in this.shape){
- if(i != "type" && i != "src"){ this.rawNode.setAttribute(i, this.shape[i]); }
+ if(i != "type" && i != "src"){ rawNode.setAttribute(i, this.shape[i]); }
}
- this.rawNode.setAttributeNS(dojo.svg.xmlns.xlink, "href", this.shape.src);
+ rawNode.setAttributeNS(dojo.svg.xmlns.xlink, "href", this.shape.src);
return this;
},
setStroke: function() { return this; },
@@ -475,6 +458,28 @@
attachFill: function(rawNode){ return null; }
});
dojo.gfx.Image.nodeType = "image";
+
+dojo.declare("dojo.gfx.Path", dojo.gfx.path.Path, {
+ initializer: function(rawNode){
+ this.inherited("initializer", [rawNode]);
+ // override inherited methods
+ var _this = this;
+ var old_updateWithSegment = this._updateWithSegment;
+ this._updateWithSegment = function(segment){
+ old_updateWithSegment.call(_this, segment);
+ if(typeof(_this.shape.path) == "string"){
+ _this.rawNode.setAttribute("d", _this.shape.path);
+ }
+ };
+ var oldSetShape = this.setShape;
+ this.setShape = function(newShape){
+ oldSetShape.call(_this, newShape);
+ _this.rawNode.setAttribute("d", _this.shape.path);
+ return _this;
+ };
+ }
+});
+dojo.gfx.Path.nodeType = "path";
dojo.gfx._creators = {
// creators