You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by jk...@apache.org on 2006/03/11 22:19:18 UTC
svn commit: r385171 [8/24] - in
/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo:
./ src/ src/animation/ src/collections/ src/crypto/ src/data/ src/dnd/
src/event/ src/flash/ src/flash/flash6/ src/flash/flash8/ src/fx/
src/graph...
Added: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/graphics/Colorspace.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/graphics/Colorspace.js?rev=385171&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/graphics/Colorspace.js (added)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/graphics/Colorspace.js Sat Mar 11 13:18:41 2006
@@ -0,0 +1,944 @@
+/*
+ Copyright (c) 2004-2005, 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.graphics.Colorspace");
+
+dojo.require("dojo.lang");
+dojo.require("dojo.math.matrix");
+
+//
+// to convert to YUV:
+// c.whitePoint = 'D65';
+// c.RGBWorkingSpace = 'pal_secam_rgb';
+// var out = c.convert([r,g,b], 'RGB', 'XYZ');
+//
+// to convert to YIQ:
+// c.whitePoint = 'D65';
+// c.RGBWorkingSpace = 'ntsc_rgb';
+// var out = c.convert([r,g,b], 'RGB', 'XYZ');
+//
+
+dojo.graphics.Colorspace =function(){
+
+ this.whitePoint = 'D65';
+ this.stdObserver = '10';
+ this.chromaticAdaptationAlg = 'bradford';
+ this.RGBWorkingSpace = 's_rgb';
+ this.useApproxCIELabMapping = 1; // see http://www.brucelindbloom.com/LContinuity.html
+
+ this.chainMaps = {
+ 'RGB_to_xyY' : ['XYZ'],
+ 'xyY_to_RGB' : ['XYZ'],
+ 'RGB_to_Lab' : ['XYZ'],
+ 'Lab_to_RGB' : ['XYZ'],
+ 'RGB_to_LCHab': ['XYZ', 'Lab'],
+ 'LCHab_to_RGB': ['Lab'],
+ 'xyY_to_Lab' : ['XYZ'],
+ 'Lab_to_xyY' : ['XYZ'],
+ 'XYZ_to_LCHab': ['Lab'],
+ 'LCHab_to_XYZ': ['Lab'],
+ 'xyY_to_LCHab': ['XYZ', 'Lab'],
+ 'LCHab_to_xyY': ['Lab', 'XYZ'],
+ 'RGB_to_Luv' : ['XYZ'],
+ 'Luv_to_RGB' : ['XYZ'],
+ 'xyY_to_Luv' : ['XYZ'],
+ 'Luv_to_xyY' : ['XYZ'],
+ 'Lab_to_Luv' : ['XYZ'],
+ 'Luv_to_Lab' : ['XYZ'],
+ 'LCHab_to_Luv': ['Lab', 'XYZ'],
+ 'Luv_to_LCHab': ['XYZ', 'Lab'],
+ 'RGB_to_LCHuv' : ['XYZ', 'Luv'],
+ 'LCHuv_to_RGB' : ['Luv', 'XYZ'],
+ 'XYZ_to_LCHuv' : ['Luv'],
+ 'LCHuv_to_XYZ' : ['Luv'],
+ 'xyY_to_LCHuv' : ['XYZ', 'Luv'],
+ 'LCHuv_to_xyY' : ['Luv', 'XYZ'],
+ 'Lab_to_LCHuv' : ['XYZ', 'Luv'],
+ 'LCHuv_to_Lab' : ['Luv', 'XYZ'],
+ 'LCHab_to_LCHuv': ['Lab', 'XYZ', 'Luv'],
+ 'LCHuv_to_LCHab': ['Luv', 'XYZ', 'Lab'],
+ 'XYZ_to_CMY' : ['RGB'],
+ 'CMY_to_XYZ' : ['RGB'],
+ 'xyY_to_CMY' : ['RGB'],
+ 'CMY_to_xyY' : ['RGB'],
+ 'Lab_to_CMY' : ['RGB'],
+ 'CMY_to_Lab' : ['RGB'],
+ 'LCHab_to_CMY' : ['RGB'],
+ 'CMY_to_LCHab' : ['RGB'],
+ 'Luv_to_CMY' : ['RGB'],
+ 'CMY_to_Luv' : ['RGB'],
+ 'LCHuv_to_CMY' : ['RGB'],
+ 'CMY_to_LCHuv' : ['RGB'],
+ 'XYZ_to_HSL' : ['RGB'],
+ 'HSL_to_XYZ' : ['RGB'],
+ 'xyY_to_HSL' : ['RGB'],
+ 'HSL_to_xyY' : ['RGB'],
+ 'Lab_to_HSL' : ['RGB'],
+ 'HSL_to_Lab' : ['RGB'],
+ 'LCHab_to_HSL' : ['RGB'],
+ 'HSL_to_LCHab' : ['RGB'],
+ 'Luv_to_HSL' : ['RGB'],
+ 'HSL_to_Luv' : ['RGB'],
+ 'LCHuv_to_HSL' : ['RGB'],
+ 'HSL_to_LCHuv' : ['RGB'],
+ 'CMY_to_HSL' : ['RGB'],
+ 'HSL_to_CMY' : ['RGB'],
+ 'CMYK_to_HSL' : ['RGB'],
+ 'HSL_to_CMYK' : ['RGB'],
+ 'XYZ_to_HSV' : ['RGB'],
+ 'HSV_to_XYZ' : ['RGB'],
+ 'xyY_to_HSV' : ['RGB'],
+ 'HSV_to_xyY' : ['RGB'],
+ 'Lab_to_HSV' : ['RGB'],
+ 'HSV_to_Lab' : ['RGB'],
+ 'LCHab_to_HSV' : ['RGB'],
+ 'HSV_to_LCHab' : ['RGB'],
+ 'Luv_to_HSV' : ['RGB'],
+ 'HSV_to_Luv' : ['RGB'],
+ 'LCHuv_to_HSV' : ['RGB'],
+ 'HSV_to_LCHuv' : ['RGB'],
+ 'CMY_to_HSV' : ['RGB'],
+ 'HSV_to_CMY' : ['RGB'],
+ 'CMYK_to_HSV' : ['RGB'],
+ 'HSV_to_CMYK' : ['RGB'],
+ 'HSL_to_HSV' : ['RGB'],
+ 'HSV_to_HSL' : ['RGB'],
+ 'XYZ_to_CMYK' : ['RGB'],
+ 'CMYK_to_XYZ' : ['RGB'],
+ 'xyY_to_CMYK' : ['RGB'],
+ 'CMYK_to_xyY' : ['RGB'],
+ 'Lab_to_CMYK' : ['RGB'],
+ 'CMYK_to_Lab' : ['RGB'],
+ 'LCHab_to_CMYK' : ['RGB'],
+ 'CMYK_to_LCHab' : ['RGB'],
+ 'Luv_to_CMYK' : ['RGB'],
+ 'CMYK_to_Luv' : ['RGB'],
+ 'LCHuv_to_CMYK' : ['RGB'],
+ 'CMYK_to_LCHuv' : ['RGB']
+ };
+
+
+ return this;
+}
+
+dojo.graphics.Colorspace.prototype.convert = function(col, model_from, model_to){
+
+ var k = model_from+'_to_'+model_to;
+
+ if (this[k]){
+ return this[k](col);
+ }else{
+ if (this.chainMaps[k]){
+
+ var cur = model_from;
+ var models = this.chainMaps[k].concat();
+ models.push(model_to);
+
+ for(var i=0; i<models.length; i++){
+
+ col = this.convert(col, cur, models[i]);
+ cur = models[i];
+ }
+
+ return col;
+
+ }else{
+
+ dojo.debug("Can't convert from "+model_from+' to '+model_to);
+ }
+ }
+}
+
+dojo.graphics.Colorspace.prototype.munge = function(keys, args){
+
+ if (dojo.lang.isArray(args[0])){
+ args = args[0];
+ }
+
+ var out = new Array();
+
+ for (var i=0; i<keys.length; i++){
+ out[keys.charAt(i)] = args[i];
+ }
+
+ return out;
+}
+
+dojo.graphics.Colorspace.prototype.getWhitePoint = function(){
+
+ var x = 0;
+ var y = 0;
+ var t = 0;
+
+ // ref: http://en.wikipedia.org/wiki/White_point
+ // TODO: i need some good/better white point values
+
+ switch(this.stdObserver){
+ case '2' :
+ switch(this.whitePoint){
+ case 'E' : x=1/3 ; y=1/3 ; t=5400; break; //Equal energy
+ case 'D50' : x=0.34567; y=0.35850; t=5000; break;
+ case 'D55' : x=0.33242; y=0.34743; t=5500; break;
+ case 'D65' : x=0.31271; y=0.32902; t=6500; break;
+ case 'D75' : x=0.29902; y=0.31485; t=7500; break;
+ case 'A' : x=0.44757; y=0.40745; t=2856; break; //Incandescent tungsten
+ case 'B' : x=0.34842; y=0.35161; t=4874; break;
+ case 'C' : x=0.31006; y=0.31616; t=6774; break;
+ case '9300': x=0.28480; y=0.29320; t=9300; break; //Blue phosphor monitors
+ case 'F2' : x=0.37207; y=0.37512; t=4200; break; //Cool White Fluorescent
+ case 'F7' : x=0.31285; y=0.32918; t=6500; break; //Narrow Band Daylight Fluorescent
+ case 'F11' : x=0.38054; y=0.37691; t=4000; break; //Narrow Band White Fluorescent
+ default: dojo.debug('White point '+this.whitePoint+" isn't defined for Std. Observer "+this.strObserver);
+ };
+ break;
+ case '10' :
+ switch(this.whitePoint){
+ case 'E' : x=1/3 ; y=1/3 ; t=5400; break; //Equal energy
+ case 'D50' : x=0.34773; y=0.35952; t=5000; break;
+ case 'D55' : x=0.33411; y=0.34877; t=5500; break;
+ case 'D65' : x=0.31382; y=0.33100; t=6500; break;
+ case 'D75' : x=0.29968; y=0.31740; t=7500; break;
+ case 'A' : x=0.45117; y=0.40594; t=2856; break; //Incandescent tungsten
+ case 'B' : x=0.3498 ; y=0.3527 ; t=4874; break;
+ case 'C' : x=0.31039; y=0.31905; t=6774; break;
+ case 'F2' : x=0.37928; y=0.36723; t=4200; break; //Cool White Fluorescent
+ case 'F7' : x=0.31565; y=0.32951; t=6500; break; //Narrow Band Daylight Fluorescent
+ case 'F11' : x=0.38543; y=0.37110; t=4000; break; //Narrow Band White Fluorescent
+ default: dojo.debug('White point '+this.whitePoint+" isn't defined for Std. Observer "+this.strObserver);
+ };
+ break;
+ default:
+ dojo.debug("Std. Observer "+this.strObserver+" isn't defined");
+ }
+
+ var z = 1 - x - y;
+
+ var wp = {'x':x, 'y':y, 'z':z, 't':t};
+
+ wp.Y = 1;
+
+ var XYZ = this.xyY_to_XYZ([wp.x, wp.y, wp.Y]);
+
+ wp.X = XYZ[0];
+ wp.Y = XYZ[1];
+ wp.Z = XYZ[2];
+
+ return wp
+}
+
+dojo.graphics.Colorspace.prototype.getPrimaries = function(){
+
+ // ref: http://www.fho-emden.de/~hoffmann/ciexyz29082000.pdf
+ // ref: http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
+
+ var m = [];
+
+ switch(this.RGBWorkingSpace){
+
+ case 'adobe_rgb_1998' : m = [2.2, 'D65', 0.6400, 0.3300, 0.297361, 0.2100, 0.7100, 0.627355, 0.1500, 0.0600, 0.075285]; break;
+ case 'apple_rgb' : m = [1.8, 'D65', 0.6250, 0.3400, 0.244634, 0.2800, 0.5950, 0.672034, 0.1550, 0.0700, 0.083332]; break;
+ case 'best_rgb' : m = [2.2, 'D50', 0.7347, 0.2653, 0.228457, 0.2150, 0.7750, 0.737352, 0.1300, 0.0350, 0.034191]; break;
+ case 'beta_rgb' : m = [2.2, 'D50', 0.6888, 0.3112, 0.303273, 0.1986, 0.7551, 0.663786, 0.1265, 0.0352, 0.032941]; break;
+ case 'bruce_rgb' : m = [2.2, 'D65', 0.6400, 0.3300, 0.240995, 0.2800, 0.6500, 0.683554, 0.1500, 0.0600, 0.075452]; break;
+ case 'cie_rgb' : m = [2.2, 'E' , 0.7350, 0.2650, 0.176204, 0.2740, 0.7170, 0.812985, 0.1670, 0.0090, 0.010811]; break;
+ case 'color_match_rgb' : m = [1.8, 'D50', 0.6300, 0.3400, 0.274884, 0.2950, 0.6050, 0.658132, 0.1500, 0.0750, 0.066985]; break;
+ case 'don_rgb_4' : m = [2.2, 'D50', 0.6960, 0.3000, 0.278350, 0.2150, 0.7650, 0.687970, 0.1300, 0.0350, 0.033680]; break;
+ case 'eci_rgb' : m = [1.8, 'D50', 0.6700, 0.3300, 0.320250, 0.2100, 0.7100, 0.602071, 0.1400, 0.0800, 0.077679]; break;
+ case 'ekta_space_ps5' : m = [2.2, 'D50', 0.6950, 0.3050, 0.260629, 0.2600, 0.7000, 0.734946, 0.1100, 0.0050, 0.004425]; break;
+ case 'ntsc_rgb' : m = [2.2, 'C' , 0.6700, 0.3300, 0.298839, 0.2100, 0.7100, 0.586811, 0.1400, 0.0800, 0.114350]; break;
+ case 'pal_secam_rgb' : m = [2.2, 'D65', 0.6400, 0.3300, 0.222021, 0.2900, 0.6000, 0.706645, 0.1500, 0.0600, 0.071334]; break;
+ case 'pro_photo_rgb' : m = [1.8, 'D50', 0.7347, 0.2653, 0.288040, 0.1596, 0.8404, 0.711874, 0.0366, 0.0001, 0.000086]; break;
+ case 'smpte-c_rgb' : m = [2.2, 'D65', 0.6300, 0.3400, 0.212395, 0.3100, 0.5950, 0.701049, 0.1550, 0.0700, 0.086556]; break;
+ case 's_rgb' : m = [2.2, 'D65', 0.6400, 0.3300, 0.212656, 0.3000, 0.6000, 0.715158, 0.1500, 0.0600, 0.072186]; break;
+ case 'wide_gamut_rgb' : m = [2.2, 'D50', 0.7350, 0.2650, 0.258187, 0.1150, 0.8260, 0.724938, 0.1570, 0.0180, 0.016875]; break;
+
+ default: dojo.debug("RGB working space "+this.RGBWorkingSpace+" isn't defined");
+ }
+
+ var p = {};
+
+ p.name = this.RGBWorkingSpace;
+ p.gamma = m[0];
+ p.wp = m[1];
+
+ p.xr = m[2];
+ p.yr = m[3];
+ p.Yr = m[4];
+
+ p.xg = m[5];
+ p.yg = m[6];
+ p.Yg = m[7];
+
+ p.xb = m[8];
+ p.yb = m[9];
+ p.Yb = m[10];
+
+ // if WP doesn't match current WP, convert the primaries over
+
+ if (p.wp != this.whitePoint){
+
+ var r = this.XYZ_to_xyY( this.chromaticAdaptation( this.xyY_to_XYZ([p.xr, p.yr, p.Yr]), p.wp, this.whitePoint ) );
+ var g = this.XYZ_to_xyY( this.chromaticAdaptation( this.xyY_to_XYZ([p.xg, p.yg, p.Yg]), p.wp, this.whitePoint ) );
+ var b = this.XYZ_to_xyY( this.chromaticAdaptation( this.xyY_to_XYZ([p.xb, p.yb, p.Yb]), p.wp, this.whitePoint ) );
+
+ p.xr = r[0];
+ p.yr = r[1];
+ p.Yr = r[2];
+
+ p.xg = g[0];
+ p.yg = g[1];
+ p.Yg = g[2];
+
+ p.xb = b[0];
+ p.yb = b[1];
+ p.Yb = b[2];
+
+ p.wp = this.whitePoint;
+ }
+
+ p.zr = 1 - p.xr - p.yr;
+ p.zg = 1 - p.xg - p.yg;
+ p.zb = 1 - p.xb - p.yb;
+
+ return p;
+}
+
+dojo.graphics.Colorspace.prototype.epsilon = function(){
+
+ return this.useApproxCIELabMapping ? 0.008856 : 216 / 24289;
+}
+
+dojo.graphics.Colorspace.prototype.kappa = function(){
+
+ return this.useApproxCIELabMapping ? 903.3 : 24389 / 27;
+}
+
+dojo.graphics.Colorspace.prototype.XYZ_to_xyY = function(){
+ var src = this.munge('XYZ', arguments);
+
+ var sum = src.X + src.Y + src.Z;
+
+ if (sum == 0){
+
+ var wp = this.getWhitePoint();
+ var x = wp.x;
+ var y = wp.y;
+ }else{
+ var x = src.X / sum;
+ var y = src.Y / sum;
+ }
+
+ var Y = src.Y;
+
+
+ return [x, y, Y];
+}
+
+dojo.graphics.Colorspace.prototype.xyY_to_XYZ = function(){
+ var src = this.munge('xyY', arguments);
+
+ if (src.y == 0){
+
+ var X = 0;
+ var Y = 0;
+ var Z = 0;
+ }else{
+ var X = (src.x * src.Y) / src.y;
+ var Y = src.Y;
+ var Z = ((1 - src.x - src.y) * src.Y) / src.y;
+ }
+
+ return [X, Y, Z];
+}
+
+dojo.graphics.Colorspace.prototype.RGB_to_XYZ = function(){
+ var src = this.munge('RGB', arguments);
+
+ var m = this.getRGB_XYZ_Matrix();
+ var pr = this.getPrimaries();
+
+ if (this.RGBWorkingSpace == 's_rgb'){
+
+ var r = (src.R > 0.04045) ? Math.pow(((src.R + 0.055) / 1.055), 2.4) : src.R / 12.92;
+ var g = (src.G > 0.04045) ? Math.pow(((src.G + 0.055) / 1.055), 2.4) : src.G / 12.92;
+ var b = (src.B > 0.04045) ? Math.pow(((src.B + 0.055) / 1.055), 2.4) : src.B / 12.92;
+
+ }else{
+
+ var r = Math.pow(src.R, pr.gamma);
+ var g = Math.pow(src.G, pr.gamma);
+ var b = Math.pow(src.B, pr.gamma);
+ }
+
+ var XYZ = dojo.math.matrix.multiply([[r, g, b]], m);
+
+ return [XYZ[0][0], XYZ[0][1], XYZ[0][2]];
+}
+
+dojo.graphics.Colorspace.prototype.XYZ_to_RGB = function(){
+ var src = this.munge('XYZ', arguments);
+
+ var mi = this.getXYZ_RGB_Matrix();
+ var pr = this.getPrimaries();
+
+ var rgb = dojo.math.matrix.multiply([[src.X, src.Y, src.Z]], mi);
+ var r = rgb[0][0];
+ var g = rgb[0][1];
+ var b = rgb[0][2];
+
+ if (this.RGBWorkingSpace == 's_rgb'){
+
+ var R = (r > 0.0031308) ? (1.055 * Math.pow(r, 1.0/2.4)) - 0.055 : 12.92 * r;
+ var G = (g > 0.0031308) ? (1.055 * Math.pow(g, 1.0/2.4)) - 0.055 : 12.92 * g;
+ var B = (b > 0.0031308) ? (1.055 * Math.pow(b, 1.0/2.4)) - 0.055 : 12.92 * b;
+ }else{
+ var R = Math.pow(r, 1/pr.gamma);
+ var G = Math.pow(g, 1/pr.gamma);
+ var B = Math.pow(b, 1/pr.gamma);
+ }
+
+ return [R, G, B];
+}
+
+dojo.graphics.Colorspace.prototype.XYZ_to_Lab = function(){
+ var src = this.munge('XYZ', arguments);
+
+ var wp = this.getWhitePoint();
+
+ var xr = src.X / wp.X;
+ var yr = src.Y / wp.Y;
+ var zr = src.Z / wp.Z;
+
+ var fx = (xr > this.epsilon()) ? Math.pow(xr, 1/3) : (this.kappa() * xr + 16) / 116;
+ var fy = (yr > this.epsilon()) ? Math.pow(yr, 1/3) : (this.kappa() * yr + 16) / 116;
+ var fz = (zr > this.epsilon()) ? Math.pow(zr, 1/3) : (this.kappa() * zr + 16) / 116;
+
+ var L = 116 * fy - 16;
+ var a = 500 * (fx - fy);
+ var b = 200 * (fy - fz);
+
+ return [L, a, b];
+}
+
+dojo.graphics.Colorspace.prototype.Lab_to_XYZ = function(){
+ var src = this.munge('Lab', arguments);
+
+ var wp = this.getWhitePoint();
+
+ var yr = (src.L > (this.kappa() * this.epsilon())) ? Math.pow((src.L + 16) / 116, 3) : src.L / this.kappa();
+
+ var fy = (yr > this.epsilon()) ? (src.L + 16) / 116 : (this.kappa() * yr + 16) / 116;
+
+ var fx = (src.a / 500) + fy;
+ var fz = fy - (src.b / 200);
+
+ var fxcube = Math.pow(fx, 3);
+ var fzcube = Math.pow(fz, 3);
+
+ var xr = (fxcube > this.epsilon()) ? fxcube : (116 * fx - 16) / this.kappa();
+ var zr = (fzcube > this.epsilon()) ? fzcube : (116 * fz - 16) / this.kappa();
+
+ var X = xr * wp.X;
+ var Y = yr * wp.Y;
+ var Z = zr * wp.Z;
+
+ return [X, Y, Z];
+}
+
+dojo.graphics.Colorspace.prototype.Lab_to_LCHab = function(){
+ var src = this.munge('Lab', arguments);
+
+ var L = src.L;
+ var C = Math.pow(src.a * src.a + src.b * src.b, 0.5);
+ var H = Math.atan2(src.b, src.a) * (180 / Math.PI);
+
+ if (H < 0){ H += 360; }
+ if (H > 360){ H -= 360; }
+
+ return [L, C, H];
+}
+
+dojo.graphics.Colorspace.prototype.LCHab_to_Lab = function(){
+ var src = this.munge('LCH', arguments);
+
+ var H_rad = src.H * (Math.PI / 180);
+
+ var L = src.L;
+
+ var a = src.C / Math.pow(Math.pow(Math.tan(H_rad), 2) + 1, 0.5);
+ if ((90 < src.H) && (src.H < 270)){ a= -a; }
+
+ var b = Math.pow(Math.pow(src.C, 2) - Math.pow(a, 2), 0.5);
+ if (src.H > 180){ b = -b; }
+
+ return [L, a, b];
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////
+//
+// this function converts an XYZ color array (col) from one whitepoint (src_w) to another (dst_w)
+//
+
+dojo.graphics.Colorspace.prototype.chromaticAdaptation = function(col, src_w, dst_w){
+
+ col = this.munge('XYZ', [col]);
+
+ //
+ // gather white point data for the source and dest
+ //
+
+ var old_wp = this.whitePoint;
+
+ this.whitePoint = src_w;
+ var wp_src = this.getWhitePoint();
+
+ this.whitePoint = dst_w;
+ var wp_dst = this.getWhitePoint();
+
+ this.whitePoint = old_wp;
+
+
+ //
+ // get a transformation matricies
+ //
+
+ switch(this.chromaticAdaptationAlg){
+ case 'xyz_scaling':
+ var ma = [[1,0,0],[0,1,0],[0,0,1]];
+ var mai = [[1,0,0],[0,1,0],[0,0,1]];
+ break;
+ case 'bradford':
+ var ma = [[0.8951, -0.7502, 0.0389],[0.2664, 1.7135, -0.0685],[-0.1614, 0.0367, 1.0296]];
+ var mai = [[0.986993, 0.432305, -0.008529],[-0.147054, 0.518360, 0.040043],[0.159963, 0.049291, 0.968487]];
+ break;
+ case 'von_kries':
+ var ma = [[0.40024, -0.22630, 0.00000],[0.70760, 1.16532, 0.00000],[-0.08081, 0.04570, 0.91822]]
+ var mai = [[1.859936, 0.361191, 0.000000],[-1.129382, 0.638812, 0.000000],[0.219897, -0.000006, 1.089064]]
+ break;
+ default:
+ dojo.debug("The "+this.chromaticAdaptationAlg+" chromatic adaptation algorithm matricies are not defined");
+ }
+
+
+ //
+ // calculate the cone response domains
+ //
+
+ var domain_src = dojo.math.matrix.multiply( [[wp_src.x, wp_src.y, wp_src.z]], ma);
+ var domain_dst = dojo.math.matrix.multiply( [[wp_dst.x, wp_dst.y, wp_dst.z]], ma);
+
+
+ //
+ // construct the centre matrix
+ //
+
+ var centre = [
+ [domain_dst[0][0]/domain_src[0][0], 0, 0],
+ [0, domain_dst[0][1]/domain_src[0][1], 0],
+ [0, 0, domain_dst[0][2]/domain_src[0][2]]
+ ];
+
+
+ //
+ // caclulate 'm'
+ //
+
+ var m = dojo.math.matrix.multiply( dojo.math.matrix.multiply( ma, centre ), mai );
+
+
+ //
+ // construct source color matrix
+ //
+
+ var dst = dojo.math.matrix.multiply( [[ col.X, col.Y, col.Z ]], m );
+
+ return dst[0];
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////
+
+dojo.graphics.Colorspace.prototype.getRGB_XYZ_Matrix = function(){
+
+ var wp = this.getWhitePoint();
+ var pr = this.getPrimaries();
+
+ var Xr = pr.xr / pr.yr;
+ var Yr = 1;
+ var Zr = (1 - pr.xr - pr.yr) / pr.yr;
+
+ var Xg = pr.xg / pr.yg;
+ var Yg = 1;
+ var Zg = (1 - pr.xg - pr.yg) / pr.yg;
+
+ var Xb = pr.xb / pr.yb;
+ var Yb = 1;
+ var Zb = (1 - pr.xb - pr.yb) / pr.yb;
+
+ var m1 = [[Xr, Yr, Zr],[Xg, Yg, Zg],[Xb, Yb, Zb]];
+ var m2 = [[wp.X, wp.Y, wp.Z]];
+ var sm = dojo.math.matrix.multiply(m2, dojo.math.matrix.inverse(m1));
+
+ var Sr = sm[0][0];
+ var Sg = sm[0][1];
+ var Sb = sm[0][2];
+
+ var m4 = [[Sr*Xr, Sr*Yr, Sr*Zr],
+ [Sg*Xg, Sg*Yg, Sg*Zg],
+ [Sb*Xb, Sb*Yb, Sb*Zb]];
+
+ return m4;
+}
+
+dojo.graphics.Colorspace.prototype.getXYZ_RGB_Matrix = function(){
+
+ var m = this.getRGB_XYZ_Matrix();
+
+ return dojo.math.matrix.inverse(m);
+}
+
+dojo.graphics.Colorspace.prototype.XYZ_to_Luv = function(){
+
+ var src = this.munge('XYZ', arguments);
+
+ var wp = this.getWhitePoint();
+
+ var ud = (4 * src.X) / (src.X + 15 * src.Y + 3 * src.Z);
+ var vd = (9 * src.Y) / (src.X + 15 * src.Y + 3 * src.Z);
+
+ var udr = (4 * wp.X) / (wp.X + 15 * wp.Y + 3 * wp.Z);
+ var vdr = (9 * wp.Y) / (wp.X + 15 * wp.Y + 3 * wp.Z);
+
+ var yr = src.Y / wp.Y;
+
+ var L = (yr > this.epsilon()) ? 116 * Math.pow(yr, 1/3) - 16 : this.kappa() * yr;
+ var u = 13 * L * (ud-udr);
+ var v = 13 * L * (vd-vdr);
+
+ return [L, u, v];
+}
+
+dojo.graphics.Colorspace.prototype.Luv_to_XYZ = function(){
+
+ var src = this.munge('Luv', arguments);
+
+ var wp = this.getWhitePoint();
+
+ var uz = (4 * wp.X) / (wp.X + 15 * wp.Y + 3 * wp.Z);
+ var vz = (9 * wp.Y) / (wp.X + 15 * wp.Y + 3 * wp.Z);
+
+ var Y = (src.L > this.kappa() * this.epsilon()) ? Math.pow((src.L + 16) / 116, 3) : src.L / this.kappa();
+
+ var a = (1 / 3) * (((52 * src.L) / (src.u + 13 * src.L * uz)) - 1);
+ var b = -5 * Y;
+ var c = - (1 / 3);
+ var d = Y * (((39 * src.L) / (src.v + 13 * src.L * vz)) - 5);
+
+ var X = (d - b) / (a - c);
+ var Z = X * a + b;
+
+ return [X, Y, Z];
+}
+
+dojo.graphics.Colorspace.prototype.Luv_to_LCHuv = function(){
+
+ var src = this.munge('Luv', arguments);
+
+ var L = src.L;
+ var C = Math.pow(src.u * src.u + src.v * src.v, 0.5);
+ var H = Math.atan2(src.v, src.u) * (180 / Math.PI);
+
+ if (H < 0){ H += 360; }
+ if (H > 360){ H -= 360; }
+
+ return [L, C, H];
+}
+
+dojo.graphics.Colorspace.prototype.LCHuv_to_Luv = function(){
+
+ var src = this.munge('LCH', arguments);
+
+ var H_rad = src.H * (Math.PI / 180);
+
+ var L = src.L;
+ var u = src.C / Math.pow(Math.pow(Math.tan(H_rad), 2) + 1, 0.5);
+ var v = Math.pow(src.C * src.C - u * u, 0.5);
+
+ if ((90 < src.H) && (src.H < 270)){ u *= -1; }
+ if (src.H > 180){ v *= -1; }
+
+ return [L, u, v];
+}
+
+dojo.graphics.Colorspace.colorTemp_to_whitePoint = function(T){
+
+ if (T < 4000){
+ dojo.debug("Can't find a white point for temperatures under 4000K");
+ return [0,0];
+ }
+
+ if (T > 25000){
+ dojo.debug("Can't find a white point for temperatures over 25000K");
+ return [0,0];
+ }
+
+ var T1 = T;
+ var T2 = T * T;
+ var T3 = T2 * T;
+
+ var ten9 = Math.pow(10, 9);
+ var ten6 = Math.pow(10, 6);
+ var ten3 = Math.pow(10, 3);
+
+ if (T <= 7000){
+
+ var x = (-4.6070 * ten9 / T3) + (2.9678 * ten6 / T2) + (0.09911 * ten3 / T) + 0.244063;
+ }else{
+ var x = (-2.0064 * ten9 / T3) + (1.9018 * ten6 / T2) + (0.24748 * ten3 / T) + 0.237040;
+ }
+
+ var y = -3.000 * x * x + 2.870 * x - 0.275;
+
+ return [x, y];
+}
+
+dojo.graphics.Colorspace.prototype.RGB_to_CMY = function(){
+
+ var src = this.munge('RGB', arguments);
+
+ var C = 1 - src.R;
+ var M = 1 - src.G;
+ var Y = 1 - src.B;
+
+ return [C, M, Y];
+}
+
+dojo.graphics.Colorspace.prototype.CMY_to_RGB = function(){
+
+ var src = this.munge('CMY', arguments);
+
+ var R = 1 - src.C;
+ var G = 1 - src.M;
+ var B = 1 - src.Y;
+
+ return [R, G, B];
+}
+
+dojo.graphics.Colorspace.prototype.RGB_to_CMYK = function(){
+
+ var src = this.munge('RGB', arguments);
+
+ var K = Math.min(1-src.R, 1-src.G, 1-src.B);
+ var C = (1 - src.R - K) / (1 - K);
+ var M = (1 - src.G - K) / (1 - K);
+ var Y = (1 - src.B - K) / (1 - K);
+
+ return [C, M, Y, K];
+}
+
+dojo.graphics.Colorspace.prototype.CMYK_to_RGB = function(){
+
+ var src = this.munge('CMYK', arguments);
+
+ var R = 1 - Math.min(1, src.C * (1-src.K) + src.K);
+ var G = 1 - Math.min(1, src.M * (1-src.K) + src.K);
+ var B = 1 - Math.min(1, src.Y * (1-src.K) + src.K);
+
+ return [R, G, B];
+}
+
+dojo.graphics.Colorspace.prototype.CMY_to_CMYK = function(){
+
+ var src = this.munge('CMY', arguments);
+
+ var K = Math.min(src.C, src.M, src.Y);
+ var C = (src.C - K) / (1 - K);
+ var M = (src.M - K) / (1 - K);
+ var Y = (src.Y - K) / (1 - K);
+
+ return [C, M, Y, K];
+}
+
+dojo.graphics.Colorspace.prototype.CMYK_to_CMY = function(){
+
+ var src = this.munge('CMYK', arguments);
+
+ var C = Math.min(1, src.C * (1-src.K) + src.K);
+ var M = Math.min(1, src.M * (1-src.K) + src.K);
+ var Y = Math.min(1, src.Y * (1-src.K) + src.K);
+
+ return [C, M, Y];
+}
+
+dojo.graphics.Colorspace.prototype.RGB_to_HSV = function(){
+
+ var src = this.munge('RGB', arguments);
+
+ // Based on C Code in "Computer Graphics -- Principles and Practice,"
+ // Foley et al, 1996, p. 592.
+
+ var min = Math.min(src.R, src.G, src.B);
+ var V = Math.max(src.R, src.G, src.B);
+
+ var delta = V - min;
+
+ var H = null;
+ var S = (V == 0) ? 0 : delta / V;
+
+ if (S == 0){
+ H = 0;
+ }else{
+ if (src.R == V){
+ H = 60 * (src.G - src.B) / delta;
+ }else{
+ if (src.G == V){
+ H = 120 + 60 * (src.B - src.R) / delta;
+ }else{
+ if (src.B == V){
+ // between magenta and cyan
+ H = 240 + 60 * (src.R - src.G) / delta;
+ }
+ }
+ }
+ if (H < 0){
+ H += 360;
+ }
+ }
+
+ H = (H == 0) ? 360 : H;
+
+ return [H, S, V];
+}
+
+dojo.graphics.Colorspace.prototype.HSV_to_RGB = function(){
+
+ var src = this.munge('HSV', arguments);
+
+ if (src.H == 360){ src.H = 0;}
+
+ // Based on C Code in "Computer Graphics -- Principles and Practice,"
+ // Foley et al, 1996, p. 593.
+
+ var r = null;
+ var g = null;
+ var b = null;
+
+ if (src.S == 0){
+ // color is on black-and-white center line
+ // achromatic: shades of gray
+ R = src.V;
+ G = src.V;
+ B = src.V;
+ }else{
+ // chromatic color
+ var hTemp = src.H / 60; // h is now IN [0,6]
+ var i = Math.floor(hTemp); // largest integer <= h
+ var f = hTemp - i; // fractional part of h
+
+ var p = src.V * (1 - src.S);
+ var q = src.V * (1 - (src.S * f));
+ var t = src.V * (1 - (src.S * (1 - f)));
+
+ switch(i){
+ case 0: R = src.V; G = t ; B = p ; break;
+ case 1: R = q ; G = src.V; B = p ; break;
+ case 2: R = p ; G = src.V; B = t ; break;
+ case 3: R = p ; G = q ; B = src.V; break;
+ case 4: R = t ; G = p ; B = src.V; break;
+ case 5: R = src.V; G = p ; B = q ; break;
+ }
+ }
+
+ return [R, G, B];
+}
+
+dojo.graphics.Colorspace.prototype.RGB_to_HSL = function(){
+
+ var src = this.munge('RGB', arguments);
+
+ //
+ // based on C code from http://astronomy.swin.edu.au/~pbourke/colour/hsl/
+ //
+
+
+ var min = Math.min(src.R, src.G, src.B);
+ var max = Math.max(src.R, src.G, src.B);
+ var delta = max - min;
+
+ var H = 0;
+ var S = 0;
+ var L = (min + max) / 2;
+
+ if ((L > 0) && (L < 1)){
+ S = delta / ((L < 0.5) ? (2 * L) : (2 - 2 * L));
+ }
+
+ if (delta > 0) {
+ if ((max == src.R) && (max != src.G)){
+ H += (src.G - src.B) / delta;
+ }
+ if ((max == src.G) && (max != src.B)){
+ H += (2 + (src.B - src.R) / delta);
+ }
+ if ((max == src.B) && (max != src.R)){
+ H += (4 + (src.R - src.G) / delta);
+ }
+ H *= 60;
+ }
+
+ H = (H == 0) ? 360 : H;
+
+ return [H, S, L];
+}
+
+dojo.graphics.Colorspace.prototype.HSL_to_RGB = function(){
+
+ var src = this.munge('HSL', arguments);
+
+ //
+ // based on C code from http://astronomy.swin.edu.au/~pbourke/colour/hsl/
+ //
+
+ while (src.H < 0){ src.H += 360; }
+ while (src.H >= 360){ src.H -= 360; }
+
+ var R = 0;
+ var G = 0;
+ var B = 0;
+
+ if (src.H < 120){
+ R = (120 - src.H) / 60;
+ G = src.H / 60;
+ B = 0;
+ }else if (src.H < 240){
+ R = 0;
+ G = (240 - src.H) / 60;
+ B = (src.H - 120) / 60;
+ }else{
+ R = (src.H - 240) / 60;
+ G = 0;
+ B = (360 - src.H) / 60;
+ }
+
+ R = 2 * src.S * Math.min(R, 1) + (1 - src.S);
+ G = 2 * src.S * Math.min(G, 1) + (1 - src.S);
+ B = 2 * src.S * Math.min(B, 1) + (1 - src.S);
+
+ if (src.L < 0.5){
+ R = src.L * R;
+ G = src.L * G;
+ B = src.L * B;
+ }else{
+ R = (1 - src.L) * R + 2 * src.L - 1;
+ G = (1 - src.L) * G + 2 * src.L - 1;
+ B = (1 - src.L) * B + 2 * src.L - 1;
+ }
+
+ return [R, G, B];
+}
Added: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/graphics/__package__.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/graphics/__package__.js?rev=385171&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/graphics/__package__.js (added)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/graphics/__package__.js Sat Mar 11 13:18:41 2006
@@ -0,0 +1,15 @@
+/*
+ Copyright (c) 2004-2005, 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.hostenv.conditionalLoadModule({
+ browser: ["dojo.graphics.htmlEffects"],
+ dashboard: ["dojo.graphics.htmlEffects"]
+});
+dojo.hostenv.moduleLoaded("dojo.graphics.*");
Added: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/graphics/color.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/graphics/color.js?rev=385171&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/graphics/color.js (added)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/graphics/color.js Sat Mar 11 13:18:41 2006
@@ -0,0 +1,420 @@
+/*
+ Copyright (c) 2004-2005, 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.graphics.color");
+dojo.require("dojo.lang.array");
+
+// TODO: rewrite the "x2y" methods to take advantage of the parsing
+// abilities of the Color object. Also, beef up the Color
+// object (as possible) to parse most common formats
+
+// takes an r, g, b, a(lpha) value, [r, g, b, a] array, "rgb(...)" string, hex string (#aaa, #aaaaaa, aaaaaaa)
+dojo.graphics.color.Color = function(r, g, b, a) {
+ // dojo.debug("r:", r[0], "g:", r[1], "b:", r[2]);
+ if(dojo.lang.isArray(r)) {
+ this.r = r[0];
+ this.g = r[1];
+ this.b = r[2];
+ this.a = r[3]||1.0;
+ } else if(dojo.lang.isString(r)) {
+ var rgb = dojo.graphics.color.extractRGB(r);
+ this.r = rgb[0];
+ this.g = rgb[1];
+ this.b = rgb[2];
+ this.a = g||1.0;
+ } else if(r instanceof dojo.graphics.color.Color) {
+ this.r = r.r;
+ this.b = r.b;
+ this.g = r.g;
+ this.a = r.a;
+ } else {
+ this.r = r;
+ this.g = g;
+ this.b = b;
+ this.a = a;
+ }
+}
+
+dojo.graphics.color.Color.fromArray = function(arr) {
+ return new dojo.graphics.color.Color(arr[0], arr[1], arr[2], arr[3]);
+}
+
+dojo.lang.extend(dojo.graphics.color.Color, {
+ toRgb: function(includeAlpha) {
+ if(includeAlpha) {
+ return this.toRgba();
+ } else {
+ return [this.r, this.g, this.b];
+ }
+ },
+
+ toRgba: function() {
+ return [this.r, this.g, this.b, this.a];
+ },
+
+ toHex: function() {
+ return dojo.graphics.color.rgb2hex(this.toRgb());
+ },
+
+ toCss: function() {
+ return "rgb(" + this.toRgb().join() + ")";
+ },
+
+ toString: function() {
+ return this.toHex(); // decent default?
+ },
+
+ toHsv: function() {
+ return dojo.graphics.color.rgb2hsv(this.toRgb());
+ },
+
+ toHsl: function() {
+ return dojo.graphics.color.rgb2hsl(this.toRgb());
+ },
+
+ blend: function(color, weight) {
+ return dojo.graphics.color.blend(this.toRgb(), new Color(color).toRgb(), weight);
+ }
+});
+
+dojo.graphics.color.named = {
+ white: [255,255,255],
+ black: [0,0,0],
+ red: [255,0,0],
+ green: [0,255,0],
+ blue: [0,0,255],
+ navy: [0,0,128],
+ gray: [128,128,128],
+ silver: [192,192,192]
+};
+
+// blend colors a and b (both as RGB array or hex strings) with weight from -1 to +1, 0 being a 50/50 blend
+dojo.graphics.color.blend = function(a, b, weight) {
+ if(typeof a == "string") { return dojo.graphics.color.blendHex(a, b, weight); }
+ if(!weight) { weight = 0; }
+ else if(weight > 1) { weight = 1; }
+ else if(weight < -1) { weight = -1; }
+ var c = new Array(3);
+ for(var i = 0; i < 3; i++) {
+ var half = Math.abs(a[i] - b[i])/2;
+ c[i] = Math.floor(Math.min(a[i], b[i]) + half + (half * weight));
+ }
+ return c;
+}
+
+// very convenient blend that takes and returns hex values
+// (will get called automatically by blend when blend gets strings)
+dojo.graphics.color.blendHex = function(a, b, weight) {
+ return dojo.graphics.color.rgb2hex(dojo.graphics.color.blend(dojo.graphics.color.hex2rgb(a), dojo.graphics.color.hex2rgb(b), weight));
+}
+
+// get RGB array from css-style color declarations
+dojo.graphics.color.extractRGB = function(color) {
+ var hex = "0123456789abcdef";
+ color = color.toLowerCase();
+ if( color.indexOf("rgb") == 0 ) {
+ var matches = color.match(/rgba*\((\d+), *(\d+), *(\d+)/i);
+ var ret = matches.splice(1, 3);
+ return ret;
+ } else {
+ var colors = dojo.graphics.color.hex2rgb(color);
+ if(colors) {
+ return colors;
+ } else {
+ // named color (how many do we support?)
+ return dojo.graphics.color.named[color] || [255, 255, 255];
+ }
+ }
+}
+
+dojo.graphics.color.hex2rgb = function(hex) {
+ var hexNum = "0123456789ABCDEF";
+ var rgb = new Array(3);
+ if( hex.indexOf("#") == 0 ) { hex = hex.substring(1); }
+ hex = hex.toUpperCase();
+ if(hex.replace(new RegExp("["+hexNum+"]", "g"), "") != "") {
+ return null;
+ }
+ if( hex.length == 3 ) {
+ rgb[0] = hex.charAt(0) + hex.charAt(0)
+ rgb[1] = hex.charAt(1) + hex.charAt(1)
+ rgb[2] = hex.charAt(2) + hex.charAt(2);
+ } else {
+ rgb[0] = hex.substring(0, 2);
+ rgb[1] = hex.substring(2, 4);
+ rgb[2] = hex.substring(4);
+ }
+ for(var i = 0; i < rgb.length; i++) {
+ rgb[i] = hexNum.indexOf(rgb[i].charAt(0)) * 16 + hexNum.indexOf(rgb[i].charAt(1));
+ }
+ return rgb;
+}
+
+dojo.graphics.color.rgb2hex = function(r, g, b) {
+ if(dojo.lang.isArray(r)) {
+ g = r[1] || 0;
+ b = r[2] || 0;
+ r = r[0] || 0;
+ }
+ function pad(x) { while(x.length < 2) { x = "0" + x; } return x; }
+ var ret = dojo.lang.map([r, g, b], function(x) {
+ var s = x.toString(16);
+ while(s.length < 2) { s = "0" + s; }
+ return s;
+ });
+ ret.unshift("#");
+ return ret.join("");
+}
+
+dojo.graphics.color.rgb2hsv = function(r, g, b){
+
+ if (dojo.lang.isArray(r)) {
+ b = r[2] || 0;
+ g = r[1] || 0;
+ r = r[0] || 0;
+ }
+
+ // r,g,b, each 0 to 255, to HSV.
+ // h = 0.0 to 360.0 (corresponding to 0..360.0 degrees around hexcone)
+ // s = 0.0 (shade of gray) to 1.0 (pure color)
+ // v = 0.0 (black) to 1.0 {white)
+ //
+ // Based on C Code in "Computer Graphics -- Principles and Practice,"
+ // Foley et al, 1996, p. 592.
+ //
+ // our calculatuions are based on 'regular' values (0-360, 0-1, 0-1)
+ // but we return bytes values (0-255, 0-255, 0-255)
+
+ var h = null;
+ var s = null;
+ var v = null;
+
+ var min = Math.min(r, g, b);
+ v = Math.max(r, g, b);
+
+ var delta = v - min;
+
+ // calculate saturation (0 if r, g and b are all 0)
+
+ s = (v == 0) ? 0 : delta/v;
+
+ if (s == 0){
+ // achromatic: when saturation is, hue is undefined
+ h = 0;
+ }else{
+ // chromatic
+ if (r == v){
+ // between yellow and magenta
+ h = 60 * (g - b) / delta;
+ }else{
+ if (g == v){
+ // between cyan and yellow
+ h = 120 + 60 * (b - r) / delta;
+ }else{
+ if (b == v){
+ // between magenta and cyan
+ h = 240 + 60 * (r - g) / delta;
+ }
+ }
+ }
+ if (h < 0){
+ h += 360;
+ }
+ }
+
+
+ h = (h == 0) ? 360 : Math.ceil((h / 360) * 255);
+ s = Math.ceil(s * 255);
+
+ return [h, s, v];
+}
+
+dojo.graphics.color.hsv2rgb = function(h, s, v){
+
+ if (dojo.lang.isArray(h)) {
+ v = h[2] || 0;
+ s = h[1] || 0;
+ h = h[0] || 0;
+ }
+
+ h = (h / 255) * 360;
+ if (h == 360){ h = 0;}
+
+ s = s / 255;
+ v = v / 255;
+
+ // Based on C Code in "Computer Graphics -- Principles and Practice,"
+ // Foley et al, 1996, p. 593.
+ //
+ // H = 0.0 to 360.0 (corresponding to 0..360 degrees around hexcone) 0 for S = 0
+ // S = 0.0 (shade of gray) to 1.0 (pure color)
+ // V = 0.0 (black) to 1.0 (white)
+
+ var r = null;
+ var g = null;
+ var b = null;
+
+ if (s == 0){
+ // color is on black-and-white center line
+ // achromatic: shades of gray
+ r = v;
+ g = v;
+ b = v;
+ }else{
+ // chromatic color
+ var hTemp = h / 60; // h is now IN [0,6]
+ var i = Math.floor(hTemp); // largest integer <= h
+ var f = hTemp - i; // fractional part of h
+
+ var p = v * (1 - s);
+ var q = v * (1 - (s * f));
+ var t = v * (1 - (s * (1 - f)));
+
+ switch(i){
+ case 0: r = v; g = t; b = p; break;
+ case 1: r = q; g = v; b = p; break;
+ case 2: r = p; g = v; b = t; break;
+ case 3: r = p; g = q; b = v; break;
+ case 4: r = t; g = p; b = v; break;
+ case 5: r = v; g = p; b = q; break;
+ }
+ }
+
+ r = Math.ceil(r * 255);
+ g = Math.ceil(g * 255);
+ b = Math.ceil(b * 255);
+
+ return [r, g, b];
+}
+
+dojo.graphics.color.rgb2hsl = function(r, g, b){
+
+ if (dojo.lang.isArray(r)) {
+ b = r[2] || 0;
+ g = r[1] || 0;
+ r = r[0] || 0;
+ }
+
+ r /= 255;
+ g /= 255;
+ b /= 255;
+
+ //
+ // based on C code from http://astronomy.swin.edu.au/~pbourke/colour/hsl/
+ //
+
+ var h = null;
+ var s = null;
+ var l = null;
+
+
+ var min = Math.min(r, g, b);
+ var max = Math.max(r, g, b);
+ var delta = max - min;
+
+ l = (min + max) / 2;
+
+ s = 0;
+
+ if ((l > 0) && (l < 1)){
+ s = delta / ((l < 0.5) ? (2 * l) : (2 - 2 * l));
+ }
+
+ h = 0;
+
+ if (delta > 0) {
+ if ((max == r) && (max != g)){
+ h += (g - b) / delta;
+ }
+ if ((max == g) && (max != b)){
+ h += (2 + (b - r) / delta);
+ }
+ if ((max == b) && (max != r)){
+ h += (4 + (r - g) / delta);
+ }
+ h *= 60;
+ }
+
+ h = (h == 0) ? 360 : Math.ceil((h / 360) * 255);
+ s = Math.ceil(s * 255);
+ l = Math.ceil(l * 255);
+
+ return [h, s, l];
+}
+
+dojo.graphics.color.hsl2rgb = function(h, s, l){
+
+ if (dojo.lang.isArray(h)) {
+ l = h[2] || 0;
+ s = h[1] || 0;
+ h = h[0] || 0;
+ }
+
+ h = (h / 255) * 360;
+ if (h == 360){ h = 0;}
+ s = s / 255;
+ l = l / 255;
+
+ //
+ // based on C code from http://astronomy.swin.edu.au/~pbourke/colour/hsl/
+ //
+
+
+ while (h < 0){ h += 360; }
+ while (h > 360){ h -= 360; }
+
+ if (h < 120){
+ r = (120 - h) / 60;
+ g = h / 60;
+ b = 0;
+ }else if (h < 240){
+ r = 0;
+ g = (240 - h) / 60;
+ b = (h - 120) / 60;
+ }else{
+ r = (h - 240) / 60;
+ g = 0;
+ b = (360 - h) / 60;
+ }
+
+ r = Math.min(r, 1);
+ g = Math.min(g, 1);
+ b = Math.min(b, 1);
+
+ r = 2 * s * r + (1 - s);
+ g = 2 * s * g + (1 - s);
+ b = 2 * s * b + (1 - s);
+
+ if (l < 0.5){
+ r = l * r;
+ g = l * g;
+ b = l * b;
+ }else{
+ r = (1 - l) * r + 2 * l - 1;
+ g = (1 - l) * g + 2 * l - 1;
+ b = (1 - l) * b + 2 * l - 1;
+ }
+
+ r = Math.ceil(r * 255);
+ g = Math.ceil(g * 255);
+ b = Math.ceil(b * 255);
+
+ return [r, g, b];
+}
+
+dojo.graphics.color.hsl2hex = function(h, s, l){
+ var rgb = dojo.graphics.color.hsl2rgb(h, s, l);
+ return dojo.graphics.color.rgb2hex(rgb[0], rgb[1], rgb[2]);
+}
+
+dojo.graphics.color.hex2hsl = function(hex){
+ var rgb = dojo.graphics.color.hex2rgb(hex);
+ return dojo.graphics.color.rgb2hsl(rgb[0], rgb[1], rgb[2]);
+}
Added: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/graphics/htmlEffects.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/graphics/htmlEffects.js?rev=385171&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/graphics/htmlEffects.js (added)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/graphics/htmlEffects.js Sat Mar 11 13:18:41 2006
@@ -0,0 +1,16 @@
+/*
+ Copyright (c) 2004-2005, 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.graphics.htmlEffects");
+dojo.require("dojo.fx.*");
+
+dj_deprecated("dojo.graphics.htmlEffects is deprecated, use dojo.fx.html instead");
+
+dojo.graphics.htmlEffects = dojo.fx.html;
Added: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_adobesvg.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_adobesvg.js?rev=385171&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_adobesvg.js (added)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_adobesvg.js Sat Mar 11 13:18:41 2006
@@ -0,0 +1,571 @@
+/*
+ Copyright (c) 2004-2005, 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
+*/
+
+/*
+ * Adobe SVG Viewer host environment
+ */
+if(typeof window == 'undefined'){
+ dj_throw("attempt to use adobe svg hostenv when no window object");
+}
+
+with(dojo.render){
+ name = navigator.appName;
+ ver = parseFloat(navigator.appVersion, 10);
+ switch(navigator.platform){
+ case "MacOS":
+ os.osx = true;
+ break;
+ case "Linux":
+ os.linux = true;
+ break;
+ case "Windows":
+ os.win = true;
+ break;
+ default:
+ os.linux = true;
+ break;
+ };
+ svg.capable = true;
+ svg.support.builtin = true;
+ svg.adobe = true;
+};
+
+// browserEval("alert(window.location);");
+
+dojo.hostenv.println = function(s){
+ try{
+ // FIXME: this may not work with adobe's viewer, as we may first need a
+ // reference to the svgDocument
+ // FIXME: need a way to determine where to position the text for this
+ var ti = document.createElement("text");
+ ti.setAttribute("x","50");
+ var yPos = 25 + 15*document.getElementsByTagName("text").length;
+ ti.setAttribute("y",yPos);
+ var tn = document.createTextNode(s);
+ ti.appendChild(tn);
+ document.documentElement.appendChild(ti);
+ }catch(e){
+
+ }
+}
+
+dojo.debug = function() {
+ if (!djConfig.isDebug) { return; }
+ var args = arguments;
+ if(typeof dojo.hostenv.println != 'function'){
+ dj_throw("attempt to call dojo.debug when there is no dojo.hostenv println implementation (yet?)");
+ }
+ var isJUM = dj_global["jum"];
+ var s = isJUM ? "": "DEBUG: ";
+ for(var i=0;i<args.length;++i){ s += args[i]; }
+ if(isJUM){ // this seems to be the only way to get JUM to "play nice"
+ jum.debug(s);
+ }else{
+ dojo.hostenv.println(s);
+ }
+}
+
+dojo.hostenv.startPackage("dojo.hostenv");
+
+dojo.hostenv.name_ = 'adobesvg';
+
+dojo.hostenv.anonCtr = 0;
+dojo.hostenv.anon = {};
+
+dojo.hostenv.nameAnonFunc = function(anonFuncPtr, namespaceObj){
+ var ret = "_"+this.anonCtr++;
+ var nso = (namespaceObj || this.anon);
+ while(typeof nso[ret] != "undefined"){
+ ret = "_"+this.anonCtr++;
+ }
+ nso[ret] = anonFuncPtr;
+ return ret;
+}
+
+dojo.hostenv.modulesLoadedFired = false;
+dojo.hostenv.modulesLoadedListeners = [];
+dojo.hostenv.getTextStack = [];
+dojo.hostenv.loadUriStack = [];
+dojo.hostenv.loadedUris = [];
+
+
+dojo.hostenv.modulesLoaded = function(){
+ if(this.modulesLoadedFired){ return; }
+ if((this.loadUriStack.length==0)&&(this.getTextStack.length==0)){
+ if(this.inFlightCount > 0){
+ dojo.debug("couldn't initialize, there are files still in flight");
+ return;
+ }
+ this.modulesLoadedFired = true;
+ var mll = this.modulesLoadedListeners;
+ for(var x=0; x<mll.length; x++){
+ mll[x]();
+ }
+ }
+}
+
+dojo.hostenv.getNewAnonFunc = function(){
+ var ret = "_"+this.anonCtr++;
+ while(typeof this.anon[ret] != "undefined"){
+ ret = "_"+this.anonCtr++;
+ }
+ // this.anon[ret] = function(){};
+ eval("dojo.nostenv.anon."+ret+" = function(){};");
+ return [ret, this.anon[ret]];
+}
+
+dojo.hostenv.displayStack = function(){
+ var oa = [];
+ var stack = this.loadUriStack;
+ for(var x=0; x<stack.length; x++){
+ oa.unshift([stack[x][0], (typeof stack[x][2])]);
+ }
+ dojo.debug("<pre>"+oa.join("\n")+"</pre>");
+}
+
+dojo.hostenv.unwindUriStack = function(){
+ var stack = this.loadUriStack;
+ for(var x in dojo.hostenv.loadedUris){
+ for(var y=stack.length-1; y>=0; y--){
+ if(stack[y][0]==x){
+ stack.splice(y, 1);
+ }
+ }
+ }
+ var next = stack.pop();
+ if((!next)&&(stack.length==0)){
+ return;
+ }
+ for(var x=0; x<stack.length; x++){
+ if((stack[x][0]==next[0])&&(stack[x][2])){
+ next[2] == stack[x][2]
+ }
+ }
+ var last = next;
+ while(dojo.hostenv.loadedUris[next[0]]){
+ last = next;
+ next = stack.pop();
+ }
+ while(typeof next[2] == "string"){ // unwind as far as we can
+ try{
+ // dojo.debug("<pre><![CDATA["+next[2]+"]]></pre>");
+ dj_eval(next[2]);
+ next[1](true);
+ }catch(e){
+ dojo.debug("we got an error when loading "+next[0]);
+ dojo.debug("error: "+e);
+ // for(var x in e){ alert(x+" "+e[x]); }
+ }
+ dojo.hostenv.loadedUris[next[0]] = true;
+ dojo.hostenv.loadedUris.push(next[0]);
+ last = next;
+ next = stack.pop();
+ if((!next)&&(stack.length==0)){ break; }
+ while(dojo.hostenv.loadedUris[next[0]]){
+ last = next;
+ next = stack.pop();
+ }
+ }
+ if(next){
+ stack.push(next);
+ dojo.debug("### CHOKED ON: "+next[0]);
+ }
+}
+
+/**
+ * Reads the contents of the URI, and evaluates the contents.
+ * Returns true if it succeeded. Returns false if the URI reading failed. Throws if the evaluation throws.
+ * The result of the eval is not available to the caller.
+ */
+dojo.hostenv.loadUri = function(uri, cb){
+ if(dojo.hostenv.loadedUris[uri]){
+ return;
+ }
+ var stack = this.loadUriStack;
+ stack.push([uri, cb, null]);
+ var tcb = function(contents){
+ // gratuitous hack for Adobe SVG 3, what a fucking POS
+ if(contents.content){
+ contents = contents.content;
+ }
+
+ // stack management
+ var next = stack.pop();
+ if((!next)&&(stack.length==0)){
+ dojo.hostenv.modulesLoaded();
+ return;
+ }
+ if(typeof contents == "string"){
+ stack.push(next);
+ for(var x=0; x<stack.length; x++){
+ if(stack[x][0]==uri){
+ stack[x][2] = contents;
+ }
+ }
+ next = stack.pop();
+ }
+ if(dojo.hostenv.loadedUris[next[0]]){
+ // dojo.debug("WE ALREADY HAD: "+next[0]);
+ dojo.hostenv.unwindUriStack();
+ return;
+ }
+ // push back onto stack
+ stack.push(next);
+ if(next[0]!=uri){
+ // and then unwind as far as we can
+ if(typeof next[2] == "string"){
+ dojo.hostenv.unwindUriStack();
+ }
+
+ }else{
+ if(!contents){
+ next[1](false);
+ }else{
+ var deps = dojo.hostenv.getDepsForEval(next[2]);
+ if(deps.length>0){
+ eval(deps.join(";"));
+ }else{
+ dojo.hostenv.unwindUriStack();
+ }
+ }
+ }
+ }
+ this.getText(uri, tcb, true);
+}
+
+/**
+ * Reads the contents of the URI, and evaluates the contents.
+ * Returns true if it succeeded. Returns false if the URI reading failed. Throws if the evaluation throws.
+ * The result of the eval is not available to the caller.
+ */
+dojo.hostenv.loadUri = function(uri, cb){
+ if(dojo.hostenv.loadedUris[uri]){
+ return;
+ }
+ var stack = this.loadUriStack;
+ stack.push([uri, cb, null]);
+ var tcb = function(contents){
+ // gratuitous hack for Adobe SVG 3, what a fucking POS
+ if(contents.content){
+ contents = contents.content;
+ }
+
+ // stack management
+ var next = stack.pop();
+ if((!next)&&(stack.length==0)){
+ dojo.hostenv.modulesLoaded();
+ return;
+ }
+ if(typeof contents == "string"){
+ stack.push(next);
+ for(var x=0; x<stack.length; x++){
+ if(stack[x][0]==uri){
+ stack[x][2] = contents;
+ }
+ }
+ next = stack.pop();
+ }
+ if(dojo.hostenv.loadedUris[next[0]]){
+ // dojo.debug("WE ALREADY HAD: "+next[0]);
+ dojo.hostenv.unwindUriStack();
+ return;
+ }
+ // push back onto stack
+ stack.push(next);
+ if(next[0]!=uri){
+ // and then unwind as far as we can
+ if(typeof next[2] == "string"){
+ dojo.hostenv.unwindUriStack();
+ }
+
+ }else{
+ if(!contents){
+ next[1](false);
+ }else{
+ var deps = dojo.hostenv.getDepsForEval(next[2]);
+ if(deps.length>0){
+ eval(deps.join(";"));
+ }else{
+ dojo.hostenv.unwindUriStack();
+ }
+ }
+ }
+ }
+ this.getText(uri, tcb, true);
+}
+
+/**
+* loadModule("A.B") first checks to see if symbol A.B is defined.
+* If it is, it is simply returned (nothing to do).
+* If it is not defined, it will look for "A/B.js" in the script root directory, followed
+* by "A.js".
+* It throws if it cannot find a file to load, or if the symbol A.B is not defined after loading.
+* It returns the object A.B.
+*
+* This does nothing about importing symbols into the current package.
+* It is presumed that the caller will take care of that. For example, to import
+* all symbols:
+*
+* with (dojo.hostenv.loadModule("A.B")) {
+* ...
+* }
+*
+* And to import just the leaf symbol:
+*
+* var B = dojo.hostenv.loadModule("A.B");
+* ...
+*
+* dj_load is an alias for dojo.hostenv.loadModule
+*/
+dojo.hostenv.loadModule = function(modulename, exact_only, omit_module_check){
+ // alert("dojo.hostenv.loadModule('"+modulename+"');");
+ var module = this.findModule(modulename, 0);
+ if(module){
+ return module;
+ }
+
+ // dojo.debug("dojo.hostenv.loadModule('"+modulename+"');");
+
+ // protect against infinite recursion from mutual dependencies
+ if (typeof this.loading_modules_[modulename] !== 'undefined'){
+ // NOTE: this should never throw an exception!! "recursive" includes
+ // are normal in the course of app and module building, so blow out of
+ // it gracefully, but log it in debug mode
+
+ // dj_throw("recursive attempt to load module '" + modulename + "'");
+ dojo.debug("recursive attempt to load module '" + modulename + "'");
+ }else{
+ this.addedToLoadingCount.push(modulename);
+ }
+ this.loading_modules_[modulename] = 1;
+
+
+ // convert periods to slashes
+ var relpath = modulename.replace(/\./g, '/') + '.js';
+
+ var syms = modulename.split(".");
+ var nsyms = modulename.split(".");
+ if(syms[0]=="dojo"){ // FIXME: need a smarter way to do this!
+ syms[0] = "src";
+ }
+ var last = syms.pop();
+ syms.push(last);
+ // figure out if we're looking for a full package, if so, we want to do
+ // things slightly diffrently
+ var _this = this;
+ var pfn = this.pkgFileName;
+ if(last=="*"){
+ modulename = (nsyms.slice(0, -1)).join('.');
+
+ var module = this.findModule(modulename, 0);
+ // dojo.debug("found: "+modulename+"="+module);
+ if(module){
+ _this.removedFromLoadingCount.push(modulename);
+ return module;
+ }
+
+ var nextTry = function(lastStatus){
+ if(lastStatus){
+ module = _this.findModule(modulename, false); // pass in false so we can give better error
+ if((!module)&&(syms[syms.length-1]!=pfn)){
+ dj_throw("Module symbol '" + modulename + "' is not defined after loading '" + relpath + "'");
+ }
+ if(module){
+ _this.removedFromLoadingCount.push(modulename);
+ dojo.hostenv.modulesLoaded();
+ return;
+ }
+ }
+ syms.pop();
+ syms.push(pfn);
+ // dojo.debug("syms: "+syms);
+ relpath = syms.join("/") + '.js';
+ if(relpath.charAt(0)=="/"){
+ relpath = relpath.slice(1);
+ }
+ // dojo.debug("relpath: "+relpath);
+ _this.loadPath(relpath, ((!omit_module_check) ? modulename : null), nextTry);
+ }
+
+ nextTry();
+ }else{
+ relpath = syms.join("/") + '.js';
+ modulename = nsyms.join('.');
+
+ var nextTry = function(lastStatus){
+ // dojo.debug("lastStatus: "+lastStatus);
+ if(lastStatus){
+ // dojo.debug("inital relpath: "+relpath);
+ module = _this.findModule(modulename, false); // pass in false so we can give better error
+ // if(!module){
+ if((!module)&&(syms[syms.length-1]!=pfn)){
+ dj_throw("Module symbol '" + modulename + "' is not defined after loading '" + relpath + "'");
+ }
+ if(module){
+ _this.removedFromLoadingCount.push(modulename);
+ dojo.hostenv.modulesLoaded();
+ return;
+ }
+ }
+ var setPKG = (syms[syms.length-1]==pfn) ? false : true;
+ syms.pop();
+ if(setPKG){
+ syms.push(pfn);
+ }
+ relpath = syms.join("/") + '.js';
+ if(relpath.charAt(0)=="/"){
+ relpath = relpath.slice(1);
+ }
+ // dojo.debug("relpath: "+relpath);
+ _this.loadPath(relpath, ((!omit_module_check) ? modulename : null), nextTry);
+ }
+
+ this.loadPath(relpath, ((!omit_module_check) ? modulename : null), nextTry);
+ }
+ return;
+}
+
+/**
+ * Read the contents of the specified uri and return those contents.
+ *
+ * FIXME: Make sure this is consistent with other implementations of getText
+ * @param uri A relative or absolute uri. If absolute, it still must be in the same "domain" as we are.
+ * @param async_cb If not specified, returns false as synchronous is not
+ * supported. If specified, load asynchronously, and use async_cb as the handler which receives the result of the request.
+ * @param fail_ok Default false. If fail_ok and !async_cb and loading fails, return null instead of throwing.
+ */
+dojo.hostenv.async_cb = null;
+
+dojo.hostenv.unWindGetTextStack = function(){
+ if(dojo.hostenv.inFlightCount>0){
+ setTimeout("dojo.hostenv.unWindGetTextStack()", 100);
+ return;
+ }
+ // we serialize because this goddamned environment is too fucked up
+ // to know how to do anything else
+ dojo.hostenv.inFlightCount++;
+ var next = dojo.hostenv.getTextStack.pop();
+ if((!next)&&(dojo.hostenv.getTextStack.length==0)){
+ dojo.hostenv.inFlightCount--;
+ dojo.hostenv.async_cb = function(){};
+ return;
+ }
+ dojo.hostenv.async_cb = next[1];
+ // http = window.getURL(uri, dojo.hostenv.anon[cbn]);
+ window.getURL(next[0], function(result){
+ dojo.hostenv.inFlightCount--;
+ dojo.hostenv.async_cb(result.content);
+ dojo.hostenv.unWindGetTextStack();
+ });
+}
+
+dojo.hostenv.getText = function(uri, async_cb, fail_ok){
+ // dojo.debug("Calling getText()");
+ try{
+ if(async_cb){
+ dojo.hostenv.getTextStack.push([uri, async_cb, fail_ok]);
+ dojo.hostenv.unWindGetTextStack();
+ }else{
+ return dj_throw("No synchronous XMLHTTP implementation available, for uri " + uri);
+ }
+ }catch(e){
+ return dj_throw("No XMLHTTP implementation available, for uri " + uri);
+ }
+}
+
+
+/**
+ * Makes an async post to the specified uri.
+ *
+ * FIXME: Not sure that we need this, but adding for completeness.
+ * More details about the implementation of this are available at
+ * http://wiki.svg.org/index.php/PostUrl
+ * @param uri A relative or absolute uri. If absolute, it still must be in the same "domain" as we are.
+ * @param async_cb If not specified, returns false as synchronous is not
+ * supported. If specified, load asynchronously, and use async_cb as the progress handler which takes the xmlhttp object as its argument. If async_cb, this function returns null.
+ * @param text Data to post
+ * @param fail_ok Default false. If fail_ok and !async_cb and loading fails, return null instead of throwing.
+ * @param mime_type optional MIME type of the posted data (such as "text/plain")
+ * @param encoding optional encoding for data. null, 'gzip' and 'deflate' are possible values. If browser does not support binary post this parameter is ignored.
+ */
+dojo.hostenv.postText = function(uri, async_cb, text, fail_ok, mime_type, encoding){
+ var http = null;
+
+ var async_callback = function(httpResponse){
+ if (!httpResponse.success) {
+ dj_throw("Request for uri '" + uri + "' resulted in " + httpResponse.status);
+ }
+
+ if(!httpResponse.content) {
+ if (!fail_ok) dj_throw("Request for uri '" + uri + "' resulted in no content");
+ return null;
+ }
+ // FIXME: wtf, I'm losing a reference to async_cb
+ async_cb(httpResponse.content);
+ }
+
+ try {
+ if(async_cb) {
+ http = window.postURL(uri, text, async_callback, mimeType, encoding);
+ } else {
+ return dj_throw("No synchronous XMLHTTP post implementation available, for uri " + uri);
+ }
+ } catch(e) {
+ return dj_throw("No XMLHTTP post implementation available, for uri " + uri);
+ }
+}
+
+/*
+ * It turns out that if we check *right now*, as this script file is being loaded,
+ * then the last script element in the window DOM is ourselves.
+ * That is because any subsequent script elements haven't shown up in the document
+ * object yet.
+ */
+function dj_last_script_src() {
+ var scripts = window.document.getElementsByTagName('script');
+ if(scripts.length < 1){
+ dj_throw("No script elements in window.document, so can't figure out my script src");
+ }
+ var li = scripts.length-1;
+ var xlinkNS = "http://www.w3.org/1999/xlink";
+ var src = null;
+ var script = null;
+ while(!src){
+ script = scripts.item(li);
+ src = script.getAttributeNS(xlinkNS,"href");
+ li--;
+ if(li<0){ break; }
+ // break;
+ }
+ if(!src){
+ dj_throw("Last script element (out of " + scripts.length + ") has no src");
+ }
+ return src;
+}
+
+if(!dojo.hostenv["library_script_uri_"]){
+ dojo.hostenv.library_script_uri_ = dj_last_script_src();
+}
+
+// dojo.hostenv.loadUri = function(uri){
+ /* FIXME: adding a script element doesn't seem to be synchronous, and so
+ * checking for namespace or object existance after loadUri using this
+ * method will error out. Need to figure out some other way of handling
+ * this!
+ */
+ /*
+ var se = document.createElement("script");
+ se.src = uri;
+ var head = document.getElementsByTagName("head")[0];
+ head.appendChild(se);
+ // document.write("<script type='text/javascript' src='"+uri+"' />");
+ return 1;
+}
+*/
Added: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_browser.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_browser.js?rev=385171&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_browser.js (added)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_browser.js Sat Mar 11 13:18:41 2006
@@ -0,0 +1,414 @@
+/*
+ Copyright (c) 2004-2005, 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
+*/
+
+/**
+* @file hostenv_browser.js
+*
+* Implements the hostenv interface for a browser environment.
+*
+* Perhaps it could be called a "dom" or "useragent" environment.
+*
+* @author Copyright 2004 Mark D. Anderson (mda@discerning.com)
+* @author Licensed under the Academic Free License 2.1 http://www.opensource.org/licenses/afl-2.1.php
+*/
+
+// make jsc shut up (so we can use jsc to sanity check the code even if it will never run it).
+/*@cc_on
+@if (@_jscript_version >= 7)
+var window; var XMLHttpRequest;
+@end
+@*/
+
+if(typeof window == 'undefined'){
+ dojo.raise("no window object");
+}
+
+// attempt to figure out the path to dojo if it isn't set in the config
+(function() {
+ // before we get any further with the config options, try to pick them out
+ // of the URL. Most of this code is from NW
+ if(djConfig.allowQueryConfig){
+ var baseUrl = document.location.toString(); // FIXME: use location.query instead?
+ var params = baseUrl.split("?", 2);
+ if(params.length > 1){
+ var paramStr = params[1];
+ var pairs = paramStr.split("&");
+ for(var x in pairs){
+ var sp = pairs[x].split("=");
+ // FIXME: is this eval dangerous?
+ if((sp[0].length > 9)&&(sp[0].substr(0, 9) == "djConfig.")){
+ var opt = sp[0].substr(9);
+ try{
+ djConfig[opt]=eval(sp[1]);
+ }catch(e){
+ djConfig[opt]=sp[1];
+ }
+ }
+ }
+ }
+ }
+
+ if(((djConfig["baseScriptUri"] == "")||(djConfig["baseRelativePath"] == "")) &&(document && document.getElementsByTagName)){
+ var scripts = document.getElementsByTagName("script");
+ var rePkg = /(__package__|dojo|bootstrap1)\.js([\?\.]|$)/i;
+ for(var i = 0; i < scripts.length; i++) {
+ var src = scripts[i].getAttribute("src");
+ if(!src) { continue; }
+ var m = src.match(rePkg);
+ if(m) {
+ root = src.substring(0, m.index);
+ if(src.indexOf("bootstrap1") > -1) { root += "../"; }
+ if(!this["djConfig"]) { djConfig = {}; }
+ if(djConfig["baseScriptUri"] == "") { djConfig["baseScriptUri"] = root; }
+ if(djConfig["baseRelativePath"] == "") { djConfig["baseRelativePath"] = root; }
+ break;
+ }
+ }
+ }
+
+ var dr = dojo.render;
+ var drh = dojo.render.html;
+ var drs = dojo.render.svg;
+ var dua = drh.UA = navigator.userAgent;
+ var dav = drh.AV = navigator.appVersion;
+ var t = true;
+ var f = false;
+ drh.capable = t;
+ drh.support.builtin = t;
+
+ dr.ver = parseFloat(drh.AV);
+ dr.os.mac = dav.indexOf("Macintosh") >= 0;
+ dr.os.win = dav.indexOf("Windows") >= 0;
+ // could also be Solaris or something, but it's the same browser
+ dr.os.linux = dav.indexOf("X11") >= 0;
+
+ drh.opera = dua.indexOf("Opera") >= 0;
+ drh.khtml = (dav.indexOf("Konqueror") >= 0)||(dav.indexOf("Safari") >= 0);
+ drh.safari = dav.indexOf("Safari") >= 0;
+ var geckoPos = dua.indexOf("Gecko");
+ drh.mozilla = drh.moz = (geckoPos >= 0)&&(!drh.khtml);
+ if (drh.mozilla) {
+ // gecko version is YYYYMMDD
+ drh.geckoVersion = dua.substring(geckoPos + 6, geckoPos + 14);
+ }
+ drh.ie = (document.all)&&(!drh.opera);
+ drh.ie50 = drh.ie && dav.indexOf("MSIE 5.0")>=0;
+ drh.ie55 = drh.ie && dav.indexOf("MSIE 5.5")>=0;
+ drh.ie60 = drh.ie && dav.indexOf("MSIE 6.0")>=0;
+
+ dr.vml.capable=drh.ie;
+ drs.capable = f;
+ drs.support.plugin = f;
+ drs.support.builtin = f;
+ drs.adobe = f;
+ if (document.implementation
+ && document.implementation.hasFeature
+ && document.implementation.hasFeature("org.w3c.dom.svg", "1.0")
+ ){
+ drs.capable = t;
+ drs.support.builtin = t;
+ drs.support.plugin = f;
+ drs.adobe = f;
+ }else{
+ // check for ASVG
+ if(navigator.mimeTypes && navigator.mimeTypes.length > 0){
+ var result = navigator.mimeTypes["image/svg+xml"] ||
+ navigator.mimeTypes["image/svg"] ||
+ navigator.mimeTypes["image/svg-xml"];
+ if (result){
+ drs.adobe = result && result.enabledPlugin &&
+ result.enabledPlugin.description &&
+ (result.enabledPlugin.description.indexOf("Adobe") > -1);
+ if(drs.adobe) {
+ drs.capable = t;
+ drs.support.plugin = t;
+ }
+ }
+ }else if(drh.ie && dr.os.win){
+ var result = f;
+ try {
+ var test = new ActiveXObject("Adobe.SVGCtl");
+ result = t;
+ } catch(e){}
+ if (result){
+ drs.capable = t;
+ drs.support.plugin = t;
+ drs.adobe = t;
+ }
+ }else{
+ drs.capable = f;
+ drs.support.plugin = f;
+ drs.adobe = f;
+ }
+ }
+})();
+
+dojo.hostenv.startPackage("dojo.hostenv");
+
+dojo.hostenv.name_ = 'browser';
+dojo.hostenv.searchIds = [];
+
+// These are in order of decreasing likelihood; this will change in time.
+var DJ_XMLHTTP_PROGIDS = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'];
+
+dojo.hostenv.getXmlhttpObject = function(){
+ var http = null;
+ var last_e = null;
+ try{ http = new XMLHttpRequest(); }catch(e){}
+ if(!http){
+ for(var i=0; i<3; ++i){
+ var progid = DJ_XMLHTTP_PROGIDS[i];
+ try{
+ http = new ActiveXObject(progid);
+ }catch(e){
+ last_e = e;
+ }
+
+ if(http){
+ DJ_XMLHTTP_PROGIDS = [progid]; // so faster next time
+ break;
+ }
+ }
+
+ /*if(http && !http.toString) {
+ http.toString = function() { "[object XMLHttpRequest]"; }
+ }*/
+ }
+
+ if(!http){
+ return dojo.raise("XMLHTTP not available", last_e);
+ }
+
+ return http;
+}
+
+/**
+ * Read the contents of the specified uri and return those contents.
+ *
+ * @param uri A relative or absolute uri. If absolute, it still must be in the
+ * same "domain" as we are.
+ *
+ * @param async_cb If not specified, load synchronously. If specified, load
+ * asynchronously, and use async_cb as the progress handler which takes the
+ * xmlhttp object as its argument. If async_cb, this function returns null.
+ *
+ * @param fail_ok Default false. If fail_ok and !async_cb and loading fails,
+ * return null instead of throwing.
+ */
+dojo.hostenv.getText = function(uri, async_cb, fail_ok){
+
+ var http = this.getXmlhttpObject();
+
+ if(async_cb){
+ http.onreadystatechange = function(){
+ if((4==http.readyState)&&(http["status"])){
+ if(http.status==200){
+ // dojo.debug("LOADED URI: "+uri);
+ async_cb(http.responseText);
+ }
+ }
+ }
+ }
+
+ http.open('GET', uri, async_cb ? true : false);
+ try {
+ http.send(null);
+ } catch (e) {
+ if (fail_ok && !async_cb) {
+ return null;
+ } else {
+ throw e;
+ }
+ }
+ if(async_cb){
+ return null;
+ }
+
+ return http.responseText;
+}
+
+/*
+ * It turns out that if we check *right now*, as this script file is being loaded,
+ * then the last script element in the window DOM is ourselves.
+ * That is because any subsequent script elements haven't shown up in the document
+ * object yet.
+ */
+ /*
+function dj_last_script_src() {
+ var scripts = window.document.getElementsByTagName('script');
+ if(scripts.length < 1){
+ dojo.raise("No script elements in window.document, so can't figure out my script src");
+ }
+ var script = scripts[scripts.length - 1];
+ var src = script.src;
+ if(!src){
+ dojo.raise("Last script element (out of " + scripts.length + ") has no src");
+ }
+ return src;
+}
+
+if(!dojo.hostenv["library_script_uri_"]){
+ dojo.hostenv.library_script_uri_ = dj_last_script_src();
+}
+*/
+
+dojo.hostenv.defaultDebugContainerId = 'dojoDebug';
+dojo.hostenv._println_buffer = [];
+dojo.hostenv._println_safe = false;
+dojo.hostenv.println = function (line){
+ if(!dojo.hostenv._println_safe){
+ dojo.hostenv._println_buffer.push(line);
+ }else{
+ try {
+ var console = document.getElementById(djConfig.debugContainerId ?
+ djConfig.debugContainerId : dojo.hostenv.defaultDebugContainerId);
+ if(!console) { console = document.getElementsByTagName("body")[0] || document.body; }
+
+ var div = document.createElement("div");
+ div.appendChild(document.createTextNode(line));
+ console.appendChild(div);
+ } catch (e) {
+ try{
+ // safari needs the output wrapped in an element for some reason
+ document.write("<div>" + line + "</div>");
+ }catch(e2){
+ window.status = line;
+ }
+ }
+ }
+}
+
+dojo.addOnLoad(function(){
+ dojo.hostenv._println_safe = true;
+ while(dojo.hostenv._println_buffer.length > 0){
+ dojo.hostenv.println(dojo.hostenv._println_buffer.shift());
+ }
+});
+
+function dj_addNodeEvtHdlr (node, evtName, fp, capture){
+ var oldHandler = node["on"+evtName] || function(){};
+ node["on"+evtName] = function(){
+ fp.apply(node, arguments);
+ oldHandler.apply(node, arguments);
+ }
+ return true;
+}
+
+
+// dj_load_init should be called right after DOM is loaded and parsed. Needs testing.
+
+dj_load_init = function(){
+ // allow multiple calls, only first one will take effect
+ if (arguments.callee.initialized) return;
+ arguments.callee.initialized = true;
+
+ // perform initialization
+ if(dojo.render.html.ie){
+ dojo.hostenv.makeWidgets();
+ }
+ dojo.hostenv.modulesLoaded();
+};
+/*
+
+// Mozilla exposes the event we could use
+if (dojo.render.html.mozilla) {
+ document.addEventListener("DOMContentLoaded", dj_load_init, null);
+}
+
+// for Internet Explorer. readyState will not be achieved on init call, but dojo doesn't need it
+if (dojo.render.html.ie) {
+ document.write("<script defer>dj_load_init()<"+"/script>");
+}
+*/
+
+// default for other browsers
+// potential TODO: apply setTimeout approach for other browsers
+// that will cause flickering though ( document is loaded and THEN is processed)
+// maybe show/hide required in this case..
+// TODO: other browsers may support DOMContentLoaded/defer attribute. Add them to above.
+dj_addNodeEvtHdlr(window, "load", dj_load_init);
+
+
+
+dojo.hostenv.makeWidgets = function(){
+ // you can put searchIds in djConfig and dojo.hostenv at the moment
+ // we should probably eventually move to one or the other
+ var sids = [];
+ if(djConfig.searchIds && djConfig.searchIds.length > 0) {
+ sids = sids.concat(djConfig.searchIds);
+ }
+ if(dojo.hostenv.searchIds && dojo.hostenv.searchIds.length > 0) {
+ sids = sids.concat(dojo.hostenv.searchIds);
+ }
+
+ if((djConfig.parseWidgets)||(sids.length > 0)){
+ if(dojo.evalObjPath("dojo.widget.Parse")){
+ // we must do this on a delay to avoid:
+ // http://www.shaftek.org/blog/archives/000212.html
+ // IE is such a tremendous peice of shit.
+ try{
+ var parser = new dojo.xml.Parse();
+ if(sids.length > 0){
+ for(var x=0; x<sids.length; x++){
+ var tmpNode = document.getElementById(sids[x]);
+ if(!tmpNode){ continue; }
+ var frag = parser.parseElement(tmpNode, null, true);
+ dojo.widget.getParser().createComponents(frag);
+ }
+ }else if(djConfig.parseWidgets){
+ var frag = parser.parseElement(document.getElementsByTagName("body")[0] || document.body, null, true);
+ dojo.widget.getParser().createComponents(frag);
+ }
+ }catch(e){
+ dojo.debug("auto-build-widgets error:", e);
+ }
+ }
+ }
+}
+
+dojo.hostenv.modulesLoadedListeners.push(function(){
+ if(!dojo.render.html.ie) {
+ dojo.hostenv.makeWidgets();
+ }
+});
+
+try {
+ if (dojo.render.html.ie) {
+ // easier and safer VML addition. Thanks Emil!
+ document.namespaces.add("v", "urn:schemas-microsoft-com:vml");
+ document.createStyleSheet().addRule("v\\:*", "behavior:url(#default#VML)");
+ }
+} catch (e) { }
+
+// stub, over-ridden by debugging code. This will at least keep us from
+// breaking when it's not included
+dojo.hostenv.writeIncludes = function(){}
+
+dojo.hostenv.byId = dojo.byId = function(id, doc){
+ if(id && (typeof id == "string" || id instanceof String)){
+ if(!doc){ doc = document; }
+ return doc.getElementById(id);
+ }
+ return id; // assume it's a node
+}
+
+dojo.hostenv.byIdArray = dojo.byIdArray = function(){
+ var ids = [];
+ for(var i = 0; i < arguments.length; i++){
+ if((arguments[i] instanceof Array)||(typeof arguments[i] == "array")){
+ for(var j = 0; j < arguments[i].length; j++){
+ ids = ids.concat(dojo.hostenv.byIdArray(arguments[i][j]));
+ }
+ }else{
+ ids.push(dojo.hostenv.byId(arguments[i]));
+ }
+ }
+ return ids;
+}
Added: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_dashboard.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_dashboard.js?rev=385171&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_dashboard.js (added)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_dashboard.js Sat Mar 11 13:18:41 2006
@@ -0,0 +1,197 @@
+/*
+ Copyright (c) 2004-2005, 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.hostenv.name_ = "dashboard";
+
+dojo.hostenv.println = function(/*String*/ message){
+ // summary: Prints a message to the OS X console
+ return alert(message); // null
+}
+
+dojo.hostenv.getXmlhttpObject = function(/*Object*/ kwArgs){
+ // summary: Returns the appropriate transfer object for the call type
+ if(widget.system && kwArgs){
+ if((kwArgs.contentType && kwArgs.contentType.indexOf("text/") != 0) || (kwArgs.headers && kwArgs.headers["content-type"] && kwArgs.headers["content-type"].indexOf("text/") != 0)){
+ var curl = new dojo.hostenv.CurlRequest;
+ curl._save = true;
+ return curl;
+ }else if(kwArgs.method && kwArgs.method.toUpperCase() == "HEAD"){
+ return new dojo.hostenv.CurlRequest;
+ }else if(kwArgs.headers && kwArgs.header.referer){
+ return new dojo.hostenv.CurlRequest;
+ }
+ }
+ return new XMLHttpRequest; // XMLHttpRequest
+}
+
+dojo.hostenv.CurlRequest = function(){
+ // summary: Emulates the XMLHttpRequest Object
+ this.onreadystatechange = null;
+ this.readyState = 0;
+ this.responseText = "";
+ this.responseXML = null;
+ this.status = 0;
+ this.statusText = "";
+ this._method = "";
+ this._url = "";
+ this._async = true;
+ this._referrer = "";
+ this._headers = [];
+ this._save = false;
+ this._responseHeader = "";
+ this._responseHeaders = {};
+ this._fileName = "";
+ this._username = "";
+ this._password = "";
+}
+
+dojo.hostenv.CurlRequest.prototype.open = function(/*String*/ method, /*URL*/ url, /*Boolean?*/ async, /*String?*/ username, /*String?*/ password){
+ this._method = method;
+ this._url = url;
+ if(async){
+ this._async = async;
+ }
+ if(username){
+ this._username = username;
+ }
+ if(password){
+ this._password = password;
+ }
+}
+
+dojo.hostenv.CurlRequest.prototype.setRequestHeader = function(/*String*/ label, /*String*/ value){
+ switch(label){
+ case "Referer":
+ this._referrer = value;
+ break;
+ case "content-type":
+ break;
+ default:
+ this._headers.push(label + "=" + value);
+ break;
+ }
+}
+
+dojo.hostenv.CurlRequest.prototype.getAllResponseHeaders = function(){
+ return this._responseHeader; // String
+}
+
+dojo.hostenv.CurlRequest.prototype.getResponseHeader = function(/*String*/ headerLabel){
+ return this._responseHeaders[headerLabel]; // String
+}
+
+// -sS = Show only errors in errorString
+// -i = Display headers with return
+// -e = Referrer URI
+// -H = Headers
+// -d = data to be sent (forces POST)
+// -G = forces GET
+// -o = Writes to file (in the cache directory)
+// -I = Only load headers
+// -u = user:password
+dojo.hostenv.CurlRequest.prototype.send = function(/*String*/ content){
+ this.readyState = 1;
+ if(this.onreadystatechange){
+ this.onreadystatechange.call(this);
+ }
+ var query = {sS: ""};
+ if(this._referrer){
+ query.e = this._referrer;
+ }
+ if(this._headers.length){
+ query.H = this._headers.join("&");
+ }
+ if(this._username){
+ if(this._password){
+ query.u = this._username + ":" + this._password;
+ }else{
+ query.u = this._username;
+ }
+ }
+ if(content){
+ query.d = this.content;
+ if(this._method != "POST"){
+ query.G = "";
+ }
+ }
+ if(this._method == "HEAD"){
+ query.I = "";
+ }else{
+ if(this._save){
+ query.I = ""; // Get the headers in the initial query
+ }else{
+ query.i = "";
+ }
+ }
+
+ var system = widget.system(dojo.hostenv.CurlRequest._formatCall(query, this._url), null);
+ this.readyState = 2;
+ if(this.onreadystatechange){
+ this.onreadystatechange.call(this);
+ }
+ if(system.errorString){
+ this.responseText = system.errorString;
+ this.status = 0;
+ }else{
+ if(this._save){
+ this._responseHeader = system.outputString;
+ }else{
+ var split = system.outputString.replace(/\r/g, "").split("\n\n", 2);
+ this._responseHeader = split[0];
+ this.responseText = split[1];
+ }
+ split = this._responseHeader.split("\n");
+ this.statusText = split.shift();
+ this.status = this.statusText.split(" ")[1];
+ for(var i = 0, header; header = split[i]; i++){
+ var header_split = header.split(": ", 2);
+ this._responseHeaders[header_split[0]] = header_split[1];
+ }
+ if(this._save){
+ widget.system("/bin/mkdir cache", null);
+ // First, make a file name
+ this._fileName = this._url.split("/").pop().replace(/\W/g, "");
+ // Then, get its extension
+ this._fileName += "." + this._responseHeaders["Content-Type"].replace(/[\r\n]/g, "").split("/").pop()
+ delete query.I;
+ query.o = "cache/" + this._fileName; // Tell it where to be saved.
+ system = widget.system(dojo.hostenv.CurlRequest._formatCall(query, this._url), null);
+ if(!system.errorString){
+ this.responseText = "cache/" + this._fileName;
+ }
+ }else if(this._method == "HEAD"){
+ this.responseText = this._responseHeader;
+ }
+ }
+
+ this.readyState = 4;
+ if(this.onreadystatechange){
+ this.onreadystatechange.call(this);
+ }
+}
+
+dojo.hostenv.CurlRequest._formatCall = function(query, url){
+ var call = ["/usr/bin/curl"];
+ for(var key in query){
+ if(query[key] != ""){
+ call.push("-" + key + " '" + query[key].replace(/'/g, "\'") + "'");
+ }else{
+ call.push("-" + key);
+ }
+ }
+ call.push("'" + url.replace(/'/g, "\'") + "'");
+ return call.join(" ");
+}
+
+dojo.hostenv.exit = function(){
+ if(widget.system){
+ widget.system("/bin/rm -rf cache/*", null);
+ }
+}
\ No newline at end of file
Added: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_jsc.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_jsc.js?rev=385171&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_jsc.js (added)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_jsc.js Sat Mar 11 13:18:41 2006
@@ -0,0 +1,76 @@
+/*
+ Copyright (c) 2004-2005, 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
+*/
+
+/*
+ * JScript .NET jsc
+ *
+ */
+
+dojo.hostenv.name_ = 'jsc';
+
+// Sanity check this is the right hostenv.
+// See the Rotor source code jscript/engine/globalobject.cs for what globals
+// are available.
+if((typeof ScriptEngineMajorVersion != 'function')||(ScriptEngineMajorVersion() < 7)){
+ dj_throw("attempt to use JScript .NET host environment with inappropriate ScriptEngine");
+}
+
+// for more than you wanted to know about why this import is required even if
+// we fully qualify all symbols, see
+// http://groups.google.com/groups?th=f050c7aeefdcbde2&rnum=12
+import System;
+
+dojo.hostenv.getText = function(uri){
+ if(!System.IO.File.Exists(uri)){
+ // dj_throw("No such file '" + uri + "'");
+ return 0;
+ }
+ var reader = new System.IO.StreamReader(uri);
+ var contents : String = reader.ReadToEnd();
+ return contents;
+}
+
+dojo.hostenv.loadUri = function(uri){
+ var contents = this.getText(uri);
+ if(!contents){
+ dj_throw("got no back contents from uri '" + uri + "': " + contents);
+ }
+ // TODO: in JScript .NET, eval will not affect the symbol table of the current code?
+ var value = dj_eval(contents);
+ dojo.debug("jsc eval of contents returned: ", value);
+ return 1;
+
+ // for an example doing runtime code compilation, see:
+ // http://groups.google.com/groups?selm=eQ1aeciCBHA.1644%40tkmsftngp05&rnum=6
+ // Microsoft.JScript or System.CodeDom.Compiler ?
+ // var engine = new Microsoft.JScript.Vsa.VsaEngine()
+ // what about loading a js file vs. a dll?
+ // GetObject("script:" . uri);
+}
+
+/* The System.Environment object is useful:
+ print ("CommandLine='" + System.Environment.CommandLine + "' " +
+ "program name='" + System.Environment.GetCommandLineArgs()[0] + "' " +
+ "CurrentDirectory='" + System.Environment.CurrentDirectory + "' " +
+ "StackTrace='" + System.Environment.StackTrace + "'");
+*/
+
+// same as System.Console.WriteLine
+// sigh; Rotor treats symbol "print" at parse time without actually putting it
+// in the builtin symbol table.
+// Note that the print symbol is not available if jsc is run with the "/print-"
+// option.
+dojo.hostenv.println = function(s){
+ print(s); // = print
+}
+
+dojo.hostenv.getLibraryScriptUri = function(){
+ return System.Environment.GetCommandLineArgs()[0];
+}
Added: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_rhino.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_rhino.js?rev=385171&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_rhino.js (added)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_rhino.js Sat Mar 11 13:18:41 2006
@@ -0,0 +1,176 @@
+/*
+ Copyright (c) 2004-2005, 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
+*/
+
+/*
+* Rhino host environment
+*/
+
+// make jsc shut up (so we can use jsc for sanity checking)
+/*@cc_on
+@if (@_jscript_version >= 7)
+var loadClass; var print; var load; var quit; var version; var Packages; var java;
+@end
+@*/
+
+// TODO: not sure what we gain from the next line, anyone?
+//if (typeof loadClass == 'undefined') { dj_throw("attempt to use Rhino host environment when no 'loadClass' global"); }
+
+dojo.hostenv.name_ = 'rhino';
+dojo.hostenv.getVersion = function() {return version()};
+
+// see comments in spidermonkey loadUri
+dojo.hostenv.loadUri = function(uri, cb){
+ dojo.debug("uri: "+uri);
+ try{
+ // FIXME: what about remote URIs?
+ var found = true;
+ if(!(new java.io.File(uri)).exists()){
+ try{
+ // try it as a file first, URL second
+ (new java.io.URL(uri)).openStream();
+ }catch(e){
+ found = false;
+ }
+ }
+ if(!found){
+ dojo.debug(uri+" does not exist");
+ if(cb){ cb(0); }
+ return 0;
+ }
+ var ok = load(uri);
+ // dojo.debug(typeof ok);
+ dojo.debug("rhino load('", uri, "') returned. Ok: ", ok);
+ if(cb){ cb(1); }
+ return 1;
+ }catch(e){
+ dojo.debug("rhino load('", uri, "') failed");
+ if(cb){ cb(0); }
+ return 0;
+ }
+}
+
+dojo.hostenv.println = print;
+dojo.hostenv.exit = function(exitcode){
+ quit(exitcode);
+}
+
+// Hack to determine current script...
+//
+// These initial attempts failed:
+// 1. get an EcmaError and look at e.getSourceName(): try {eval ("static in return")} catch(e) { ...
+// Won't work because NativeGlobal.java only does a put of "name" and "message", not a wrapped reflecting object.
+// Even if the EcmaError object had the sourceName set.
+//
+// 2. var e = Packages.org.mozilla.javascript.Context.getCurrentContext().reportError('');
+// Won't work because it goes directly to the errorReporter, not the return value.
+// We want context.interpreterSourceFile and context.interpreterLine, which are used in static Context.getSourcePositionFromStack
+// (set by Interpreter.java at interpretation time, if in interpreter mode).
+//
+// 3. var e = Packages.org.mozilla.javascript.Context.getCurrentContext().reportRuntimeError('');
+// This returns an object, but e.message still does not have source info.
+// In compiler mode, perhaps not set; in interpreter mode, perhaps not used by errorReporter?
+//
+// What we found works is to do basically the same hack as is done in getSourcePositionFromStack,
+// making a new java.lang.Exception() and then calling printStackTrace on a string stream.
+// We have to parse the string for the .js files (different from the java files).
+// This only works however in compiled mode (-opt 0 or higher).
+// In interpreter mode, entire stack is java.
+// When compiled, printStackTrace is like:
+// java.lang.Exception
+// at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
+// at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
+// at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
+// at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
+// at org.mozilla.javascript.NativeJavaClass.constructSpecific(NativeJavaClass.java:228)
+// at org.mozilla.javascript.NativeJavaClass.construct(NativeJavaClass.java:185)
+// at org.mozilla.javascript.ScriptRuntime.newObject(ScriptRuntime.java:1269)
+// at org.mozilla.javascript.gen.c2.call(/Users/mda/Sites/burstproject/testrhino.js:27)
+// ...
+// at org.mozilla.javascript.tools.shell.Main.main(Main.java:76)
+//
+// Note may get different answers based on:
+// Context.setOptimizationLevel(-1)
+// Context.setGeneratingDebug(true)
+// Context.setGeneratingSource(true)
+//
+// Some somewhat helpful posts:
+// http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&selm=9v9n0g%246gr1%40ripley.netscape.com
+// http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&selm=3BAA2DC4.6010702%40atg.com
+//
+// Note that Rhino1.5R5 added source name information in some exceptions.
+// But this seems not to help in command-line Rhino, because Context.java has an error reporter
+// so no EvaluationException is thrown.
+
+// do it by using java java.lang.Exception
+function dj_rhino_current_script_via_java(depth) {
+ var optLevel = Packages.org.mozilla.javascript.Context.getCurrentContext().getOptimizationLevel();
+ if (optLevel == -1) dj_unimplemented("getCurrentScriptURI (determine current script path for rhino when interpreter mode)", '');
+ var caw = new java.io.CharArrayWriter();
+ var pw = new java.io.PrintWriter(caw);
+ var exc = new java.lang.Exception();
+ exc.printStackTrace(pw);
+ var s = caw.toString();
+ // we have to exclude the ones with or without line numbers because they put double entries in:
+ // at org.mozilla.javascript.gen.c3._c4(/Users/mda/Sites/burstproject/burst/Runtime.js:56)
+ // at org.mozilla.javascript.gen.c3.call(/Users/mda/Sites/burstproject/burst/Runtime.js)
+ var matches = s.match(/[^\(]*\.js\)/gi);
+ if(!matches){
+ throw Error("cannot parse printStackTrace output: " + s);
+ }
+
+ // matches[0] is entire string, matches[1] is this function, matches[2] is caller, ...
+ var fname = ((typeof depth != 'undefined')&&(depth)) ? matches[depth + 1] : matches[matches.length - 1];
+ var fname = matches[3];
+ if(!fname){ fname = matches[1]; }
+ // print("got fname '" + fname + "' from stack string '" + s + "'");
+ if (!fname) throw Error("could not find js file in printStackTrace output: " + s);
+ //print("Rhino getCurrentScriptURI returning '" + fname + "' from: " + s);
+ return fname;
+}
+
+// UNUSED: leverage new support in native exception for getSourceName
+/*
+function dj_rhino_current_script_via_eval_exception() {
+ var exc;
+ // 'ReferenceError: "undefinedsymbol" is not defined.'
+ try {eval ("undefinedsymbol()") } catch(e) {exc = e;}
+ // 'Error: whatever'
+ // try{throw Error("whatever");} catch(e) {exc = e;}
+ // 'SyntaxError: identifier is a reserved word'
+ // try {eval ("static in return")} catch(e) { exc = e; }
+ print("got exception: '" + exc + "'");
+ print("exc.stack=" + (typeof exc.stack));
+ var sn = exc.getSourceName();
+ print("SourceName=" + sn);
+ return sn;
+}
+*/
+
+// reading a file from disk in Java is a humiliating experience by any measure.
+// Lets avoid that and just get the freaking text
+function readText(uri){
+ // NOTE: we intentionally avoid handling exceptions, since the caller will
+ // want to know
+ var jf = new java.io.File(uri);
+ var sb = new java.lang.StringBuffer();
+ var input = new java.io.BufferedReader(new java.io.FileReader(jf));
+ var line = "";
+ while((line = input.readLine()) != null){
+ sb.append(line);
+ sb.append(java.lang.System.getProperty("line.separator"));
+ }
+ return sb.toString();
+}
+
+// call this now because later we may not be on the top of the stack
+if(!djConfig.libraryScriptUri.length){
+ djConfig.libraryScriptUri = dj_rhino_current_script_via_java(1);
+}
+
Added: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_spidermonkey.js
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_spidermonkey.js?rev=385171&view=auto
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_spidermonkey.js (added)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/html/dojo/src/hostenv_spidermonkey.js Sat Mar 11 13:18:41 2006
@@ -0,0 +1,80 @@
+/*
+ Copyright (c) 2004-2005, 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
+*/
+
+/*
+ * SpiderMonkey host environment
+ */
+
+dojo.hostenv.name_ = 'spidermonkey';
+
+dojo.hostenv.println = print;
+dojo.hostenv.exit = function(exitcode){
+ quit(exitcode);
+}
+
+// version() returns 0, sigh. and build() returns nothing but just prints.
+dojo.hostenv.getVersion = function(){ return version(); }
+
+// make jsc shut up (so we can use jsc for sanity checking)
+/*@cc_on
+@if (@_jscript_version >= 7)
+var line2pc; var print; var load; var quit;
+@end
+@*/
+
+if(typeof line2pc == 'undefined'){
+ dojo.raise("attempt to use SpiderMonkey host environment when no 'line2pc' global");
+}
+
+/*
+ * This is a hack that determines the current script file by parsing a generated
+ * stack trace (relying on the non-standard "stack" member variable of the
+ * SpiderMonkey Error object).
+ * If param depth is passed in, it'll return the script file which is that far down
+ * the stack, but that does require that you know how deep your stack is when you are
+ * calling.
+ */
+function dj_spidermonkey_current_file(depth){
+ var s = '';
+ try{
+ throw Error("whatever");
+ }catch(e){
+ s = e.stack;
+ }
+ // lines are like: bu_getCurrentScriptURI_spidermonkey("ScriptLoader.js")@burst/Runtime.js:101
+ var matches = s.match(/[^@]*\.js/gi);
+ if(!matches){
+ dojo.raise("could not parse stack string: '" + s + "'");
+ }
+ var fname = (typeof depth != 'undefined' && depth) ? matches[depth + 1] : matches[matches.length - 1];
+ if(!fname){
+ dojo.raise("could not find file name in stack string '" + s + "'");
+ }
+ //print("SpiderMonkeyRuntime got fname '" + fname + "' from stack string '" + s + "'");
+ return fname;
+}
+
+// call this now because later we may not be on the top of the stack
+//dojo.hostenv.getLibraryScriptUri = dj_spidermonkey_current_file;
+if(!dojo.hostenv.library_script_uri_){
+ dojo.hostenv.library_script_uri_ = dj_spidermonkey_current_file(0);
+}
+
+dojo.hostenv.loadUri = function(uri){
+ // spidermonkey load() evaluates the contents into the global scope (which
+ // is what we want).
+ // TODO: sigh, load() does not return a useful value.
+ // Perhaps it is returning the value of the last thing evaluated?
+ var ok = load(uri);
+ // dojo.debug("spidermonkey load(", uri, ") returned ", ok);
+ return 1;
+}
+
+
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org