Return-Path: Delivered-To: apmail-struts-commits-archive@locus.apache.org Received: (qmail 6865 invoked from network); 3 Mar 2007 05:54:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Mar 2007 05:54:26 -0000 Received: (qmail 54941 invoked by uid 500); 3 Mar 2007 05:51:17 -0000 Delivered-To: apmail-struts-commits-archive@struts.apache.org Received: (qmail 54895 invoked by uid 500); 3 Mar 2007 05:51:16 -0000 Mailing-List: contact commits-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list commits@struts.apache.org Received: (qmail 54875 invoked by uid 99); 3 Mar 2007 05:51:16 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Mar 2007 21:51:16 -0800 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Mar 2007 21:50:57 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 2C0A81A9873; Fri, 2 Mar 2007 21:49:51 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r514083 [16/49] - in /struts/struts2/trunk/plugins/dojo: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/struts2/ src/main/java/org/apache/struts2/components/ src/main/java/org/apache/s... Date: Sat, 03 Mar 2007 05:49:21 -0000 To: commits@struts.apache.org From: musachy@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070303054951.2C0A81A9873@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/flash/flash6/DojoExternalInterface.as URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/flash/flash6/DojoExternalInterface.as?view=auto&rev=514083 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/flash/flash6/DojoExternalInterface.as (added) +++ struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/flash/flash6/DojoExternalInterface.as Fri Mar 2 21:48:54 2007 @@ -0,0 +1,215 @@ +/* + 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 +*/ + +/** + An implementation of Flash 8's ExternalInterface that works with Flash 6 + and which is source-compatible with Flash 8. + + @author Brad Neuberg, bkn3@columbia.edu +*/ + +class DojoExternalInterface{ + public static var available:Boolean; + public static var dojoPath = ""; + + public static var _fscommandReady = false; + public static var _callbacks = new Array(); + + public static function initialize(){ + //getURL("javascript:dojo.debug('FLASH:DojoExternalInterface initialize')"); + // FIXME: Set available variable by testing for capabilities + DojoExternalInterface.available = true; + + // extract the dojo base path + DojoExternalInterface.dojoPath = DojoExternalInterface.getDojoPath(); + //getURL("javascript:dojo.debug('FLASH:dojoPath="+DojoExternalInterface.dojoPath+"')"); + + // Sometimes, on IE, the fscommand infrastructure can take a few hundred + // milliseconds the first time a page loads. Set a timer to keep checking + // to make sure we can issue fscommands; otherwise, our calls to fscommand + // for setCallback() and loaded() will just "disappear" + _root.fscommandReady = false; + var fsChecker = function(){ + // issue a test fscommand + fscommand("fscommandReady"); + + // JavaScript should set _root.fscommandReady if it got the call + if(_root.fscommandReady == "true"){ + DojoExternalInterface._fscommandReady = true; + clearInterval(_root.fsTimer); + } + }; + _root.fsTimer = setInterval(fsChecker, 100); + } + + public static function addCallback(methodName:String, instance:Object, + method:Function) : Boolean{ + // A variable that indicates whether the call below succeeded + _root._succeeded = null; + + // Callbacks are registered with the JavaScript side as follows. + // On the Flash side, we maintain a lookup table that associates + // the methodName with the actual instance and method that are + // associated with this method. + // Using fscommand, we send over the action "addCallback", with the + // argument being the methodName to add, such as "foobar". + // The JavaScript takes these values and registers the existence of + // this callback point. + + // precede the method name with a _ character in case it starts + // with a number + _callbacks["_" + methodName] = {_instance: instance, _method: method}; + _callbacks[_callbacks.length] = methodName; + + // The API for ExternalInterface says we have to make sure the call + // succeeded; check to see if there is a value + // for _succeeded, which is set by the JavaScript side + if(_root._succeeded == null){ + return false; + }else{ + return true; + } + } + + public static function call(methodName:String, + resultsCallback:Function) : Void{ + // FIXME: support full JSON serialization + + // First, we pack up all of the arguments to this call and set them + // as Flash variables, which the JavaScript side will unpack using + // plugin.GetVariable(). We set the number of arguments as "_numArgs", + // and add each argument as a variable, such as "_1", "_2", etc., starting + // from 0. + // We then execute an fscommand with the action "call" and the + // argument being the method name. JavaScript takes the method name, + // retrieves the arguments using GetVariable, executes the method, + // and then places the return result in a Flash variable + // named "_returnResult". + _root._numArgs = arguments.length - 2; + for(var i = 2; i < arguments.length; i++){ + var argIndex = i - 2; + _root["_" + argIndex] = arguments[i]; + } + + _root._returnResult = undefined; + fscommand("call", methodName); + + // immediately return if the caller is not waiting for return results + if(resultsCallback == undefined || resultsCallback == null){ + return; + } + + // check at regular intervals for return results + var resultsChecker = function(){ + if((typeof _root._returnResult != "undefined")&& + (_root._returnResult != "undefined")){ + clearInterval(_root._callbackID); + resultsCallback.call(null, _root._returnResult); + } + }; + _root._callbackID = setInterval(resultsChecker, 100); + } + + /** + Called by Flash to indicate to JavaScript that we are ready to have + our Flash functions called. Calling loaded() + will fire the dojo.flash.loaded() event, so that JavaScript can know that + Flash has finished loading and adding its callbacks, and can begin to + interact with the Flash file. + */ + public static function loaded(){ + //getURL("javascript:dojo.debug('FLASH:loaded')"); + + // one more step: see if fscommands are ready to be executed; if not, + // set an interval that will keep running until fscommands are ready; + // make sure the gateway is loaded as well + var execLoaded = function(){ + if(DojoExternalInterface._fscommandReady == true){ + clearInterval(_root.loadedInterval); + + // initialize the small Flash file that helps gateway JS to Flash + // calls + DojoExternalInterface._initializeFlashRunner(); + } + }; + + if(_fscommandReady == true){ + execLoaded(); + }else{ + _root.loadedInterval = setInterval(execLoaded, 50); + } + } + + /** + Handles and executes a JavaScript to Flash method call. Used by + initializeFlashRunner. + */ + public static function _handleJSCall(){ + // get our parameters + var numArgs = parseInt(_root._numArgs); + var jsArgs = new Array(); + for(var i = 0; i < numArgs; i++){ + var currentValue = _root["_" + i]; + jsArgs.push(currentValue); + } + + // get our function name + var functionName = _root._functionName; + + // now get the actual instance and method object to execute on, + // using our lookup table that was constructed by calls to + // addCallback on initialization + var instance = _callbacks["_" + functionName]._instance; + var method = _callbacks["_" + functionName]._method; + + // execute it + var results = method.apply(instance, jsArgs); + + // return the results + _root._returnResult = results; + } + + /** Called by the flash6_gateway.swf to indicate that it is loaded. */ + public static function _gatewayReady(){ + for(var i = 0; i < _callbacks.length; i++){ + fscommand("addCallback", _callbacks[i]); + } + call("dojo.flash.loaded"); + } + + /** + When JavaScript wants to communicate with Flash it simply sets + the Flash variable "_execute" to true; this method creates the + internal Movie Clip, called the Flash Runner, that makes this + magic happen. + */ + public static function _initializeFlashRunner(){ + // figure out where our Flash movie is + var swfLoc = DojoExternalInterface.dojoPath + "flash6_gateway.swf"; + + // load our gateway helper file + _root.createEmptyMovieClip("_flashRunner", 5000); + _root._flashRunner._lockroot = true; + _root._flashRunner.loadMovie(swfLoc); + } + + private static function getDojoPath(){ + var url = _root._url; + var start = url.indexOf("baseRelativePath=") + "baseRelativePath=".length; + var path = url.substring(start); + var end = path.indexOf("&"); + if(end != -1){ + path = path.substring(0, end); + } + return path; + } +} + +// vim:ts=4:noet:tw=0: Added: struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/flash/flash6/flash6_gateway.fla URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/flash/flash6/flash6_gateway.fla?view=auto&rev=514083 ============================================================================== Binary file - no diff available. Propchange: struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/flash/flash6/flash6_gateway.fla ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/flash/flash8/DojoExternalInterface.as URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/flash/flash8/DojoExternalInterface.as?view=auto&rev=514083 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/flash/flash8/DojoExternalInterface.as (added) +++ struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/flash/flash8/DojoExternalInterface.as Fri Mar 2 21:48:54 2007 @@ -0,0 +1,234 @@ +/* + 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 +*/ + +/** + A wrapper around Flash 8's ExternalInterface; DojoExternalInterface is needed so that we + can do a Flash 6 implementation of ExternalInterface, and be able + to support having a single codebase that uses DojoExternalInterface + across Flash versions rather than having two seperate source bases, + where one uses ExternalInterface and the other uses DojoExternalInterface. + + DojoExternalInterface class does a variety of optimizations to bypass ExternalInterface's + unbelievably bad performance so that we can have good performance + on Safari; see the blog post + http://codinginparadise.org/weblog/2006/02/how-to-speed-up-flash-8s.html + for details. + + @author Brad Neuberg, bkn3@columbia.edu +*/ +import flash.external.ExternalInterface; + +class DojoExternalInterface{ + public static var available:Boolean; + public static var dojoPath = ""; + + private static var flashMethods:Array = new Array(); + private static var numArgs:Number; + private static var argData:Array; + private static var resultData = null; + + public static function initialize(){ + // extract the dojo base path + DojoExternalInterface.dojoPath = DojoExternalInterface.getDojoPath(); + + // see if we need to do an express install + var install:ExpressInstall = new ExpressInstall(); + if(install.needsUpdate){ + install.init(); + } + + // register our callback functions + ExternalInterface.addCallback("startExec", DojoExternalInterface, startExec); + ExternalInterface.addCallback("setNumberArguments", DojoExternalInterface, + setNumberArguments); + ExternalInterface.addCallback("chunkArgumentData", DojoExternalInterface, + chunkArgumentData); + ExternalInterface.addCallback("exec", DojoExternalInterface, exec); + ExternalInterface.addCallback("getReturnLength", DojoExternalInterface, + getReturnLength); + ExternalInterface.addCallback("chunkReturnData", DojoExternalInterface, + chunkReturnData); + ExternalInterface.addCallback("endExec", DojoExternalInterface, endExec); + + // set whether communication is available + DojoExternalInterface.available = ExternalInterface.available; + DojoExternalInterface.call("loaded"); + } + + public static function addCallback(methodName:String, instance:Object, + method:Function) : Boolean{ + // register DojoExternalInterface methodName with it's instance + DojoExternalInterface.flashMethods[methodName] = instance; + + // tell JavaScript about DojoExternalInterface new method so we can create a proxy + ExternalInterface.call("dojo.flash.comm._addExternalInterfaceCallback", + methodName); + + return true; + } + + public static function call(methodName:String, + resultsCallback:Function) : Void{ + // we might have any number of optional arguments, so we have to + // pass them in dynamically; strip out the results callback + var parameters = new Array(); + for(var i = 0; i < arguments.length; i++){ + if(i != 1){ // skip the callback + parameters.push(arguments[i]); + } + } + + var results = ExternalInterface.call.apply(ExternalInterface, parameters); + + // immediately give the results back, since ExternalInterface is + // synchronous + if(resultsCallback != null && typeof resultsCallback != "undefined"){ + resultsCallback.call(null, results); + } + } + + /** + Called by Flash to indicate to JavaScript that we are ready to have + our Flash functions called. Calling loaded() + will fire the dojo.flash.loaded() event, so that JavaScript can know that + Flash has finished loading and adding its callbacks, and can begin to + interact with the Flash file. + */ + public static function loaded(){ + DojoExternalInterface.call("dojo.flash.loaded"); + } + + public static function startExec():Void{ + DojoExternalInterface.numArgs = null; + DojoExternalInterface.argData = null; + DojoExternalInterface.resultData = null; + } + + public static function setNumberArguments(numArgs):Void{ + DojoExternalInterface.numArgs = numArgs; + DojoExternalInterface.argData = new Array(DojoExternalInterface.numArgs); + } + + public static function chunkArgumentData(value, argIndex:Number):Void{ + //getURL("javascript:dojo.debug('FLASH: chunkArgumentData, value="+value+", argIndex="+argIndex+"')"); + var currentValue = DojoExternalInterface.argData[argIndex]; + if(currentValue == null || typeof currentValue == "undefined"){ + DojoExternalInterface.argData[argIndex] = value; + }else{ + DojoExternalInterface.argData[argIndex] += value; + } + } + + public static function exec(methodName):Void{ + // decode all of the arguments that were passed in + for(var i = 0; i < DojoExternalInterface.argData.length; i++){ + DojoExternalInterface.argData[i] = + DojoExternalInterface.decodeData(DojoExternalInterface.argData[i]); + } + + var instance = DojoExternalInterface.flashMethods[methodName]; + DojoExternalInterface.resultData = instance[methodName].apply( + instance, DojoExternalInterface.argData); + // encode the result data + DojoExternalInterface.resultData = + DojoExternalInterface.encodeData(DojoExternalInterface.resultData); + + //getURL("javascript:dojo.debug('FLASH: encoded result data="+DojoExternalInterface.resultData+"')"); + } + + public static function getReturnLength():Number{ + if(DojoExternalInterface.resultData == null || + typeof DojoExternalInterface.resultData == "undefined"){ + return 0; + } + var segments = Math.ceil(DojoExternalInterface.resultData.length / 1024); + return segments; + } + + public static function chunkReturnData(segment:Number):String{ + var numSegments = DojoExternalInterface.getReturnLength(); + var startCut = segment * 1024; + var endCut = segment * 1024 + 1024; + if(segment == (numSegments - 1)){ + endCut = segment * 1024 + DojoExternalInterface.resultData.length; + } + + var piece = DojoExternalInterface.resultData.substring(startCut, endCut); + + //getURL("javascript:dojo.debug('FLASH: chunking return piece="+piece+"')"); + + return piece; + } + + public static function endExec():Void{ + } + + private static function decodeData(data):String{ + // we have to use custom encodings for certain characters when passing + // them over; for example, passing a backslash over as //// from JavaScript + // to Flash doesn't work + data = DojoExternalInterface.replaceStr(data, "&custom_backslash;", "\\"); + + data = DojoExternalInterface.replaceStr(data, "\\\'", "\'"); + data = DojoExternalInterface.replaceStr(data, "\\\"", "\""); + + return data; + } + + private static function encodeData(data){ + //getURL("javascript:dojo.debug('inside flash, data before="+data+"')"); + + // double encode all entity values, or they will be mis-decoded + // by Flash when returned + data = DojoExternalInterface.replaceStr(data, "&", "&"); + + // certain XMLish characters break Flash's wire serialization for + // ExternalInterface; encode these into a custom encoding, rather than + // the standard entity encoding, because otherwise we won't be able to + // differentiate between our own encoding and any entity characters + // that are being used in the string itself + data = DojoExternalInterface.replaceStr(data, '<', '&custom_lt;'); + data = DojoExternalInterface.replaceStr(data, '>', '&custom_gt;'); + + // encode control characters and JavaScript delimiters + data = DojoExternalInterface.replaceStr(data, "\n", "\\n"); + data = DojoExternalInterface.replaceStr(data, "\r", "\\r"); + data = DojoExternalInterface.replaceStr(data, "\f", "\\f"); + data = DojoExternalInterface.replaceStr(data, "'", "\\'"); + data = DojoExternalInterface.replaceStr(data, '"', '\"'); + + //getURL("javascript:dojo.debug('inside flash, data after="+data+"')"); + return data; + } + + /** + Flash ActionScript has no String.replace method or support for + Regular Expressions! We roll our own very simple one. + */ + private static function replaceStr(inputStr:String, replaceThis:String, + withThis:String):String { + var splitStr = inputStr.split(replaceThis) + inputStr = splitStr.join(withThis) + return inputStr; + } + + private static function getDojoPath(){ + var url = _root._url; + var start = url.indexOf("baseRelativePath=") + "baseRelativePath=".length; + var path = url.substring(start); + var end = path.indexOf("&"); + if(end != -1){ + path = path.substring(0, end); + } + return path; + } +} + +// vim:ts=4:noet:tw=0: Added: struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/flash/flash8/ExpressInstall.as URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/flash/flash8/ExpressInstall.as?view=auto&rev=514083 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/flash/flash8/ExpressInstall.as (added) +++ struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/flash/flash8/ExpressInstall.as Fri Mar 2 21:48:54 2007 @@ -0,0 +1,81 @@ +/* + 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 +*/ + +/** + * Based on the expressinstall.as class created by Geoff Stearns as part + * of the FlashObject library. + * + * Use this file to invoke the Macromedia Flash Player Express Install functionality + * This file is intended for use with the FlashObject embed script. You can download FlashObject + * and this file at the following URL: http://blog.deconcept.com/flashobject/ + * + * Usage: + * var ExpressInstall = new ExpressInstall(); + * + * // test to see if install is needed: + * if (ExpressInstall.needsUpdate) { // returns true if update is needed + * ExpressInstall.init(); // starts the update + * } + * + * NOTE: Your Flash movie must be at least 214px by 137px in order to use ExpressInstall. + * + */ + +class ExpressInstall { + public var needsUpdate:Boolean; + private var updater:MovieClip; + private var hold:MovieClip; + + public function ExpressInstall(){ + // does the user need to update? + this.needsUpdate = (_root.MMplayerType == undefined) ? false : true; + } + + public function init():Void{ + this.loadUpdater(); + } + + public function loadUpdater():Void { + System.security.allowDomain("fpdownload.macromedia.com"); + + // hope that nothing is at a depth of 10000000, you can change this depth if needed, but you want + // it to be on top of your content if you have any stuff on the first frame + this.updater = _root.createEmptyMovieClip("expressInstallHolder", 10000000); + + // register the callback so we know if they cancel or there is an error + var _self = this; + this.updater.installStatus = _self.onInstallStatus; + this.hold = this.updater.createEmptyMovieClip("hold", 1); + + // can't use movieClipLoader because it has to work in 6.0.65 + this.updater.onEnterFrame = function():Void { + if(typeof this.hold.startUpdate == 'function'){ + _self.initUpdater(); + this.onEnterFrame = null; + } + } + + var cacheBuster:Number = Math.random(); + + this.hold.loadMovie("http://fpdownload.macromedia.com/pub/flashplayer/" + +"update/current/swf/autoUpdater.swf?"+ cacheBuster); + } + + private function initUpdater():Void{ + this.hold.redirectURL = _root.MMredirectURL; + this.hold.MMplayerType = _root.MMplayerType; + this.hold.MMdoctitle = _root.MMdoctitle; + this.hold.startUpdate(); + } + + public function onInstallStatus(msg):Void{ + getURL("javascript:dojo.flash.install._onInstallStatus('"+msg+"')"); + } +} Added: struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/fx/__package__.js URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/fx/__package__.js?view=auto&rev=514083 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/fx/__package__.js (added) +++ struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/fx/__package__.js Fri Mar 2 21:48:54 2007 @@ -0,0 +1,14 @@ +/* + 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.fx.html"] +}); +dojo.hostenv.moduleLoaded("dojo.fx.*"); Added: struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/fx/html.js URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/fx/html.js?view=auto&rev=514083 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/fx/html.js (added) +++ struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/fx/html.js Fri Mar 2 21:48:54 2007 @@ -0,0 +1,565 @@ +/* + 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.fx.html"); + +dojo.require("dojo.html"); +dojo.require("dojo.style"); +dojo.require("dojo.lang"); +dojo.require("dojo.animation.*"); +dojo.require("dojo.event.*"); +dojo.require("dojo.graphics.color"); + +dojo.fx.duration = 500; + +dojo.fx.html._makeFadeable = function(node){ + if(dojo.render.html.ie){ + // only set the zoom if the "tickle" value would be the same as the + // default + if( (node.style.zoom.length == 0) && + (dojo.style.getStyle(node, "zoom") == "normal") ){ + // make sure the node "hasLayout" + // NOTE: this has been tested with larger and smaller user-set text + // sizes and works fine + node.style.zoom = "1"; + // node.style.zoom = "normal"; + } + // don't set the width to auto if it didn't already cascade that way. + // We don't want to f anyones designs + if( (node.style.width.length == 0) && + (dojo.style.getStyle(node, "width") == "auto") ){ + node.style.width = "auto"; + } + } +} + +dojo.fx.html.fadeOut = function(node, duration, callback, dontPlay) { + return dojo.fx.html.fade(node, duration, dojo.style.getOpacity(node), 0, callback, dontPlay); +}; + +dojo.fx.html.fadeIn = function(node, duration, callback, dontPlay) { + return dojo.fx.html.fade(node, duration, dojo.style.getOpacity(node), 1, callback, dontPlay); +}; + +dojo.fx.html.fadeHide = function(node, duration, callback, dontPlay) { + node = dojo.byId(node); + if(!duration) { duration = 150; } // why not have a default? + return dojo.fx.html.fadeOut(node, duration, function(node) { + node.style.display = "none"; + if(typeof callback == "function") { callback(node); } + }); +}; + +dojo.fx.html.fadeShow = function(node, duration, callback, dontPlay) { + node = dojo.byId(node); + if(!duration) { duration = 150; } // why not have a default? + node.style.display = "block"; + return dojo.fx.html.fade(node, duration, 0, 1, callback, dontPlay); +}; + +dojo.fx.html.fade = function(node, duration, startOpac, endOpac, callback, dontPlay) { + node = dojo.byId(node); + dojo.fx.html._makeFadeable(node); + var anim = new dojo.animation.Animation( + new dojo.math.curves.Line([startOpac],[endOpac]), + duration||dojo.fx.duration, 0); + dojo.event.connect(anim, "onAnimate", function(e) { + dojo.style.setOpacity(node, e.x); + }); + if(callback) { + dojo.event.connect(anim, "onEnd", function(e) { + callback(node, anim); + }); + } + if(!dontPlay) { anim.play(true); } + return anim; +}; + +dojo.fx.html.slideTo = function(node, duration, endCoords, callback, dontPlay) { + if(!dojo.lang.isNumber(duration)) { + var tmp = duration; + duration = endCoords; + endCoords = tmp; + } + node = dojo.byId(node); + + var top = node.offsetTop; + var left = node.offsetLeft; + var pos = dojo.style.getComputedStyle(node, 'position'); + + if (pos == 'relative' || pos == 'static') { + top = parseInt(dojo.style.getComputedStyle(node, 'top')) || 0; + left = parseInt(dojo.style.getComputedStyle(node, 'left')) || 0; + } + + return dojo.fx.html.slide(node, duration, [left, top], + endCoords, callback, dontPlay); +}; + +dojo.fx.html.slideBy = function(node, duration, coords, callback, dontPlay) { + if(!dojo.lang.isNumber(duration)) { + var tmp = duration; + duration = coords; + coords = tmp; + } + node = dojo.byId(node); + + var top = node.offsetTop; + var left = node.offsetLeft; + var pos = dojo.style.getComputedStyle(node, 'position'); + + if (pos == 'relative' || pos == 'static') { + top = parseInt(dojo.style.getComputedStyle(node, 'top')) || 0; + left = parseInt(dojo.style.getComputedStyle(node, 'left')) || 0; + } + + return dojo.fx.html.slideTo(node, duration, [left+coords[0], top+coords[1]], + callback, dontPlay); +}; + +dojo.fx.html.slide = function(node, duration, startCoords, endCoords, callback, dontPlay) { + if(!dojo.lang.isNumber(duration)) { + var tmp = duration; + duration = endCoords; + endCoords = startCoords; + startCoords = tmp; + } + node = dojo.byId(node); + + if (dojo.style.getComputedStyle(node, 'position') == 'static') { + node.style.position = 'relative'; + } + + var anim = new dojo.animation.Animation( + new dojo.math.curves.Line(startCoords, endCoords), + duration||dojo.fx.duration, 0); + dojo.event.connect(anim, "onAnimate", function(e) { + with( node.style ) { + left = e.x + "px"; + top = e.y + "px"; + } + }); + if(callback) { + dojo.event.connect(anim, "onEnd", function(e) { + callback(node, anim); + }); + } + if(!dontPlay) { anim.play(true); } + return anim; +}; + +// Fade from startColor to the node's background color +dojo.fx.html.colorFadeIn = function(node, duration, startColor, delay, callback, dontPlay) { + if(!dojo.lang.isNumber(duration)) { + var tmp = duration; + duration = startColor; + startColor = tmp; + } + node = dojo.byId(node); + var color = dojo.html.getBackgroundColor(node); + var bg = dojo.style.getStyle(node, "background-color").toLowerCase(); + var wasTransparent = bg == "transparent" || bg == "rgba(0, 0, 0, 0)"; + while(color.length > 3) { color.pop(); } + + var rgb = new dojo.graphics.color.Color(startColor).toRgb(); + var anim = dojo.fx.html.colorFade(node, duration||dojo.fx.duration, startColor, color, callback, true); + dojo.event.connect(anim, "onEnd", function(e) { + if( wasTransparent ) { + node.style.backgroundColor = "transparent"; + } + }); + if( delay > 0 ) { + node.style.backgroundColor = "rgb(" + rgb.join(",") + ")"; + if(!dontPlay) { setTimeout(function(){anim.play(true)}, delay); } + } else { + if(!dontPlay) { anim.play(true); } + } + return anim; +}; +// alias for (probably?) common use/terminology +dojo.fx.html.highlight = dojo.fx.html.colorFadeIn; +dojo.fx.html.colorFadeFrom = dojo.fx.html.colorFadeIn; + +// Fade from node's background color to endColor +dojo.fx.html.colorFadeOut = function(node, duration, endColor, delay, callback, dontPlay) { + if(!dojo.lang.isNumber(duration)) { + var tmp = duration; + duration = endColor; + endColor = tmp; + } + node = dojo.byId(node); + var color = new dojo.graphics.color.Color(dojo.html.getBackgroundColor(node)).toRgb(); + + var rgb = new dojo.graphics.color.Color(endColor).toRgb(); + var anim = dojo.fx.html.colorFade(node, duration||dojo.fx.duration, color, rgb, callback, delay > 0 || dontPlay); + if( delay > 0 ) { + node.style.backgroundColor = "rgb(" + color.join(",") + ")"; + if(!dontPlay) { setTimeout(function(){anim.play(true)}, delay); } + } + return anim; +}; +// FIXME: not sure which name is better. an alias here may be bad. +dojo.fx.html.unhighlight = dojo.fx.html.colorFadeOut; +dojo.fx.html.colorFadeTo = dojo.fx.html.colorFadeOut; + +// Fade node background from startColor to endColor +dojo.fx.html.colorFade = function(node, duration, startColor, endColor, callback, dontPlay) { + if(!dojo.lang.isNumber(duration)) { + var tmp = duration; + duration = endColor; + endColor = startColor; + startColor = tmp; + } + node = dojo.byId(node); + var startRgb = new dojo.graphics.color.Color(startColor).toRgb(); + var endRgb = new dojo.graphics.color.Color(endColor).toRgb(); + var anim = new dojo.animation.Animation( + new dojo.math.curves.Line(startRgb, endRgb), + duration||dojo.fx.duration, 0); + dojo.event.connect(anim, "onAnimate", function(e) { + node.style.backgroundColor = "rgb(" + e.coordsAsInts().join(",") + ")"; + }); + if(callback) { + dojo.event.connect(anim, "onEnd", function(e) { + callback(node, anim); + }); + } + if( !dontPlay ) { anim.play(true); } + return anim; +}; + +dojo.fx.html.wipeShow = function(node, duration, callback, dontPlay) { + node = dojo.byId(node); + var overflow = dojo.html.getStyle(node, "overflow"); + node.style.overflow = "hidden"; + node.style.height = 0; + dojo.html.show(node); + var anim = new dojo.animation.Animation([[0], [node.scrollHeight]], duration||dojo.fx.duration, 0); + dojo.event.connect(anim, "onAnimate", function(e) { + node.style.height = e.x + "px"; + }); + dojo.event.connect(anim, "onEnd", function() { + node.style.overflow = overflow; + node.style.height = "auto"; + if(callback) { callback(node, anim); } + }); + if(!dontPlay) { anim.play(); } + return anim; +} + +dojo.fx.html.wipeHide = function(node, duration, callback, dontPlay) { + node = dojo.byId(node); + var overflow = dojo.html.getStyle(node, "overflow"); + node.style.overflow = "hidden"; + var anim = new dojo.animation.Animation([[node.offsetHeight], [0]], duration||dojo.fx.duration, 0); + dojo.event.connect(anim, "onAnimate", function(e) { + node.style.height = e.x + "px"; + }); + dojo.event.connect(anim, "onEnd", function() { + node.style.overflow = overflow; + dojo.html.hide(node); + if(callback) { callback(node, anim); } + }); + if(!dontPlay) { anim.play(); } + return anim; +} + +dojo.fx.html.wiper = function(node, controlNode) { + this.node = dojo.byId(node); + if(controlNode) { + dojo.event.connect(dojo.byId(controlNode), "onclick", this, "toggle"); + } +} +dojo.lang.extend(dojo.fx.html.wiper, { + duration: dojo.fx.duration, + _anim: null, + + toggle: function() { + if(!this._anim) { + var type = "wipe" + (dojo.html.isVisible(this.node) ? "Hide" : "Show"); + this._anim = dojo.fx[type](this.node, this.duration, dojo.lang.hitch(this, "_callback")); + } + }, + + _callback: function() { + this._anim = null; + } +}); + +dojo.fx.html.wipeIn = function(node, duration, callback, dontPlay) { + node = dojo.byId(node); + var savedHeight = dojo.html.getStyle(node, "height"); + dojo.html.show(node); + var height = node.offsetHeight; + var anim = dojo.fx.html.wipeInToHeight(node, duration, height, function(e) { + node.style.height = savedHeight || "auto"; + if(callback) { callback(node, anim); } + }, dontPlay); +}; + +dojo.fx.html.wipeInToHeight = function(node, duration, height, callback, dontPlay) { + node = dojo.byId(node); + var savedOverflow = dojo.html.getStyle(node, "overflow"); + // FIXME: should we be setting display to something other than "" for the table elements? + node.style.height = "0px"; + node.style.display = "none"; + if(savedOverflow == "visible") { + node.style.overflow = "hidden"; + } + var dispType = dojo.lang.inArray(node.tagName.toLowerCase(), ['tr', 'td', 'th']) ? "" : "block"; + node.style.display = dispType; + + var anim = new dojo.animation.Animation( + new dojo.math.curves.Line([0], [height]), + duration||dojo.fx.duration, 0); + dojo.event.connect(anim, "onAnimate", function(e) { + node.style.height = Math.round(e.x) + "px"; + }); + dojo.event.connect(anim, "onEnd", function(e) { + if(savedOverflow != "visible") { + node.style.overflow = savedOverflow; + } + if(callback) { callback(node, anim); } + }); + if( !dontPlay ) { anim.play(true); } + return anim; +} + +dojo.fx.html.wipeOut = function(node, duration, callback, dontPlay) { + node = dojo.byId(node); + var savedOverflow = dojo.html.getStyle(node, "overflow"); + var savedHeight = dojo.html.getStyle(node, "height"); + var height = node.offsetHeight; + node.style.overflow = "hidden"; + + var anim = new dojo.animation.Animation( + new dojo.math.curves.Line([height], [0]), + duration||dojo.fx.duration, 0); + dojo.event.connect(anim, "onAnimate", function(e) { + node.style.height = Math.round(e.x) + "px"; + }); + dojo.event.connect(anim, "onEnd", function(e) { + node.style.display = "none"; + node.style.overflow = savedOverflow; + node.style.height = savedHeight || "auto"; + if(callback) { callback(node, anim); } + }); + if( !dontPlay ) { anim.play(true); } + return anim; +}; + +dojo.fx.html.explode = function(start, endNode, duration, callback, dontPlay) { + var startCoords = dojo.html.toCoordinateArray(start); + + var outline = document.createElement("div"); + with(outline.style) { + position = "absolute"; + border = "1px solid black"; + display = "none"; + } + dojo.html.body().appendChild(outline); + + endNode = dojo.byId(endNode); + with(endNode.style) { + visibility = "hidden"; + display = "block"; + } + var endCoords = dojo.html.toCoordinateArray(endNode); + + with(endNode.style) { + display = "none"; + visibility = "visible"; + } + + var anim = new dojo.animation.Animation( + new dojo.math.curves.Line(startCoords, endCoords), + duration||dojo.fx.duration, 0 + ); + dojo.event.connect(anim, "onBegin", function(e) { + outline.style.display = "block"; + }); + dojo.event.connect(anim, "onAnimate", function(e) { + with(outline.style) { + left = e.x + "px"; + top = e.y + "px"; + width = e.coords[2] + "px"; + height = e.coords[3] + "px"; + } + }); + + dojo.event.connect(anim, "onEnd", function() { + endNode.style.display = "block"; + outline.parentNode.removeChild(outline); + if(callback) { callback(endNode, anim); } + }); + if(!dontPlay) { anim.play(); } + return anim; +}; + +dojo.fx.html.implode = function(startNode, end, duration, callback, dontPlay) { + var startCoords = dojo.html.toCoordinateArray(startNode); + var endCoords = dojo.html.toCoordinateArray(end); + + startNode = dojo.byId(startNode); + var outline = document.createElement("div"); + with(outline.style) { + position = "absolute"; + border = "1px solid black"; + display = "none"; + } + dojo.html.body().appendChild(outline); + + var anim = new dojo.animation.Animation( + new dojo.math.curves.Line(startCoords, endCoords), + duration||dojo.fx.duration, 0 + ); + dojo.event.connect(anim, "onBegin", function(e) { + startNode.style.display = "none"; + outline.style.display = "block"; + }); + dojo.event.connect(anim, "onAnimate", function(e) { + with(outline.style) { + left = e.x + "px"; + top = e.y + "px"; + width = e.coords[2] + "px"; + height = e.coords[3] + "px"; + } + }); + + dojo.event.connect(anim, "onEnd", function() { + outline.parentNode.removeChild(outline); + if(callback) { callback(startNode, anim); } + }); + if(!dontPlay) { anim.play(); } + return anim; +}; + +dojo.fx.html.Exploder = function(triggerNode, boxNode) { + triggerNode = dojo.byId(triggerNode); + boxNode = dojo.byId(boxNode); + var _this = this; + + // custom options + this.waitToHide = 500; + this.timeToShow = 100; + this.waitToShow = 200; + this.timeToHide = 70; + this.autoShow = false; + this.autoHide = false; + + var animShow = null; + var animHide = null; + + var showTimer = null; + var hideTimer = null; + + var startCoords = null; + var endCoords = null; + + this.showing = false; + + this.onBeforeExplode = null; + this.onAfterExplode = null; + this.onBeforeImplode = null; + this.onAfterImplode = null; + this.onExploding = null; + this.onImploding = null; + + this.timeShow = function() { + clearTimeout(showTimer); + showTimer = setTimeout(_this.show, _this.waitToShow); + } + + this.show = function() { + clearTimeout(showTimer); + clearTimeout(hideTimer); + //triggerNode.blur(); + + if( (animHide && animHide.status() == "playing") + || (animShow && animShow.status() == "playing") + || _this.showing ) { return; } + + if(typeof _this.onBeforeExplode == "function") { _this.onBeforeExplode(triggerNode, boxNode); } + animShow = dojo.fx.html.explode(triggerNode, boxNode, _this.timeToShow, function(e) { + _this.showing = true; + if(typeof _this.onAfterExplode == "function") { _this.onAfterExplode(triggerNode, boxNode); } + }); + if(typeof _this.onExploding == "function") { + dojo.event.connect(animShow, "onAnimate", this, "onExploding"); + } + } + + this.timeHide = function() { + clearTimeout(showTimer); + clearTimeout(hideTimer); + if(_this.showing) { + hideTimer = setTimeout(_this.hide, _this.waitToHide); + } + } + + this.hide = function() { + clearTimeout(showTimer); + clearTimeout(hideTimer); + if( animShow && animShow.status() == "playing" ) { + return; + } + + _this.showing = false; + if(typeof _this.onBeforeImplode == "function") { _this.onBeforeImplode(triggerNode, boxNode); } + animHide = dojo.fx.html.implode(boxNode, triggerNode, _this.timeToHide, function(e){ + if(typeof _this.onAfterImplode == "function") { _this.onAfterImplode(triggerNode, boxNode); } + }); + if(typeof _this.onImploding == "function") { + dojo.event.connect(animHide, "onAnimate", this, "onImploding"); + } + } + + // trigger events + dojo.event.connect(triggerNode, "onclick", function(e) { + if(_this.showing) { + _this.hide(); + } else { + _this.show(); + } + }); + dojo.event.connect(triggerNode, "onmouseover", function(e) { + if(_this.autoShow) { + _this.timeShow(); + } + }); + dojo.event.connect(triggerNode, "onmouseout", function(e) { + if(_this.autoHide) { + _this.timeHide(); + } + }); + + // box events + dojo.event.connect(boxNode, "onmouseover", function(e) { + clearTimeout(hideTimer); + }); + dojo.event.connect(boxNode, "onmouseout", function(e) { + if(_this.autoHide) { + _this.timeHide(); + } + }); + + // document events + dojo.event.connect(document.documentElement || dojo.html.body(), "onclick", function(e) { + if(_this.autoHide && _this.showing + && !dojo.dom.isDescendantOf(e.target, boxNode) + && !dojo.dom.isDescendantOf(e.target, triggerNode) ) { + _this.hide(); + } + }); + + return this; +}; + +dojo.lang.mixin(dojo.fx, dojo.fx.html); Added: struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/fx/svg.js URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/fx/svg.js?view=auto&rev=514083 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/fx/svg.js (added) +++ struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/fx/svg.js Fri Mar 2 21:48:54 2007 @@ -0,0 +1,100 @@ +/* + 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.fx.svg"); + +dojo.require("dojo.svg"); +dojo.require("dojo.lang"); +dojo.require("dojo.animation.*"); +dojo.require("dojo.event.*"); + +dojo.fx.svg.fadeOut = function(node, duration, callback){ + return dojo.fx.svg.fade(node, duration, dojo.svg.getOpacity(node), 0, callback); +}; +dojo.fx.svg.fadeIn = function(node, duration, callback){ + return dojo.fx.svg.fade(node, duration, dojo.svg.getOpacity(node), 1, callback); +}; +dojo.fx.svg.fadeHide = function(node, duration, callback){ + if(!duration) { duration = 150; } // why not have a default? + return dojo.fx.svg.fadeOut(node, duration, function(node) { + if(typeof callback == "function") { callback(node); } + }); +}; +dojo.fx.svg.fadeShow = function(node, duration, callback){ + if(!duration) { duration = 150; } // why not have a default? + return dojo.fx.svg.fade(node, duration, 0, 1, callback); +}; +dojo.fx.svg.fade = function(node, duration, startOpac, endOpac, callback){ + var anim = new dojo.animation.Animation( + new dojo.math.curves.Line([startOpac],[endOpac]), + duration, + 0 + ); + dojo.event.connect(anim, "onAnimate", function(e){ + dojo.svg.setOpacity(node, e.x); + }); + if (callback) { + dojo.event.connect(anim, "onEnd", function(e){ + callback(node, anim); + }); + }; + anim.play(true); + return anim; +}; + +///////////////////////////////////////////////////////////////////////////////////////// +// TODO +///////////////////////////////////////////////////////////////////////////////////////// + +// SLIDES +dojo.fx.svg.slideTo = function(node, endCoords, duration, callback) { }; +dojo.fx.svg.slideBy = function(node, coords, duration, callback) { }; +dojo.fx.svg.slide = function(node, startCoords, endCoords, duration, callback) { + var anim = new dojo.animation.Animation( + new dojo.math.curves.Line([startCoords],[endCoords]), + duration, + 0 + ); + dojo.event.connect(anim, "onAnimate", function(e){ + dojo.svg.setCoords(node, {x: e.x, y: e.y }); + }); + if (callback) { + dojo.event.connect(anim, "onEnd", function(e){ + callback(node, anim); + }); + }; + anim.play(true); + return anim; +}; + +// COLORS +dojo.fx.svg.colorFadeIn = function(node, startRGB, duration, delay, callback) { }; +dojo.fx.svg.highlight = dojo.fx.svg.colorFadeIn; +dojo.fx.svg.colorFadeFrom = dojo.fx.svg.colorFadeIn; + +dojo.fx.svg.colorFadeOut = function(node, endRGB, duration, delay, callback) { }; +dojo.fx.svg.unhighlight = dojo.fx.svg.colorFadeOut; +dojo.fx.svg.colorFadeTo = dojo.fx.svg.colorFadeOut; + +dojo.fx.svg.colorFade = function(node, startRGB, endRGB, duration, callback, dontPlay) { }; + +// WIPES +dojo.fx.svg.wipeIn = function(node, duration, callback, dontPlay) { }; +dojo.fx.svg.wipeInToHeight = function(node, duration, height, callback, dontPlay) { } +dojo.fx.svg.wipeOut = function(node, duration, callback, dontPlay) { }; + +// Explode and Implode +dojo.fx.svg.explode = function(startNode, endNode, duration, callback) { }; +dojo.fx.svg.explodeFromBox = function(startCoords, endNode, duration, callback) { }; +dojo.fx.svg.implode = function(startNode, endNode, duration, callback) { }; +dojo.fx.svg.implodeToBox = function(startNode, endCoords, duration, callback) { }; +dojo.fx.svg.Exploder = function(triggerNode, boxNode) { }; + +// html mixes in, we want SVG to remain separate Added: struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/gfx/Colorspace.js URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/gfx/Colorspace.js?view=auto&rev=514083 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/gfx/Colorspace.js (added) +++ struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/gfx/Colorspace.js Fri Mar 2 21:48:54 2007 @@ -0,0 +1,820 @@ +/* + 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.Colorspace"); + +dojo.require("dojo.lang.common"); +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.gfx.Colorspace = function(){ + // summary + // An object for dealing with colorspace conversions. + 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.gfx.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 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.gfx.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.gfx.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.gfx.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.gfx.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.gfx.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.gfx.Colorspace.prototype.chromaticAdaptation = function(col, src_w, dst_w){ + col = this.munge('XYZ', [col]); + 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; + + 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"); + } + + 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); + + 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]] + ]; + + var m = dojo.math.matrix.multiply( dojo.math.matrix.multiply( ma, centre ), mai ); + var dst = dojo.math.matrix.multiply( [[ col.X, col.Y, col.Z ]], m ); + return dst[0]; +} + +////////////////////////////////////////////////////////////////////////////////////////////////////// +dojo.gfx.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.gfx.Colorspace.prototype.getXYZ_RGB_Matrix = function(){ + var m = this.getRGB_XYZ_Matrix(); + return dojo.math.matrix.inverse(m); +} + +dojo.gfx.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.gfx.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.gfx.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.gfx.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.gfx.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.gfx.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.gfx.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.gfx.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.gfx.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.gfx.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.gfx.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.gfx.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.gfx.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 + var R = src.V; + var G = src.V; + var 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.gfx.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.gfx.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: struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/gfx/__package__.js URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/gfx/__package__.js?view=auto&rev=514083 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/gfx/__package__.js (added) +++ struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/gfx/__package__.js Fri Mar 2 21:48:54 2007 @@ -0,0 +1,23 @@ +/* + 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.kwCompoundRequire({ + common: [ + "dojo.gfx.color", + "dojo.gfx.matrix", + "dojo.gfx.common" + ] +}); + +// include a renderer conditionally +dojo["requireIf"](dojo.render.svg.capable, "dojo.gfx.svg"); +dojo["requireIf"](!dojo.render.svg.capable && dojo.render.vml.capable, "dojo.gfx.vml"); + +dojo.provide("dojo.gfx.*"); \ No newline at end of file Added: struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/gfx/color.js URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/gfx/color.js?view=auto&rev=514083 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/gfx/color.js (added) +++ struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/gfx/color.js Fri Mar 2 21:48:54 2007 @@ -0,0 +1,183 @@ +/* + 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.color"); +dojo.require("dojo.lang.common"); +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.gfx.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.gfx.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.gfx.color.Color){ + // why does this create a new instance if we were passed one? + 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.gfx.color.Color.fromArray = function(arr) { + return new dojo.gfx.color.Color(arr[0], arr[1], arr[2], arr[3]); +} + +dojo.extend(dojo.gfx.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.gfx.color.rgb2hex(this.toRgb()); + }, + toCss: function() { + return "rgb(" + this.toRgb().join() + ")"; + }, + toString: function() { + return this.toHex(); // decent default? + }, + blend: function(color, weight){ + var rgb = null; + if(dojo.lang.isArray(color)){ + rgb = color; + }else if(color instanceof dojo.gfx.color.Color){ + rgb = color.toRgb(); + }else{ + rgb = new dojo.gfx.color.Color(color).toRgb(); + } + return dojo.gfx.color.blend(this.toRgb(), rgb, weight); + } +}); + +dojo.gfx.color.named = { + white: [255,255,255], + black: [0,0,0], + red: [255,0,0], + green: [0,255,0], + lime: [0,255,0], + blue: [0,0,255], + navy: [0,0,128], + gray: [128,128,128], + silver: [192,192,192] +}; + +dojo.gfx.color.blend = function(a, b, weight){ + // summary: + // blend colors a and b (both as RGB array or hex strings) with weight + // from -1 to +1, 0 being a 50/50 blend + if(typeof a == "string"){ + return dojo.gfx.color.blendHex(a, b, weight); + } + if(!weight){ + weight = 0; + } + weight = Math.min(Math.max(-1, weight), 1); + + // alex: this interface blows. + // map -1 to 1 to the range 0 to 1 + weight = ((weight + 1)/2); + + var c = []; + + // var stop = (1000*weight); + for(var x = 0; x < 3; x++){ + c[x] = parseInt( b[x] + ( (a[x] - b[x]) * weight) ); + } + return c; +} + +// very convenient blend that takes and returns hex values +// (will get called automatically by blend when blend gets strings) +dojo.gfx.color.blendHex = function(a, b, weight) { + return dojo.gfx.color.rgb2hex(dojo.gfx.color.blend(dojo.gfx.color.hex2rgb(a), dojo.gfx.color.hex2rgb(b), weight)); +} + +// get RGB array from css-style color declarations +dojo.gfx.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.gfx.color.hex2rgb(color); + if(colors) { + return colors; + } else { + // named color (how many do we support?) + return dojo.gfx.color.named[color] || [255, 255, 255]; + } + } +} + +dojo.gfx.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.gfx.color.rgb2hex = function(r, g, b) { + if(dojo.lang.isArray(r)) { + g = r[1] || 0; + b = r[2] || 0; + r = r[0] || 0; + } + var ret = dojo.lang.map([r, g, b], function(x) { + x = new Number(x); + var s = x.toString(16); + while(s.length < 2) { s = "0" + s; } + return s; + }); + ret.unshift("#"); + return ret.join(""); +} Added: struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/gfx/color/hsl.js URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/gfx/color/hsl.js?view=auto&rev=514083 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/gfx/color/hsl.js (added) +++ struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/gfx/color/hsl.js Fri Mar 2 21:48:54 2007 @@ -0,0 +1,139 @@ +/* + 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.color.hsl"); +dojo.require("dojo.lang.array"); + +dojo.lang.extend(dojo.gfx.color.Color, { + toHsl: function() { + return dojo.gfx.color.rgb2hsl(this.toRgb()); + } +}); + +dojo.gfx.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.gfx.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; } + var r, g, b; + 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.gfx.color.hsl2hex = function(h, s, l){ + var rgb = dojo.gfx.color.hsl2rgb(h, s, l); + return dojo.gfx.color.rgb2hex(rgb[0], rgb[1], rgb[2]); +} + +dojo.gfx.color.hex2hsl = function(hex){ + var rgb = dojo.gfx.color.hex2rgb(hex); + return dojo.gfx.color.rgb2hsl(rgb[0], rgb[1], rgb[2]); +} Added: struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/gfx/color/hsv.js URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/gfx/color/hsv.js?view=auto&rev=514083 ============================================================================== --- struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/gfx/color/hsv.js (added) +++ struts/struts2/trunk/plugins/dojo/src/main/resources/org/apache/struts2/static/dojo/src/gfx/color/hsv.js Fri Mar 2 21:48:54 2007 @@ -0,0 +1,246 @@ +/* + 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.color.hsv"); +dojo.require("dojo.lang.array"); +dojo.require("dojo.math"); + +dojo.lang.extend(dojo.gfx.color.Color, { + toHsv: function() { + return dojo.gfx.color.rgb2hsv(this.toRgb()); + } + +}); + +// Default input range for RBG values is 0-255 +dojo.gfx.color.rgb2hsv = function(/* int || Array */r, /* int */g, /* int */b, /* Object? */options){ + // summary + // converts an RGB value set to HSV, ranges depending on optional options object. + // patch for options by Matthew Eernisse + if (dojo.lang.isArray(r)) { + if(g) { + options = g; + } + b = r[2] || 0; + g = r[1] || 0; + r = r[0] || 0; + } + + var opt = { + inputRange: (options && options.inputRange) ? options.inputRange : 255, + outputRange: (options && options.outputRange) ? options.outputRange : [255, 255, 255] + }; + + // 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; + + switch(opt.inputRange) { + // 0.0-1.0 + case 1: + r = (r * 255); + g = (g * 255); + b = (b * 255); + break; + // 0-100 + case 100: + r = (r / 100) * 255; + g = (g / 100) * 255; + b = (b / 100) * 255; + break; + // 0-255 + default: + // Do nothing + break; + } + + 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; + } + } + // Hue + switch (opt.outputRange[0]) { + case 360: + // Do nothing + break; + case 100: + h = (h / 360) * 100; + break; + case 1: + h = (h / 360); + break; + default: // 255 + h = (h / 360) * 255; + break; + } + // Saturation + switch (opt.outputRange[1]) { + case 100: + s = s * 100; + case 1: + // Do nothing + break; + default: // 255 + s = s * 255; + break; + } + // Value + switch (opt.outputRange[2]) { + case 100: + v = (v / 255) * 100; + break; + case 1: + v = (v / 255); + break; + default: // 255 + // Do nothing + break; + } + h = dojo.math.round(h); + s = dojo.math.round(s); + v = dojo.math.round(v); + return [h, s, v]; +} + +// Based on C Code in "Computer Graphics -- Principles and Practice," +// Foley et al, 1996, p. 593. +// +// H = 0 to 255 (corresponding to 0..360 degrees around hexcone) 0 for S = 0 +// S = 0 (shade of gray) to 255 (pure color) +// V = 0 (black) to 255 (white) +dojo.gfx.color.hsv2rgb = function(/* int || Array */h, /* int */s, /* int */v, /* Object? */options){ + // summary + // converts an HSV value set to RGB, ranges depending on optional options object. + // patch for options by Matthew Eernisse + if (dojo.lang.isArray(h)) { + if(s){ + options = s; + } + v = h[2] || 0; + s = h[1] || 0; + h = h[0] || 0; + } + + var opt = { + inputRange: (options && options.inputRange) ? options.inputRange : [255, 255, 255], + outputRange: (options && options.outputRange) ? options.outputRange : 255 + }; + + switch(opt.inputRange[0]) { + // 0.0-1.0 + case 1: h = h * 360; break; + // 0-100 + case 100: h = (h / 100) * 360; break; + // 0-360 + case 360: h = h; break; + // 0-255 + default: h = (h / 255) * 360; + } + if (h == 360){ h = 0;} + + // no need to alter if inputRange[1] = 1 + switch(opt.inputRange[1]){ + case 100: s /= 100; break; + case 255: s /= 255; + } + + // no need to alter if inputRange[1] = 1 + switch(opt.inputRange[2]){ + case 100: v /= 100; break; + case 255: v /= 255; + } + + 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; + } + } + + switch(opt.outputRange){ + case 1: + r = dojo.math.round(r, 2); + g = dojo.math.round(g, 2); + b = dojo.math.round(b, 2); + break; + case 100: + r = Math.round(r * 100); + g = Math.round(g * 100); + b = Math.round(b * 100); + break; + default: + r = Math.round(r * 255); + g = Math.round(g * 255); + b = Math.round(b * 255); + } + + return [r, g, b]; +}