%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.tags.swing.BorderTagSupport |
|
|
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 javax.swing.border.Border; |
|
19 | ||
20 | import org.apache.commons.jelly.JellyTagException; |
|
21 | import org.apache.commons.jelly.TagSupport; |
|
22 | import org.apache.commons.jelly.XMLOutput; |
|
23 | import org.apache.commons.logging.Log; |
|
24 | import org.apache.commons.logging.LogFactory; |
|
25 | ||
26 | /** |
|
27 | * An abstract base class used for concrete border tags which create new Border implementations |
|
28 | * and sets then on parent widgets and optionally export them as variables . |
|
29 | * |
|
30 | * @author <a href="mailto:jstrachan@apache.org">James Strachan</a> |
|
31 | * @version $Revision: 155420 $ |
|
32 | */ |
|
33 | public abstract class BorderTagSupport extends TagSupport { |
|
34 | ||
35 | /** The Log to which logging calls will be made. */ |
|
36 | 8 | private static final Log log = LogFactory.getLog(BorderTagSupport.class); |
37 | ||
38 | private String var; |
|
39 | ||
40 | 0 | public BorderTagSupport() { |
41 | 0 | } |
42 | ||
43 | // Tag interface |
|
44 | //------------------------------------------------------------------------- |
|
45 | public void doTag(final XMLOutput output) throws JellyTagException { |
|
46 | ||
47 | 0 | Border border = createBorder(); |
48 | ||
49 | // allow some nested tags to set properties |
|
50 | 0 | invokeBody(output); |
51 | ||
52 | 0 | if (var != null) { |
53 | 0 | context.setVariable(var, border); |
54 | } |
|
55 | 0 | ComponentTag tag = (ComponentTag) findAncestorWithClass( ComponentTag.class ); |
56 | 0 | if ( tag != null ) { |
57 | 0 | tag.setBorder(border); |
58 | } |
|
59 | else { |
|
60 | 0 | if (var == null) { |
61 | 0 | throw new JellyTagException( "Either the 'var' attribute must be specified to export this Border or this tag must be nested within a JellySwing widget tag" ); |
62 | } |
|
63 | } |
|
64 | 0 | } |
65 | ||
66 | // Properties |
|
67 | //------------------------------------------------------------------------- |
|
68 | ||
69 | ||
70 | /** |
|
71 | * Sets the name of the variable to use to expose the new Border object. |
|
72 | * If this attribute is not set then the parent widget tag will have its |
|
73 | * border property set. |
|
74 | */ |
|
75 | public void setVar(String var) { |
|
76 | 0 | this.var = class="keyword">var; |
77 | 0 | } |
78 | ||
79 | // Implementation methods |
|
80 | //------------------------------------------------------------------------- |
|
81 | ||
82 | /** |
|
83 | * Factory method to create a new Border instance. |
|
84 | */ |
|
85 | protected abstract Border createBorder(); |
|
86 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |