Source for javax.swing.border.EmptyBorder

   1: /* EmptyBorder.java -- 
   2:    Copyright (C) 2003 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package javax.swing.border;
  40: 
  41: import java.awt.Component;
  42: import java.awt.Graphics;
  43: import java.awt.Insets;
  44: 
  45: 
  46: /**
  47:  * A border for leaving a specifiable number of pixels empty around
  48:  * the enclosed component.  An EmptyBorder requires some space on each
  49:  * edge, but does not perform any drawing.
  50:  *
  51:  * <p><img src="EmptyBorder-1.png" width="290" height="200"
  52:  * alt="[An illustration of EmptyBorder]" />
  53:  *
  54:  * @author Sascha Brawer (brawer@dandelis.ch)
  55:  */
  56: public class EmptyBorder extends AbstractBorder
  57: {
  58:   /**
  59:    * Determined using the <code>serialver</code> tool
  60:    * of Apple/Sun JDK 1.3.1 on MacOS X 10.1.5.
  61:    */
  62:   static final long serialVersionUID = -8116076291731988694L;
  63: 
  64: 
  65:   /**
  66:    * The number of pixels required at the left edge.
  67:    */
  68:   protected int left;
  69: 
  70: 
  71:   /**
  72:    * The number of pixels required at the right edge.
  73:    */
  74:   protected int right;
  75: 
  76: 
  77:   /**
  78:    * The number of pixels required at the top edge.
  79:    */
  80:   protected int top;
  81: 
  82: 
  83:   /**
  84:    * The number of pixels required at the bottom edge.
  85:    */
  86:   protected int bottom;
  87: 
  88: 
  89:   /**
  90:    * Constructs an empty border given the number of pixels required
  91:    * on each side.
  92:    *
  93:    * @param top the number of pixels that the border will need
  94:    *        for its top edge.
  95:    *
  96:    * @param left the number of pixels that the border will need
  97:    *        for its left edge.
  98:    *
  99:    * @param bottom the number of pixels that the border will need
 100:    *        for its bottom edge.
 101:    *
 102:    * @param right the number of pixels that the border will need
 103:    *        for its right edge.
 104:    */
 105:   public EmptyBorder(int top, int left, int bottom, int right)
 106:   {
 107:     this.top = top;
 108:     this.left = left;
 109:     this.bottom = bottom;
 110:     this.right = right;
 111:   }
 112: 
 113: 
 114:   /**
 115:    * Constructs an empty border given the number of pixels required
 116:    * on each side, passed in an Insets object.
 117:    *
 118:    * @param borderInsets the Insets for the new border.
 119:    */
 120:   public EmptyBorder(Insets borderInsets)
 121:   {
 122:     this(borderInsets.top, borderInsets.left,
 123:          borderInsets.bottom, borderInsets.right);
 124:   }
 125: 
 126: 
 127:   /**
 128:    * Performs nothing because an EmptyBorder does not paint any
 129:    * pixels. While the inherited implementation provided by
 130:    * {@link AbstractBorder#paintBorder} is a no-op as well,
 131:    * it is overwritten in order to match the API of the Sun
 132:    * reference implementation.
 133:    *
 134:    * @param c the component whose border is to be painted.
 135:    * @param g the graphics for painting.
 136:    * @param x the horizontal position for painting the border.
 137:    * @param y the vertical position for painting the border.
 138:    * @param width the width of the available area for painting the border.
 139:    * @param height the height of the available area for painting the border.
 140:    */
 141:   public void paintBorder(Component c, Graphics g,
 142:                           int x, int y, int width, int height)
 143:   {
 144:     // Nothing to do here.
 145:   }
 146: 
 147: 
 148:   /**
 149:    * Measures the width of this border.
 150:    *
 151:    * @param c the component whose border is to be measured.
 152:    *
 153:    * @return an Insets object whose <code>left</code>, <code>right</code>,
 154:    *         <code>top</code> and <code>bottom</code> fields indicate the
 155:    *         width of the border at the respective edge.
 156:    *
 157:    * @see #getBorderInsets(java.awt.Component, java.awt.Insets)
 158:    */
 159:   public Insets getBorderInsets(Component c)
 160:   {
 161:     return getBorderInsets(c, null);
 162:   }
 163: 
 164: 
 165:   /**
 166:    * Measures the width of this border, storing the results into a
 167:    * pre-existing Insets object.
 168:    *
 169:    * @param insets an Insets object for holding the result values.
 170:    *        After invoking this method, the <code>left</code>,
 171:    *        <code>right</code>, <code>top</code> and
 172:    *        <code>bottom</code> fields indicate the width of the
 173:    *        border at the respective edge.
 174:    *
 175:    * @return the same object that was passed for <code>insets</code>.
 176:    *
 177:    * @see #getBorderInsets()
 178:    */
 179:   public Insets getBorderInsets(Component c, Insets insets)
 180:   {
 181:     if (insets == null)
 182:       insets = new Insets(0, 0, 0, 0);
 183: 
 184:     insets.left = left;
 185:     insets.right = right;
 186:     insets.top = top;
 187:     insets.bottom = bottom;
 188:     return insets;
 189:   }
 190: 
 191: 
 192:   /**
 193:    * Measures the width of this border.
 194:    *
 195:    * @return an Insets object whose <code>left</code>, <code>right</code>,
 196:    *         <code>top</code> and <code>bottom</code> fields indicate the
 197:    *         width of the border at the respective edge.
 198:    *
 199:    * @see #getBorderInsets(java.awt.Component, java.awt.Insets)
 200:    */
 201:   public Insets getBorderInsets()
 202:   {
 203:     return getBorderInsets(null, null);
 204:   }
 205:   
 206:   
 207:   /**
 208:    * Determines whether this border fills every pixel in its area
 209:    * when painting. Since an empty border does not paint any pixels
 210:    * whatsoever, the result is <code>false</code>.
 211:    *
 212:    * @return <code>false</code>.
 213:    */
 214:   public boolean isBorderOpaque()
 215:   {
 216:     /* The inherited implementation of AbstractBorder.isBorderOpaque()
 217:      * would also return false. It is not clear why this is overriden
 218:      * in the Sun implementation, at least not from just reading the
 219:      * JavaDoc.
 220:      */
 221:     return false;
 222:   }
 223: }