%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.tags.swing.ButtonGroupTag |
|
|
1 | /* |
|
2 | * Copyright 2002,2004 The Apache Software Foundation. |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
10 | * Unless required by applicable law or agreed to in writing, software |
|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 | * See the License for the specific language governing permissions and |
|
14 | * limitations under the License. |
|
15 | */ |
|
16 | package org.apache.commons.jelly.tags.swing; |
|
17 | ||
18 | import java.awt.Component; |
|
19 | import java.util.Map; |
|
20 | ||
21 | import javax.swing.AbstractButton; |
|
22 | import javax.swing.ButtonGroup; |
|
23 | ||
24 | import org.apache.commons.jelly.JellyTagException; |
|
25 | import org.apache.commons.jelly.XMLOutput; |
|
26 | ||
27 | /** Implements a ButtonGroup. This tag acts like a Swing component |
|
28 | * except that adding a component other than an AbstractButton, will be passed |
|
29 | * through to the parent tag. This is meant to make the |
|
30 | * buttonGroup easier to use like this: |
|
31 | * <pre> |
|
32 | * <panel> |
|
33 | * <buttonGroup> |
|
34 | * <panel> |
|
35 | * <radioButton/> |
|
36 | * </panel> |
|
37 | * <panel> |
|
38 | * <radioButton/> |
|
39 | * </panel> |
|
40 | * </buttonGroup> |
|
41 | * </panel> |
|
42 | * </pre> |
|
43 | * |
|
44 | * <p> Note that the following construct will silently fail, and shame on s/he who even tried it: |
|
45 | * <pre> |
|
46 | * <panel> |
|
47 | * <buttonGroup> |
|
48 | * <font .../> |
|
49 | * <panel> |
|
50 | * <radioButton/> |
|
51 | * </panel> |
|
52 | * <panel> |
|
53 | * <radioButton/> |
|
54 | * </panel> |
|
55 | * </buttonGroup> |
|
56 | * </panel> |
|
57 | * </pre> |
|
58 | * </p> |
|
59 | * |
|
60 | * @author Hans Gilde |
|
61 | * |
|
62 | */ |
|
63 | 0 | public class ButtonGroupTag extends ComponentTag { |
64 | ||
65 | /**If the child is an AbstractButton, add it to the button group. Otherwise, |
|
66 | * pass through to the parent component tag. |
|
67 | * @throws JellyTagException |
|
68 | * @see org.apache.commons.jelly.tags.swing.ContainerTag#addChild(java.awt.Component, java.lang.Object) |
|
69 | */ |
|
70 | public void addChild(Component component, Object constraints) throws JellyTagException { |
|
71 | 0 | if (component instanceof AbstractButton) { |
72 | 0 | getButtonGroup().add((AbstractButton) component); |
73 | } else { |
|
74 | 0 | if ( component != null ) { |
75 | 0 | ContainerTag parentTag = (ContainerTag) findAncestorWithClass( ContainerTag.class ); |
76 | 0 | if ( parentTag != null ) { |
77 | 0 | parentTag.addChild(component, getConstraint()); |
78 | } |
|
79 | else { |
|
80 | 0 | throw new JellyTagException( "This buttonGroup tag must be nested within a Swing component tag." ); |
81 | } |
|
82 | } |
|
83 | } |
|
84 | 0 | } |
85 | ||
86 | /**Creates a new buttonGroup. |
|
87 | * @see org.apache.commons.jelly.tags.core.UseBeanTag#newInstance(java.lang.Class, java.util.Map, org.apache.commons.jelly.XMLOutput) |
|
88 | */ |
|
89 | protected Object newInstance(Class theClass, Map attributes, |
|
90 | XMLOutput output) throws JellyTagException { |
|
91 | 0 | return new ButtonGroup(); |
92 | } |
|
93 | ||
94 | protected ButtonGroup getButtonGroup() { |
|
95 | 0 | return (ButtonGroup) getBean(); |
96 | } |
|
97 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |