71 */ |
69 */ |
72 public class TitledBorder extends AbstractBorder |
70 public class TitledBorder extends AbstractBorder |
73 { |
71 { |
74 protected String title; |
72 protected String title; |
75 protected Border border; |
73 protected Border border; |
76 protected int titlePosition; |
74 protected int titlePosition; |
77 protected int titleJustification; |
75 protected int titleJustification; |
78 protected Font titleFont; |
76 protected Font titleFont; |
79 protected Color titleColor; |
77 protected Color titleColor; |
80 |
78 |
81 private Point textLoc = new Point(); |
79 private final JLabel label; |
82 |
80 |
83 /** |
81 /** |
84 * Use the default vertical orientation for the title text. |
82 * Use the default vertical orientation for the title text. |
85 */ |
83 */ |
86 static public final int DEFAULT_POSITION = 0; |
84 static public final int DEFAULT_POSITION = 0; |
87 /** Position the title above the border's top line. */ |
85 /** Position the title above the border's top line. */ |
88 static public final int ABOVE_TOP = 1; |
86 static public final int ABOVE_TOP = 1; |
89 /** Position the title in the middle of the border's top line. */ |
87 /** Position the title in the middle of the border's top line. */ |
90 static public final int TOP = 2; |
88 static public final int TOP = 2; |
91 /** Position the title below the border's top line. */ |
89 /** Position the title below the border's top line. */ |
92 static public final int BELOW_TOP = 3; |
90 static public final int BELOW_TOP = 3; |
93 /** Position the title above the border's bottom line. */ |
91 /** Position the title above the border's bottom line. */ |
94 static public final int ABOVE_BOTTOM = 4; |
92 static public final int ABOVE_BOTTOM = 4; |
95 /** Position the title in the middle of the border's bottom line. */ |
93 /** Position the title in the middle of the border's bottom line. */ |
96 static public final int BOTTOM = 5; |
94 static public final int BOTTOM = 5; |
97 /** Position the title below the border's bottom line. */ |
95 /** Position the title below the border's bottom line. */ |
98 static public final int BELOW_BOTTOM = 6; |
96 static public final int BELOW_BOTTOM = 6; |
99 |
97 |
100 /** |
98 /** |
101 * Use the default justification for the title text. |
99 * Use the default justification for the title text. |
102 */ |
100 */ |
103 static public final int DEFAULT_JUSTIFICATION = 0; |
101 static public final int DEFAULT_JUSTIFICATION = 0; |
104 /** Position title text at the left side of the border line. */ |
102 /** Position title text at the left side of the border line. */ |
105 static public final int LEFT = 1; |
103 static public final int LEFT = 1; |
106 /** Position title text in the center of the border line. */ |
104 /** Position title text in the center of the border line. */ |
107 static public final int CENTER = 2; |
105 static public final int CENTER = 2; |
108 /** Position title text at the right side of the border line. */ |
106 /** Position title text at the right side of the border line. */ |
109 static public final int RIGHT = 3; |
107 static public final int RIGHT = 3; |
110 /** Position title text at the left side of the border line |
108 /** Position title text at the left side of the border line |
111 * for left to right orientation, at the right side of the |
109 * for left to right orientation, at the right side of the |
112 * border line for right to left orientation. |
110 * border line for right to left orientation. |
113 */ |
111 */ |
114 static public final int LEADING = 4; |
112 static public final int LEADING = 4; |
230 * @param y the y position of the painted border |
232 * @param y the y position of the painted border |
231 * @param width the width of the painted border |
233 * @param width the width of the painted border |
232 * @param height the height of the painted border |
234 * @param height the height of the painted border |
233 */ |
235 */ |
234 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { |
236 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { |
235 |
237 Border border = getBorderUI(); |
236 Border border = getBorder(); |
238 String title = getTitle(); |
237 |
239 if ((title != null) && !title.isEmpty()) { |
238 if (getTitle() == null || getTitle().equals("")) { |
240 int edge = (border instanceof TitledBorder) ? 0 : EDGE_SPACING; |
|
241 JLabel label = getLabel(c); |
|
242 Dimension size = label.getPreferredSize(); |
|
243 Insets insets = (border != null) |
|
244 ? border.getBorderInsets(c) |
|
245 : new Insets(0, 0, 0, 0); |
|
246 |
|
247 int borderX = x + edge; |
|
248 int borderY = y + edge; |
|
249 int borderW = width - edge - edge; |
|
250 int borderH = height - edge - edge; |
|
251 |
|
252 int labelY = y; |
|
253 int labelH = size.height; |
|
254 int position = getPosition(); |
|
255 switch (position) { |
|
256 case ABOVE_TOP: |
|
257 insets.left = 0; |
|
258 insets.right = 0; |
|
259 borderY += labelH - edge; |
|
260 borderH -= labelH - edge; |
|
261 break; |
|
262 case TOP: |
|
263 insets.top = edge + insets.top/2 - labelH/2; |
|
264 if (insets.top < edge) { |
|
265 borderY -= insets.top; |
|
266 borderH += insets.top; |
|
267 } |
|
268 else { |
|
269 labelY += insets.top; |
|
270 } |
|
271 break; |
|
272 case BELOW_TOP: |
|
273 labelY += insets.top + edge; |
|
274 break; |
|
275 case ABOVE_BOTTOM: |
|
276 labelY += height - labelH - insets.bottom - edge; |
|
277 break; |
|
278 case BOTTOM: |
|
279 labelY += height - labelH; |
|
280 insets.bottom = edge + (insets.bottom - labelH) / 2; |
|
281 if (insets.bottom < edge) { |
|
282 borderH += insets.bottom; |
|
283 } |
|
284 else { |
|
285 labelY -= insets.bottom; |
|
286 } |
|
287 break; |
|
288 case BELOW_BOTTOM: |
|
289 insets.left = 0; |
|
290 insets.right = 0; |
|
291 labelY += height - labelH; |
|
292 borderH -= labelH - edge; |
|
293 break; |
|
294 } |
|
295 insets.left += edge + TEXT_INSET_H; |
|
296 insets.right += edge + TEXT_INSET_H; |
|
297 |
|
298 int labelX = x; |
|
299 int labelW = width - insets.left - insets.right; |
|
300 if (labelW > size.width) { |
|
301 labelW = size.width; |
|
302 } |
|
303 switch (getJustification(c)) { |
|
304 case LEFT: |
|
305 labelX += insets.left; |
|
306 break; |
|
307 case RIGHT: |
|
308 labelX += width - insets.right - labelW; |
|
309 break; |
|
310 case CENTER: |
|
311 labelX += (width - labelW) / 2; |
|
312 break; |
|
313 } |
|
314 |
239 if (border != null) { |
315 if (border != null) { |
240 border.paintBorder(c, g, x, y, width, height); |
316 if ((position != TOP) && (position != BOTTOM)) { |
241 } |
317 border.paintBorder(c, g, borderX, borderY, borderW, borderH); |
242 return; |
|
243 } |
|
244 |
|
245 Rectangle grooveRect = new Rectangle(x + EDGE_SPACING, y + EDGE_SPACING, |
|
246 width - (EDGE_SPACING * 2), |
|
247 height - (EDGE_SPACING * 2)); |
|
248 Font font = g.getFont(); |
|
249 Color color = g.getColor(); |
|
250 |
|
251 g.setFont(getFont(c)); |
|
252 |
|
253 JComponent jc = (c instanceof JComponent) ? (JComponent)c : null; |
|
254 FontMetrics fm = SwingUtilities2.getFontMetrics(jc, g); |
|
255 int fontHeight = fm.getHeight(); |
|
256 int descent = fm.getDescent(); |
|
257 int ascent = fm.getAscent(); |
|
258 int diff; |
|
259 int stringWidth = SwingUtilities2.stringWidth(jc, fm, |
|
260 getTitle()); |
|
261 Insets insets; |
|
262 |
|
263 if (border != null) { |
|
264 insets = border.getBorderInsets(c); |
|
265 } else { |
|
266 insets = new Insets(0, 0, 0, 0); |
|
267 } |
|
268 |
|
269 int titlePos = getTitlePosition(); |
|
270 switch (titlePos) { |
|
271 case ABOVE_TOP: |
|
272 diff = ascent + descent + (Math.max(EDGE_SPACING, |
|
273 TEXT_SPACING*2) - EDGE_SPACING); |
|
274 grooveRect.y += diff; |
|
275 grooveRect.height -= diff; |
|
276 textLoc.y = grooveRect.y - (descent + TEXT_SPACING); |
|
277 break; |
|
278 case TOP: |
|
279 case DEFAULT_POSITION: |
|
280 diff = Math.max(0, ((ascent/2) + TEXT_SPACING) - EDGE_SPACING); |
|
281 grooveRect.y += diff; |
|
282 grooveRect.height -= diff; |
|
283 textLoc.y = (grooveRect.y - descent) + |
|
284 (insets.top + ascent + descent)/2; |
|
285 break; |
|
286 case BELOW_TOP: |
|
287 textLoc.y = grooveRect.y + insets.top + ascent + TEXT_SPACING; |
|
288 break; |
|
289 case ABOVE_BOTTOM: |
|
290 textLoc.y = (grooveRect.y + grooveRect.height) - |
|
291 (insets.bottom + descent + TEXT_SPACING); |
|
292 break; |
|
293 case BOTTOM: |
|
294 grooveRect.height -= fontHeight/2; |
|
295 textLoc.y = ((grooveRect.y + grooveRect.height) - descent) + |
|
296 ((ascent + descent) - insets.bottom)/2; |
|
297 break; |
|
298 case BELOW_BOTTOM: |
|
299 grooveRect.height -= fontHeight; |
|
300 textLoc.y = grooveRect.y + grooveRect.height + ascent + |
|
301 TEXT_SPACING; |
|
302 break; |
|
303 } |
|
304 |
|
305 int justification = getTitleJustification(); |
|
306 if(isLeftToRight(c)) { |
|
307 if(justification==LEADING || |
|
308 justification==DEFAULT_JUSTIFICATION) { |
|
309 justification = LEFT; |
|
310 } |
|
311 else if(justification==TRAILING) { |
|
312 justification = RIGHT; |
|
313 } |
|
314 } |
|
315 else { |
|
316 if(justification==LEADING || |
|
317 justification==DEFAULT_JUSTIFICATION) { |
|
318 justification = RIGHT; |
|
319 } |
|
320 else if(justification==TRAILING) { |
|
321 justification = LEFT; |
|
322 } |
|
323 } |
|
324 |
|
325 switch (justification) { |
|
326 case LEFT: |
|
327 textLoc.x = grooveRect.x + TEXT_INSET_H + insets.left; |
|
328 break; |
|
329 case RIGHT: |
|
330 textLoc.x = (grooveRect.x + grooveRect.width) - |
|
331 (stringWidth + TEXT_INSET_H + insets.right); |
|
332 break; |
|
333 case CENTER: |
|
334 textLoc.x = grooveRect.x + |
|
335 ((grooveRect.width - stringWidth) / 2); |
|
336 break; |
|
337 } |
|
338 |
|
339 // If title is positioned in middle of border AND its fontsize |
|
340 // is greater than the border's thickness, we'll need to paint |
|
341 // the border in sections to leave space for the component's background |
|
342 // to show through the title. |
|
343 // |
|
344 if (border != null) { |
|
345 if (((titlePos == TOP || titlePos == DEFAULT_POSITION) && |
|
346 (grooveRect.y > textLoc.y - ascent)) || |
|
347 (titlePos == BOTTOM && |
|
348 (grooveRect.y + grooveRect.height < textLoc.y + descent))) { |
|
349 |
|
350 Rectangle clipRect = new Rectangle(); |
|
351 |
|
352 // save original clip |
|
353 Rectangle saveClip = g.getClipBounds(); |
|
354 |
|
355 // paint strip left of text |
|
356 clipRect.setBounds(saveClip); |
|
357 if (computeIntersection(clipRect, x, y, textLoc.x-1-x, height)) { |
|
358 g.setClip(clipRect); |
|
359 border.paintBorder(c, g, grooveRect.x, grooveRect.y, |
|
360 grooveRect.width, grooveRect.height); |
|
361 } |
318 } |
362 |
319 else { |
363 // paint strip right of text |
320 Graphics g2 = g.create(); |
364 clipRect.setBounds(saveClip); |
321 if (g2 instanceof Graphics2D) { |
365 if (computeIntersection(clipRect, textLoc.x+stringWidth+1, y, |
322 Graphics2D g2d = (Graphics2D) g2; |
366 x+width-(textLoc.x+stringWidth+1), height)) { |
323 Path2D path = new Path2D.Float(); |
367 g.setClip(clipRect); |
324 path.append(new Rectangle(borderX, borderY, borderW, labelY - borderY), false); |
368 border.paintBorder(c, g, grooveRect.x, grooveRect.y, |
325 path.append(new Rectangle(borderX, labelY, labelX - borderX - TEXT_SPACING, labelH), false); |
369 grooveRect.width, grooveRect.height); |
326 path.append(new Rectangle(labelX + labelW + TEXT_SPACING, labelY, borderX - labelX + borderW - labelW - TEXT_SPACING, labelH), false); |
|
327 path.append(new Rectangle(borderX, labelY + labelH, borderW, borderY - labelY + borderH - labelH), false); |
|
328 g2d.clip(path); |
|
329 } |
|
330 border.paintBorder(c, g2, borderX, borderY, borderW, borderH); |
|
331 g2.dispose(); |
370 } |
332 } |
371 |
333 } |
372 if (titlePos == TOP || titlePos == DEFAULT_POSITION) { |
334 g.translate(labelX, labelY); |
373 // paint strip below text |
335 label.setSize(labelW, labelH); |
374 clipRect.setBounds(saveClip); |
336 label.paint(g); |
375 if (computeIntersection(clipRect, textLoc.x-1, textLoc.y+descent, |
337 g.translate(-labelX, -labelY); |
376 stringWidth+2, y+height-textLoc.y-descent)) { |
338 } |
377 g.setClip(clipRect); |
339 else if (border != null) { |
378 border.paintBorder(c, g, grooveRect.x, grooveRect.y, |
340 border.paintBorder(c, g, x, y, width, height); |
379 grooveRect.width, grooveRect.height); |
341 } |
380 } |
|
381 |
|
382 } else { // titlePos == BOTTOM |
|
383 // paint strip above text |
|
384 clipRect.setBounds(saveClip); |
|
385 if (computeIntersection(clipRect, textLoc.x-1, y, |
|
386 stringWidth+2, textLoc.y - ascent - y)) { |
|
387 g.setClip(clipRect); |
|
388 border.paintBorder(c, g, grooveRect.x, grooveRect.y, |
|
389 grooveRect.width, grooveRect.height); |
|
390 } |
|
391 } |
|
392 |
|
393 // restore clip |
|
394 g.setClip(saveClip); |
|
395 |
|
396 } else { |
|
397 border.paintBorder(c, g, grooveRect.x, grooveRect.y, |
|
398 grooveRect.width, grooveRect.height); |
|
399 } |
|
400 } |
|
401 |
|
402 g.setColor(getTitleColor()); |
|
403 SwingUtilities2.drawString(jc, g, getTitle(), textLoc.x, textLoc.y); |
|
404 |
|
405 g.setFont(font); |
|
406 g.setColor(color); |
|
407 } |
342 } |
408 |
343 |
409 /** |
344 /** |
410 * Reinitialize the insets parameter with this Border's current Insets. |
345 * Reinitialize the insets parameter with this Border's current Insets. |
411 * @param c the component for which this border insets value applies |
346 * @param c the component for which this border insets value applies |
412 * @param insets the object to be reinitialized |
347 * @param insets the object to be reinitialized |
413 */ |
348 */ |
414 public Insets getBorderInsets(Component c, Insets insets) { |
349 public Insets getBorderInsets(Component c, Insets insets) { |
415 FontMetrics fm; |
350 Border border = getBorderUI(); |
416 int descent = 0; |
351 if (border == null) { |
417 int ascent = 16; |
352 insets.set(0, 0, 0, 0); |
418 int height = 16; |
353 } |
419 |
354 else if (border instanceof AbstractBorder) { |
420 Border border = getBorder(); |
355 AbstractBorder ab = (AbstractBorder) border; |
421 if (border != null) { |
356 insets = ab.getBorderInsets(c, insets); |
422 if (border instanceof AbstractBorder) { |
357 } |
423 ((AbstractBorder)border).getBorderInsets(c, insets); |
358 else { |
424 } else { |
359 Insets i = border.getBorderInsets(c); |
425 // Can't reuse border insets because the Border interface |
360 insets.set(i.top, i.left, i.bottom, i.right); |
426 // can't be enhanced. |
361 } |
427 Insets i = border.getBorderInsets(c); |
362 String title = getTitle(); |
428 insets.top = i.top; |
363 if ((title != null) && !title.isEmpty()) { |
429 insets.right = i.right; |
364 int edge = (border instanceof TitledBorder) ? 0 : EDGE_SPACING; |
430 insets.bottom = i.bottom; |
365 JLabel label = getLabel(c); |
431 insets.left = i.left; |
366 Dimension size = label.getPreferredSize(); |
432 } |
367 |
433 } else { |
368 switch (getPosition()) { |
434 insets.left = insets.top = insets.right = insets.bottom = 0; |
369 case ABOVE_TOP: |
435 } |
370 insets.top += size.height - edge; |
436 |
371 break; |
437 insets.left += EDGE_SPACING + TEXT_SPACING; |
372 case TOP: { |
438 insets.right += EDGE_SPACING + TEXT_SPACING; |
373 if (insets.top < size.height) { |
439 insets.top += EDGE_SPACING + TEXT_SPACING; |
374 insets.top = size.height - edge; |
440 insets.bottom += EDGE_SPACING + TEXT_SPACING; |
375 } |
441 |
376 break; |
442 if(c == null || getTitle() == null || getTitle().equals("")) { |
377 } |
443 return insets; |
378 case BELOW_TOP: |
444 } |
379 insets.top += size.height; |
445 |
380 break; |
446 Font font = getFont(c); |
381 case ABOVE_BOTTOM: |
447 |
382 insets.bottom += size.height; |
448 fm = c.getFontMetrics(font); |
383 break; |
449 |
384 case BOTTOM: { |
450 if(fm != null) { |
385 if (insets.bottom < size.height) { |
451 descent = fm.getDescent(); |
386 insets.bottom = size.height - edge; |
452 ascent = fm.getAscent(); |
387 } |
453 height = fm.getHeight(); |
388 break; |
454 } |
389 } |
455 |
390 case BELOW_BOTTOM: |
456 switch (getTitlePosition()) { |
391 insets.bottom += size.height - edge; |
457 case ABOVE_TOP: |
392 break; |
458 insets.top += ascent + descent |
393 } |
459 + (Math.max(EDGE_SPACING, TEXT_SPACING*2) |
394 insets.top += edge + TEXT_SPACING; |
460 - EDGE_SPACING); |
395 insets.left += edge + TEXT_SPACING; |
461 break; |
396 insets.right += edge + TEXT_SPACING; |
462 case TOP: |
397 insets.bottom += edge + TEXT_SPACING; |
463 case DEFAULT_POSITION: |
|
464 insets.top += ascent + descent; |
|
465 break; |
|
466 case BELOW_TOP: |
|
467 insets.top += ascent + descent + TEXT_SPACING; |
|
468 break; |
|
469 case ABOVE_BOTTOM: |
|
470 insets.bottom += ascent + descent + TEXT_SPACING; |
|
471 break; |
|
472 case BOTTOM: |
|
473 insets.bottom += ascent + descent; |
|
474 break; |
|
475 case BELOW_BOTTOM: |
|
476 insets.bottom += height; |
|
477 break; |
|
478 } |
398 } |
479 return insets; |
399 return insets; |
480 } |
400 } |
481 |
401 |
482 /** |
402 /** |
730 * @since 1.6 |
601 * @since 1.6 |
731 */ |
602 */ |
732 public Component.BaselineResizeBehavior getBaselineResizeBehavior( |
603 public Component.BaselineResizeBehavior getBaselineResizeBehavior( |
733 Component c) { |
604 Component c) { |
734 super.getBaselineResizeBehavior(c); |
605 super.getBaselineResizeBehavior(c); |
735 switch(getTitlePosition()) { |
606 switch (getPosition()) { |
736 case TitledBorder.ABOVE_TOP: |
607 case TitledBorder.ABOVE_TOP: |
737 case TitledBorder.TOP: |
608 case TitledBorder.TOP: |
738 case TitledBorder.DEFAULT_POSITION: |
609 case TitledBorder.BELOW_TOP: |
739 case TitledBorder.BELOW_TOP: |
610 return Component.BaselineResizeBehavior.CONSTANT_ASCENT; |
740 return Component.BaselineResizeBehavior.CONSTANT_ASCENT; |
611 case TitledBorder.ABOVE_BOTTOM: |
741 case TitledBorder.ABOVE_BOTTOM: |
612 case TitledBorder.BOTTOM: |
742 case TitledBorder.BOTTOM: |
613 case TitledBorder.BELOW_BOTTOM: |
743 case TitledBorder.BELOW_BOTTOM: |
614 return JComponent.BaselineResizeBehavior.CONSTANT_DESCENT; |
744 return JComponent.BaselineResizeBehavior.CONSTANT_DESCENT; |
|
745 } |
615 } |
746 return Component.BaselineResizeBehavior.OTHER; |
616 return Component.BaselineResizeBehavior.OTHER; |
747 } |
617 } |
748 |
618 |
|
619 private Border getBorderUI() { |
|
620 Border border = getBorder(); |
|
621 return border != null |
|
622 ? border |
|
623 : UIManager.getBorder("TitledBorder.border"); |
|
624 } |
|
625 |
|
626 private int getPosition() { |
|
627 int position = getTitlePosition(); |
|
628 if (position != DEFAULT_POSITION) { |
|
629 return position; |
|
630 } |
|
631 Object value = UIManager.get("TitledBorder.position"); |
|
632 if (value instanceof Integer) { |
|
633 int i = (Integer) value; |
|
634 if ((0 < i) && (i <= 6)) { |
|
635 return i; |
|
636 } |
|
637 } |
|
638 else if (value instanceof String) { |
|
639 String s = (String) value; |
|
640 if (s.equalsIgnoreCase("ABOVE_TOP")) { |
|
641 return ABOVE_TOP; |
|
642 } |
|
643 if (s.equalsIgnoreCase("TOP")) { |
|
644 return TOP; |
|
645 } |
|
646 if (s.equalsIgnoreCase("BELOW_TOP")) { |
|
647 return BELOW_TOP; |
|
648 } |
|
649 if (s.equalsIgnoreCase("ABOVE_BOTTOM")) { |
|
650 return ABOVE_BOTTOM; |
|
651 } |
|
652 if (s.equalsIgnoreCase("BOTTOM")) { |
|
653 return BOTTOM; |
|
654 } |
|
655 if (s.equalsIgnoreCase("BELOW_BOTTOM")) { |
|
656 return BELOW_BOTTOM; |
|
657 } |
|
658 } |
|
659 return TOP; |
|
660 } |
|
661 |
|
662 private int getJustification(Component c) { |
|
663 int justification = getTitleJustification(); |
|
664 if ((justification == LEADING) || (justification == DEFAULT_JUSTIFICATION)) { |
|
665 return c.getComponentOrientation().isLeftToRight() ? LEFT : RIGHT; |
|
666 } |
|
667 if (justification == TRAILING) { |
|
668 return c.getComponentOrientation().isLeftToRight() ? RIGHT : LEFT; |
|
669 } |
|
670 return justification; |
|
671 } |
|
672 |
749 protected Font getFont(Component c) { |
673 protected Font getFont(Component c) { |
750 Font font; |
674 Font font = getTitleFont(); |
751 if ((font = getTitleFont()) != null) { |
675 if (font != null) { |
752 return font; |
676 return font; |
753 } else if (c != null && (font = c.getFont()) != null) { |
677 } |
|
678 font = UIManager.getFont("TitledBorder.font"); |
|
679 if (font != null) { |
754 return font; |
680 return font; |
755 } |
681 } |
|
682 if (c != null) { |
|
683 font = c.getFont(); |
|
684 if (font != null) { |
|
685 return font; |
|
686 } |
|
687 } |
756 return new Font(Font.DIALOG, Font.PLAIN, 12); |
688 return new Font(Font.DIALOG, Font.PLAIN, 12); |
757 } |
689 } |
758 |
690 |
759 private static boolean computeIntersection(Rectangle dest, |
691 private Color getColor(Component c) { |
760 int rx, int ry, int rw, int rh) { |
692 Color color = getTitleColor(); |
761 int x1 = Math.max(rx, dest.x); |
693 if (color != null) { |
762 int x2 = Math.min(rx + rw, dest.x + dest.width); |
694 return color; |
763 int y1 = Math.max(ry, dest.y); |
695 } |
764 int y2 = Math.min(ry + rh, dest.y + dest.height); |
696 color = UIManager.getColor("TitledBorder.titleColor"); |
765 dest.x = x1; |
697 if (color != null) { |
766 dest.y = y1; |
698 return color; |
767 dest.width = x2 - x1; |
699 } |
768 dest.height = y2 - y1; |
700 return (c != null) |
769 |
701 ? c.getForeground() |
770 if (dest.width <= 0 || dest.height <= 0) { |
702 : null; |
771 return false; |
703 } |
772 } |
704 |
773 return true; |
705 private JLabel getLabel(Component c) { |
|
706 this.label.setText(getTitle()); |
|
707 this.label.setFont(getFont(c)); |
|
708 this.label.setForeground(getColor(c)); |
|
709 this.label.setComponentOrientation(c.getComponentOrientation()); |
|
710 this.label.setEnabled(c.isEnabled()); |
|
711 return this.label; |
774 } |
712 } |
775 } |
713 } |