1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.swing;
17
18 import java.awt.Color;
19 import javax.swing.BorderFactory;
20 import javax.swing.border.Border;
21 import javax.swing.border.EtchedBorder;
22
23 import org.apache.commons.jelly.JellyTagException;
24 import org.apache.commons.jelly.MissingAttributeException;
25 import org.apache.commons.jelly.XMLOutput;
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 /***
30 * Creates an etched border.
31 * The border will either be exported as a variable defined by the 'var' attribute
32 * or will be set on the parent widget's border property
33 *
34 * @author <a href="mailto:robert@bull-enterprises.com">Robert McIntosh</a>
35 * @version $Revision: 155420 $
36 */
37 public class EtchedBorderTag extends BorderTagSupport {
38
39 /*** The Log to which logging calls will be made. */
40 private static final Log log = LogFactory.getLog(EtchedBorderTag.class);
41
42 private int etchType = -1;
43 private Color highlight = null;
44 private Color shadow = null;
45
46
47
48 public void doTag(final XMLOutput output) throws MissingAttributeException, JellyTagException {
49 if( highlight != null && shadow == null ) {
50 throw new MissingAttributeException("shadow must be supplied when highlight is supplied");
51 }
52 if( shadow != null && highlight == null) {
53 throw new MissingAttributeException("highlight must be supplied when shadow is supplied");
54 }
55 if( etchType != EtchedBorder.LOWERED || etchType != EtchedBorder.RAISED ) {
56 if( log.isDebugEnabled() ) log.debug( "etchType set to [" + etchType + "], which is invalid. Reseting to -1" );
57 }
58 super.doTag(output);
59 }
60
61
62
63 /***
64 * Sets the etch type. Must be either EtchedBorder.LOWERED or EtchedBorder.RAISED
65 * @param type
66 */
67 public void setEtchType( int type ) {
68 etchType = type;
69 }
70
71 /***
72 * Sets the highlight color
73 * @param highlight
74 */
75 public void setHighlight( Color highlight ) {
76 this.highlight = highlight;
77 }
78
79 /***
80 * Sets the shadow color
81 * @param shadow
82 */
83 public void setTop( Color shadow ) {
84 this.shadow = shadow;
85 }
86
87 /***
88 * Factory method to create a new EtchedBorder instance.
89 */
90 protected Border createBorder() {
91 if( etchType == -1 && shadow == null && highlight == null) {
92 return BorderFactory.createEtchedBorder();
93 }
94 else if ( highlight != null && shadow != null && etchType > -1 ) {
95 return BorderFactory.createEtchedBorder( etchType, highlight, shadow );
96 }
97 else {
98 return BorderFactory.createEtchedBorder( highlight, shadow );
99 }
100
101 }
102
103 }