%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.tags.swing.TitledBorderTag |
|
|
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.Color; |
|
19 | import java.awt.Font; |
|
20 | ||
21 | import javax.swing.BorderFactory; |
|
22 | import javax.swing.border.Border; |
|
23 | import javax.swing.border.TitledBorder; |
|
24 | ||
25 | import org.apache.commons.jelly.JellyTagException; |
|
26 | import org.apache.commons.jelly.MissingAttributeException; |
|
27 | import org.apache.commons.jelly.XMLOutput; |
|
28 | import org.apache.commons.logging.Log; |
|
29 | import org.apache.commons.logging.LogFactory; |
|
30 | ||
31 | /** |
|
32 | * Creates a titled border. |
|
33 | * The border will either be exported as a variable defined by the 'var' attribute |
|
34 | * or will be set on the parent widget's border property |
|
35 | * |
|
36 | * @author <a href="mailto:jstrachan@apache.org">James Strachan</a> |
|
37 | * @version $Revision: 155420 $ |
|
38 | */ |
|
39 | 0 | public class TitledBorderTag extends BorderTagSupport { |
40 | ||
41 | /** The Log to which logging calls will be made. */ |
|
42 | 8 | private static final Log log = LogFactory.getLog(TitledBorderTag.class); |
43 | ||
44 | private String title; |
|
45 | private String titleJustification; |
|
46 | private String titlePosition; |
|
47 | private Border border; |
|
48 | private Font font; |
|
49 | private Color color; |
|
50 | ||
51 | ||
52 | // Tag interface |
|
53 | //------------------------------------------------------------------------- |
|
54 | public void doTag(final XMLOutput output) throws MissingAttributeException, JellyTagException { |
|
55 | 0 | if ( title == null) { |
56 | 0 | throw new MissingAttributeException("title"); |
57 | } |
|
58 | 0 | super.doTag(output); |
59 | 0 | } |
60 | ||
61 | // Properties |
|
62 | //------------------------------------------------------------------------- |
|
63 | ||
64 | /** |
|
65 | * Sets the color of the title for this border. Can be set via a nested <color> tag. |
|
66 | */ |
|
67 | public void setColor(Color color) { |
|
68 | 0 | this.color = color; |
69 | 0 | } |
70 | ||
71 | /** |
|
72 | * Sets the Font to be used by the title. Can be set via a nested <font> tag. |
|
73 | */ |
|
74 | public void setFont(Font font) { |
|
75 | 0 | this.font = font; |
76 | 0 | } |
77 | ||
78 | /** |
|
79 | * Sets the title text for this border. |
|
80 | */ |
|
81 | public void setTitle(String title) { |
|
82 | 0 | this.title = title; |
83 | 0 | } |
84 | ||
85 | /** |
|
86 | * Sets the justification of the title. The String is case insensitive. |
|
87 | * Possible values are {LEFT, CENTER, RIGHT, LEADING, TRAILING} |
|
88 | */ |
|
89 | public void setTitleJustification(String titleJustification) { |
|
90 | 0 | this.titleJustification = titleJustification; |
91 | 0 | } |
92 | ||
93 | /** |
|
94 | * Sets the position of the title. The String is case insensitive. |
|
95 | * Possible values are {ABOVE_TOP, TOP, BELOW_TOP, ABOVE_BOTTOM, BOTTOM, BELOW_BOTTOM} |
|
96 | */ |
|
97 | public void setTitlePosition(String titlePosition) { |
|
98 | 0 | this.titlePosition = titlePosition; |
99 | 0 | } |
100 | ||
101 | ||
102 | ||
103 | // Implementation methods |
|
104 | //------------------------------------------------------------------------- |
|
105 | ||
106 | /** |
|
107 | * Factory method to create a new Border instance. |
|
108 | */ |
|
109 | protected Border createBorder() { |
|
110 | 0 | if (border != null) { |
111 | 0 | if (titleJustclass="keyword">ification != null && titlePosition != null) { |
112 | 0 | int justification = asTitleJustification(titleJustification); |
113 | 0 | int position = asTitlePosition(titlePosition); |
114 | ||
115 | 0 | if (font != null) { |
116 | 0 | if (color != null) { |
117 | 0 | return BorderFactory.createTitledBorder(border, title, justification, position, font, color); |
118 | } |
|
119 | else { |
|
120 | 0 | return BorderFactory.createTitledBorder(border, title, justification, position, font); |
121 | } |
|
122 | } |
|
123 | 0 | return BorderFactory.createTitledBorder(border, title, justification, position); |
124 | } |
|
125 | 0 | return BorderFactory.createTitledBorder(border, title); |
126 | } |
|
127 | 0 | return BorderFactory.createTitledBorder(title); |
128 | } |
|
129 | ||
130 | /** |
|
131 | * @return the enumeration for the title justification |
|
132 | */ |
|
133 | protected int asTitleJustification(String text) { |
|
134 | 0 | if (text.equalsIgnoreCase("LEFT")) { |
135 | 0 | return TitledBorder.LEFT; |
136 | } |
|
137 | 0 | else if (text.equalsIgnoreCase("CENTER")) { |
138 | 0 | return TitledBorder.CENTER; |
139 | } |
|
140 | 0 | else if (text.equalsIgnoreCase("RIGHT")) { |
141 | 0 | return TitledBorder.RIGHT; |
142 | } |
|
143 | 0 | else if (text.equalsIgnoreCase("LEADING")) { |
144 | 0 | return TitledBorder.LEADING; |
145 | } |
|
146 | 0 | else if (text.equalsIgnoreCase("TRAILING")) { |
147 | 0 | return TitledBorder.TRAILING; |
148 | } |
|
149 | else { |
|
150 | 0 | return TitledBorder.DEFAULT_JUSTIFICATION; |
151 | } |
|
152 | } |
|
153 | ||
154 | /** |
|
155 | * @return the enumeration for the title position |
|
156 | */ |
|
157 | protected int asTitlePosition(String text) { |
|
158 | 0 | if (text.equalsIgnoreCase("ABOVE_TOP")) { |
159 | 0 | return TitledBorder.ABOVE_TOP; |
160 | } |
|
161 | 0 | else if (text.equalsIgnoreCase("TOP")) { |
162 | 0 | return TitledBorder.TOP; |
163 | } |
|
164 | 0 | else if (text.equalsIgnoreCase("BELOW_TOP")) { |
165 | 0 | return TitledBorder.BELOW_TOP; |
166 | } |
|
167 | 0 | else if (text.equalsIgnoreCase("ABOVE_BOTTOM")) { |
168 | 0 | return TitledBorder.ABOVE_BOTTOM; |
169 | } |
|
170 | 0 | else if (text.equalsIgnoreCase("BOTTOM")) { |
171 | 0 | return TitledBorder.BOTTOM; |
172 | } |
|
173 | 0 | else if (text.equalsIgnoreCase("BELOW_BOTTOM")) { |
174 | 0 | return TitledBorder.BELOW_BOTTOM; |
175 | } |
|
176 | else { |
|
177 | 0 | return TitledBorder.DEFAULT_POSITION; |
178 | } |
|
179 | } |
|
180 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |