1 |
/* AbstractBorder.java -- |
/* AbstractBorder.java -- |
2 |
Copyright (C) 2002 Free Software Foundation, Inc. |
Copyright (C) 2003 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
44 |
import java.awt.Rectangle; |
import java.awt.Rectangle; |
45 |
import java.io.Serializable; |
import java.io.Serializable; |
46 |
|
|
47 |
public abstract class AbstractBorder implements Border, Serializable |
|
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; |
static final long serialVersionUID = -545885975315191844L; |
59 |
|
|
60 |
|
|
61 |
|
/** |
62 |
|
* Constructs a new AbstractBorder. |
63 |
|
*/ |
64 |
public AbstractBorder () |
public AbstractBorder () |
65 |
{ |
{ |
66 |
} |
} |
67 |
|
|
|
public void paintBorder(Component c, |
|
|
Graphics g, |
|
|
int x, |
|
|
int y, |
|
|
int width, |
|
|
int height) |
|
|
{ |
|
|
System.out.println("HMMMMM, abstract-border.paintBorder"); |
|
|
} |
|
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 |
|
|
|
public Insets getBorderInsets(Component c, Insets insets) |
|
|
{ |
|
|
if (insets == null) |
|
|
insets = new Insets(0,0,0,0); |
|
|
|
|
|
insets.left = insets.top = insets.right = insets.bottom = 5; |
|
92 |
|
|
93 |
return insets; |
/** |
94 |
} |
* Determines the insets of this border. The implementation provided |
95 |
|
* by AbstractButton returns Insets for a zero-width border, whose |
96 |
|
* <code>left</code>, <code>right</code>, <code>top</code> and |
97 |
|
* <code>bottom</code> fields are all zero. |
98 |
|
* |
99 |
|
* @param c the component whose border is to be measured. |
100 |
|
* |
101 |
|
* @return a newly created Insets object, indicating a zero-width |
102 |
|
* border. |
103 |
|
*/ |
104 |
|
public Insets getBorderInsets (Component c) |
105 |
|
{ |
106 |
|
return new Insets (0, 0, 0, 0); |
107 |
|
} |
108 |
|
|
|
public Insets getBorderInsets(Component c) |
|
|
{ |
|
|
return getBorderInsets(c, new Insets(0,0,0,0)); |
|
|
} |
|
109 |
|
|
110 |
|
/** |
111 |
|
* Determines the insets of this border. The implementation provided |
112 |
|
* by AbstractButton sets the <code>left</code>, <code>right</code>, |
113 |
|
* <code>top</code> and <code>bottom</code> fields of the passed |
114 |
|
* <code>insets</code> parameter to zero. |
115 |
|
* |
116 |
|
* @param c the component in the center of this border. |
117 |
|
* |
118 |
|
* @param insets an Insets object for holding the insets of this |
119 |
|
* border. |
120 |
|
* |
121 |
|
* @return the <code>insets</code> object. |
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 |
|
|
|
public boolean isBorderOpaque() |
|
|
{ return false; } |
|
129 |
|
|
130 |
public Rectangle getInteriorRectangle(Component c, |
/** |
131 |
int x, |
* Determines whether or not this border is opaque. An opaque border |
132 |
int y, |
* fills every pixel in its area when painting. Partially |
133 |
int width, |
* translucent borders must return <code>false</code>, or ugly |
134 |
int height) |
* artifacts can appear on screen. The default implementation |
135 |
{ |
* provided by AbstractBorder always returns <code>false</code>. |
136 |
return getInteriorRectangle(c, |
* |
137 |
this, |
* @return <code>false</code>. |
138 |
x, |
*/ |
139 |
y, |
public boolean isBorderOpaque () |
140 |
width, |
{ |
141 |
height); |
return false; |
142 |
} |
} |
143 |
|
|
144 |
|
|
145 |
public static Rectangle getInteriorRectangle(Component c, |
/** |
146 |
Border b, |
* Returns a rectangle that covers the specified area minus this |
147 |
int x, |
* border. Components that wish to determine an area into which |
148 |
int y, |
* they can safely draw without intersecting with a border might |
149 |
int width, |
* want to use this helper method. |
150 |
int height) |
* |
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 |
if(b != null) |
borderInsets = b.getBorderInsets (c); |
184 |
{ |
x += borderInsets.left; |
185 |
Insets insets = b.getBorderInsets(c); |
y += borderInsets.top; |
186 |
|
width -= borderInsets.left + borderInsets.right; |
187 |
int w = insets.right - insets.left; |
height -= borderInsets.top + borderInsets.bottom; |
|
int h = insets.top - insets.bottom; |
|
|
|
|
|
return new Rectangle(x + insets.left, |
|
|
y + insets.top, |
|
|
width - w, |
|
|
height - h); |
|
|
} |
|
|
else |
|
|
{ |
|
|
return new Rectangle(x, |
|
|
y, |
|
|
width, |
|
|
height); |
|
|
} |
|
188 |
} |
} |
|
} |
|
189 |
|
|
190 |
|
return new Rectangle (x, y, width, height); |
191 |
|
} |
192 |
|
} |