You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by pr...@apache.org on 2003/07/28 02:34:11 UTC
cvs commit: jakarta-commons/jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing KeyListenerTag.java FocusListenerTag.java SwingTagLibrary.java ComponentTag.java
proyal 2003/07/27 17:34:11
Modified: jelly/jelly-tags/swing maven.xml
jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing
SwingTagLibrary.java ComponentTag.java
Added: jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing
KeyListenerTag.java FocusListenerTag.java
Log:
[JELLY-65] Swing Tag Library
Add Key and Focus Listeners
patch from Sean Ferguson
Revision Changes Path
1.4 +1 -1 jakarta-commons/jelly/jelly-tags/swing/maven.xml
Index: maven.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/swing/maven.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- maven.xml 13 Jan 2003 16:10:18 -0000 1.3
+++ maven.xml 28 Jul 2003 00:34:11 -0000 1.4
@@ -1,4 +1,4 @@
-<project default="java:jar" xmlns:j="jelly:core">
+<project default="jar:jar" xmlns:j="jelly:core">
<!-- define the classpath used to run examples -->
<goal name="create-classpath" prereqs="java:compile, test:compile">
1.20 +3 -2 jakarta-commons/jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/SwingTagLibrary.java
Index: SwingTagLibrary.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/SwingTagLibrary.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- SwingTagLibrary.java 24 Jan 2003 06:41:22 -0000 1.19
+++ SwingTagLibrary.java 28 Jul 2003 00:34:11 -0000 1.20
@@ -114,8 +114,9 @@
registerTag( "action", ActionTag.class );
registerTag( "font", FontTag.class );
registerTag( "windowListener", WindowListenerTag.class );
-
-
+ registerTag( "focusListener", FocusListenerTag.class );
+ registerTag( "keyListener", KeyListenerTag.class );
+
// the model tags
registerTag( "tableModel", TableModelTag.class );
registerTag( "tableModelColumn", TableModelColumnTag.class );
1.15 +18 -0 jakarta-commons/jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/ComponentTag.java
Index: ComponentTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/ComponentTag.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- ComponentTag.java 26 Jan 2003 07:50:23 -0000 1.14
+++ ComponentTag.java 28 Jul 2003 00:34:11 -0000 1.15
@@ -71,6 +71,8 @@
import java.awt.Color;
import java.awt.Window;
import java.awt.event.WindowListener;
+import java.awt.event.KeyListener;
+import java.awt.event.FocusListener;
import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;
import java.util.Map;
@@ -206,6 +208,22 @@
Window window = (Window) component;
window.addWindowListener(listener);
}
+ }
+
+ /**
+ * Adds a FocusListener to this component
+ */
+ public void addFocusListener(FocusListener listener) {
+ Component component = getComponent();
+ component.addFocusListener(listener);
+ }
+
+ /**
+ * Adds a KeyListener to this component
+ */
+ public void addKeyListener(KeyListener listener) {
+ Component component = getComponent();
+ component.addKeyListener(listener);
}
// Properties
1.1 jakarta-commons/jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/KeyListenerTag.java
Index: KeyListenerTag.java
===================================================================
package org.apache.commons.jelly.tags.swing;
import java.awt.event.*;
import org.apache.commons.jelly.*;
import org.apache.commons.jelly.tags.swing.*;
import org.apache.commons.logging.*;
public class KeyListenerTag extends TagSupport
{
protected static final Log log = LogFactory.getLog(KeyListenerTag.class);
protected String var;
protected Script pressed;
protected Script typed;
protected Script released;
public KeyListenerTag()
{
super();
}
public void setVar(String var)
{
this.var = var;
}
public void setPressed(Script pressed)
{
this.pressed = pressed;
}
public void setReleased(Script released)
{
this.released = released;
}
public void setTyped(Script typed)
{
this.typed = typed;
}
public void doTag(final XMLOutput output) throws JellyTagException
{
// now lets add this action to its parent if we have one
ComponentTag tag = (ComponentTag)findAncestorWithClass(ComponentTag.class);
if (tag != null)
{
KeyListener listener = new KeyListener()
{
public void keyTyped(KeyEvent e)
{
invokeScript(output, e, typed);
}
public void keyPressed(KeyEvent e)
{
invokeScript(output, e, pressed);
}
public void keyReleased(KeyEvent e)
{
invokeScript(output, e, released);
}
};
tag.addKeyListener(listener);
}
}
protected void invokeScript(XMLOutput output, KeyEvent event, Script script)
{
if (var != null)
{
// define a variable of the event
context.setVariable(var, event);
}
try
{
if (script != null)
{
script.run(context, output);
}
else
{
// invoke the body
invokeBody(output);
}
}
catch (Exception e)
{
log.error("Caught exception processing window event: " + event, e);
}
}
}
1.1 jakarta-commons/jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/FocusListenerTag.java
Index: FocusListenerTag.java
===================================================================
package org.apache.commons.jelly.tags.swing;
import java.awt.event.*;
import org.apache.commons.jelly.*;
import org.apache.commons.jelly.tags.swing.*;
import org.apache.commons.logging.*;
public class FocusListenerTag extends TagSupport
{
protected static final Log log = LogFactory.getLog(FocusListenerTag.class);
protected String var;
protected Script gained;
protected Script lost;
/**
*
*/
public FocusListenerTag()
{
super();
}
/**
* @param var
*/
public void setVar(String var)
{
this.var = var;
}
/**
* @param gained
*/
public void setGained(Script gained)
{
this.gained = gained;
}
/**
* @param lost
*/
public void setLost(Script lost)
{
this.lost = lost;
}
public void doTag(final XMLOutput output) throws JellyTagException
{
// now lets add this action to its parent if we have one
ComponentTag tag = (ComponentTag)findAncestorWithClass(ComponentTag.class);
if (tag != null)
{
FocusListener listener = new FocusListener()
{
public void focusGained(FocusEvent e)
{
invokeScript(output, e, gained);
}
public void focusLost(FocusEvent e)
{
invokeScript(output, e, lost);
}
};
tag.addFocusListener(listener);
}
}
protected void invokeScript(XMLOutput output, FocusEvent event, Script script)
{
if (var != null)
{
// define a variable of the event
context.setVariable(var, event);
}
try
{
if (script != null)
{
script.run(context, output);
}
else
{
// invoke the body
invokeBody(output);
}
}
catch (Exception e)
{
log.error("Caught exception processing window event: " + event, e);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org