415 /** 416 * {@inheritDoc} 417 */ 418 @Override 419 public Dimension getPreferredSize(JComponent c) { 420 Dimension size = null; 421 Insets border = progressBar.getInsets(); 422 FontMetrics fontSizer = progressBar.getFontMetrics(progressBar.getFont()); 423 String progString = progressBar.getString(); 424 int stringHeight = fontSizer.getHeight() + fontSizer.getDescent(); 425 426 if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { 427 size = new Dimension(getPreferredInnerHorizontal()); 428 if (progressBar.isStringPainted()) { 429 // adjust the height if necessary to make room for the string 430 if (stringHeight > size.height) { 431 size.height = stringHeight; 432 } 433 434 // adjust the width if necessary to make room for the string 435 int stringWidth = SwingUtilities2.stringWidth( 436 progressBar, fontSizer, progString); 437 if (stringWidth > size.width) { 438 size.width = stringWidth; 439 } 440 } 441 } else { 442 size = new Dimension(getPreferredInnerVertical()); 443 if (progressBar.isStringPainted()) { 444 // make sure the width is big enough for the string 445 if (stringHeight > size.width) { 446 size.width = stringHeight; 447 } 448 449 // make sure the height is big enough for the string 450 int stringWidth = SwingUtilities2.stringWidth( 451 progressBar, fontSizer, progString); 452 if (stringWidth > size.height) { 453 size.height = stringWidth; 454 } 455 } 456 } 457 458 // handle scaling for sizeVarients for special case components. The 459 // key "JComponent.sizeVariant" scales for large/small/mini 460 // components are based on Apples LAF 461 String scaleKey = (String)progressBar.getClientProperty( 462 "JComponent.sizeVariant"); 463 if (scaleKey != null){ 464 if ("large".equals(scaleKey)){ 465 size.width *= 1.15f; 466 size.height *= 1.15f; 467 } else if ("small".equals(scaleKey)){ 468 size.width *= 0.90f; 469 size.height *= 0.90f; 470 } else if ("mini".equals(scaleKey)){ | 415 /** 416 * {@inheritDoc} 417 */ 418 @Override 419 public Dimension getPreferredSize(JComponent c) { 420 Dimension size = null; 421 Insets border = progressBar.getInsets(); 422 FontMetrics fontSizer = progressBar.getFontMetrics(progressBar.getFont()); 423 String progString = progressBar.getString(); 424 int stringHeight = fontSizer.getHeight() + fontSizer.getDescent(); 425 426 if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { 427 size = new Dimension(getPreferredInnerHorizontal()); 428 if (progressBar.isStringPainted()) { 429 // adjust the height if necessary to make room for the string 430 if (stringHeight > size.height) { 431 size.height = stringHeight; 432 } 433 434 // adjust the width if necessary to make room for the string 435 int stringWidth = getTextUIDrawing().getStringWidth( 436 progressBar, fontSizer, progString); 437 if (stringWidth > size.width) { 438 size.width = stringWidth; 439 } 440 } 441 } else { 442 size = new Dimension(getPreferredInnerVertical()); 443 if (progressBar.isStringPainted()) { 444 // make sure the width is big enough for the string 445 if (stringHeight > size.width) { 446 size.width = stringHeight; 447 } 448 449 // make sure the height is big enough for the string 450 int stringWidth = getTextUIDrawing().getStringWidth( 451 progressBar, fontSizer, progString); 452 if (stringWidth > size.height) { 453 size.height = stringWidth; 454 } 455 } 456 } 457 458 // handle scaling for sizeVarients for special case components. The 459 // key "JComponent.sizeVariant" scales for large/small/mini 460 // components are based on Apples LAF 461 String scaleKey = (String)progressBar.getClientProperty( 462 "JComponent.sizeVariant"); 463 if (scaleKey != null){ 464 if ("large".equals(scaleKey)){ 465 size.width *= 1.15f; 466 size.height *= 1.15f; 467 } else if ("small".equals(scaleKey)){ 468 size.width *= 0.90f; 469 size.height *= 0.90f; 470 } else if ("mini".equals(scaleKey)){ |