View Javadoc

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.BorderFactory;
19  import javax.swing.border.Border;
20  
21  import org.apache.commons.jelly.JellyTagException;
22  import org.apache.commons.jelly.MissingAttributeException;
23  import org.apache.commons.jelly.XMLOutput;
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  
27  /***
28   * Creates an empty border.
29   * The border will either be exported as a variable defined by the 'var' attribute
30   * or will be set on the parent widget's border property
31   *
32   * @author <a href="mailto:robert@bull-enterprises.com">Robert McIntosh</a>
33   * @version $Revision: 155420 $
34   */
35  public class EmptyBorderTag extends BorderTagSupport {
36  
37      /*** The Log to which logging calls will be made. */
38      private static final Log log = LogFactory.getLog(EmptyBorderTag.class);
39  
40      private int left   = -1;
41      private int right  = -1;
42      private int top    = -1;
43      private int bottom = -1;
44  
45      // Tag interface
46      //-------------------------------------------------------------------------
47      public void doTag(final XMLOutput output) throws MissingAttributeException, JellyTagException {
48          if ( left == -1) {
49              throw new MissingAttributeException("left");
50          }
51          if ( right == -1) {
52              throw new MissingAttributeException("right");
53          }
54          if ( top == -1) {
55              throw new MissingAttributeException("top");
56          }
57          if ( bottom == -1) {
58              throw new MissingAttributeException("bottom");
59          }
60          super.doTag(output);
61      }
62  
63      // Properties
64      //-------------------------------------------------------------------------
65      /***
66       * Sets the left inset
67       * @param left
68       */
69      public void setLeft( int left ) {
70          this.left = left;
71      }
72  
73      /***
74       * Sets the right inset
75       * @param right
76       */
77      public void setRight( int right ) {
78          this.right = right;
79      }
80  
81      /***
82       * Sets the top inset
83       * @param top
84       */
85      public void setTop( int top ) {
86          this.top = top;
87      }
88  
89      /***
90       * Sets the bottom inset
91       * @param bottom
92       */
93      public void setBottom( int bottom ) {
94          this.bottom = bottom;
95      }
96  
97      /***
98       * Factory method to create a new EmptyBorder instance.
99       */
100     protected Border createBorder() {
101         return BorderFactory.createEmptyBorder( top, left, bottom, right);
102     }
103 
104 }