1 |
/* EmptyBorder.java -- |
/* EmptyBorder.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 |
|
|
42 |
import java.awt.Graphics; |
import java.awt.Graphics; |
43 |
import java.awt.Insets; |
import java.awt.Insets; |
44 |
|
|
45 |
public class EmptyBorder extends AbstractBorder |
|
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 |
57 |
|
extends AbstractBorder |
58 |
{ |
{ |
59 |
|
/** |
60 |
|
* Determined using the <code>serialver</code> tool |
61 |
|
* of Apple/Sun JDK 1.3.1 on MacOS X 10.1.5. |
62 |
|
*/ |
63 |
|
static final long serialVersionUID = -8116076291731988694L; |
64 |
|
|
65 |
|
|
66 |
|
/** |
67 |
|
* The number of pixels required at the left edge. |
68 |
|
*/ |
69 |
protected int left; |
protected int left; |
70 |
|
|
71 |
|
|
72 |
|
/** |
73 |
|
* The number of pixels required at the right edge. |
74 |
|
*/ |
75 |
protected int right; |
protected int right; |
76 |
protected int bottom; |
|
77 |
|
|
78 |
|
/** |
79 |
|
* The number of pixels required at the top edge. |
80 |
|
*/ |
81 |
protected int top; |
protected int top; |
82 |
|
|
|
public EmptyBorder (Insets borderInsets) |
|
|
{ |
|
|
this (borderInsets.left, borderInsets.right, |
|
|
borderInsets.top, borderInsets.bottom); |
|
|
} |
|
83 |
|
|
84 |
public EmptyBorder (int left, int right, int top, int bottom) |
/** |
85 |
|
* The number of pixels required at the bottom edge. |
86 |
|
*/ |
87 |
|
protected int bottom; |
88 |
|
|
89 |
|
|
90 |
|
/** |
91 |
|
* Constructs an empty border given the number of pixels required |
92 |
|
* on each side. |
93 |
|
* |
94 |
|
* @param top the number of pixels that the border will need |
95 |
|
* for its top edge. |
96 |
|
* |
97 |
|
* @param left the number of pixels that the border will need |
98 |
|
* for its left edge. |
99 |
|
* |
100 |
|
* @param bottom the number of pixels that the border will need |
101 |
|
* for its bottom edge. |
102 |
|
* |
103 |
|
* @param right the number of pixels that the border will need |
104 |
|
* for its right edge. |
105 |
|
*/ |
106 |
|
public EmptyBorder(int top, int left, int bottom, int right) |
107 |
{ |
{ |
|
this.left = left; |
|
|
this.right = right; |
|
108 |
this.top = top; |
this.top = top; |
109 |
|
this.left = left; |
110 |
this.bottom = bottom; |
this.bottom = bottom; |
111 |
|
this.right = right; |
112 |
} |
} |
113 |
|
|
114 |
public Insets getBorderInsets (Component c, Insets s) |
|
115 |
|
/** |
116 |
|
* Constructs an empty border given the number of pixels required |
117 |
|
* on each side, passed in an Insets object. |
118 |
|
* |
119 |
|
* @param borderInsets the Insets for the new border. |
120 |
|
*/ |
121 |
|
public EmptyBorder(Insets borderInsets) |
122 |
{ |
{ |
123 |
if (s == null) |
this(borderInsets.top, borderInsets.left, |
124 |
s = new Insets (0,0,0,0); |
borderInsets.bottom, borderInsets.right); |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
s.left = left; |
/** |
129 |
s.right = right; |
* Performs nothing because an EmptyBorder does not paint any |
130 |
s.top = top; |
* pixels. While the inherited implementation provided by |
131 |
s.bottom = bottom; |
* {@link AbstractBorder#paintBorder} is a no-op as well, |
132 |
return s; |
* it is overwritten in order to match the API of the Sun |
133 |
|
* reference implementation. |
134 |
|
* |
135 |
|
* @param c the component whose border is to be painted. |
136 |
|
* @param g the graphics for painting. |
137 |
|
* @param x the horizontal position for painting the border. |
138 |
|
* @param y the vertical position for painting the border. |
139 |
|
* @param width the width of the available area for painting the border. |
140 |
|
* @param height the height of the available area for painting the border. |
141 |
|
*/ |
142 |
|
public void paintBorder(Component c, Graphics g, |
143 |
|
int x, int y, int width, int height) |
144 |
|
{ |
145 |
} |
} |
146 |
|
|
147 |
public boolean isBorderOpaque () |
|
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 false; |
return getBorderInsets(c, null); |
162 |
} |
} |
163 |
|
|
164 |
public void paintBorder (Component c, Graphics g, int x, int y, |
|
165 |
int width, int height) |
/** |
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 |
|
* Determines whether this border fills every pixel in its area |
194 |
|
* when painting. Since an empty border does not paint any pixels |
195 |
|
* whatsoever, the result is <code>false</code>. |
196 |
|
* |
197 |
|
* @return <code>false</code>. |
198 |
|
*/ |
199 |
|
public boolean isBorderOpaque() |
200 |
|
{ |
201 |
|
/* The inherited implementation of AbstractBorder.isBorderOpaque() |
202 |
|
* would also return false. It is not clear why this is overriden |
203 |
|
* in the Sun implementation, at least not from just reading the |
204 |
|
* JavaDoc. |
205 |
|
*/ |
206 |
|
return false; |
207 |
|
} |
208 |
|
} |