Merge from mainline.
[official-gcc.git] / libjava / classpath / javax / swing / border / AbstractBorder.java
blobc995de1c2029144684b68ec36454eb1e7aa4863c
1 /* AbstractBorder.java --
2 Copyright (C) 2003, 2006, Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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.
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.
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.
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.
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. */
39 package javax.swing.border;
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;
48 /**
49 * An invisible zero-width border, serving as a base class for
50 * implementing more interesting borders.
52 * @author Sascha Brawer (brawer@dandelis.ch)
53 * @author Ronald Veldema (rveldema@cs.vu.nl)
55 public abstract class AbstractBorder implements Border, Serializable
57 static final long serialVersionUID = -545885975315191844L;
59 /**
60 * Constructs a new AbstractBorder.
62 public AbstractBorder()
64 // Nothing to do here.
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 * to do so.
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.
80 public void paintBorder(Component c, Graphics g, int x, int y, int width,
81 int height)
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.
89 /**
90 * Returns the insets required for drawing this border around the specified
91 * component.
93 * @param c the component that the border applies to (ignored here,
94 * subclasses may use it).
96 * @return an Insets object whose <code>left</code>, <code>right</code>,
97 * <code>top</code> and <code>bottom</code> fields indicate the
98 * width of the border at the respective edge, which is zero
99 * for the default implementation provided by AbstractButton.
101 * @see #getBorderInsets(java.awt.Component, java.awt.Insets)
103 public Insets getBorderInsets(Component c)
105 return new Insets(0, 0, 0, 0);
109 * Returns the insets required for drawing this border around the specified
110 * component. The default implementation provided here sets the
111 * <code>left</code>, <code>right</code>, <code>top</code> and
112 * <code>bottom</code> fields of the passed <code>insets</code> parameter to
113 * zero.
115 * @param c the component that the border applies to (ignored here,
116 * subclasses may use it).
117 * @param insets an instance that will be overwritten and returned as the
118 * result (<code>null</code> not permitted).
120 * @return The border insets (the same object that was passed as the
121 * <code>insets</code> argument).
123 * @see #getBorderInsets(Component)
125 * @throws NullPointerException if <code>insets</code> is <code>null</code>.
127 public Insets getBorderInsets(Component c, Insets insets)
129 insets.left = insets.right = insets.top = insets.bottom = 0;
130 return insets;
134 * Determines whether or not this border is opaque. An opaque border
135 * fills every pixel in its area when painting. Partially
136 * translucent borders must return <code>false</code>, or ugly
137 * artifacts can appear on screen. The default implementation
138 * provided here always returns <code>false</code>.
140 * @return <code>false</code>.
142 public boolean isBorderOpaque()
144 return false;
148 * Returns a rectangle that covers the specified area minus the insets
149 * required to draw this border. Components that wish to determine an area
150 * into which they can safely draw without intersecting with a border might
151 * want to use this helper method.
153 * @param c the component in the center of this border.
154 * @param x the horizontal position of the border.
155 * @param y the vertical position of the border.
156 * @param width the width of the available area for the border.
157 * @param height the height of the available area for the border.
159 * @return The interior rectangle.
161 public Rectangle getInteriorRectangle(Component c, int x, int y, int width,
162 int height)
164 return getInteriorRectangle(c, this, x, y, width, height);
168 * Returns a rectangle that covers the specified area minus the insets
169 * required to draw the specified border (if the border is <code>null</code>,
170 * zero insets are assumed). Components that wish to determine an area into
171 * which they can safely draw without intersecting with a border might want
172 * to use this helper method.
174 * @param c the component in the center of this border.
175 * @param b the border (<code>null</code> permitted).
176 * @param x the horizontal position of the border.
177 * @param y the vertical position of the border.
178 * @param width the width of the available area for the border.
179 * @param height the height of the available area for the border.
181 * @return The interior rectangle.
183 public static Rectangle getInteriorRectangle(Component c, Border b, int x,
184 int y, int width, int height)
186 Insets borderInsets;
188 if (b != null)
190 borderInsets = b.getBorderInsets(c);
191 x += borderInsets.left;
192 y += borderInsets.top;
193 width -= borderInsets.left + borderInsets.right;
194 height -= borderInsets.top + borderInsets.bottom;
197 return new Rectangle (x, y, width, height);