author | prr |
Sat, 19 Sep 2015 15:45:59 -0700 | |
changeset 32865 | f9cb6e427f9e |
parent 30450 | 7e62d3d777b6 |
child 36923 | aa29023245f4 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
30450
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
2 |
* Copyright (c) 1997, 2015, 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 |
||
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
27 |
import java.awt.Color; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
28 |
import java.awt.Component; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
29 |
import java.awt.Dimension; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
30 |
import java.awt.Font; |
2 | 31 |
import java.awt.Graphics; |
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
32 |
import java.awt.Graphics2D; |
2 | 33 |
import java.awt.Insets; |
34 |
import java.awt.Rectangle; |
|
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
35 |
import java.awt.geom.Path2D; |
2 | 36 |
import java.beans.ConstructorProperties; |
37 |
import javax.swing.JComponent; |
|
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
38 |
import javax.swing.JLabel; |
2 | 39 |
import javax.swing.UIManager; |
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
40 |
import javax.swing.plaf.basic.BasicHTML; |
2 | 41 |
|
42 |
/** |
|
43 |
* A class which implements an arbitrary border |
|
44 |
* with the addition of a String title in a |
|
45 |
* specified position and justification. |
|
46 |
* <p> |
|
47 |
* If the border, font, or color property values are not |
|
21278 | 48 |
* specified in the constructor or by invoking the appropriate |
2 | 49 |
* set methods, the property values will be defined by the current |
50 |
* look and feel, using the following property names in the |
|
51 |
* Defaults Table: |
|
52 |
* <ul> |
|
53 |
* <li>"TitledBorder.border" |
|
54 |
* <li>"TitledBorder.font" |
|
55 |
* <li>"TitledBorder.titleColor" |
|
56 |
* </ul> |
|
57 |
* <p> |
|
58 |
* <strong>Warning:</strong> |
|
59 |
* Serialized objects of this class will not be compatible with |
|
60 |
* future Swing releases. The current serialization support is |
|
61 |
* appropriate for short term storage or RMI between applications running |
|
62 |
* the same version of Swing. As of 1.4, support for long term storage |
|
20458 | 63 |
* of all JavaBeans™ |
2 | 64 |
* has been added to the <code>java.beans</code> package. |
65 |
* Please see {@link java.beans.XMLEncoder}. |
|
66 |
* |
|
67 |
* @author David Kloba |
|
68 |
* @author Amy Fowler |
|
69 |
*/ |
|
11268 | 70 |
@SuppressWarnings("serial") |
2 | 71 |
public class TitledBorder extends AbstractBorder |
72 |
{ |
|
30450
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
73 |
/** |
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
74 |
* The title the border should display. |
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
75 |
*/ |
2 | 76 |
protected String title; |
30450
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
77 |
/** |
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
78 |
* The border. |
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
79 |
*/ |
2 | 80 |
protected Border border; |
30450
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
81 |
/** |
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
82 |
* The position for the title. |
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
83 |
*/ |
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
84 |
protected int titlePosition; |
30450
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
85 |
/** |
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
86 |
* The justification for the title. |
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
87 |
*/ |
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
88 |
protected int titleJustification; |
30450
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
89 |
/** |
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
90 |
* The font for rendering the title. |
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
91 |
*/ |
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
92 |
protected Font titleFont; |
30450
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
93 |
/** |
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
94 |
* The color of the title. |
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
95 |
*/ |
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
96 |
protected Color titleColor; |
2 | 97 |
|
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
98 |
private final JLabel label; |
2 | 99 |
|
100 |
/** |
|
101 |
* Use the default vertical orientation for the title text. |
|
102 |
*/ |
|
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
30450
diff
changeset
|
103 |
public static final int DEFAULT_POSITION = 0; |
2 | 104 |
/** Position the title above the border's top line. */ |
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
30450
diff
changeset
|
105 |
public static final int ABOVE_TOP = 1; |
2 | 106 |
/** Position the title in the middle of the border's top line. */ |
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
30450
diff
changeset
|
107 |
public static final int TOP = 2; |
2 | 108 |
/** Position the title below the border's top line. */ |
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
30450
diff
changeset
|
109 |
public static final int BELOW_TOP = 3; |
2 | 110 |
/** Position the title above the border's bottom line. */ |
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
30450
diff
changeset
|
111 |
public static final int ABOVE_BOTTOM = 4; |
2 | 112 |
/** Position the title in the middle of the border's bottom line. */ |
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
30450
diff
changeset
|
113 |
public static final int BOTTOM = 5; |
2 | 114 |
/** Position the title below the border's bottom line. */ |
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
30450
diff
changeset
|
115 |
public static final int BELOW_BOTTOM = 6; |
2 | 116 |
|
117 |
/** |
|
118 |
* Use the default justification for the title text. |
|
119 |
*/ |
|
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
30450
diff
changeset
|
120 |
public static final int DEFAULT_JUSTIFICATION = 0; |
2 | 121 |
/** Position title text at the left side of the border line. */ |
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
30450
diff
changeset
|
122 |
public static final int LEFT = 1; |
2 | 123 |
/** Position title text in the center of the border line. */ |
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
30450
diff
changeset
|
124 |
public static final int CENTER = 2; |
2 | 125 |
/** Position title text at the right side of the border line. */ |
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
30450
diff
changeset
|
126 |
public static final int RIGHT = 3; |
2 | 127 |
/** Position title text at the left side of the border line |
128 |
* for left to right orientation, at the right side of the |
|
129 |
* border line for right to left orientation. |
|
130 |
*/ |
|
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
30450
diff
changeset
|
131 |
public static final int LEADING = 4; |
2 | 132 |
/** Position title text at the right side of the border line |
133 |
* for left to right orientation, at the left side of the |
|
134 |
* border line for right to left orientation. |
|
135 |
*/ |
|
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
30450
diff
changeset
|
136 |
public static final int TRAILING = 5; |
2 | 137 |
|
30450
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
138 |
/** |
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
139 |
* Space between the border and the component's edge |
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
140 |
*/ |
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
30450
diff
changeset
|
141 |
protected static final int EDGE_SPACING = 2; |
2 | 142 |
|
30450
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
143 |
/** |
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
144 |
* Space between the border and text |
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
145 |
*/ |
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
30450
diff
changeset
|
146 |
protected static final int TEXT_SPACING = 2; |
2 | 147 |
|
30450
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
148 |
/** |
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
149 |
* Horizontal inset of text that is left or right justified |
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
150 |
*/ |
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
30450
diff
changeset
|
151 |
protected static final int TEXT_INSET_H = 5; |
2 | 152 |
|
153 |
/** |
|
154 |
* Creates a TitledBorder instance. |
|
155 |
* |
|
156 |
* @param title the title the border should display |
|
157 |
*/ |
|
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
158 |
public TitledBorder(String title) { |
2658 | 159 |
this(null, title, LEADING, DEFAULT_POSITION, null, null); |
2 | 160 |
} |
161 |
||
162 |
/** |
|
163 |
* Creates a TitledBorder instance with the specified border |
|
164 |
* and an empty title. |
|
165 |
* |
|
166 |
* @param border the border |
|
167 |
*/ |
|
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
168 |
public TitledBorder(Border border) { |
2658 | 169 |
this(border, "", LEADING, DEFAULT_POSITION, null, null); |
2 | 170 |
} |
171 |
||
172 |
/** |
|
173 |
* Creates a TitledBorder instance with the specified border |
|
174 |
* and title. |
|
175 |
* |
|
176 |
* @param border the border |
|
177 |
* @param title the title the border should display |
|
178 |
*/ |
|
179 |
public TitledBorder(Border border, String title) { |
|
2658 | 180 |
this(border, title, LEADING, DEFAULT_POSITION, null, null); |
2 | 181 |
} |
182 |
||
183 |
/** |
|
184 |
* Creates a TitledBorder instance with the specified border, |
|
185 |
* title, title-justification, and title-position. |
|
186 |
* |
|
187 |
* @param border the border |
|
188 |
* @param title the title the border should display |
|
189 |
* @param titleJustification the justification for the title |
|
190 |
* @param titlePosition the position for the title |
|
191 |
*/ |
|
192 |
public TitledBorder(Border border, |
|
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
193 |
String title, |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
194 |
int titleJustification, |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
195 |
int titlePosition) { |
2 | 196 |
this(border, title, titleJustification, |
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
197 |
titlePosition, null, null); |
2 | 198 |
} |
199 |
||
200 |
/** |
|
201 |
* Creates a TitledBorder instance with the specified border, |
|
202 |
* title, title-justification, title-position, and title-font. |
|
203 |
* |
|
204 |
* @param border the border |
|
205 |
* @param title the title the border should display |
|
206 |
* @param titleJustification the justification for the title |
|
207 |
* @param titlePosition the position for the title |
|
208 |
* @param titleFont the font for rendering the title |
|
209 |
*/ |
|
210 |
public TitledBorder(Border border, |
|
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
211 |
String title, |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
212 |
int titleJustification, |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
213 |
int titlePosition, |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
214 |
Font titleFont) { |
2 | 215 |
this(border, title, titleJustification, |
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
216 |
titlePosition, titleFont, null); |
2 | 217 |
} |
218 |
||
219 |
/** |
|
220 |
* Creates a TitledBorder instance with the specified border, |
|
221 |
* title, title-justification, title-position, title-font, and |
|
222 |
* title-color. |
|
223 |
* |
|
224 |
* @param border the border |
|
225 |
* @param title the title the border should display |
|
226 |
* @param titleJustification the justification for the title |
|
227 |
* @param titlePosition the position for the title |
|
228 |
* @param titleFont the font of the title |
|
229 |
* @param titleColor the color of the title |
|
230 |
*/ |
|
231 |
@ConstructorProperties({"border", "title", "titleJustification", "titlePosition", "titleFont", "titleColor"}) |
|
232 |
public TitledBorder(Border border, |
|
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
233 |
String title, |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
234 |
int titleJustification, |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
235 |
int titlePosition, |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
236 |
Font titleFont, |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
237 |
Color titleColor) { |
2 | 238 |
this.title = title; |
239 |
this.border = border; |
|
240 |
this.titleFont = titleFont; |
|
241 |
this.titleColor = titleColor; |
|
242 |
||
243 |
setTitleJustification(titleJustification); |
|
244 |
setTitlePosition(titlePosition); |
|
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
245 |
|
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
246 |
this.label = new JLabel(); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
247 |
this.label.setOpaque(false); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
248 |
this.label.putClientProperty(BasicHTML.propertyKey, null); |
2 | 249 |
} |
250 |
||
251 |
/** |
|
252 |
* Paints the border for the specified component with the |
|
253 |
* specified position and size. |
|
254 |
* @param c the component for which this border is being painted |
|
255 |
* @param g the paint graphics |
|
256 |
* @param x the x position of the painted border |
|
257 |
* @param y the y position of the painted border |
|
258 |
* @param width the width of the painted border |
|
259 |
* @param height the height of the painted border |
|
260 |
*/ |
|
261 |
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { |
|
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
262 |
Border border = getBorder(); |
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
263 |
String title = getTitle(); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
264 |
if ((title != null) && !title.isEmpty()) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
265 |
int edge = (border instanceof TitledBorder) ? 0 : EDGE_SPACING; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
266 |
JLabel label = getLabel(c); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
267 |
Dimension size = label.getPreferredSize(); |
9233
9170d0732f7a
7034614: The insets of TitledBorder vary, will be modified by another method, in JDK7
malenkov
parents:
7263
diff
changeset
|
268 |
Insets insets = getBorderInsets(border, c, new Insets(0, 0, 0, 0)); |
2 | 269 |
|
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
270 |
int borderX = x + edge; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
271 |
int borderY = y + edge; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
272 |
int borderW = width - edge - edge; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
273 |
int borderH = height - edge - edge; |
2 | 274 |
|
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
275 |
int labelY = y; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
276 |
int labelH = size.height; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
277 |
int position = getPosition(); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
278 |
switch (position) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
279 |
case ABOVE_TOP: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
280 |
insets.left = 0; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
281 |
insets.right = 0; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
282 |
borderY += labelH - edge; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
283 |
borderH -= labelH - edge; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
284 |
break; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
285 |
case TOP: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
286 |
insets.top = edge + insets.top/2 - labelH/2; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
287 |
if (insets.top < edge) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
288 |
borderY -= insets.top; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
289 |
borderH += insets.top; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
290 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
291 |
else { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
292 |
labelY += insets.top; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
293 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
294 |
break; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
295 |
case BELOW_TOP: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
296 |
labelY += insets.top + edge; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
297 |
break; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
298 |
case ABOVE_BOTTOM: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
299 |
labelY += height - labelH - insets.bottom - edge; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
300 |
break; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
301 |
case BOTTOM: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
302 |
labelY += height - labelH; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
303 |
insets.bottom = edge + (insets.bottom - labelH) / 2; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
304 |
if (insets.bottom < edge) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
305 |
borderH += insets.bottom; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
306 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
307 |
else { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
308 |
labelY -= insets.bottom; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
309 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
310 |
break; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
311 |
case BELOW_BOTTOM: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
312 |
insets.left = 0; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
313 |
insets.right = 0; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
314 |
labelY += height - labelH; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
315 |
borderH -= labelH - edge; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
316 |
break; |
2 | 317 |
} |
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
318 |
insets.left += edge + TEXT_INSET_H; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
319 |
insets.right += edge + TEXT_INSET_H; |
2 | 320 |
|
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
321 |
int labelX = x; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
322 |
int labelW = width - insets.left - insets.right; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
323 |
if (labelW > size.width) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
324 |
labelW = size.width; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
325 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
326 |
switch (getJustification(c)) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
327 |
case LEFT: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
328 |
labelX += insets.left; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
329 |
break; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
330 |
case RIGHT: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
331 |
labelX += width - insets.right - labelW; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
332 |
break; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
333 |
case CENTER: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
334 |
labelX += (width - labelW) / 2; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
335 |
break; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
336 |
} |
2 | 337 |
|
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
338 |
if (border != null) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
339 |
if ((position != TOP) && (position != BOTTOM)) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
340 |
border.paintBorder(c, g, borderX, borderY, borderW, borderH); |
2 | 341 |
} |
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
342 |
else { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
343 |
Graphics g2 = g.create(); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
344 |
if (g2 instanceof Graphics2D) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
345 |
Graphics2D g2d = (Graphics2D) g2; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
346 |
Path2D path = new Path2D.Float(); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
347 |
path.append(new Rectangle(borderX, borderY, borderW, labelY - borderY), false); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
348 |
path.append(new Rectangle(borderX, labelY, labelX - borderX - TEXT_SPACING, labelH), false); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
349 |
path.append(new Rectangle(labelX + labelW + TEXT_SPACING, labelY, borderX - labelX + borderW - labelW - TEXT_SPACING, labelH), false); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
350 |
path.append(new Rectangle(borderX, labelY + labelH, borderW, borderY - labelY + borderH - labelH), false); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
351 |
g2d.clip(path); |
2 | 352 |
} |
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
353 |
border.paintBorder(c, g2, borderX, borderY, borderW, borderH); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
354 |
g2.dispose(); |
2 | 355 |
} |
356 |
} |
|
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
357 |
g.translate(labelX, labelY); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
358 |
label.setSize(labelW, labelH); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
359 |
label.paint(g); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
360 |
g.translate(-labelX, -labelY); |
2 | 361 |
} |
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
362 |
else if (border != null) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
363 |
border.paintBorder(c, g, x, y, width, height); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
364 |
} |
2 | 365 |
} |
366 |
||
367 |
/** |
|
368 |
* Reinitialize the insets parameter with this Border's current Insets. |
|
369 |
* @param c the component for which this border insets value applies |
|
370 |
* @param insets the object to be reinitialized |
|
371 |
*/ |
|
372 |
public Insets getBorderInsets(Component c, Insets insets) { |
|
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
373 |
Border border = getBorder(); |
9233
9170d0732f7a
7034614: The insets of TitledBorder vary, will be modified by another method, in JDK7
malenkov
parents:
7263
diff
changeset
|
374 |
insets = getBorderInsets(border, c, insets); |
9170d0732f7a
7034614: The insets of TitledBorder vary, will be modified by another method, in JDK7
malenkov
parents:
7263
diff
changeset
|
375 |
|
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
376 |
String title = getTitle(); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
377 |
if ((title != null) && !title.isEmpty()) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
378 |
int edge = (border instanceof TitledBorder) ? 0 : EDGE_SPACING; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
379 |
JLabel label = getLabel(c); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
380 |
Dimension size = label.getPreferredSize(); |
2 | 381 |
|
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
382 |
switch (getPosition()) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
383 |
case ABOVE_TOP: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
384 |
insets.top += size.height - edge; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
385 |
break; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
386 |
case TOP: { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
387 |
if (insets.top < size.height) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
388 |
insets.top = size.height - edge; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
389 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
390 |
break; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
391 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
392 |
case BELOW_TOP: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
393 |
insets.top += size.height; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
394 |
break; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
395 |
case ABOVE_BOTTOM: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
396 |
insets.bottom += size.height; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
397 |
break; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
398 |
case BOTTOM: { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
399 |
if (insets.bottom < size.height) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
400 |
insets.bottom = size.height - edge; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
401 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
402 |
break; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
403 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
404 |
case BELOW_BOTTOM: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
405 |
insets.bottom += size.height - edge; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
406 |
break; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
407 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
408 |
insets.top += edge + TEXT_SPACING; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
409 |
insets.left += edge + TEXT_SPACING; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
410 |
insets.right += edge + TEXT_SPACING; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
411 |
insets.bottom += edge + TEXT_SPACING; |
2 | 412 |
} |
413 |
return insets; |
|
414 |
} |
|
415 |
||
416 |
/** |
|
417 |
* Returns whether or not the border is opaque. |
|
418 |
*/ |
|
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
419 |
public boolean isBorderOpaque() { |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
420 |
return false; |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
421 |
} |
2 | 422 |
|
423 |
/** |
|
424 |
* Returns the title of the titled border. |
|
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
425 |
* |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
426 |
* @return the title of the titled border |
2 | 427 |
*/ |
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
428 |
public String getTitle() { |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
429 |
return title; |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
430 |
} |
2 | 431 |
|
432 |
/** |
|
433 |
* Returns the border of the titled border. |
|
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
434 |
* |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
435 |
* @return the border of the titled border |
2 | 436 |
*/ |
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
437 |
public Border getBorder() { |
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
438 |
return border != null |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
439 |
? border |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
440 |
: UIManager.getBorder("TitledBorder.border"); |
2 | 441 |
} |
442 |
||
443 |
/** |
|
444 |
* Returns the title-position of the titled border. |
|
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
445 |
* |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
446 |
* @return the title-position of the titled border |
2 | 447 |
*/ |
2658 | 448 |
public int getTitlePosition() { |
449 |
return titlePosition; |
|
450 |
} |
|
2 | 451 |
|
452 |
/** |
|
453 |
* Returns the title-justification of the titled border. |
|
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
454 |
* |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
455 |
* @return the title-justification of the titled border |
2 | 456 |
*/ |
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
457 |
public int getTitleJustification() { |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
458 |
return titleJustification; |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
459 |
} |
2 | 460 |
|
461 |
/** |
|
462 |
* Returns the title-font of the titled border. |
|
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
463 |
* |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
464 |
* @return the title-font of the titled border |
2 | 465 |
*/ |
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
466 |
public Font getTitleFont() { |
13236 | 467 |
return titleFont == null ? UIManager.getFont("TitledBorder.font") : titleFont; |
2 | 468 |
} |
469 |
||
470 |
/** |
|
471 |
* Returns the title-color of the titled border. |
|
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
472 |
* |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
473 |
* @return the title-color of the titled border |
2 | 474 |
*/ |
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
475 |
public Color getTitleColor() { |
13236 | 476 |
return titleColor == null ? UIManager.getColor("TitledBorder.titleColor") : titleColor; |
2 | 477 |
} |
478 |
||
479 |
||
480 |
// REMIND(aim): remove all or some of these set methods? |
|
481 |
||
482 |
/** |
|
483 |
* Sets the title of the titled border. |
|
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
484 |
* @param title the title for the border |
2 | 485 |
*/ |
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
486 |
public void setTitle(String title) { |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
487 |
this.title = title; |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
488 |
} |
2 | 489 |
|
490 |
/** |
|
491 |
* Sets the border of the titled border. |
|
492 |
* @param border the border |
|
493 |
*/ |
|
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
494 |
public void setBorder(Border border) { |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
495 |
this.border = border; |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
496 |
} |
2 | 497 |
|
498 |
/** |
|
499 |
* Sets the title-position of the titled border. |
|
500 |
* @param titlePosition the position for the border |
|
501 |
*/ |
|
502 |
public void setTitlePosition(int titlePosition) { |
|
503 |
switch (titlePosition) { |
|
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
504 |
case ABOVE_TOP: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
505 |
case TOP: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
506 |
case BELOW_TOP: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
507 |
case ABOVE_BOTTOM: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
508 |
case BOTTOM: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
509 |
case BELOW_BOTTOM: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
510 |
case DEFAULT_POSITION: |
2 | 511 |
this.titlePosition = titlePosition; |
512 |
break; |
|
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
513 |
default: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
514 |
throw new IllegalArgumentException(titlePosition + |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
515 |
" is not a valid title position."); |
2 | 516 |
} |
517 |
} |
|
518 |
||
519 |
/** |
|
520 |
* Sets the title-justification of the titled border. |
|
521 |
* @param titleJustification the justification for the border |
|
522 |
*/ |
|
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
523 |
public void setTitleJustification(int titleJustification) { |
2 | 524 |
switch (titleJustification) { |
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
525 |
case DEFAULT_JUSTIFICATION: |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
526 |
case LEFT: |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
527 |
case CENTER: |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
528 |
case RIGHT: |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
529 |
case LEADING: |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
530 |
case TRAILING: |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
531 |
this.titleJustification = titleJustification; |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
532 |
break; |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
533 |
default: |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
534 |
throw new IllegalArgumentException(titleJustification + |
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
535 |
" is not a valid title justification."); |
2 | 536 |
} |
537 |
} |
|
538 |
||
539 |
/** |
|
540 |
* Sets the title-font of the titled border. |
|
541 |
* @param titleFont the font for the border title |
|
542 |
*/ |
|
543 |
public void setTitleFont(Font titleFont) { |
|
544 |
this.titleFont = titleFont; |
|
545 |
} |
|
546 |
||
547 |
/** |
|
548 |
* Sets the title-color of the titled border. |
|
549 |
* @param titleColor the color for the border title |
|
550 |
*/ |
|
551 |
public void setTitleColor(Color titleColor) { |
|
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
552 |
this.titleColor = titleColor; |
2 | 553 |
} |
554 |
||
555 |
/** |
|
556 |
* Returns the minimum dimensions this border requires |
|
557 |
* in order to fully display the border and title. |
|
558 |
* @param c the component where this border will be drawn |
|
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
559 |
* @return the {@code Dimension} object |
2 | 560 |
*/ |
561 |
public Dimension getMinimumSize(Component c) { |
|
562 |
Insets insets = getBorderInsets(c); |
|
563 |
Dimension minSize = new Dimension(insets.right+insets.left, |
|
564 |
insets.top+insets.bottom); |
|
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
565 |
String title = getTitle(); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
566 |
if ((title != null) && !title.isEmpty()) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
567 |
JLabel label = getLabel(c); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
568 |
Dimension size = label.getPreferredSize(); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
569 |
|
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
570 |
int position = getPosition(); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
571 |
if ((position != ABOVE_TOP) && (position != BELOW_BOTTOM)) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
572 |
minSize.width += size.width; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
573 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
574 |
else if (minSize.width < size.width) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
575 |
minSize.width += size.width; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
576 |
} |
2 | 577 |
} |
578 |
return minSize; |
|
579 |
} |
|
580 |
||
581 |
/** |
|
582 |
* Returns the baseline. |
|
583 |
* |
|
584 |
* @throws NullPointerException {@inheritDoc} |
|
585 |
* @throws IllegalArgumentException {@inheritDoc} |
|
586 |
* @see javax.swing.JComponent#getBaseline(int, int) |
|
587 |
* @since 1.6 |
|
588 |
*/ |
|
589 |
public int getBaseline(Component c, int width, int height) { |
|
590 |
if (c == null) { |
|
591 |
throw new NullPointerException("Must supply non-null component"); |
|
592 |
} |
|
463
435cd1cc42b6
6625450: javax.swing.border.TitledBorder.getBaseline() doesn't throw IAE when width is < 0
malenkov
parents:
2
diff
changeset
|
593 |
if (width < 0) { |
435cd1cc42b6
6625450: javax.swing.border.TitledBorder.getBaseline() doesn't throw IAE when width is < 0
malenkov
parents:
2
diff
changeset
|
594 |
throw new IllegalArgumentException("Width must be >= 0"); |
435cd1cc42b6
6625450: javax.swing.border.TitledBorder.getBaseline() doesn't throw IAE when width is < 0
malenkov
parents:
2
diff
changeset
|
595 |
} |
2 | 596 |
if (height < 0) { |
597 |
throw new IllegalArgumentException("Height must be >= 0"); |
|
598 |
} |
|
7263
3da4189127ac
6981576: TitledBorder.getBorder() returns null in java build 1.7.0-ea-b107
malenkov
parents:
5953
diff
changeset
|
599 |
Border border = getBorder(); |
2 | 600 |
String title = getTitle(); |
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
601 |
if ((title != null) && !title.isEmpty()) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
602 |
int edge = (border instanceof TitledBorder) ? 0 : EDGE_SPACING; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
603 |
JLabel label = getLabel(c); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
604 |
Dimension size = label.getPreferredSize(); |
9233
9170d0732f7a
7034614: The insets of TitledBorder vary, will be modified by another method, in JDK7
malenkov
parents:
7263
diff
changeset
|
605 |
Insets insets = getBorderInsets(border, c, new Insets(0, 0, 0, 0)); |
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
606 |
|
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
607 |
int baseline = label.getBaseline(size.width, size.height); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
608 |
switch (getPosition()) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
609 |
case ABOVE_TOP: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
610 |
return baseline; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
611 |
case TOP: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
612 |
insets.top = edge + (insets.top - size.height) / 2; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
613 |
return (insets.top < edge) |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
614 |
? baseline |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
615 |
: baseline + insets.top; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
616 |
case BELOW_TOP: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
617 |
return baseline + insets.top + edge; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
618 |
case ABOVE_BOTTOM: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
619 |
return baseline + height - size.height - insets.bottom - edge; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
620 |
case BOTTOM: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
621 |
insets.bottom = edge + (insets.bottom - size.height) / 2; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
622 |
return (insets.bottom < edge) |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
623 |
? baseline + height - size.height |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
624 |
: baseline + height - size.height + insets.bottom; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
625 |
case BELOW_BOTTOM: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
626 |
return baseline + height - size.height; |
2 | 627 |
} |
628 |
} |
|
629 |
return -1; |
|
630 |
} |
|
631 |
||
632 |
/** |
|
633 |
* Returns an enum indicating how the baseline of the border |
|
634 |
* changes as the size changes. |
|
635 |
* |
|
636 |
* @throws NullPointerException {@inheritDoc} |
|
637 |
* @see javax.swing.JComponent#getBaseline(int, int) |
|
638 |
* @since 1.6 |
|
639 |
*/ |
|
640 |
public Component.BaselineResizeBehavior getBaselineResizeBehavior( |
|
641 |
Component c) { |
|
642 |
super.getBaselineResizeBehavior(c); |
|
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
643 |
switch (getPosition()) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
644 |
case TitledBorder.ABOVE_TOP: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
645 |
case TitledBorder.TOP: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
646 |
case TitledBorder.BELOW_TOP: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
647 |
return Component.BaselineResizeBehavior.CONSTANT_ASCENT; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
648 |
case TitledBorder.ABOVE_BOTTOM: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
649 |
case TitledBorder.BOTTOM: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
650 |
case TitledBorder.BELOW_BOTTOM: |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
651 |
return JComponent.BaselineResizeBehavior.CONSTANT_DESCENT; |
2 | 652 |
} |
653 |
return Component.BaselineResizeBehavior.OTHER; |
|
654 |
} |
|
655 |
||
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
656 |
private int getPosition() { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
657 |
int position = getTitlePosition(); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
658 |
if (position != DEFAULT_POSITION) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
659 |
return position; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
660 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
661 |
Object value = UIManager.get("TitledBorder.position"); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
662 |
if (value instanceof Integer) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
663 |
int i = (Integer) value; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
664 |
if ((0 < i) && (i <= 6)) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
665 |
return i; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
666 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
667 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
668 |
else if (value instanceof String) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
669 |
String s = (String) value; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
670 |
if (s.equalsIgnoreCase("ABOVE_TOP")) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
671 |
return ABOVE_TOP; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
672 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
673 |
if (s.equalsIgnoreCase("TOP")) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
674 |
return TOP; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
675 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
676 |
if (s.equalsIgnoreCase("BELOW_TOP")) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
677 |
return BELOW_TOP; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
678 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
679 |
if (s.equalsIgnoreCase("ABOVE_BOTTOM")) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
680 |
return ABOVE_BOTTOM; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
681 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
682 |
if (s.equalsIgnoreCase("BOTTOM")) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
683 |
return BOTTOM; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
684 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
685 |
if (s.equalsIgnoreCase("BELOW_BOTTOM")) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
686 |
return BELOW_BOTTOM; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
687 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
688 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
689 |
return TOP; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
690 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
691 |
|
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
692 |
private int getJustification(Component c) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
693 |
int justification = getTitleJustification(); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
694 |
if ((justification == LEADING) || (justification == DEFAULT_JUSTIFICATION)) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
695 |
return c.getComponentOrientation().isLeftToRight() ? LEFT : RIGHT; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
696 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
697 |
if (justification == TRAILING) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
698 |
return c.getComponentOrientation().isLeftToRight() ? RIGHT : LEFT; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
699 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
700 |
return justification; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
701 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
702 |
|
30450
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
703 |
/** |
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
704 |
* Returns default font of the titled border. |
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
705 |
* @return default font of the titled border |
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
706 |
* @param c the component |
7e62d3d777b6
8076422: Fix missing doclint warnings in javax.swing.border
darcy
parents:
25859
diff
changeset
|
707 |
*/ |
2 | 708 |
protected Font getFont(Component c) { |
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
709 |
Font font = getTitleFont(); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
710 |
if (font != null) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
711 |
return font; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
712 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
713 |
if (c != null) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
714 |
font = c.getFont(); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
715 |
if (font != null) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
716 |
return font; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
717 |
} |
2 | 718 |
} |
719 |
return new Font(Font.DIALOG, Font.PLAIN, 12); |
|
720 |
} |
|
721 |
||
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
722 |
private Color getColor(Component c) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
723 |
Color color = getTitleColor(); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
724 |
if (color != null) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
725 |
return color; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
726 |
} |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
727 |
return (c != null) |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
728 |
? c.getForeground() |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
729 |
: null; |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
730 |
} |
2 | 731 |
|
5953
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
732 |
private JLabel getLabel(Component c) { |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
733 |
this.label.setText(getTitle()); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
734 |
this.label.setFont(getFont(c)); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
735 |
this.label.setForeground(getColor(c)); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
736 |
this.label.setComponentOrientation(c.getComponentOrientation()); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
737 |
this.label.setEnabled(c.isEnabled()); |
33ad0303d717
4129681: Cannot get a title border to display its label as disabled
malenkov
parents:
5506
diff
changeset
|
738 |
return this.label; |
2 | 739 |
} |
9233
9170d0732f7a
7034614: The insets of TitledBorder vary, will be modified by another method, in JDK7
malenkov
parents:
7263
diff
changeset
|
740 |
|
9170d0732f7a
7034614: The insets of TitledBorder vary, will be modified by another method, in JDK7
malenkov
parents:
7263
diff
changeset
|
741 |
private static Insets getBorderInsets(Border border, Component c, Insets insets) { |
9170d0732f7a
7034614: The insets of TitledBorder vary, will be modified by another method, in JDK7
malenkov
parents:
7263
diff
changeset
|
742 |
if (border == null) { |
9170d0732f7a
7034614: The insets of TitledBorder vary, will be modified by another method, in JDK7
malenkov
parents:
7263
diff
changeset
|
743 |
insets.set(0, 0, 0, 0); |
9170d0732f7a
7034614: The insets of TitledBorder vary, will be modified by another method, in JDK7
malenkov
parents:
7263
diff
changeset
|
744 |
} |
9170d0732f7a
7034614: The insets of TitledBorder vary, will be modified by another method, in JDK7
malenkov
parents:
7263
diff
changeset
|
745 |
else if (border instanceof AbstractBorder) { |
9170d0732f7a
7034614: The insets of TitledBorder vary, will be modified by another method, in JDK7
malenkov
parents:
7263
diff
changeset
|
746 |
AbstractBorder ab = (AbstractBorder) border; |
9170d0732f7a
7034614: The insets of TitledBorder vary, will be modified by another method, in JDK7
malenkov
parents:
7263
diff
changeset
|
747 |
insets = ab.getBorderInsets(c, insets); |
9170d0732f7a
7034614: The insets of TitledBorder vary, will be modified by another method, in JDK7
malenkov
parents:
7263
diff
changeset
|
748 |
} |
9170d0732f7a
7034614: The insets of TitledBorder vary, will be modified by another method, in JDK7
malenkov
parents:
7263
diff
changeset
|
749 |
else { |
9170d0732f7a
7034614: The insets of TitledBorder vary, will be modified by another method, in JDK7
malenkov
parents:
7263
diff
changeset
|
750 |
Insets i = border.getBorderInsets(c); |
9170d0732f7a
7034614: The insets of TitledBorder vary, will be modified by another method, in JDK7
malenkov
parents:
7263
diff
changeset
|
751 |
insets.set(i.top, i.left, i.bottom, i.right); |
9170d0732f7a
7034614: The insets of TitledBorder vary, will be modified by another method, in JDK7
malenkov
parents:
7263
diff
changeset
|
752 |
} |
9170d0732f7a
7034614: The insets of TitledBorder vary, will be modified by another method, in JDK7
malenkov
parents:
7263
diff
changeset
|
753 |
return insets; |
9170d0732f7a
7034614: The insets of TitledBorder vary, will be modified by another method, in JDK7
malenkov
parents:
7263
diff
changeset
|
754 |
} |
2 | 755 |
} |