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