1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
127 }
128
129 public static Border getInternalFrameBorder() {
130 UIDefaults table = UIManager.getLookAndFeelDefaults();
131 Border internalFrameBorder = new BorderUIResource.CompoundBorderUIResource(
132 new BevelBorder(BevelBorder.RAISED,
133 table.getColor("InternalFrame.borderLight"),
134 table.getColor("InternalFrame.borderHighlight"),
135 table.getColor("InternalFrame.borderDarkShadow"),
136 table.getColor("InternalFrame.borderShadow")),
137 BorderFactory.createLineBorder(
138 table.getColor("InternalFrame.borderColor"), 1));
139
140 return internalFrameBorder;
141 }
142
143 /**
144 * Special thin border for rollover toolbar buttons.
145 * @since 1.4
146 */
147 public static class RolloverButtonBorder extends ButtonBorder {
148
149 public RolloverButtonBorder(Color shadow, Color darkShadow,
150 Color highlight, Color lightHighlight) {
151 super(shadow, darkShadow, highlight, lightHighlight);
152 }
153
154 public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
155 AbstractButton b = (AbstractButton) c;
156 ButtonModel model = b.getModel();
157
158 Color shade = shadow;
159 Component p = b.getParent();
160 if (p != null && p.getBackground().equals(shadow)) {
161 shade = darkShadow;
162 }
163
164 if ((model.isRollover() && !(model.isPressed() && !model.isArmed())) ||
165 model.isSelected()) {
166
179 g.setColor(lightHighlight);
180 g.drawRect(0, 0, w-1, h-1);
181 g.setColor(shade);
182 g.drawLine(w-1, 0, w-1, h-1);
183 g.drawLine(0, h-1, w-1, h-1);
184 }
185 g.translate(-x, -y);
186 g.setColor(oldColor);
187 }
188 }
189 }
190
191
192 /**
193 * A border which is like a Margin border but it will only honor the margin
194 * if the margin has been explicitly set by the developer.
195 *
196 * Note: This is identical to the package private class
197 * MetalBorders.RolloverMarginBorder and should probably be consolidated.
198 */
199 static class RolloverMarginBorder extends EmptyBorder {
200
201 public RolloverMarginBorder() {
202 super(3,3,3,3); // hardcoded margin for JLF requirements.
203 }
204
205 public Insets getBorderInsets(Component c, Insets insets) {
206 Insets margin = null;
207
208 if (c instanceof AbstractButton) {
209 margin = ((AbstractButton)c).getMargin();
210 }
211 if (margin == null || margin instanceof UIResource) {
212 // default margin so replace
213 insets.left = left;
214 insets.top = top;
215 insets.right = right;
216 insets.bottom = bottom;
217 } else {
218 // Margin which has been explicitly set by the user.
219 insets.left = margin.left;
220 insets.top = margin.top;
221 insets.right = margin.right;
222 insets.bottom = margin.bottom;
223 }
224 return insets;
225 }
226 }
227
228 public static class ButtonBorder extends AbstractBorder implements UIResource {
229 protected Color shadow;
230 protected Color darkShadow;
231 protected Color highlight;
232 protected Color lightHighlight;
233
234 public ButtonBorder(Color shadow, Color darkShadow,
235 Color highlight, Color lightHighlight) {
236 this.shadow = shadow;
237 this.darkShadow = darkShadow;
238 this.highlight = highlight;
239 this.lightHighlight = lightHighlight;
240 }
241
242 public void paintBorder(Component c, Graphics g, int x, int y,
243 int width, int height) {
244 boolean isPressed = false;
245 boolean isDefault = false;
246
247 if (c instanceof AbstractButton) {
250
251 isPressed = model.isPressed() && model.isArmed();
252
253 if (c instanceof JButton) {
254 isDefault = ((JButton)c).isDefaultButton();
255 }
256 }
257 BasicGraphicsUtils.drawBezel(g, x, y, width, height,
258 isPressed, isDefault, shadow,
259 darkShadow, highlight, lightHighlight);
260 }
261
262 public Insets getBorderInsets(Component c, Insets insets) {
263 // leave room for default visual
264 insets.set(2, 3, 3, 3);
265 return insets;
266 }
267
268 }
269
270 public static class ToggleButtonBorder extends ButtonBorder {
271
272 public ToggleButtonBorder(Color shadow, Color darkShadow,
273 Color highlight, Color lightHighlight) {
274 super(shadow, darkShadow, highlight, lightHighlight);
275 }
276
277 public void paintBorder(Component c, Graphics g, int x, int y,
278 int width, int height) {
279 BasicGraphicsUtils.drawBezel(g, x, y, width, height,
280 false, false,
281 shadow, darkShadow,
282 highlight, lightHighlight);
283 }
284
285 public Insets getBorderInsets(Component c, Insets insets) {
286 insets.set(2, 2, 2, 2);
287 return insets;
288 }
289 }
290
291 public static class RadioButtonBorder extends ButtonBorder {
292
293 public RadioButtonBorder(Color shadow, Color darkShadow,
294 Color highlight, Color lightHighlight) {
295 super(shadow, darkShadow, highlight, lightHighlight);
296 }
297
298
299 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
300
301 if (c instanceof AbstractButton) {
302 AbstractButton b = (AbstractButton)c;
303 ButtonModel model = b.getModel();
304
305 if (model.isArmed() && model.isPressed() || model.isSelected()) {
306 BasicGraphicsUtils.drawLoweredBezel(g, x, y, width, height,
307 shadow, darkShadow,
308 highlight, lightHighlight);
309 } else {
310 BasicGraphicsUtils.drawBezel(g, x, y, width, height,
311 false, b.isFocusPainted() && b.hasFocus(),
312 shadow, darkShadow,
313 highlight, lightHighlight);
314 }
315 } else {
316 BasicGraphicsUtils.drawBezel(g, x, y, width, height, false, false,
317 shadow, darkShadow, highlight, lightHighlight);
318 }
319 }
320
321 public Insets getBorderInsets(Component c, Insets insets) {
322 insets.set(2, 2, 2, 2);
323 return insets;
324 }
325 }
326
327 public static class MenuBarBorder extends AbstractBorder implements UIResource {
328 private Color shadow;
329 private Color highlight;
330
331 public MenuBarBorder(Color shadow, Color highlight) {
332 this.shadow = shadow;
333 this.highlight = highlight;
334 }
335
336 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
337 Color oldColor = g.getColor();
338 g.translate(x, y);
339 g.setColor(shadow);
340 g.drawLine(0, height-2, width, height-2);
341 g.setColor(highlight);
342 g.drawLine(0, height-1, width, height-1);
343 g.translate(-x,-y);
344 g.setColor(oldColor);
345 }
346
347 public Insets getBorderInsets(Component c, Insets insets) {
348 insets.set(0, 0, 2, 0);
349 return insets;
350 }
351 }
352
353 public static class MarginBorder extends AbstractBorder implements UIResource {
354 public Insets getBorderInsets(Component c, Insets insets) {
355 Insets margin = null;
356 //
357 // Ideally we'd have an interface defined for classes which
358 // support margins (to avoid this hackery), but we've
359 // decided against it for simplicity
360 //
361 if (c instanceof AbstractButton) {
362 AbstractButton b = (AbstractButton)c;
363 margin = b.getMargin();
364 } else if (c instanceof JToolBar) {
365 JToolBar t = (JToolBar)c;
366 margin = t.getMargin();
367 } else if (c instanceof JTextComponent) {
368 JTextComponent t = (JTextComponent)c;
369 margin = t.getMargin();
370 }
371 insets.top = margin != null? margin.top : 0;
372 insets.left = margin != null? margin.left : 0;
373 insets.bottom = margin != null? margin.bottom : 0;
374 insets.right = margin != null? margin.right : 0;
375
376 return insets;
377 }
378 }
379
380 public static class FieldBorder extends AbstractBorder implements UIResource {
381 protected Color shadow;
382 protected Color darkShadow;
383 protected Color highlight;
384 protected Color lightHighlight;
385
386 public FieldBorder(Color shadow, Color darkShadow,
387 Color highlight, Color lightHighlight) {
388 this.shadow = shadow;
389 this.highlight = highlight;
390 this.darkShadow = darkShadow;
391 this.lightHighlight = lightHighlight;
392 }
393
394 public void paintBorder(Component c, Graphics g, int x, int y,
395 int width, int height) {
396 BasicGraphicsUtils.drawEtchedRect(g, x, y, width, height,
397 shadow, darkShadow,
398 highlight, lightHighlight);
399 }
|
1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
127 }
128
129 public static Border getInternalFrameBorder() {
130 UIDefaults table = UIManager.getLookAndFeelDefaults();
131 Border internalFrameBorder = new BorderUIResource.CompoundBorderUIResource(
132 new BevelBorder(BevelBorder.RAISED,
133 table.getColor("InternalFrame.borderLight"),
134 table.getColor("InternalFrame.borderHighlight"),
135 table.getColor("InternalFrame.borderDarkShadow"),
136 table.getColor("InternalFrame.borderShadow")),
137 BorderFactory.createLineBorder(
138 table.getColor("InternalFrame.borderColor"), 1));
139
140 return internalFrameBorder;
141 }
142
143 /**
144 * Special thin border for rollover toolbar buttons.
145 * @since 1.4
146 */
147 @SuppressWarnings("serial") // Superclass is not serializable across versions
148 public static class RolloverButtonBorder extends ButtonBorder {
149
150 public RolloverButtonBorder(Color shadow, Color darkShadow,
151 Color highlight, Color lightHighlight) {
152 super(shadow, darkShadow, highlight, lightHighlight);
153 }
154
155 public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
156 AbstractButton b = (AbstractButton) c;
157 ButtonModel model = b.getModel();
158
159 Color shade = shadow;
160 Component p = b.getParent();
161 if (p != null && p.getBackground().equals(shadow)) {
162 shade = darkShadow;
163 }
164
165 if ((model.isRollover() && !(model.isPressed() && !model.isArmed())) ||
166 model.isSelected()) {
167
180 g.setColor(lightHighlight);
181 g.drawRect(0, 0, w-1, h-1);
182 g.setColor(shade);
183 g.drawLine(w-1, 0, w-1, h-1);
184 g.drawLine(0, h-1, w-1, h-1);
185 }
186 g.translate(-x, -y);
187 g.setColor(oldColor);
188 }
189 }
190 }
191
192
193 /**
194 * A border which is like a Margin border but it will only honor the margin
195 * if the margin has been explicitly set by the developer.
196 *
197 * Note: This is identical to the package private class
198 * MetalBorders.RolloverMarginBorder and should probably be consolidated.
199 */
200 @SuppressWarnings("serial") // Superclass is not serializable across versions
201 static class RolloverMarginBorder extends EmptyBorder {
202
203 public RolloverMarginBorder() {
204 super(3,3,3,3); // hardcoded margin for JLF requirements.
205 }
206
207 public Insets getBorderInsets(Component c, Insets insets) {
208 Insets margin = null;
209
210 if (c instanceof AbstractButton) {
211 margin = ((AbstractButton)c).getMargin();
212 }
213 if (margin == null || margin instanceof UIResource) {
214 // default margin so replace
215 insets.left = left;
216 insets.top = top;
217 insets.right = right;
218 insets.bottom = bottom;
219 } else {
220 // Margin which has been explicitly set by the user.
221 insets.left = margin.left;
222 insets.top = margin.top;
223 insets.right = margin.right;
224 insets.bottom = margin.bottom;
225 }
226 return insets;
227 }
228 }
229
230 @SuppressWarnings("serial") // Superclass is not serializable across versions
231 public static class ButtonBorder extends AbstractBorder implements UIResource {
232 protected Color shadow;
233 protected Color darkShadow;
234 protected Color highlight;
235 protected Color lightHighlight;
236
237 public ButtonBorder(Color shadow, Color darkShadow,
238 Color highlight, Color lightHighlight) {
239 this.shadow = shadow;
240 this.darkShadow = darkShadow;
241 this.highlight = highlight;
242 this.lightHighlight = lightHighlight;
243 }
244
245 public void paintBorder(Component c, Graphics g, int x, int y,
246 int width, int height) {
247 boolean isPressed = false;
248 boolean isDefault = false;
249
250 if (c instanceof AbstractButton) {
253
254 isPressed = model.isPressed() && model.isArmed();
255
256 if (c instanceof JButton) {
257 isDefault = ((JButton)c).isDefaultButton();
258 }
259 }
260 BasicGraphicsUtils.drawBezel(g, x, y, width, height,
261 isPressed, isDefault, shadow,
262 darkShadow, highlight, lightHighlight);
263 }
264
265 public Insets getBorderInsets(Component c, Insets insets) {
266 // leave room for default visual
267 insets.set(2, 3, 3, 3);
268 return insets;
269 }
270
271 }
272
273 @SuppressWarnings("serial") // Superclass is not serializable across versions
274 public static class ToggleButtonBorder extends ButtonBorder {
275
276 public ToggleButtonBorder(Color shadow, Color darkShadow,
277 Color highlight, Color lightHighlight) {
278 super(shadow, darkShadow, highlight, lightHighlight);
279 }
280
281 public void paintBorder(Component c, Graphics g, int x, int y,
282 int width, int height) {
283 BasicGraphicsUtils.drawBezel(g, x, y, width, height,
284 false, false,
285 shadow, darkShadow,
286 highlight, lightHighlight);
287 }
288
289 public Insets getBorderInsets(Component c, Insets insets) {
290 insets.set(2, 2, 2, 2);
291 return insets;
292 }
293 }
294
295 @SuppressWarnings("serial") // Superclass is not serializable across versions
296 public static class RadioButtonBorder extends ButtonBorder {
297
298 public RadioButtonBorder(Color shadow, Color darkShadow,
299 Color highlight, Color lightHighlight) {
300 super(shadow, darkShadow, highlight, lightHighlight);
301 }
302
303
304 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
305
306 if (c instanceof AbstractButton) {
307 AbstractButton b = (AbstractButton)c;
308 ButtonModel model = b.getModel();
309
310 if (model.isArmed() && model.isPressed() || model.isSelected()) {
311 BasicGraphicsUtils.drawLoweredBezel(g, x, y, width, height,
312 shadow, darkShadow,
313 highlight, lightHighlight);
314 } else {
315 BasicGraphicsUtils.drawBezel(g, x, y, width, height,
316 false, b.isFocusPainted() && b.hasFocus(),
317 shadow, darkShadow,
318 highlight, lightHighlight);
319 }
320 } else {
321 BasicGraphicsUtils.drawBezel(g, x, y, width, height, false, false,
322 shadow, darkShadow, highlight, lightHighlight);
323 }
324 }
325
326 public Insets getBorderInsets(Component c, Insets insets) {
327 insets.set(2, 2, 2, 2);
328 return insets;
329 }
330 }
331
332 @SuppressWarnings("serial") // Superclass is not serializable across versions
333 public static class MenuBarBorder extends AbstractBorder implements UIResource {
334 private Color shadow;
335 private Color highlight;
336
337 public MenuBarBorder(Color shadow, Color highlight) {
338 this.shadow = shadow;
339 this.highlight = highlight;
340 }
341
342 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
343 Color oldColor = g.getColor();
344 g.translate(x, y);
345 g.setColor(shadow);
346 g.drawLine(0, height-2, width, height-2);
347 g.setColor(highlight);
348 g.drawLine(0, height-1, width, height-1);
349 g.translate(-x,-y);
350 g.setColor(oldColor);
351 }
352
353 public Insets getBorderInsets(Component c, Insets insets) {
354 insets.set(0, 0, 2, 0);
355 return insets;
356 }
357 }
358
359 @SuppressWarnings("serial") // Superclass is not serializable across versions
360 public static class MarginBorder extends AbstractBorder implements UIResource {
361 public Insets getBorderInsets(Component c, Insets insets) {
362 Insets margin = null;
363 //
364 // Ideally we'd have an interface defined for classes which
365 // support margins (to avoid this hackery), but we've
366 // decided against it for simplicity
367 //
368 if (c instanceof AbstractButton) {
369 AbstractButton b = (AbstractButton)c;
370 margin = b.getMargin();
371 } else if (c instanceof JToolBar) {
372 JToolBar t = (JToolBar)c;
373 margin = t.getMargin();
374 } else if (c instanceof JTextComponent) {
375 JTextComponent t = (JTextComponent)c;
376 margin = t.getMargin();
377 }
378 insets.top = margin != null? margin.top : 0;
379 insets.left = margin != null? margin.left : 0;
380 insets.bottom = margin != null? margin.bottom : 0;
381 insets.right = margin != null? margin.right : 0;
382
383 return insets;
384 }
385 }
386
387 @SuppressWarnings("serial") // Superclass is not serializable across versions
388 public static class FieldBorder extends AbstractBorder implements UIResource {
389 protected Color shadow;
390 protected Color darkShadow;
391 protected Color highlight;
392 protected Color lightHighlight;
393
394 public FieldBorder(Color shadow, Color darkShadow,
395 Color highlight, Color lightHighlight) {
396 this.shadow = shadow;
397 this.highlight = highlight;
398 this.darkShadow = darkShadow;
399 this.lightHighlight = lightHighlight;
400 }
401
402 public void paintBorder(Component c, Graphics g, int x, int y,
403 int width, int height) {
404 BasicGraphicsUtils.drawEtchedRect(g, x, y, width, height,
405 shadow, darkShadow,
406 highlight, lightHighlight);
407 }
|