1 14 package org.compiere.plaf; 15 16 import java.awt.Color ; 17 import java.awt.Component ; 18 import java.awt.Dimension ; 19 import java.awt.Font ; 20 import java.awt.FontMetrics ; 21 import java.awt.GradientPaint ; 22 import java.awt.Graphics ; 23 import java.awt.Graphics2D ; 24 import java.awt.Insets ; 25 import java.awt.LayoutManager ; 26 import java.awt.Polygon ; 27 import java.awt.Rectangle ; 28 import java.awt.Shape ; 29 30 import javax.swing.Icon ; 31 import javax.swing.JComponent ; 32 import javax.swing.JPanel ; 33 import javax.swing.SwingUtilities ; 34 import javax.swing.plaf.ComponentUI ; 35 import javax.swing.plaf.basic.BasicGraphicsUtils ; 36 import javax.swing.plaf.metal.MetalTabbedPaneUI ; 37 38 46 public class CompiereTabbedPaneUI extends MetalTabbedPaneUI 47 { 48 53 public static ComponentUI createUI(JComponent c) 54 { 55 return new CompiereTabbedPaneUI(); 56 } 58 61 protected void installDefaults() 62 { 63 super.installDefaults(); 64 tabPane.setOpaque(false); 65 } 67 68 69 84 public void update (Graphics g, JComponent c) 85 { 86 95 96 98 if (c.isOpaque()) 99 CompierePanelUI.updateIt (g, c); paint (g, c); 101 } 103 108 public void paint( Graphics g, JComponent c ) 109 { 110 int tabPlacement = tabPane.getTabPlacement(); 111 Insets insets = c.getInsets(); 112 Dimension size = c.getSize(); 113 114 if ( tabPane.isOpaque() ) 115 { 116 g.setColor(c.getBackground()); 117 118 switch (tabPlacement) 119 { 120 case LEFT: 121 g.fillRect( insets.left, insets.top, 122 calculateTabAreaWidth( tabPlacement, runCount, maxTabWidth ), 123 size.height - insets.bottom - insets.top ); 124 break; 125 case BOTTOM: 126 int totalTabHeight = calculateTabAreaHeight( tabPlacement, runCount, maxTabHeight ); 127 g.fillRect( insets.left, size.height - insets.bottom - totalTabHeight, 128 size.width - insets.left - insets.right, 129 totalTabHeight ); 130 break; 131 case RIGHT: 132 int totalTabWidth = calculateTabAreaWidth( tabPlacement, runCount, maxTabWidth ); 133 g.fillRect( size.width - insets.right - totalTabWidth, 134 insets.top, totalTabWidth, 135 size.height - insets.top - insets.bottom ); 136 break; 137 case TOP: 138 default: 139 g.fillRect( insets.left, insets.top, 140 size.width - insets.right - insets.left, 141 calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight) ); 142 paintHighlightBelowTab(); 143 } 144 } 145 146 super.paint( g, c ); 147 } 149 150 151 179 protected void paintTabBackground (Graphics g, int tabPlacement, 180 int tabIndex, int x, int y, int w, int h, boolean isSelected) 181 { 182 Graphics2D g2D = (Graphics2D )g; 183 184 185 Component comp = tabPane.getComponentAt(tabIndex); 187 g2D.setPaint(comp.getBackground()); 189 CompiereColor bg = null; 190 if (comp instanceof JPanel ) 191 { 192 JPanel jp = (JPanel )comp; 193 try 194 { 195 bg = (CompiereColor)jp.getClientProperty(CompierePLAF.BACKGROUND); 196 } 197 catch (Exception e) 198 { 199 System.err.println("CompiereTabbedPaneUI - ClientProperty: " + e.getMessage()); 200 } 201 } 202 203 if (bg == null) { 205 if (CompiereUtils.isLeftToRight(tabPane)) 206 { 207 switch (tabPlacement) 208 { 209 case LEFT: 210 g2D.fillRect( x + 5, y + 1, w - 5, h - 1); 211 g2D.fillRect( x + 2, y + 4, 3, h - 4 ); 212 break; 213 case BOTTOM: 214 g2D.fillRect( x + 2, y, w - 2, h - 4 ); 215 g2D.fillRect( x + 5, y + (h - 1) - 3, w - 5, 3 ); 216 break; 217 case RIGHT: 218 g2D.fillRect( x + 1, y + 1, w - 5, h - 1); 219 g2D.fillRect( x + (w - 1) - 3, y + 5, 3, h - 5 ); 220 break; 221 case TOP: 222 default: 223 g2D.fillRect( x + 4, y + 2, (w - 1) - 3, (h - 1) - 1 ); 224 g2D.fillRect( x + 2, y + 5, 2, h - 5 ); 225 } 226 } 227 else 228 { 229 switch (tabPlacement) 230 { 231 case LEFT: 232 g2D.fillRect( x + 5, y + 1, w - 5, h - 1); 233 g2D.fillRect( x + 2, y + 4, 3, h - 4 ); 234 break; 235 case BOTTOM: 236 g2D.fillRect( x, y, w - 5, h - 1 ); 237 g2D.fillRect( x + (w - 1) - 4, y, 4, h - 5); 238 g2D.fillRect( x + (w - 1) - 4, y + (h - 1) - 4, 2, 2); 239 break; 240 case RIGHT: 241 g2D.fillRect( x + 1, y + 1, w - 5, h - 1); 242 g2D.fillRect( x + (w - 1) - 3, y + 5, 3, h - 5 ); 243 break; 244 case TOP: 245 default: 246 g2D.fillRect( x, y + 2, (w - 1) - 3, (h - 1) - 1 ); 247 g2D.fillRect( x + (w - 1) - 3, y + 4, 3, h - 4 ); 248 } 249 } 250 } 251 else { 253 if (CompiereUtils.isLeftToRight(tabPane)) 254 { 255 switch (tabPlacement) 256 { 257 case LEFT: 258 bg.paintRect (g2D, tabPane, x + 5, y + 1, w - 5, h - 1); 259 bg.paintRect (g2D, tabPane, x + 2, y + 4, 3, h - 4 ); 260 break; 261 case BOTTOM: 262 bg.paintRect (g2D, tabPane, x + 2, y, w - 2, h - 4 ); 263 bg.paintRect (g2D, tabPane, x + 5, y + (h - 1) - 3, w - 5, 3 ); 264 break; 265 case RIGHT: 266 bg.paintRect (g2D, tabPane, x, y + 2, w - 4, h - 2); bg.paintRect (g2D, tabPane, x + (w - 1) - 3, y + 5, 3, h - 5 ); 269 break; 270 case TOP: 271 default: 272 bg.paintRect (g2D, tabPane, x + 4, y + 2, (w - 1) - 3, (h - 1) - 1 ); 273 bg.paintRect (g2D, tabPane, x + 2, y + 5, 2, h - 5 ); 274 } 275 } 276 else 277 { 278 switch (tabPlacement) 279 { 280 case LEFT: 281 bg.paintRect (g2D, tabPane, x + 5, y + 1, w - 5, h - 1); 282 bg.paintRect (g2D, tabPane, x + 2, y + 4, 3, h - 4 ); 283 break; 284 case BOTTOM: 285 bg.paintRect (g2D, tabPane, x, y, w - 5, h - 1 ); 286 bg.paintRect (g2D, tabPane, x + (w - 1) - 4, y, 4, h - 5); 287 bg.paintRect (g2D, tabPane, x + (w - 1) - 4, y + (h - 1) - 4, 2, 2); 288 break; 289 case RIGHT: 290 bg.paintRect (g2D, tabPane, x + 1, y + 1, w - 5, h - 1); 291 bg.paintRect (g2D, tabPane, x + (w - 1) - 3, y + 5, 3, h - 5 ); 292 break; 293 case TOP: 294 default: 295 bg.paintRect (g2D, tabPane, x, y + 2, (w - 1) - 3, (h - 1) - 1 ); 296 bg.paintRect (g2D, tabPane, x + (w - 1) - 3, y + 4, 3, h - 4 ); 297 } 298 } 299 } 300 301 if (!(isSelected && (tabPlacement == RIGHT || tabPlacement == LEFT || tabPlacement == BOTTOM))) 303 { 304 Shape top = new Rectangle (x, y, w, h/2); if (tabPlacement == TOP || tabPlacement == LEFT) 306 top = new Polygon ( new int[] {x+6, x+w, x+w, x, x }, 308 new int[] {y, y, y+(h/2), y+(h/2), y+6 }, 5); 309 else if (tabPlacement == RIGHT) 310 top = new Polygon ( new int[] {x, x+w-6, x+w, x+w, x }, 312 new int[] {y, y, y+6, y+(h/2), y+(h/2) }, 5); 313 GradientPaint paint = new GradientPaint ( 315 x, y, CompiereUtils.COL_1TOP, 316 x, y+(h/2), CompiereUtils.COL_1END); 317 g2D.setPaint(paint); 318 g2D.fill(top); 319 } 320 321 if (!(isSelected && (tabPlacement == TOP || tabPlacement == RIGHT || tabPlacement == LEFT))) 323 { 324 Shape end = new Rectangle (x, y+(h/2), w, h/2); if (tabPlacement == BOTTOM) 326 end = new Polygon ( new int[] {x, x+w, x+w, x+6, x }, 328 new int[] {y+(h/2), y+(h/2), y+h, y+h, y+h-6 }, 5); 329 GradientPaint paint = new GradientPaint ( 331 x, y+(h/2), CompiereUtils.COL_2TOP, 332 x, y+h, CompiereUtils.COL_2END); 333 g2D.setPaint(paint); 334 g2D.fill(end); 335 } 336 337 } 339 340 341 348 protected void paintContentBorder (Graphics g, int tabPlacement, int selectedIndex) 349 { 350 int width = tabPane.getWidth(); 352 int height = tabPane.getHeight(); 353 Insets insets = tabPane.getInsets(); 354 355 int x = insets.left; 356 int y = insets.top; 357 int w = width - insets.right - insets.left; 358 int h = height - insets.top - insets.bottom; 359 360 switch (tabPlacement) 361 { 362 case LEFT: 363 x += calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth); 364 w -= (x - insets.left); 365 break; 366 case RIGHT: 367 w -= calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth); 368 break; 369 case BOTTOM: 370 h -= calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight); 371 break; 372 case TOP: 373 default: 374 y += calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight); 375 h -= (y - insets.top); 376 } 377 378 Component comp = null; 380 if (selectedIndex != -1) 381 comp = tabPane.getComponentAt(selectedIndex); 382 if (comp != null && comp instanceof JComponent ) 383 { 384 JComponent jc = (JComponent )comp; 385 CompiereColor bg = null; 386 try 387 { 388 bg = (CompiereColor)jc.getClientProperty(CompierePLAF.BACKGROUND); 389 } 390 catch (Exception e) 391 { 392 System.err.println("CompiereTabbedPaneUI - ClientProperty: " + e.getMessage()); 393 } 394 if (bg == null) 395 { 396 bg = new CompiereColor(jc.getBackground()); 397 jc.putClientProperty(CompierePLAF.BACKGROUND, bg); 398 } 399 bg.paintRect(g, jc, x,y, w,h); 400 } 401 else if (comp != null) 403 { 404 g.setColor(comp.getBackground()); 405 g.fillRect(x,y, w,h); 406 } 407 408 paintContentBorderTopEdge(g, tabPlacement, selectedIndex, x, y, w, h); 409 paintContentBorderLeftEdge(g, tabPlacement, selectedIndex, x, y, w, h); 410 paintContentBorderBottomEdge(g, tabPlacement, selectedIndex, x, y, w, h); 411 paintContentBorderRightEdge(g, tabPlacement, selectedIndex, x, y, w, h); 412 } 414 424 protected void paintContentBorderLeftEdge (Graphics g, int tabPlacement, 425 int selectedIndex, int x, int y, int w, int h) 426 { 427 Rectangle selRect = selectedIndex < 0 ? null : getTabBounds(selectedIndex, calcRect); 428 g.setColor(selectHighlight); 429 430 if (tabPlacement != LEFT || selectedIndex < 0 434 || (selRect.x + selRect.width + 1 < x) 435 || (selRect.y < y || selRect.y > y + h)) 436 { 437 g.drawLine(x, y, x, y+h-2); 438 } 439 else 440 { 441 g.drawLine(x, y, x, selRect.y + 1); 443 if (selRect.y + selRect.height < y + h - 2) 444 g.drawLine(x, selRect.y + selRect.height + 1, x, y+h-2); } 446 } 447 448 458 protected void paintContentBorderBottomEdge (Graphics g, int tabPlacement, 459 int selectedIndex, int x, int y, int w, int h) 460 { 461 boolean leftToRight = CompiereUtils.isLeftToRight(tabPane); 462 int bottom = y + h - 1; 463 int right = x + w - 1; 464 Rectangle selRect = selectedIndex < 0 ? null : getTabBounds(selectedIndex, calcRect); 465 g.setColor(shadow); 466 467 if (tabPlacement != BOTTOM 471 || selectedIndex < 0 472 || (selRect.x < x || selRect.x > x + w)) 474 { 475 g.setColor(darkShadow); 476 g.drawLine(x, y+h-1, x+w-1, y+h-1); 477 } 478 else 479 { 480 boolean lastInRun = isLastInRun(selectedIndex); 482 g.setColor(darkShadow); 483 if ( leftToRight || lastInRun ) 484 g.drawLine(x, bottom, selRect.x, bottom); 485 else 486 g.drawLine(x, bottom, selRect.x - 1, bottom); 487 488 if (selRect.x + selRect.width < x + w - 2) 489 { 490 if ( leftToRight && !lastInRun ) 491 g.drawLine(selRect.x + selRect.width, bottom, right, bottom); 492 else 493 g.drawLine(selRect.x + selRect.width - 1, bottom, right, bottom); 494 } 495 } 496 } 498 508 protected void paintContentBorderRightEdge (Graphics g, int tabPlacement, 509 int selectedIndex, int x, int y, int w, int h) 510 { 511 Rectangle selRect = selectedIndex < 0 ? null : getTabBounds(selectedIndex, calcRect); 512 g.setColor(shadow); 513 514 if (tabPlacement != RIGHT 518 || selectedIndex < 0 519 || (selRect.y < y || selRect.y > y + h) 521 ) 522 { 523 g.setColor(darkShadow); 524 g.drawLine(x+w-1, y, x+w-1, y+h-1); 525 } 526 else 527 { 528 g.setColor(darkShadow); 530 g.drawLine(x+w-1, y, x+w-1, selRect.y); 531 if (selRect.y + selRect.height < y + h - 2) 532 { 533 g.setColor(darkShadow); 534 g.drawLine(x+w-1, selRect.y + selRect.height, x+w-1, y+h-2); 535 } 536 } 537 } 539 544 private boolean isLastInRun (int tabIndex) 545 { 546 int run = getRunForTab( tabPane.getTabCount(), tabIndex ); 547 int lastIndex = lastTabInRun( tabPane.getTabCount(), run ); 548 return tabIndex == lastIndex; 549 } 551 552 553 561 protected boolean shouldFillGap (int currentRun, int tabIndex, int x, int y) 562 { 563 return false; 564 } 566 578 protected void paintTopTabBorder ( int tabIndex, Graphics g, 579 int x, int y, int w, int h, int btm, int rght, boolean isSelected ) 580 { 581 int currentRun = getRunForTab( tabPane.getTabCount(), tabIndex ); 582 int lastIndex = lastTabInRun( tabPane.getTabCount(), currentRun ); 583 int firstIndex = tabRuns[ currentRun ]; 584 boolean leftToRight = CompiereUtils.isLeftToRight(tabPane); 585 int bottom = h - 1; 586 int right = w - 1; 587 588 if ( shouldFillGap( currentRun, tabIndex, x, y ) ) 590 { 591 g.translate( x, y ); 592 if ( leftToRight ) 593 { 594 g.setColor( getColorForGap( currentRun, x, y + 1 ) ); 595 g.fillRect( 1, 0, 5, 3 ); 596 g.fillRect( 1, 3, 2, 2 ); 597 } 598 else 599 { 600 g.setColor( getColorForGap( currentRun, x + w - 1, y + 1 ) ); 601 g.fillRect( right - 5, 0, 5, 3 ); 602 g.fillRect( right - 2, 3, 2, 2 ); 603 } 604 g.translate( -x, -y ); 605 } 606 607 g.translate( x, y ); 608 g.setColor( darkShadow ); 610 if (leftToRight) 611 { 612 g.drawLine( 1, 5, 6, 0 ); 614 g.drawLine( 6, 0, right, 0 ); 616 if ( tabIndex==lastIndex ) g.drawLine( right, 1, right, bottom ); 619 if ( tabIndex != tabRuns[ runCount - 1 ] ) g.drawLine( 0, 0, 0, bottom ); 622 else g.drawLine( 0, 6, 0, bottom ); 624 } 625 else 626 { 627 g.drawLine( right - 1, 5, right - 6, 0 ); 629 g.drawLine( right - 6, 0, 0, 0 ); 631 if ( tabIndex != tabRuns[ runCount - 1 ] ) g.drawLine( right, 0, right, bottom ); 634 else g.drawLine( right, 6, right, bottom ); 636 if ( tabIndex==lastIndex ) g.drawLine( 0, 1, 0, bottom ); 639 } 640 641 if (!isSelected) 643 g.drawLine(0, bottom, right, bottom); 645 g.setColor( isSelected ? selectHighlight : highlight ); 647 if ( leftToRight ) 648 { 649 g.drawLine( 1, 6, 6, 1 ); 651 if (tabIndex == lastIndex) 653 g.drawLine( 6, 1, right-1, 1 ); 654 else 655 g.drawLine( 6, 1, right, 1 ); g.drawLine( 1, 6, 1, bottom ); 658 659 if ( tabIndex==firstIndex && tabIndex!=tabRuns[runCount - 1] ) 662 { 663 if (tabPane.getSelectedIndex()==tabRuns[currentRun+1]) 665 { 666 g.setColor( selectHighlight ); 668 } 669 else 670 { 671 g.setColor( highlight ); 673 } 674 g.drawLine( 1, 0, 1, 4 ); 675 } 676 } 677 else 678 { 679 g.drawLine( right - 1, 6, right - 6, 1 ); 681 g.drawLine( right - 6, 1, 1, 1 ); 683 684 if ( tabIndex==lastIndex ) g.drawLine( 1, 1, 1, bottom ); 687 else 688 g.drawLine( 0, 1, 0, bottom ); 689 } 690 g.translate( -x, -y ); 691 } 693 707 protected void paintLeftTabBorder (int tabIndex, Graphics g, 708 int x, int y, int w, int h, int btm, int rght, boolean isSelected) 709 { 710 int tabCount = tabPane.getTabCount(); 711 int currentRun = getRunForTab( tabCount, tabIndex ); 712 int lastIndex = lastTabInRun( tabCount, currentRun ); 713 int firstIndex = tabRuns[ currentRun ]; 714 715 g.translate( x, y ); 716 717 int bottom = h - 1; 718 int right = w - 1; 719 720 g.setColor( isSelected ? selectHighlight : highlight ); 722 g.drawLine( 1, 6, 6, 1 ); 724 g.drawLine( 6, 1, right, 1 ); 726 g.drawLine( 1, 6, 1, bottom ); 728 if (!isSelected) 730 g.drawLine(right-1, 0, right-1, bottom ); 731 732 g.setColor( darkShadow ); 734 g.drawLine( 1, 5, 6, 0 ); 736 g.drawLine( 6, 0, right, 0 ); 738 g.drawLine( 0, 6, 0, bottom ); 740 g.drawLine( 0, bottom, right, bottom ); 742 if (!isSelected) 744 g.drawLine(right, 0, right, bottom ); 745 g.translate( -x, -y ); 747 } 749 750 764 protected void paintRightTabBorder (int tabIndex, Graphics g, 765 int x, int y, int w, int h, int btm, int rght, boolean isSelected) 766 { 767 int tabCount = tabPane.getTabCount(); 768 int currentRun = getRunForTab( tabCount, tabIndex ); 769 int lastIndex = lastTabInRun( tabCount, currentRun ); 770 int firstIndex = tabRuns[ currentRun ]; 771 772 g.translate( x, y ); 773 774 int bottom = h - 1; 775 int right = w - 1; 776 777 g.setColor( isSelected ? selectHighlight : highlight ); 779 g.drawLine (right-6, 1, right-1, 6 ); 781 g.drawLine (0, 1, right - 6, 1 ); 783 g.drawLine (right-1, 6, right-1, bottom-1); 785 if (!isSelected) 787 g.drawLine (0, 1, 0, bottom-1); 788 789 g.setColor( darkShadow ); 791 g.drawLine (right - 6, 0, right, 6 ); 793 g.drawLine (0, 0, right - 6, 0 ); 795 g.drawLine (right, 6, right, bottom ); 797 g.drawLine( 0, bottom, right, bottom ); 799 800 g.translate( -x, -y ); 801 } 803 804 805 806 814 protected int calculateTabWidth (int tabPlacement, int tabIndex, FontMetrics metrics) 815 { 816 boolean calculate = !(tabPlacement == TOP || tabPlacement == BOTTOM); 817 if (getTextViewForTab(tabIndex) != null) 819 calculate = false; 820 String title = tabPane.getTitleAt(tabIndex); 822 int pos = title.indexOf(" "); 823 if (calculate && pos == -1) 824 calculate = false; 825 if (!calculate) 826 return super.calculateTabWidth (tabPlacement, tabIndex, metrics); 827 Icon icon = getIconForTab(tabIndex); 829 Insets tabInsetsLocal = getTabInsets(tabPlacement, tabIndex); 830 int width = tabInsetsLocal.left + tabInsetsLocal.right + 3; 831 832 if (icon != null) 833 width += icon.getIconWidth() + textIconGap; 834 835 String firstLine = title.substring(0, pos); 836 String secondLine = title.substring(pos+1); 837 width += Math.max(SwingUtilities.computeStringWidth (metrics, firstLine), 838 SwingUtilities.computeStringWidth (metrics, secondLine)); 839 return width; 840 } 842 849 protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight) 850 { 851 boolean calculate = !(tabPlacement == TOP || tabPlacement == BOTTOM); 852 if (getTextViewForTab(tabIndex) != null) 854 calculate = false; 855 String title = tabPane.getTitleAt(tabIndex); 857 int pos = title.indexOf(" "); 858 if (calculate && pos == -1) 859 calculate = false; 860 if (!calculate) 861 return super.calculateTabHeight (tabPlacement, tabIndex, fontHeight); 862 int height = fontHeight * 2; 864 Icon icon = getIconForTab(tabIndex); 865 Insets tabInsetsLocal = getTabInsets(tabPlacement, tabIndex); 866 if (icon != null) 867 height = Math.max(height, icon.getIconHeight()); 868 height += tabInsetsLocal.top + tabInsetsLocal.bottom + 2; 869 return height; 870 } 871 872 884 protected void layoutLabel(int tabPlacement, 885 FontMetrics metrics, int tabIndex, String title, Icon icon, 886 Rectangle tabRect, Rectangle iconRect, Rectangle textRect, boolean isSelected) 887 { 888 boolean calculate = !(tabPlacement == TOP || tabPlacement == BOTTOM); 889 if (getTextViewForTab(tabIndex) != null) 891 calculate = false; 892 if (!calculate) 893 { 894 super.layoutLabel (tabPlacement, metrics, tabIndex, title, icon, 895 tabRect, iconRect, textRect, isSelected); 896 return; 898 } 899 textRect.x = textRect.y = iconRect.x = iconRect.y = 0; 901 SwingUtilities.layoutCompoundLabel(tabPane, 902 metrics, title, icon, 903 SwingUtilities.TOP, SwingUtilities.LEFT, SwingUtilities.CENTER, SwingUtilities.TRAILING, tabRect, 908 iconRect, 909 textRect, 910 textIconGap); 911 tabPane.putClientProperty("html", null); 912 int xNudge = getTabLabelShiftX(tabPlacement, tabIndex, isSelected); 913 int yNudge = getTabLabelShiftY(tabPlacement, tabIndex, isSelected); 914 Insets tabInsetsLocal = getTabInsets(tabPlacement, tabIndex); 916 xNudge += tabInsetsLocal.left; 917 yNudge += tabInsetsLocal.top + 1; 918 iconRect.x += xNudge; 919 iconRect.y += yNudge; 920 textRect.x += xNudge; 921 textRect.y += yNudge; 922 } 924 925 936 protected void paintText (Graphics g, int tabPlacement, 937 Font font, FontMetrics metrics, int tabIndex, 938 String title, Rectangle textRect, boolean isSelected) 939 { 940 boolean calculate = !(tabPlacement == TOP || tabPlacement == BOTTOM); 941 if (getTextViewForTab(tabIndex) != null) 943 calculate = false; 944 if (!calculate) 945 { 946 super.paintText (g, tabPlacement, font, metrics, tabIndex, 947 title, textRect, isSelected); 948 return; 949 } 950 951 String firstLine = title; 953 String secondLine = null; 954 int pos = title.indexOf(' '); 955 if (pos != -1) 956 { 957 firstLine = title.substring(0, pos); 958 secondLine = title.substring(pos+1); 959 } 960 961 g.setFont(font); 962 int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex); 963 if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) 964 { 965 Color c = tabPane.getForegroundAt(tabIndex); 966 if (!isSelected) 967 { 968 if (c.equals(Color.black)) 969 c = Color.darkGray; 970 else 971 c = c.brighter(); 972 } 973 g.setColor(c); 974 BasicGraphicsUtils.drawStringUnderlineCharAt 976 (g, firstLine, mnemIndex, textRect.x, textRect.y + metrics.getAscent()); 977 if (secondLine != null) 979 BasicGraphicsUtils.drawStringUnderlineCharAt 980 (g, secondLine, mnemIndex-firstLine.length(), 981 textRect.x, textRect.y + metrics.getAscent() + metrics.getHeight()); 982 } 983 else 984 { g.setColor(tabPane.getBackgroundAt(tabIndex).brighter()); 986 BasicGraphicsUtils.drawStringUnderlineCharAt 987 (g, firstLine, mnemIndex, textRect.x, textRect.y + metrics.getAscent()); 988 if (secondLine != null) 990 BasicGraphicsUtils.drawStringUnderlineCharAt 991 (g, secondLine, mnemIndex-firstLine.length(), 992 textRect.x, textRect.y + metrics.getAscent() + metrics.getHeight()); 993 g.setColor(tabPane.getBackgroundAt(tabIndex).darker()); 995 BasicGraphicsUtils.drawStringUnderlineCharAt 996 (g, firstLine, mnemIndex, textRect.x -1, textRect.y + metrics.getAscent() -1); 997 if (secondLine != null) 999 BasicGraphicsUtils.drawStringUnderlineCharAt 1000 (g, secondLine, mnemIndex-firstLine.length(), 1001 textRect.x -1, textRect.y + metrics.getAscent() + metrics.getHeight() -1); 1002 } 1003 } 1005 1006 1007 1011 protected LayoutManager createLayoutManager() 1012 { 1013 return new TabbedPaneLayout(); 1014 } 1016 1019 public class TabbedPaneLayout extends MetalTabbedPaneUI.TabbedPaneLayout 1020 { 1021 1026 protected void calculateTabRects(int tabPlacement, int tabCount) 1027 { 1028 super.calculateTabRects(tabPlacement, tabCount); 1029 if (tabPlacement == TOP || tabPlacement == BOTTOM) 1030 return; 1031 int tabHeight = calculateMaxTabHeight(tabPlacement); 1033 for (int i = 0; i < rects.length; i++) 1034 { 1035 int level = 0; 1036 Component comp = tabPane.getComponentAt(i); 1037 if (comp instanceof JComponent ) 1038 { 1039 JComponent jc = (JComponent )comp; 1040 try 1041 { 1042 Integer ll = (Integer )jc.getClientProperty(CompierePLAF.TABLEVEL); 1043 if (ll != null) 1044 level = ll.intValue(); 1045 } 1046 catch (Exception e) 1047 { 1048 System.err.println("CompiereTabbedPaneUI - ClientProperty: " + e.getMessage()); 1049 } 1050 } 1051 if (level != 0) 1052 { 1053 if (tabPlacement == LEFT) 1054 rects[i].x += level * 5; 1055 rects[i].width -= level * 5; 1056 } 1057 rects[i].height = tabHeight; 1059 if (i > 0) 1060 rects[i].y = rects[i-1].y + tabHeight; } } 1064 } 1066} | Popular Tags |