Author: SergeySmirnov
Date: 2008-06-11 13:47:45 -0400 (Wed, 11 Jun 2008)
New Revision: 9006
Added:
trunk/sandbox/ui/hotKey/
trunk/sandbox/ui/hotKey/pom.xml
trunk/sandbox/ui/hotKey/src/
trunk/sandbox/ui/hotKey/src/main/
trunk/sandbox/ui/hotKey/src/main/config/
trunk/sandbox/ui/hotKey/src/main/config/component/
trunk/sandbox/ui/hotKey/src/main/config/component/README
trunk/sandbox/ui/hotKey/src/main/config/component/hotKey.xml
trunk/sandbox/ui/hotKey/src/main/java/
trunk/sandbox/ui/hotKey/src/main/java/META-INF/
trunk/sandbox/ui/hotKey/src/main/java/META-INF/MANIFEST.MF
trunk/sandbox/ui/hotKey/src/main/java/org/
trunk/sandbox/ui/hotKey/src/main/java/org/richfaces/
trunk/sandbox/ui/hotKey/src/main/java/org/richfaces/component/
trunk/sandbox/ui/hotKey/src/main/java/org/richfaces/component/README
trunk/sandbox/ui/hotKey/src/main/java/org/richfaces/component/UIHotKey.java
trunk/sandbox/ui/hotKey/src/main/resources/
trunk/sandbox/ui/hotKey/src/main/resources/org/
trunk/sandbox/ui/hotKey/src/main/resources/org/richfaces/
trunk/sandbox/ui/hotKey/src/main/resources/org/richfaces/renderkit/
trunk/sandbox/ui/hotKey/src/main/resources/org/richfaces/renderkit/html/
trunk/sandbox/ui/hotKey/src/main/resources/org/richfaces/renderkit/html/scripts/
trunk/sandbox/ui/hotKey/src/main/resources/org/richfaces/renderkit/html/scripts/hotKey.js
trunk/sandbox/ui/hotKey/src/main/resources/org/richfaces/renderkit/html/scripts/jquery.hotkeys.js
trunk/sandbox/ui/hotKey/src/main/templates/
trunk/sandbox/ui/hotKey/src/main/templates/README
trunk/sandbox/ui/hotKey/src/main/templates/org/
trunk/sandbox/ui/hotKey/src/main/templates/org/richfaces/
trunk/sandbox/ui/hotKey/src/main/templates/org/richfaces/htmlHotKey.jspx
trunk/sandbox/ui/hotKey/src/test/
trunk/sandbox/ui/hotKey/src/test/java/
trunk/sandbox/ui/hotKey/src/test/java/org/
trunk/sandbox/ui/hotKey/src/test/java/org/richfaces/
trunk/sandbox/ui/hotKey/src/test/java/org/richfaces/component/
trunk/sandbox/ui/hotKey/src/test/java/org/richfaces/component/JSFComponentTest.java
Log:
hot key init
Added: trunk/sandbox/ui/hotKey/pom.xml
===================================================================
--- trunk/sandbox/ui/hotKey/pom.xml (rev 0)
+++ trunk/sandbox/ui/hotKey/pom.xml 2008-06-11 17:47:45 UTC (rev 9006)
@@ -0,0 +1,50 @@
+<?xml version="1.0"?><project>
+ <parent>
+ <artifactId>ui</artifactId>
+ <groupId>org.richfaces.sandbox</groupId>
+ <version>3.2.2-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.richfaces.ui</groupId>
+ <artifactId>hotKey</artifactId>
+ <name>hotKey</name>
+ <version>3.2.2-SNAPSHOT</version>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.richfaces.cdk</groupId>
+ <artifactId>maven-cdk-plugin</artifactId>
+ <version>3.2.2-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <library>
+ <prefix>org.richfaces</prefix>
+ <taglib>
+ <shortName>hotKey</shortName>
+ </taglib>
+ </library>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.richfaces.framework</groupId>
+ <artifactId>richfaces-impl</artifactId>
+ <version>3.2.2-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Added: trunk/sandbox/ui/hotKey/src/main/config/component/README
===================================================================
Added: trunk/sandbox/ui/hotKey/src/main/config/component/hotKey.xml
===================================================================
--- trunk/sandbox/ui/hotKey/src/main/config/component/hotKey.xml
(rev 0)
+++ trunk/sandbox/ui/hotKey/src/main/config/component/hotKey.xml 2008-06-11 17:47:45 UTC
(rev 9006)
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE components PUBLIC "-//AJAX4JSF//CDK Generator config/EN"
"http://labs.jboss.com/jbossrichfaces/component-config.dtd">
+
+<components>
+ <component>
+ <name>org.richfaces.HotKey</name>
+ <family>org.richfaces.HotKey</family>
+ <classname>org.richfaces.component.html.HtmlHotKey</classname>
+ <superclass>org.richfaces.component.UIHotKey</superclass>
+ <description>
+ <![CDATA[
+ ]]>
+ </description>
+ <renderer generate="true" override="true">
+ <name>org.richfaces.HotKeyRenderer</name>
+ <template>org/richfaces/htmlHotKey.jspx</template>
+ </renderer>
+ <tag>
+ <name>hotKey</name>
+ <classname>org.richfaces.taglib.HotKeyTag</classname>
+ <superclass>
+ org.ajax4jsf.webapp.taglib.HtmlComponentTagBase
+ </superclass>
+ </tag>
+ <!--
+ <taghandler>
+ <classname>org.ajax4jsf.tag.TestHandler</classname>
+ </taghandler>
+ -->
+ &ui_component_attributes;
+ <property>
+ <name>key</name>
+ <classname>java.lang.String</classname>
+ <description>
+ </description>
+ <defaultvalue>""</defaultvalue>
+ </property>
+ <property>
+ <name>operation</name>
+ <classname>java.lang.String</classname>
+ <description>
+ </description>
+ <defaultvalue>"add"</defaultvalue>
+ </property>
+ <property>
+ <name>timing</name>
+ <classname>java.lang.String</classname>
+ <description>
+ </description>
+ <defaultvalue>"immediate"</defaultvalue>
+ </property>
+ <property>
+ <name>target</name>
+ <classname>java.lang.String</classname>
+ <description>
+ </description>
+ <defaultvalue>""</defaultvalue>
+ </property>
+ <property>
+ <name>type</name>
+ <classname>java.lang.String</classname>
+ <description>
+ </description>
+ <defaultvalue>""</defaultvalue>
+ </property>
+ <property>
+ <name>propagete</name>
+ <classname>java.lang.String</classname>
+ <description>
+ </description>
+ <defaultvalue>""</defaultvalue>
+ </property>
+ <property>
+ <name>disableInInput</name>
+ <classname>java.lang.String</classname>
+ <description>
+ </description>
+ <defaultvalue>""</defaultvalue>
+ </property>
+ <property>
+ <name>checkParent</name>
+ <classname>java.lang.String</classname>
+ <description>
+ </description>
+ <defaultvalue>""</defaultvalue>
+ </property>
+ <property>
+ <name>handler</name>
+ <classname>java.lang.String</classname>
+ <description>
+ </description>
+ <defaultvalue>""</defaultvalue>
+ </property>
+ </component>
+</components>
Added: trunk/sandbox/ui/hotKey/src/main/java/META-INF/MANIFEST.MF
===================================================================
--- trunk/sandbox/ui/hotKey/src/main/java/META-INF/MANIFEST.MF
(rev 0)
+++ trunk/sandbox/ui/hotKey/src/main/java/META-INF/MANIFEST.MF 2008-06-11 17:47:45 UTC
(rev 9006)
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path:
+
Added: trunk/sandbox/ui/hotKey/src/main/java/org/richfaces/component/README
===================================================================
Added: trunk/sandbox/ui/hotKey/src/main/java/org/richfaces/component/UIHotKey.java
===================================================================
--- trunk/sandbox/ui/hotKey/src/main/java/org/richfaces/component/UIHotKey.java
(rev 0)
+++ trunk/sandbox/ui/hotKey/src/main/java/org/richfaces/component/UIHotKey.java 2008-06-11
17:47:45 UTC (rev 9006)
@@ -0,0 +1,19 @@
+/**
+ *
+ */
+
+package org.richfaces.component;
+
+import javax.faces.component.UIComponentBase;
+
+/**
+ * JSF component class
+ *
+ */
+public abstract class UIHotKey extends UIComponentBase {
+
+ public static final String COMPONENT_TYPE = "org.richfaces.HotKey";
+
+ public static final String COMPONENT_FAMILY = "org.richfaces.HotKey";
+
+}
Added:
trunk/sandbox/ui/hotKey/src/main/resources/org/richfaces/renderkit/html/scripts/hotKey.js
===================================================================
---
trunk/sandbox/ui/hotKey/src/main/resources/org/richfaces/renderkit/html/scripts/hotKey.js
(rev 0)
+++
trunk/sandbox/ui/hotKey/src/main/resources/org/richfaces/renderkit/html/scripts/hotKey.js 2008-06-11
17:47:45 UTC (rev 9006)
@@ -0,0 +1,41 @@
+if (!window.Richfaces) window.Richfaces = {};
+
+Richfaces.hotKey = function(id, key, options, handler) {
+ this.id = id;
+ this.key = key;
+ this.options = options;
+ this.handler = handler;
+ this["rich:destructor"] = "destroy";
+ document.getElementById(id).component = this;
+
+ this.invoke = function() {
+ if ("add" == this.options.operation)
+ this.add(this.key, this.options, this.handler);
+ else if ("remove" == this.options.operation)
+ this.remove(this.key, this.options);
+ }
+ this.destroy = function() {
+ this.element.component = null;
+ this.element = null;
+ this.hotKey = null;
+ }
+ this.add = function (key, options, handler) {
+ jQuery.hotkeys.add(key, options, function(){ eval(handler) });
+ }
+
+ this.remove = function () {
+ jQuery.hotkeys.remove(this.key, this.options);
+ }
+
+ if ("immediate" == options.timing) {
+ this.invoke();
+ } else if ("onload" == options.timing) {
+ jQuery(document).ready(function() {
+ if ("add" == options.operation)
+ jQuery.hotkeys.add(key, options, function(){ eval(handler) });
+ else if ("remove" == options.operation)
+ jQuery.hotkeys.remove(key, options);
+ });
+ }
+
+};
\ No newline at end of file
Added:
trunk/sandbox/ui/hotKey/src/main/resources/org/richfaces/renderkit/html/scripts/jquery.hotkeys.js
===================================================================
---
trunk/sandbox/ui/hotKey/src/main/resources/org/richfaces/renderkit/html/scripts/jquery.hotkeys.js
(rev 0)
+++
trunk/sandbox/ui/hotKey/src/main/resources/org/richfaces/renderkit/html/scripts/jquery.hotkeys.js 2008-06-11
17:47:45 UTC (rev 9006)
@@ -0,0 +1,127 @@
+/******************************************************************************************************************************
+
+ * @ Original idea by by Binny V A, Original version: 2.00.A
+ * @
http://www.openjs.com/scripts/events/keyboard_shortcuts/
+ * @ Original License : BSD
+
+ * @ jQuery Plugin by Tzury Bar Yochay
+ mail: tzury.by(a)gmail.com
+ blog:
evalinux.wordpress.com
+ face:
facebook.com/profile.php?id=513676303
+
+ (c) Copyrights 2007
+
+ * @ jQuery Plugin version Beta (0.0.2)
+ * @ License: jQuery-License.
+
+TODO:
+ add queue support (as in gmail) e.g. 'x' then 'y', etc.
+ add mouse + mouse wheel events.
+
+USAGE:
+ $.hotkeys.add('Ctrl+c', function(){ alert('copy anyone?');});
+ $.hotkeys.add('Ctrl+c', {target:'div#editor', type:'keyup',
propagate: true},function(){ alert('copy anyone?');});>
+ $.hotkeys.remove('Ctrl+c');
+ $.hotkeys.remove('Ctrl+c', {target:'div#editor',
type:'keypress'});
+
+******************************************************************************************************************************/
+(function (jQuery){
+ this.version = '(beta)(0.0.3)';
+ this.all = {};
+ this.special_keys = {
+ 27: 'esc', 9: 'tab', 32:'space', 13: 'return',
8:'backspace', 145: 'scroll', 20: 'capslock',
+ 144: 'numlock', 19:'pause', 45:'insert',
36:'home', 46:'del',35:'end', 33: 'pageup',
+ 34:'pagedown', 37:'left', 38:'up',
39:'right',40:'down', 112:'f1',113:'f2', 114:'f3',
+ 115:'f4', 116:'f5', 117:'f6', 118:'f7',
119:'f8', 120:'f9', 121:'f10', 122:'f11',
123:'f12'};
+
+ this.shift_nums = { "`":"~", "1":"!",
"2":"@", "3":"#", "4":"$",
"5":"%", "6":"^", "7":"&",
+ "8":"*", "9":"(",
"0":")", "-":"_", "=":"+",
";":":", "'":"\"",
",":"<",
+ ".":">", "/":"?",
"\\":"|" };
+
+ this.add = function(combi, options, callback) {
+ if (jQuery.isFunction(options)){
+ callback = options;
+ options = {};
+ }
+ var opt = {},
+ defaults = {type: 'keydown', propagate: false, disableInInput: false,
target: jQuery('html')[0], checkParent: true},
+ that = this;
+ opt = jQuery.extend( opt , defaults, options || {} );
+ combi = combi.toLowerCase();
+
+ // inspect if keystroke matches
+ var inspector = function(event) {
+ event = jQuery.event.fix(event); // jQuery event normalization.
+ var element = event.target;
+ // @ TextNode -> nodeType == 3
+ element = (element.nodeType==3) ? element.parentNode : element;
+
+ if(opt['disableInInput']) { // Disable shortcut keys in Input,
Textarea fields
+ var target = jQuery(element);
+ if( target.is("input") || target.is("textarea")){
+ return;
+ }
+ }
+ var code = event.which,
+ type = event.type,
+ character = String.fromCharCode(code).toLowerCase(),
+ special = that.special_keys[code],
+ shift = event.shiftKey,
+ ctrl = event.ctrlKey,
+ alt= event.altKey,
+ propagate = true, // default behaivour
+ mapPoint = null;
+
+ // in opera + safari, the event.target is unpredictable.
+ // for example: 'keydown' might be associated with HtmlBodyElement
+ // or the element where you last clicked with your mouse.
+ if (jQuery.browser.opera || jQuery.browser.safari || opt.checkParent){
+ while (!that.all[element] && element.parentNode){
+ element = element.parentNode;
+ }
+ }
+
+ var cbMap = that.all[element].events[type].callbackMap;
+ if(!shift && !ctrl && !alt) { // No Modifiers
+ mapPoint = cbMap[special] || cbMap[character]
+ }
+ // deals with combinaitons (alt|ctrl|shift+anything)
+ else{
+ var modif = '';
+ if(alt) modif +='alt+';
+ if(ctrl) modif+= 'ctrl+';
+ if(shift) modif += 'shift+';
+ // modifiers + special keys or modifiers + characters or modifiers +
shift characters
+ mapPoint = cbMap[modif+special] || cbMap[modif+character] ||
cbMap[modif+that.shift_nums[character]]
+ }
+ if (mapPoint){
+ mapPoint.cb(event);
+ if(!mapPoint.propagate) {
+ event.stopPropagation();
+ event.preventDefault();
+ return false;
+ }
+ }
+ };
+ // first hook for this element
+ if (!this.all[opt.target]){
+ this.all[opt.target] = {events:{}};
+ }
+ if (!this.all[opt.target].events[opt.type]){
+ this.all[opt.target].events[opt.type] = {callbackMap: {}}
+ jQuery.event.add(opt.target, opt.type, inspector);
+ }
+ this.all[opt.target].events[opt.type].callbackMap[combi] = {cb: callback,
propagate:opt.propagate};
+ return jQuery;
+ };
+ this.remove = function(exp, opt) {
+ opt = opt || {};
+ target = opt.target || jQuery('html')[0];
+ type = opt.type || 'keydown';
+ exp = exp.toLowerCase();
+ delete this.all[target].events[type].callbackMap[exp]
+ return jQuery;
+ };
+ jQuery.hotkeys = this;
+ return jQuery;
+})(jQuery);
\ No newline at end of file
Added: trunk/sandbox/ui/hotKey/src/main/templates/README
===================================================================
Added: trunk/sandbox/ui/hotKey/src/main/templates/org/richfaces/htmlHotKey.jspx
===================================================================
--- trunk/sandbox/ui/hotKey/src/main/templates/org/richfaces/htmlHotKey.jspx
(rev 0)
+++ trunk/sandbox/ui/hotKey/src/main/templates/org/richfaces/htmlHotKey.jspx 2008-06-11
17:47:45 UTC (rev 9006)
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<f:root
+
xmlns:f="http://ajax4jsf.org/cdk/template"
+ xmlns:c="
http://java.sun.com/jsf/core"
+ xmlns:ui="
http://ajax4jsf.org/cdk/ui"
+ xmlns:u="
http://ajax4jsf.org/cdk/u"
+ xmlns:x="
http://ajax4jsf.org/cdk/x"
+ class="org.richfaces.renderkit.html.HotKeyRenderer"
+ baseclass="org.ajax4jsf.renderkit.AjaxComponentRendererBase"
+ component="org.richfaces.component.UIHotKey"
+ >
+ <f:clientid var="clientId"/>
+ <c:set var="key"
value="#{component.attributes['key']}"/>
+ <c:set var="operation"
value="#{component.attributes['operation']}"/>
+ <c:set var="timing"
value="#{component.attributes['timing']}"/>
+ <c:set var="type"
value="#{component.attributes['type']}"/>
+ <c:set var="propagete"
value="#{component.attributes['propagete']}"/>
+ <c:set var="disableInInput"
value="#{component.attributes['disableInInput']}"/>
+ <c:set var="checkParent"
value="#{component.attributes['checkParent']}"/>
+ <c:set var="handler"
value="#{component.attributes['handler']}"/>
+
+ <h:scripts>/org/richfaces/renderkit/html/scripts/jquery/jquery.js,/org/richfaces/renderkit/html/scripts/jquery.hotkeys.js,/org/richfaces/renderkit/html/scripts/hotKey.js</h:scripts>
+ <jsp:scriptlet>
+ <![CDATA[
+ StringBuffer options= new StringBuffer("{");
+ String operation = (String) variables.getVariable("operation");
+ options.append("operation:'");
+ options.append(operation);
+ options.append("'");
+
+ String type = (String) variables.getVariable("type");
+ if (!type.equals("")) {
+ options.append(",type:'");
+ options.append(type);
+ options.append("'");
+ }
+ String propagete = (String) variables.getVariable("propagete");
+ if (!propagete.equals("")) {
+ options.append(",propagete:");
+ options.append(propagete);
+ }
+
+ String disableInInput = (String) variables.getVariable("disableInInput");
+ if (!propagete.equals("")) {
+ options.append(",disableInInput:");
+ options.append(disableInInput);
+ }
+
+ String checkParent = (String) variables.getVariable("checkParent");
+ if (!propagete.equals("")) {
+ options.append(",checkParent:");
+ options.append(checkParent);
+ }
+
+ String timing = (String) variables.getVariable("timing");
+ options.append(",timing:'");
+ options.append(timing);
+ options.append("'");
+
+
+ options.append("}");
+ variables.setVariable("options", options);
+ ]]>
+ </jsp:scriptlet>
+ <span id="#{clientId}" style="display:none"
+ x:passThruWithExclusions="id"
+ >
+
+ <script>
+ new Richfaces.hotKey("#{clientId}","#{key}", #{options},
"#{handler}");
+ </script>
+ </span>
+</f:root>
\ No newline at end of file
Added:
trunk/sandbox/ui/hotKey/src/test/java/org/richfaces/component/JSFComponentTest.java
===================================================================
--- trunk/sandbox/ui/hotKey/src/test/java/org/richfaces/component/JSFComponentTest.java
(rev 0)
+++
trunk/sandbox/ui/hotKey/src/test/java/org/richfaces/component/JSFComponentTest.java 2008-06-11
17:47:45 UTC (rev 9006)
@@ -0,0 +1,53 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.component;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import javax.faces.component.UIComponent;
+
+/**
+ * Unit test for simple Component.
+ */
+public class JSFComponentTest
+ extends TestCase
+{
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public JSFComponentTest( String testName )
+ {
+ super( testName );
+ }
+
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testComponent()
+ {
+ assertTrue( true );
+ }
+}