|
1 /* |
|
2 * CDDL HEADER START |
|
3 * |
|
4 * The contents of this file are subject to the terms of the |
|
5 * Common Development and Distribution License (the "License"). |
|
6 * You may not use this file except in compliance with the License. |
|
7 * |
|
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 * or http://www.opensolaris.org/os/licensing. |
|
10 * See the License for the specific language governing permissions |
|
11 * and limitations under the License. |
|
12 * |
|
13 * When distributing Covered Code, include this CDDL HEADER in each |
|
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 * If applicable, add the following below this CDDL HEADER, with the |
|
16 * fields enclosed by brackets "[]" replaced with your own identifying |
|
17 * information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 * |
|
19 * CDDL HEADER END |
|
20 */ |
|
21 |
|
22 /* |
|
23 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. |
|
24 */ |
|
25 |
|
26 package com.oracle.solaris.vp.util.swing; |
|
27 |
|
28 import java.awt.*; |
|
29 import java.awt.geom.RoundRectangle2D; |
|
30 import java.awt.geom.RoundRectangle2D.Float; |
|
31 import javax.swing.border.Border; |
|
32 |
|
33 public class RoundRectBorder implements Border { |
|
34 // |
|
35 // Instance data |
|
36 // |
|
37 |
|
38 private Color color; |
|
39 private int thickness; |
|
40 private int arc; |
|
41 |
|
42 // |
|
43 // Constructors |
|
44 // |
|
45 |
|
46 public RoundRectBorder(Color color, int thickness, int arc) { |
|
47 this.color = color; |
|
48 this.thickness = thickness; |
|
49 this.arc = arc; |
|
50 } |
|
51 |
|
52 // |
|
53 // Border methods |
|
54 // |
|
55 |
|
56 @Override |
|
57 public Insets getBorderInsets(Component c) { |
|
58 return new Insets(thickness, thickness, thickness, thickness); |
|
59 } |
|
60 |
|
61 @Override |
|
62 public boolean isBorderOpaque() { |
|
63 return false; |
|
64 } |
|
65 |
|
66 @Override |
|
67 public void paintBorder(Component c, Graphics g, int x, int y, int width, |
|
68 int height) { |
|
69 |
|
70 Graphics2D g2 = (Graphics2D)g; |
|
71 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
|
72 RenderingHints.VALUE_ANTIALIAS_ON); |
|
73 |
|
74 g2.setColor(getColor()); |
|
75 g2.setStroke(new BasicStroke((float)thickness)); |
|
76 g2.drawRoundRect(x + thickness / 2, y + thickness / 2, |
|
77 width - thickness, height - thickness, arc, arc); |
|
78 } |
|
79 |
|
80 // |
|
81 // RoundRectBorder methods |
|
82 // |
|
83 |
|
84 public Color getColor() { |
|
85 return color; |
|
86 } |
|
87 |
|
88 public int getThickness() { |
|
89 return thickness; |
|
90 } |
|
91 |
|
92 public int getArc() { |
|
93 return arc; |
|
94 } |
|
95 |
|
96 public Float getClip(Component c) { |
|
97 return new Float(0, 0, (float)c.getWidth(), (float)c.getHeight(), |
|
98 (float)arc, (float)arc); |
|
99 } |
|
100 } |