author | rriggs |
Tue, 03 Jun 2014 11:18:03 -0400 | |
changeset 25122 | 1ecc464c69d2 |
parent 24500 | 399b77799d66 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
21982
diff
changeset
|
2 |
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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 |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
package javax.swing.border; |
|
26 |
||
27 |
import java.awt.Graphics; |
|
28 |
import java.awt.Insets; |
|
29 |
import java.awt.Component; |
|
30 |
import java.beans.ConstructorProperties; |
|
31 |
||
32 |
/** |
|
33 |
* A composite Border class used to compose two Border objects |
|
34 |
* into a single border by nesting an inside Border object within |
|
35 |
* the insets of an outside Border object. |
|
36 |
* |
|
37 |
* For example, this class may be used to add blank margin space |
|
38 |
* to a component with an existing decorative border: |
|
21982 | 39 |
* |
20428
929cd48fca8a
8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents:
11268
diff
changeset
|
40 |
* <pre> |
2 | 41 |
* Border border = comp.getBorder(); |
42 |
* Border margin = new EmptyBorder(10,10,10,10); |
|
43 |
* comp.setBorder(new CompoundBorder(border, margin)); |
|
20428
929cd48fca8a
8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents:
11268
diff
changeset
|
44 |
* </pre> |
2 | 45 |
* <p> |
46 |
* <strong>Warning:</strong> |
|
47 |
* Serialized objects of this class will not be compatible with |
|
48 |
* future Swing releases. The current serialization support is |
|
49 |
* appropriate for short term storage or RMI between applications running |
|
50 |
* the same version of Swing. As of 1.4, support for long term storage |
|
20458 | 51 |
* of all JavaBeans™ |
2 | 52 |
* has been added to the <code>java.beans</code> package. |
53 |
* Please see {@link java.beans.XMLEncoder}. |
|
54 |
* |
|
55 |
* @author David Kloba |
|
56 |
*/ |
|
11268 | 57 |
@SuppressWarnings("serial") |
2 | 58 |
public class CompoundBorder extends AbstractBorder { |
59 |
protected Border outsideBorder; |
|
60 |
protected Border insideBorder; |
|
61 |
||
62 |
/** |
|
63 |
* Creates a compound border with null outside and inside borders. |
|
64 |
*/ |
|
65 |
public CompoundBorder() { |
|
66 |
this.outsideBorder = null; |
|
67 |
this.insideBorder = null; |
|
68 |
} |
|
69 |
||
70 |
/** |
|
71 |
* Creates a compound border with the specified outside and |
|
72 |
* inside borders. Either border may be null. |
|
73 |
* @param outsideBorder the outside border |
|
74 |
* @param insideBorder the inside border to be nested |
|
75 |
*/ |
|
76 |
@ConstructorProperties({"outsideBorder", "insideBorder"}) |
|
77 |
public CompoundBorder(Border outsideBorder, Border insideBorder) { |
|
78 |
this.outsideBorder = outsideBorder; |
|
79 |
this.insideBorder = insideBorder; |
|
80 |
} |
|
81 |
||
82 |
/** |
|
1286
2c43fda67ddf
4778988: CompoundBorder.isBorderOpaque() has incorrect documentation.
malenkov
parents:
2
diff
changeset
|
83 |
* Returns whether or not the compound border is opaque. |
2c43fda67ddf
4778988: CompoundBorder.isBorderOpaque() has incorrect documentation.
malenkov
parents:
2
diff
changeset
|
84 |
* |
2c43fda67ddf
4778988: CompoundBorder.isBorderOpaque() has incorrect documentation.
malenkov
parents:
2
diff
changeset
|
85 |
* @return {@code true} if the inside and outside borders |
2c43fda67ddf
4778988: CompoundBorder.isBorderOpaque() has incorrect documentation.
malenkov
parents:
2
diff
changeset
|
86 |
* are each either {@code null} or opaque; |
2c43fda67ddf
4778988: CompoundBorder.isBorderOpaque() has incorrect documentation.
malenkov
parents:
2
diff
changeset
|
87 |
* or {@code false} otherwise |
2 | 88 |
*/ |
1286
2c43fda67ddf
4778988: CompoundBorder.isBorderOpaque() has incorrect documentation.
malenkov
parents:
2
diff
changeset
|
89 |
@Override |
2 | 90 |
public boolean isBorderOpaque() { |
91 |
return (outsideBorder == null || outsideBorder.isBorderOpaque()) && |
|
92 |
(insideBorder == null || insideBorder.isBorderOpaque()); |
|
93 |
} |
|
94 |
||
95 |
/** |
|
96 |
* Paints the compound border by painting the outside border |
|
97 |
* with the specified position and size and then painting the |
|
98 |
* inside border at the specified position and size offset by |
|
99 |
* the insets of the outside border. |
|
100 |
* @param c the component for which this border is being painted |
|
101 |
* @param g the paint graphics |
|
102 |
* @param x the x position of the painted border |
|
103 |
* @param y the y position of the painted border |
|
104 |
* @param width the width of the painted border |
|
105 |
* @param height the height of the painted border |
|
106 |
*/ |
|
107 |
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { |
|
108 |
Insets nextInsets; |
|
109 |
int px, py, pw, ph; |
|
110 |
||
111 |
px = x; |
|
112 |
py = y; |
|
113 |
pw = width; |
|
114 |
ph = height; |
|
115 |
||
116 |
if(outsideBorder != null) { |
|
117 |
outsideBorder.paintBorder(c, g, px, py, pw, ph); |
|
118 |
||
119 |
nextInsets = outsideBorder.getBorderInsets(c); |
|
120 |
px += nextInsets.left; |
|
121 |
py += nextInsets.top; |
|
122 |
pw = pw - nextInsets.right - nextInsets.left; |
|
123 |
ph = ph - nextInsets.bottom - nextInsets.top; |
|
124 |
} |
|
125 |
if(insideBorder != null) |
|
126 |
insideBorder.paintBorder(c, g, px, py, pw, ph); |
|
127 |
||
128 |
} |
|
129 |
||
130 |
/** |
|
131 |
* Reinitialize the insets parameter with this Border's current Insets. |
|
132 |
* @param c the component for which this border insets value applies |
|
133 |
* @param insets the object to be reinitialized |
|
134 |
*/ |
|
135 |
public Insets getBorderInsets(Component c, Insets insets) { |
|
136 |
Insets nextInsets; |
|
137 |
||
138 |
insets.top = insets.left = insets.right = insets.bottom = 0; |
|
139 |
if(outsideBorder != null) { |
|
140 |
nextInsets = outsideBorder.getBorderInsets(c); |
|
141 |
insets.top += nextInsets.top; |
|
142 |
insets.left += nextInsets.left; |
|
143 |
insets.right += nextInsets.right; |
|
144 |
insets.bottom += nextInsets.bottom; |
|
145 |
} |
|
146 |
if(insideBorder != null) { |
|
147 |
nextInsets = insideBorder.getBorderInsets(c); |
|
148 |
insets.top += nextInsets.top; |
|
149 |
insets.left += nextInsets.left; |
|
150 |
insets.right += nextInsets.right; |
|
151 |
insets.bottom += nextInsets.bottom; |
|
152 |
} |
|
153 |
return insets; |
|
154 |
} |
|
155 |
||
156 |
/** |
|
157 |
* Returns the outside border object. |
|
24500
399b77799d66
8040893: Add block tags for @return and @param to swing border classes
yan
parents:
23010
diff
changeset
|
158 |
* |
399b77799d66
8040893: Add block tags for @return and @param to swing border classes
yan
parents:
23010
diff
changeset
|
159 |
* @return the outside {@code Border} object |
2 | 160 |
*/ |
161 |
public Border getOutsideBorder() { |
|
162 |
return outsideBorder; |
|
163 |
} |
|
164 |
||
165 |
/** |
|
166 |
* Returns the inside border object. |
|
24500
399b77799d66
8040893: Add block tags for @return and @param to swing border classes
yan
parents:
23010
diff
changeset
|
167 |
* |
399b77799d66
8040893: Add block tags for @return and @param to swing border classes
yan
parents:
23010
diff
changeset
|
168 |
* @return the inside {@code Border} object |
2 | 169 |
*/ |
170 |
public Border getInsideBorder() { |
|
171 |
return insideBorder; |
|
172 |
} |
|
173 |
} |