Source for javax.swing.border.AbstractBorder

   1: /* AbstractBorder.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: import java.awt.Rectangle;
  45: import java.io.Serializable;
  46: 
  47: 
  48: /**
  49:  * An invisible zero-width border, serving as a base class for
  50:  * implementing more interesting borders.
  51:  *
  52:  * @author Sascha Brawer (brawer@dandelis.ch)
  53:  * @author Ronald Veldema (rveldema@cs.vu.nl)
  54:  */
  55: public abstract class AbstractBorder implements Border, Serializable
  56: {
  57:   static final long serialVersionUID = -545885975315191844L;
  58: 
  59:   /**
  60:    * Constructs a new AbstractBorder.
  61:    */
  62:   public AbstractBorder()
  63:   {
  64:     // Nothing to do here.
  65:   }
  66: 
  67:   /**
  68:    * Performs nothing, because the default implementation provided by
  69:    * this class is an invisible, zero-width border. Subclasses will
  70:    * likely want to override this method, but they are not required
  71:    * for doing so.
  72:    *
  73:    * @param c the component whose border is to be painted.
  74:    * @param g the graphics for painting.
  75:    * @param x the horizontal position for painting the border.
  76:    * @param y the vertical position for painting the border.
  77:    * @param width the width of the available area for painting the border.
  78:    * @param height the height of the available area for painting the border.
  79:    */
  80:   public void paintBorder(Component c, Graphics g, int x, int y, int width,
  81:                           int height)
  82:   {
  83:     // A previous version of Classpath had emitted a warning when
  84:     // this method was called. The warning was removed because it is
  85:     // perfectly legal for a subclass to not override the paintBorder
  86:     // method. An example would be EmptyBorder.
  87:   }
  88: 
  89:   /**
  90:    * Measures the width of this border.
  91:    *
  92:    * @param c the component whose border is to be measured.
  93:    *
  94:    * @return an Insets object whose <code>left</code>, <code>right</code>,
  95:    *         <code>top</code> and <code>bottom</code> fields indicate the
  96:    *         width of the border at the respective edge, which is zero
  97:    *         for the default implementation provided by AbstractButton.
  98:    *
  99:    * @see #getBorderInsets(java.awt.Component, java.awt.Insets)
 100:    */
 101:   public Insets getBorderInsets(Component c)
 102:   {
 103:     return new Insets(0, 0, 0, 0);
 104:   }
 105: 
 106:   /**
 107:    * Determines the insets of this border. The implementation provided
 108:    * by AbstractButton sets the <code>left</code>, <code>right</code>,
 109:    * <code>top</code> and <code>bottom</code> fields of the passed
 110:    * <code>insets</code> parameter to zero.
 111:    *
 112:    * @param c the component whose border is to be measured
 113:    *
 114:    * @return the same object that was passed for <code>insets</code>
 115:    *
 116:    * @see #getBorderInsets(Component)
 117:    */
 118:   public Insets getBorderInsets(Component c, Insets insets) 
 119:   {
 120:     insets.left = insets.right = insets.top = insets.bottom = 0;
 121:     return insets;
 122:   }
 123: 
 124:   /**
 125:    * Determines whether or not this border is opaque. An opaque border
 126:    * fills every pixel in its area when painting. Partially
 127:    * translucent borders must return <code>false</code>, or ugly
 128:    * artifacts can appear on screen. The default implementation
 129:    * provided by AbstractBorder always returns <code>false</code>.
 130:    *
 131:    * @return <code>false</code>.
 132:    */
 133:   public boolean isBorderOpaque() 
 134:   {
 135:     return false;
 136:   }
 137: 
 138:   /**
 139:    * Returns a rectangle that covers the specified area minus this
 140:    * border.  Components that wish to determine an area into which
 141:    * they can safely draw without intersecting with a border might
 142:    * want to use this helper method.
 143:    *
 144:    * @param c the component in the center of this border.
 145:    * @param x the horizontal position of the border.
 146:    * @param y the vertical position of the border.
 147:    * @param width the width of the available area for the border.
 148:    * @param height the height of the available area for the border.
 149:    */
 150:   public Rectangle getInteriorRectangle(Component c, int x, int y, int width,
 151:                                         int height)
 152:   {
 153:     return getInteriorRectangle (c, this, x, y, width, height);
 154:   }
 155:   
 156:   /**
 157:    * Returns a rectangle that covers the specified area minus a
 158:    * border.  Components that wish to determine an area into which
 159:    * they can safely draw without intersecting with a border might
 160:    * want to use this helper method.
 161:    *
 162:    * @param c the component in the center of this border.
 163:    * @param x the horizontal position of the border.
 164:    * @param y the vertical position of the border.
 165:    * @param width the width of the available area for the border.
 166:    * @param height the height of the available area for the border.
 167:    */
 168:   public static Rectangle getInteriorRectangle(Component c, Border b, int x,
 169:                                                int y, int width, int height)
 170:   {
 171:     Insets borderInsets;
 172: 
 173:     if (b != null)
 174:     {
 175:       borderInsets = b.getBorderInsets (c);
 176:       x += borderInsets.left;
 177:       y += borderInsets.top;
 178:       width -= borderInsets.left + borderInsets.right;
 179:       height -= borderInsets.top + borderInsets.bottom;
 180:     }
 181: 
 182:     return new Rectangle (x, y, width, height);
 183:   }
 184: }