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