dion 2004/09/07 23:39:01
Modified: jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing
SwingTagLibrary.java ComponentTag.java
jelly/jelly-tags/swing/src/test/org/apache/commons/jelly/swing
swingTags.jelly TestSwingTags.java
Added: jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing
ButtonGroupTag.java
Log:
Jelly-132/133
Revision Changes Path
1.27 +1 -1
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.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- SwingTagLibrary.java 7 Sep 2004 07:19:21 -0000 1.26
+++ SwingTagLibrary.java 8 Sep 2004 06:39:00 -0000 1.27
@@ -66,6 +66,7 @@
public SwingTagLibrary() {
registerTag( "action", ActionTag.class );
+ registerTag( "buttonGroup", ButtonGroupTag.class );
registerTag( "component", ComponentTag.class );
registerTag( "font", FontTag.class );
registerTag( "windowListener", WindowListenerTag.class );
@@ -139,7 +140,6 @@
*/
protected void registerFactories() {
registerBeanFactory( "button", JButton.class );
- registerBeanFactory( "buttonGroup", ButtonGroup.class );
registerBeanFactory( "checkBox", JCheckBox.class );
registerBeanFactory( "checkBoxMenuItem", JCheckBoxMenuItem.class );
registerBeanFactory( "comboBox", JComboBox.class );
1.20 +4 -4
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.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- ComponentTag.java 7 Sep 2004 07:04:38 -0000 1.19
+++ ComponentTag.java 8 Sep 2004 06:39:00 -0000 1.20
@@ -162,7 +162,7 @@
/**
* Adds a WindowListener to this component
*/
- public void addWindowListener(WindowListener listener) {
+ public void addWindowListener(WindowListener listener) throws JellyTagException
{
Component component = getComponent();
if ( component instanceof Window ) {
Window window = (Window) component;
@@ -173,7 +173,7 @@
/**
* Adds a FocusListener to this component
*/
- public void addFocusListener(FocusListener listener) {
+ public void addFocusListener(FocusListener listener) throws JellyTagException {
Component component = getComponent();
component.addFocusListener(listener);
}
@@ -181,7 +181,7 @@
/**
* Adds a KeyListener to this component
*/
- public void addKeyListener(KeyListener listener) {
+ public void addKeyListener(KeyListener listener) throws JellyTagException {
Component component = getComponent();
component.addKeyListener(listener);
}
@@ -207,7 +207,7 @@
/**
* Adds a child component to this parent
*/
- public void addChild(Component component, Object constraints) {
+ public void addChild(Component component, Object constraints) throws
JellyTagException {
Object parent = getBean();
if ( parent instanceof JFrame && component instanceof JMenuBar ) {
JFrame frame = (JFrame) parent;
1.1
jakarta-commons/jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/ButtonGroupTag.java
Index: ButtonGroupTag.java
===================================================================
/*
* Copyright 2002,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jelly.tags.swing;
import java.awt.Component;
import java.util.Map;
import javax.swing.AbstractButton;
import javax.swing.ButtonGroup;
import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.XMLOutput;
/** Implements a ButtonGroup. This tag acts like a Swing component
* except that adding a component other than an AbstractButton, will be passed
* through to the parent tag. This is meant to make the
* buttonGroup easier to use like this:
* <pre>
* <panel>
* <buttonGroup>
* <panel>
* <radioButton/>
* </panel>
* <panel>
* <radioButton/>
* </panel>
* </buttonGroup>
* </panel>
* </pre>
*
* <p> Note that the following construct will silently fail, and shame on s/he who
even tried it:
* <pre>
* <panel>
* <buttonGroup>
* <font .../>
* <panel>
* <radioButton/>
* </panel>
* <panel>
* <radioButton/>
* </panel>
* </buttonGroup>
* </panel>
* </pre>
* </p>
*
* @author Hans Gilde
*
*/
public class ButtonGroupTag extends ComponentTag {
/**If the child is an AbstractButton, add it to the button group. Otherwise,
* pass through to the parent component tag.
* @throws JellyTagException
* @see
org.apache.commons.jelly.tags.swing.ContainerTag#addChild(java.awt.Component,
java.lang.Object)
*/
public void addChild(Component component, Object constraints) throws
JellyTagException {
if (component instanceof AbstractButton) {
getButtonGroup().add((AbstractButton) component);
} else {
if ( component != null ) {
ContainerTag parentTag = (ContainerTag) findAncestorWithClass(
ContainerTag.class );
if ( parentTag != null ) {
parentTag.addChild(component, getConstraint());
}
else {
throw new JellyTagException( "This buttonGroup tag must be
nested within a Swing component tag." );
}
}
}
}
/**Creates a new buttonGroup.
* @see
org.apache.commons.jelly.tags.core.UseBeanTag#newInstance(java.lang.Class,
java.util.Map, org.apache.commons.jelly.XMLOutput)
*/
protected Object newInstance(Class theClass, Map attributes,
XMLOutput output) throws JellyTagException {
return new ButtonGroup();
}
protected ButtonGroup getButtonGroup() {
return (ButtonGroup) getBean();
}
}
1.3 +2 -1
jakarta-commons/jelly/jelly-tags/swing/src/test/org/apache/commons/jelly/swing/swingTags.jelly
Index: swingTags.jelly
===================================================================
RCS file:
/home/cvs/jakarta-commons/jelly/jelly-tags/swing/src/test/org/apache/commons/jelly/swing/swingTags.jelly,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- swingTags.jelly 8 Sep 2004 05:34:01 -0000 1.2
+++ swingTags.jelly 8 Sep 2004 06:39:00 -0000 1.3
@@ -62,7 +62,8 @@
<frame name="frame" var="frame">
<buttonGroup var="bg">
<checkBox name="cb1"/>
- <checkBox name="cb2"/>
+ <checkBox name="cb2" selected="true"/>
+ <checkBox name="cb3"/>
</buttonGroup>
</frame>
</j:if>
1.6 +2 -2
jakarta-commons/jelly/jelly-tags/swing/src/test/org/apache/commons/jelly/swing/TestSwingTags.java
Index: TestSwingTags.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/jelly/jelly-tags/swing/src/test/org/apache/commons/jelly/swing/TestSwingTags.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TestSwingTags.java 7 Sep 2004 07:11:19 -0000 1.5
+++ TestSwingTags.java 8 Sep 2004 06:39:00 -0000 1.6
@@ -130,8 +130,8 @@
runSwingScript("test.buttonGroup");
JellyContext context = getJellyContext();
ButtonGroup bg = (ButtonGroup) context.getVariable("bg");
- //buttonGroup is broken
- // assertEquals(2, bg.getButtonCount());
+ assertEquals(3, bg.getButtonCount());
+ assertNotNull(bg.getSelection());
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]