1 7 8 package javax.swing.plaf.metal; 9 10 import javax.swing.*; 11 import javax.swing.plaf.UIResource ; 12 import java.awt.*; 13 import java.awt.image.BufferedImage ; 14 import java.io.Serializable ; 15 import java.util.Enumeration ; 16 import java.util.Vector ; 17 18 43 public class MetalIconFactory implements Serializable { 44 45 private static Icon fileChooserDetailViewIcon; 47 private static Icon fileChooserHomeFolderIcon; 48 private static Icon fileChooserListViewIcon; 49 private static Icon fileChooserNewFolderIcon; 50 private static Icon fileChooserUpFolderIcon; 51 private static Icon internalFrameAltMaximizeIcon; 52 private static Icon internalFrameCloseIcon; 53 private static Icon internalFrameDefaultMenuIcon; 54 private static Icon internalFrameMaximizeIcon; 55 private static Icon internalFrameMinimizeIcon; 56 private static Icon radioButtonIcon; 57 private static Icon treeComputerIcon; 58 private static Icon treeFloppyDriveIcon; 59 private static Icon treeHardDriveIcon; 60 61 62 private static Icon menuArrowIcon; 63 private static Icon menuItemArrowIcon; 64 private static Icon checkBoxMenuItemIcon; 65 private static Icon radioButtonMenuItemIcon; 66 private static Icon checkBoxIcon; 67 68 69 private static Icon oceanHorizontalSliderThumb; 71 private static Icon oceanVerticalSliderThumb; 72 73 public static final boolean DARK = false; 75 public static final boolean LIGHT = true; 76 77 public static Icon getFileChooserDetailViewIcon() { 79 if (fileChooserDetailViewIcon == null) { 80 fileChooserDetailViewIcon = new FileChooserDetailViewIcon(); 81 } 82 return fileChooserDetailViewIcon; 83 } 84 85 public static Icon getFileChooserHomeFolderIcon() { 86 if (fileChooserHomeFolderIcon == null) { 87 fileChooserHomeFolderIcon = new FileChooserHomeFolderIcon(); 88 } 89 return fileChooserHomeFolderIcon; 90 } 91 92 public static Icon getFileChooserListViewIcon() { 93 if (fileChooserListViewIcon == null) { 94 fileChooserListViewIcon = new FileChooserListViewIcon(); 95 } 96 return fileChooserListViewIcon; 97 } 98 99 public static Icon getFileChooserNewFolderIcon() { 100 if (fileChooserNewFolderIcon == null) { 101 fileChooserNewFolderIcon = new FileChooserNewFolderIcon(); 102 } 103 return fileChooserNewFolderIcon; 104 } 105 106 public static Icon getFileChooserUpFolderIcon() { 107 if (fileChooserUpFolderIcon == null) { 108 fileChooserUpFolderIcon = new FileChooserUpFolderIcon(); 109 } 110 return fileChooserUpFolderIcon; 111 } 112 113 public static Icon getInternalFrameAltMaximizeIcon(int size) { 114 return new InternalFrameAltMaximizeIcon(size); 115 } 116 117 public static Icon getInternalFrameCloseIcon(int size) { 118 return new InternalFrameCloseIcon(size); 119 } 120 121 public static Icon getInternalFrameDefaultMenuIcon() { 122 if (internalFrameDefaultMenuIcon == null) { 123 internalFrameDefaultMenuIcon = new InternalFrameDefaultMenuIcon(); 124 } 125 return internalFrameDefaultMenuIcon; 126 } 127 128 public static Icon getInternalFrameMaximizeIcon(int size) { 129 return new InternalFrameMaximizeIcon(size); 130 } 131 132 public static Icon getInternalFrameMinimizeIcon(int size) { 133 return new InternalFrameMinimizeIcon(size); 134 } 135 136 public static Icon getRadioButtonIcon() { 137 if (radioButtonIcon == null) { 138 radioButtonIcon = new RadioButtonIcon(); 139 } 140 return radioButtonIcon; 141 } 142 143 147 public static Icon getCheckBoxIcon() { 148 if (checkBoxIcon == null) { 149 checkBoxIcon = new CheckBoxIcon(); 150 } 151 return checkBoxIcon; 152 } 153 154 public static Icon getTreeComputerIcon() { 155 if ( treeComputerIcon == null ) { 156 treeComputerIcon = new TreeComputerIcon(); 157 } 158 return treeComputerIcon; 159 } 160 161 public static Icon getTreeFloppyDriveIcon() { 162 if ( treeFloppyDriveIcon == null ) { 163 treeFloppyDriveIcon = new TreeFloppyDriveIcon(); 164 } 165 return treeFloppyDriveIcon; 166 } 167 168 public static Icon getTreeFolderIcon() { 169 return new TreeFolderIcon(); 170 } 171 172 public static Icon getTreeHardDriveIcon() { 173 if ( treeHardDriveIcon == null ) { 174 treeHardDriveIcon = new TreeHardDriveIcon(); 175 } 176 return treeHardDriveIcon; 177 } 178 179 public static Icon getTreeLeafIcon() { 180 return new TreeLeafIcon(); 181 } 182 183 public static Icon getTreeControlIcon( boolean isCollapsed ) { 184 return new TreeControlIcon( isCollapsed ); 185 } 186 187 public static Icon getMenuArrowIcon() { 188 if (menuArrowIcon == null) { 189 menuArrowIcon = new MenuArrowIcon(); 190 } 191 return menuArrowIcon; 192 } 193 194 200 public static Icon getMenuItemCheckIcon() { 201 return null; 202 } 203 204 public static Icon getMenuItemArrowIcon() { 205 if (menuItemArrowIcon == null) { 206 menuItemArrowIcon = new MenuItemArrowIcon(); 207 } 208 return menuItemArrowIcon; 209 } 210 211 public static Icon getCheckBoxMenuItemIcon() { 212 if (checkBoxMenuItemIcon == null) { 213 checkBoxMenuItemIcon = new CheckBoxMenuItemIcon(); 214 } 215 return checkBoxMenuItemIcon; 216 } 217 218 public static Icon getRadioButtonMenuItemIcon() { 219 if (radioButtonMenuItemIcon == null) { 220 radioButtonMenuItemIcon = new RadioButtonMenuItemIcon(); 221 } 222 return radioButtonMenuItemIcon; 223 } 224 225 public static Icon getHorizontalSliderThumbIcon() { 226 if (MetalLookAndFeel.usingOcean()) { 227 if (oceanHorizontalSliderThumb == null) { 228 oceanHorizontalSliderThumb = 229 new OceanHorizontalSliderThumbIcon(); 230 } 231 return oceanHorizontalSliderThumb; 232 } 233 return new HorizontalSliderThumbIcon(); 235 } 236 237 public static Icon getVerticalSliderThumbIcon() { 238 if (MetalLookAndFeel.usingOcean()) { 239 if (oceanVerticalSliderThumb == null) { 240 oceanVerticalSliderThumb = new OceanVerticalSliderThumbIcon(); 241 } 242 return oceanVerticalSliderThumb; 243 } 244 return new VerticalSliderThumbIcon(); 246 } 247 248 private static class FileChooserDetailViewIcon implements Icon, UIResource , Serializable { 250 public void paintIcon(Component c, Graphics g, int x, int y) { 251 g.translate(x, y); 252 253 g.setColor(MetalLookAndFeel.getPrimaryControlInfo()); 255 g.drawLine(2,2, 5,2); g.drawLine(2,3, 2,7); g.drawLine(3,7, 6,7); g.drawLine(6,6, 6,3); g.drawLine(2,10, 5,10); g.drawLine(2,11, 2,15); g.drawLine(3,15, 6,15); g.drawLine(6,14, 6,11); 266 g.drawLine(8,5, 15,5); g.drawLine(8,13, 15,13); 271 g.setColor(MetalLookAndFeel.getPrimaryControl()); 273 g.drawRect(3,3, 2,3); g.drawRect(3,11, 2,3); 276 g.setColor(MetalLookAndFeel.getPrimaryControlHighlight()); 278 g.drawLine(4,4, 4,5); g.drawLine(4,12, 4,13); 281 g.translate(-x, -y); 282 } 283 284 public int getIconWidth() { 285 return 18; 286 } 287 288 public int getIconHeight() { 289 return 18; 290 } 291 } 293 private static class FileChooserHomeFolderIcon implements Icon, UIResource , Serializable { 295 public void paintIcon(Component c, Graphics g, int x, int y) { 296 g.translate(x, y); 297 298 g.setColor(MetalLookAndFeel.getPrimaryControlInfo()); 300 g.drawLine(8,1, 1,8); g.drawLine(8,1, 15,8); g.drawLine(11,2, 11,3); g.drawLine(12,2, 12,4); g.drawLine(3,7, 3,15); g.drawLine(13,7, 13,15); g.drawLine(4,15, 12,15); g.drawLine( 6,9, 6,14); g.drawLine(10,9, 10,14); g.drawLine( 7,9, 9, 9); 313 g.setColor(MetalLookAndFeel.getControlDarkShadow()); 315 g.fillRect(8,2, 1,1); g.fillRect(7,3, 3,1); 317 g.fillRect(6,4, 5,1); 318 g.fillRect(5,5, 7,1); 319 g.fillRect(4,6, 9,2); 320 g.drawLine(9,12, 9,12); 323 324 g.setColor(MetalLookAndFeel.getPrimaryControl()); 326 g.drawLine(4,8, 12,8); g.fillRect(4,9, 2,6); g.fillRect(11,9, 2,6); 330 g.translate(-x, -y); 331 } 332 333 public int getIconWidth() { 334 return 18; 335 } 336 337 public int getIconHeight() { 338 return 18; 339 } 340 } 342 private static class FileChooserListViewIcon implements Icon, UIResource , Serializable { 344 public void paintIcon(Component c, Graphics g, int x, int y) { 345 g.translate(x, y); 346 347 g.setColor(MetalLookAndFeel.getPrimaryControlInfo()); 349 g.drawLine(2,2, 5,2); g.drawLine(2,3, 2,7); g.drawLine(3,7, 6,7); g.drawLine(6,6, 6,3); g.drawLine(10,2, 13,2); g.drawLine(10,3, 10,7); g.drawLine(11,7, 14,7); g.drawLine(14,6, 14,3); g.drawLine(2,10, 5,10); g.drawLine(2,11, 2,15); g.drawLine(3,15, 6,15); g.drawLine(6,14, 6,11); g.drawLine(10,10, 13,10); g.drawLine(10,11, 10,15); g.drawLine(11,15, 14,15); g.drawLine(14,14, 14,11); 370 g.drawLine(8,5, 8,5); g.drawLine(16,5, 16,5); g.drawLine(8,13, 8,13); g.drawLine(16,13, 16,13); 377 g.setColor(MetalLookAndFeel.getPrimaryControl()); 379 g.drawRect(3,3, 2,3); g.drawRect(11,3, 2,3); g.drawRect(3,11, 2,3); g.drawRect(11,11, 2,3); 384 g.setColor(MetalLookAndFeel.getPrimaryControlHighlight()); 386 g.drawLine(4,4, 4,5); g.drawLine(12,4, 12,5); g.drawLine(4,12, 4,13); g.drawLine(12,12, 12,13); 391 g.translate(-x, -y); 392 } 393 394 public int getIconWidth() { 395 return 18; 396 } 397 398 public int getIconHeight() { 399 return 18; 400 } 401 } 403 private static class FileChooserNewFolderIcon implements Icon, UIResource , Serializable { 405 public void paintIcon(Component c, Graphics g, int x, int y) { 406 g.translate(x, y); 407 408 g.setColor(MetalLookAndFeel.getPrimaryControl()); 410 g.fillRect(3,5, 12,9); 411 412 g.setColor(MetalLookAndFeel.getPrimaryControlInfo()); 414 g.drawLine(1,6, 1,14); g.drawLine(2,14, 15,14); g.drawLine(15,13, 15,5); g.drawLine(2,5, 9,5); g.drawLine(10,6, 14,6); 420 g.setColor(MetalLookAndFeel.getPrimaryControlHighlight()); 422 g.drawLine( 2,6, 2,13); g.drawLine( 3,6, 9,6); g.drawLine(10,7, 14,7); 426 g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); 428 g.drawLine(11,3, 15,3); g.drawLine(10,4, 15,4); 431 g.translate(-x, -y); 432 } 433 434 public int getIconWidth() { 435 return 18; 436 } 437 438 public int getIconHeight() { 439 return 18; 440 } 441 } 443 private static class FileChooserUpFolderIcon implements Icon, UIResource , Serializable { 445 public void paintIcon(Component c, Graphics g, int x, int y) { 446 g.translate(x, y); 447 448 g.setColor(MetalLookAndFeel.getPrimaryControl()); 450 g.fillRect(3,5, 12,9); 451 452 g.setColor(MetalLookAndFeel.getPrimaryControlInfo()); 454 g.drawLine(1,6, 1,14); g.drawLine(2,14, 15,14); g.drawLine(15,13, 15,5); g.drawLine(2,5, 9,5); g.drawLine(10,6, 14,6); g.drawLine(8,13, 8,16); g.drawLine(8, 9, 8, 9); g.drawLine(7,10, 9,10); 464 g.drawLine(6,11, 10,11); 465 g.drawLine(5,12, 11,12); 466 467 g.setColor(MetalLookAndFeel.getPrimaryControlHighlight()); 469 g.drawLine( 2,6, 2,13); g.drawLine( 3,6, 9,6); g.drawLine(10,7, 14,7); 473 g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); 475 g.drawLine(11,3, 15,3); g.drawLine(10,4, 15,4); 478 g.translate(-x, -y); 479 } 480 481 public int getIconWidth() { 482 return 18; 483 } 484 485 public int getIconHeight() { 486 return 18; 487 } 488 } 490 491 495 public static class PaletteCloseIcon implements Icon, UIResource , Serializable { 496 int iconSize = 7; 497 498 public void paintIcon(Component c, Graphics g, int x, int y) { 499 JButton parentButton = (JButton)c; 500 ButtonModel buttonModel = parentButton.getModel(); 501 502 Color back; 503 Color highlight = MetalLookAndFeel.getPrimaryControlHighlight(); 504 Color shadow = MetalLookAndFeel.getPrimaryControlInfo(); 505 if (buttonModel.isPressed() && buttonModel.isArmed()) { 506 back = shadow; 507 } else { 508 back = MetalLookAndFeel.getPrimaryControlDarkShadow(); 509 } 510 511 g.translate(x, y); 512 g.setColor(back); 513 g.drawLine( 0, 1, 5, 6); 514 g.drawLine( 1, 0, 6, 5); 515 g.drawLine( 1, 1, 6, 6); 516 g.drawLine( 6, 1, 1, 6); 517 g.drawLine( 5,0, 0,5); 518 g.drawLine(5,1, 1,5); 519 520 g.setColor(highlight); 521 g.drawLine(6,2, 5,3); 522 g.drawLine(2,6, 3, 5); 523 g.drawLine(6,6,6,6); 524 525 526 g.translate(-x, -y); 527 } 528 529 public int getIconWidth() { 530 return iconSize; 531 } 532 533 public int getIconHeight() { 534 return iconSize; 535 } 536 } 537 538 private static class InternalFrameCloseIcon implements Icon, UIResource , Serializable { 540 int iconSize = 16; 541 542 public InternalFrameCloseIcon(int size) { 543 iconSize = size; 544 } 545 546 public void paintIcon(Component c, Graphics g, int x, int y) { 547 JButton parentButton = (JButton)c; 548 ButtonModel buttonModel = parentButton.getModel(); 549 550 Color backgroundColor = MetalLookAndFeel.getPrimaryControl(); 551 Color internalBackgroundColor = 552 MetalLookAndFeel.getPrimaryControl(); 553 Color mainItemColor = 554 MetalLookAndFeel.getPrimaryControlDarkShadow(); 555 Color darkHighlightColor = MetalLookAndFeel.getBlack(); 556 Color xLightHighlightColor = MetalLookAndFeel.getWhite(); 557 Color boxLightHighlightColor = MetalLookAndFeel.getWhite(); 558 559 if (parentButton.getClientProperty("paintActive") != Boolean.TRUE) 561 { 562 backgroundColor = MetalLookAndFeel.getControl(); 563 internalBackgroundColor = backgroundColor; 564 mainItemColor = MetalLookAndFeel.getControlDarkShadow(); 565 if (buttonModel.isPressed() && buttonModel.isArmed()) { 567 internalBackgroundColor = 568 MetalLookAndFeel.getControlShadow(); 569 xLightHighlightColor = internalBackgroundColor; 570 mainItemColor = darkHighlightColor; 571 } 572 } 573 else if (buttonModel.isPressed() && buttonModel.isArmed()) { 575 internalBackgroundColor = 576 MetalLookAndFeel.getPrimaryControlShadow(); 577 xLightHighlightColor = internalBackgroundColor; 578 mainItemColor = darkHighlightColor; 579 } 581 582 int oneHalf = (int)(iconSize / 2); 585 g.translate(x, y); 586 587 g.setColor(backgroundColor); 589 g.fillRect(0,0, iconSize,iconSize); 590 591 g.setColor(internalBackgroundColor); 593 g.fillRect(3,3, iconSize-6,iconSize-6); 594 595 g.setColor(darkHighlightColor); 598 g.drawRect(1,1, iconSize-3,iconSize-3); 599 g.drawRect(2,2, iconSize-5,iconSize-5); 601 g.setColor(boxLightHighlightColor); 603 g.drawRect(2,2, iconSize-3,iconSize-3); 604 g.setColor(mainItemColor); 606 g.drawRect(2,2, iconSize-4,iconSize-4); 607 g.drawLine(3,iconSize-3, 3,iconSize-3); g.drawLine(iconSize-3,3, iconSize-3,3); 610 g.setColor(darkHighlightColor); 613 g.drawLine(4,5, 5,4); g.drawLine(4,iconSize-6, iconSize-6,4); g.setColor(xLightHighlightColor); 617 g.drawLine(6,iconSize-5, iconSize-5,6); g.drawLine(oneHalf,oneHalf+2, oneHalf+2,oneHalf); 620 g.drawLine(iconSize-5,iconSize-5, iconSize-4,iconSize-5); 622 g.drawLine(iconSize-5,iconSize-4, iconSize-5,iconSize-4); 623 g.setColor(mainItemColor); 625 g.drawLine(5,5, iconSize-6,iconSize-6); g.drawLine(6,5, iconSize-5,iconSize-6); g.drawLine(5,6, iconSize-6,iconSize-5); g.drawLine(5,iconSize-5, iconSize-5,5); g.drawLine(5,iconSize-6, iconSize-6,5); 633 g.translate(-x, -y); 634 } 635 636 public int getIconWidth() { 637 return iconSize; 638 } 639 640 public int getIconHeight() { 641 return iconSize; 642 } 643 } 645 private static class InternalFrameAltMaximizeIcon implements Icon, UIResource , Serializable { 647 int iconSize = 16; 648 649 public InternalFrameAltMaximizeIcon(int size) { 650 iconSize = size; 651 } 652 653 public void paintIcon(Component c, Graphics g, int x, int y) { 654 JButton parentButton = (JButton)c; 655 ButtonModel buttonModel = parentButton.getModel(); 656 657 Color backgroundColor = MetalLookAndFeel.getPrimaryControl(); 658 Color internalBackgroundColor = 659 MetalLookAndFeel.getPrimaryControl(); 660 Color mainItemColor = 661 MetalLookAndFeel.getPrimaryControlDarkShadow(); 662 Color darkHighlightColor = MetalLookAndFeel.getBlack(); 663 Color ulLightHighlightColor = MetalLookAndFeel.getWhite(); 665 Color lrLightHighlightColor = MetalLookAndFeel.getWhite(); 666 667 if (parentButton.getClientProperty("paintActive") != Boolean.TRUE) 669 { 670 backgroundColor = MetalLookAndFeel.getControl(); 671 internalBackgroundColor = backgroundColor; 672 mainItemColor = MetalLookAndFeel.getControlDarkShadow(); 673 if (buttonModel.isPressed() && buttonModel.isArmed()) { 675 internalBackgroundColor = 676 MetalLookAndFeel.getControlShadow(); 677 ulLightHighlightColor = internalBackgroundColor; 678 mainItemColor = darkHighlightColor; 679 } 680 } 681 else if (buttonModel.isPressed() && buttonModel.isArmed()) { 683 internalBackgroundColor = 684 MetalLookAndFeel.getPrimaryControlShadow(); 685 ulLightHighlightColor = internalBackgroundColor; 686 mainItemColor = darkHighlightColor; 687 } 689 690 g.translate(x, y); 691 692 g.setColor(backgroundColor); 694 g.fillRect(0,0, iconSize,iconSize); 695 696 g.setColor(internalBackgroundColor); 699 g.fillRect(3,6, iconSize-9,iconSize-9); 700 701 g.setColor(darkHighlightColor); 703 g.drawRect(1,5, iconSize-8,iconSize-8); 704 g.drawLine(1,iconSize-2, 1,iconSize-2); 706 g.setColor(lrLightHighlightColor); 708 g.drawRect(2,6, iconSize-7,iconSize-7); 709 g.setColor(ulLightHighlightColor); 711 g.drawRect(3,7, iconSize-9,iconSize-9); 712 713 g.setColor(mainItemColor); 715 g.drawRect(2,6, iconSize-8,iconSize-8); 716 717 g.setColor(ulLightHighlightColor); 719 g.drawLine(iconSize-6,8,iconSize-6,8); 720 g.drawLine(iconSize-9,6, iconSize-7,8); 721 g.setColor(mainItemColor); 722 g.drawLine(3,iconSize-3,3,iconSize-3); 723 g.setColor(darkHighlightColor); 724 g.drawLine(iconSize-6,9,iconSize-6,9); 725 g.setColor(backgroundColor); 726 g.drawLine(iconSize-9,5,iconSize-9,5); 727 728 g.setColor(mainItemColor); 731 g.fillRect(iconSize-7,3, 3,5); g.drawLine(iconSize-6,5, iconSize-3,2); g.drawLine(iconSize-6,6, iconSize-2,2); g.drawLine(iconSize-6,7, iconSize-3,7); 736 g.setColor(darkHighlightColor); 738 g.drawLine(iconSize-8,2, iconSize-7,2); g.drawLine(iconSize-8,3, iconSize-8,7); g.drawLine(iconSize-6,4, iconSize-3,1); g.drawLine(iconSize-4,6, iconSize-3,6); 743 g.setColor(lrLightHighlightColor); 745 g.drawLine(iconSize-6,3, iconSize-6,3); g.drawLine(iconSize-4,5, iconSize-2,3); g.drawLine(iconSize-4,8, iconSize-3,8); g.drawLine(iconSize-2,8, iconSize-2,7); 750 g.translate(-x, -y); 751 } 752 753 public int getIconWidth() { 754 return iconSize; 755 } 756 757 public int getIconHeight() { 758 return iconSize; 759 } 760 } 762 private static class InternalFrameDefaultMenuIcon implements Icon, UIResource , Serializable { 764 public void paintIcon(Component c, Graphics g, int x, int y) { 765 766 Color windowBodyColor = MetalLookAndFeel.getWindowBackground(); 767 Color titleColor = MetalLookAndFeel.getPrimaryControl(); 768 Color edgeColor = MetalLookAndFeel.getPrimaryControlDarkShadow(); 769 770 g.translate(x, y); 771 772 g.setColor(titleColor); 775 g.fillRect(0,0, 16,16); 776 777 g.setColor(windowBodyColor); 779 g.fillRect(2,6, 13,9); 780 g.drawLine(2,2, 2,2); 782 g.drawLine(5,2, 5,2); 783 g.drawLine(8,2, 8,2); 784 g.drawLine(11,2, 11,2); 785 786 g.setColor(edgeColor); 788 g.drawRect(1,1, 13,13); g.drawLine(1,0, 14,0); g.drawLine(15,1, 15,14); g.drawLine(1,15, 14,15); g.drawLine(0,1, 0,14); g.drawLine(2,5, 13,5); g.drawLine(3,3, 3,3); 796 g.drawLine(6,3, 6,3); 797 g.drawLine(9,3, 9,3); 798 g.drawLine(12,3, 12,3); 799 800 g.translate(-x, -y); 801 } 802 803 public int getIconWidth() { 804 return 16; 805 } 806 807 public int getIconHeight() { 808 return 16; 809 } 810 } 812 private static class InternalFrameMaximizeIcon implements Icon, UIResource , Serializable { 814 protected int iconSize = 16; 815 816 public InternalFrameMaximizeIcon(int size) { 817 iconSize = size; 818 } 819 820 public void paintIcon(Component c, Graphics g, int x, int y) { 821 JButton parentButton = (JButton)c; 822 ButtonModel buttonModel = parentButton.getModel(); 823 824 Color backgroundColor = MetalLookAndFeel.getPrimaryControl(); 825 Color internalBackgroundColor = 826 MetalLookAndFeel.getPrimaryControl(); 827 Color mainItemColor = 828 MetalLookAndFeel.getPrimaryControlDarkShadow(); 829 Color darkHighlightColor = MetalLookAndFeel.getBlack(); 830 Color ulLightHighlightColor = MetalLookAndFeel.getWhite(); 832 Color lrLightHighlightColor = MetalLookAndFeel.getWhite(); 833 834 if (parentButton.getClientProperty("paintActive") != Boolean.TRUE) 836 { 837 backgroundColor = MetalLookAndFeel.getControl(); 838 internalBackgroundColor = backgroundColor; 839 mainItemColor = MetalLookAndFeel.getControlDarkShadow(); 840 if (buttonModel.isPressed() && buttonModel.isArmed()) { 842 internalBackgroundColor = 843 MetalLookAndFeel.getControlShadow(); 844 ulLightHighlightColor = internalBackgroundColor; 845 mainItemColor = darkHighlightColor; 846 } 847 } 848 else if (buttonModel.isPressed() && buttonModel.isArmed()) { 850 internalBackgroundColor = 851 MetalLookAndFeel.getPrimaryControlShadow(); 852 ulLightHighlightColor = internalBackgroundColor; 853 mainItemColor = darkHighlightColor; 854 } 856 857 g.translate(x, y); 858 859 g.setColor(backgroundColor); 861 g.fillRect(0,0, iconSize,iconSize); 862 863 g.setColor(internalBackgroundColor); 866 g.fillRect(3,7, iconSize-10,iconSize-10); 867 868 g.setColor(ulLightHighlightColor); 870 g.drawRect(3,7, iconSize-10,iconSize-10); g.setColor(lrLightHighlightColor); 872 g.drawRect(2,6, iconSize-7,iconSize-7); g.setColor(darkHighlightColor); 875 g.drawRect(1,5, iconSize-7,iconSize-7); g.drawRect(2,6, iconSize-9,iconSize-9); g.setColor(mainItemColor); 879 g.drawRect(2,6, iconSize-8,iconSize-8); 881 g.setColor(darkHighlightColor); 884 g.drawLine(3,iconSize-5, iconSize-9,7); 886 g.drawLine(iconSize-6,4, iconSize-5,3); 888 g.drawLine(iconSize-7,1, iconSize-7,2); 890 g.drawLine(iconSize-6,1, iconSize-2,1); 892 g.setColor(ulLightHighlightColor); 894 g.drawLine(5,iconSize-4, iconSize-8,9); 896 g.setColor(lrLightHighlightColor); 897 g.drawLine(iconSize-6,3, iconSize-4,5); g.drawLine(iconSize-4,5, iconSize-4,6); g.drawLine(iconSize-2,7, iconSize-1,7); g.drawLine(iconSize-1,2, iconSize-1,6); g.setColor(mainItemColor); 903 g.drawLine(3,iconSize-4, iconSize-3,2); g.drawLine(3,iconSize-3, iconSize-2,2); g.drawLine(4,iconSize-3, 5,iconSize-3); g.drawLine(iconSize-7,8, iconSize-7,9); g.drawLine(iconSize-6,2, iconSize-4,2); g.drawRect(iconSize-3,3, 1,3); 910 g.translate(-x, -y); 911 } 912 913 public int getIconWidth() { 914 return iconSize; 915 } 916 917 public int getIconHeight() { 918 return iconSize; 919 } 920 } 922 private static class InternalFrameMinimizeIcon implements Icon, UIResource , Serializable { 924 int iconSize = 16; 925 926 public InternalFrameMinimizeIcon(int size) { 927 iconSize = size; 928 } 929 930 public void paintIcon(Component c, Graphics g, int x, int y) { 931 JButton parentButton = (JButton)c; 932 ButtonModel buttonModel = parentButton.getModel(); 933 934 935 Color backgroundColor = MetalLookAndFeel.getPrimaryControl(); 936 Color internalBackgroundColor = 937 MetalLookAndFeel.getPrimaryControl(); 938 Color mainItemColor = 939 MetalLookAndFeel.getPrimaryControlDarkShadow(); 940 Color darkHighlightColor = MetalLookAndFeel.getBlack(); 941 Color ulLightHighlightColor = MetalLookAndFeel.getWhite(); 943 Color lrLightHighlightColor = MetalLookAndFeel.getWhite(); 944 945 if (parentButton.getClientProperty("paintActive") != Boolean.TRUE) 947 { 948 backgroundColor = MetalLookAndFeel.getControl(); 949 internalBackgroundColor = backgroundColor; 950 mainItemColor = MetalLookAndFeel.getControlDarkShadow(); 951 if (buttonModel.isPressed() && buttonModel.isArmed()) { 953 internalBackgroundColor = 954 MetalLookAndFeel.getControlShadow(); 955 ulLightHighlightColor = internalBackgroundColor; 956 mainItemColor = darkHighlightColor; 957 } 958 } 959 else if (buttonModel.isPressed() && buttonModel.isArmed()) { 961 internalBackgroundColor = 962 MetalLookAndFeel.getPrimaryControlShadow(); 963 ulLightHighlightColor = internalBackgroundColor; 964 mainItemColor = darkHighlightColor; 965 } 967 968 g.translate(x, y); 969 970 g.setColor(backgroundColor); 972 g.fillRect(0,0, iconSize,iconSize); 973 974 g.setColor(internalBackgroundColor); 977 g.fillRect(4,11, iconSize-13,iconSize-13); 978 g.setColor(lrLightHighlightColor); 980 g.drawRect(2,10, iconSize-10,iconSize-11); g.setColor(ulLightHighlightColor); 982 g.drawRect(3,10, iconSize-12,iconSize-12); g.setColor(darkHighlightColor); 985 g.drawRect(1,8, iconSize-10,iconSize-10); g.drawRect(2,9, iconSize-12,iconSize-12); g.setColor(mainItemColor); 989 g.drawRect(2,9, iconSize-11,iconSize-11); 990 g.drawLine(iconSize-10,10, iconSize-10,10); g.drawLine(3,iconSize-3, 3,iconSize-3); 993 g.setColor(mainItemColor); 996 g.fillRect(iconSize-7,3, 3,5); g.drawLine(iconSize-6,5, iconSize-3,2); g.drawLine(iconSize-6,6, iconSize-2,2); g.drawLine(iconSize-6,7, iconSize-3,7); 1001 g.setColor(darkHighlightColor); 1003 g.drawLine(iconSize-8,2, iconSize-7,2); g.drawLine(iconSize-8,3, iconSize-8,7); g.drawLine(iconSize-6,4, iconSize-3,1); g.drawLine(iconSize-4,6, iconSize-3,6); 1008 g.setColor(lrLightHighlightColor); 1010 g.drawLine(iconSize-6,3, iconSize-6,3); g.drawLine(iconSize-4,5, iconSize-2,3); g.drawLine(iconSize-7,8, iconSize-3,8); g.drawLine(iconSize-2,8, iconSize-2,7); 1015 g.translate(-x, -y); 1016 } 1017 1018 public int getIconWidth() { 1019 return iconSize; 1020 } 1021 1022 public int getIconHeight() { 1023 return iconSize; 1024 } 1025 } 1027 private static class CheckBoxIcon implements Icon, UIResource , Serializable { 1028 1029 protected int getControlSize() { return 13; } 1030 1031 private void paintOceanIcon(Component c, Graphics g, int x, int y) { 1032 ButtonModel model = ((JCheckBox)c).getModel(); 1033 1034 g.translate(x, y); 1035 int w = getIconWidth(); 1036 int h = getIconHeight(); 1037 if ( model.isEnabled() ) { 1038 if (model.isPressed() && model.isArmed()) { 1039 g.setColor(MetalLookAndFeel.getControlShadow()); 1040 g.fillRect(0, 0, w, h); 1041 g.setColor(MetalLookAndFeel.getControlDarkShadow()); 1042 g.fillRect(0, 0, w, 2); 1043 g.fillRect(0, 2, 2, h - 2); 1044 g.fillRect(w - 1, 1, 1, h - 1); 1045 g.fillRect(1, h - 1, w - 2, 1); 1046 } else if (model.isRollover()) { 1047 MetalUtils.drawGradient(c, g, "CheckBox.gradient", 0, 0, 1048 w, h, true); 1049 g.setColor(MetalLookAndFeel.getControlDarkShadow()); 1050 g.drawRect(0, 0, w - 1, h - 1); 1051 g.setColor(MetalLookAndFeel.getPrimaryControl()); 1052 g.drawRect(1, 1, w - 3, h - 3); 1053 g.drawRect(2, 2, w - 5, h - 5); 1054 } 1055 else { 1056 MetalUtils.drawGradient(c, g, "CheckBox.gradient", 0, 0, 1057 w, h, true); 1058 g.setColor(MetalLookAndFeel.getControlDarkShadow()); 1059 g.drawRect(0, 0, w - 1, h - 1); 1060 } 1061 g.setColor( MetalLookAndFeel.getControlInfo() ); 1062 } else { 1063 g.setColor(MetalLookAndFeel.getControlDarkShadow()); 1064 g.drawRect(0, 0, w - 1, h - 1); 1065 } 1066 g.translate(-x, -y); 1067 if (model.isSelected()) { 1068 drawCheck(c,g,x,y); 1069 } 1070 } 1071 1072 public void paintIcon(Component c, Graphics g, int x, int y) { 1073 if (MetalLookAndFeel.usingOcean()) { 1074 paintOceanIcon(c, g, x, y); 1075 return; 1076 } 1077 ButtonModel model = ((JCheckBox)c).getModel(); 1078 int controlSize = getControlSize(); 1079 1080 if ( model.isEnabled() ) { 1081 if (model.isPressed() && model.isArmed()) { 1082 g.setColor( MetalLookAndFeel.getControlShadow() ); 1083 g.fillRect( x, y, controlSize-1, controlSize-1); 1084 MetalUtils.drawPressed3DBorder(g, x, y, controlSize, controlSize); 1085 } else { 1086 MetalUtils.drawFlush3DBorder(g, x, y, controlSize, controlSize); 1087 } 1088 g.setColor( MetalLookAndFeel.getControlInfo() ); 1089 } else { 1090 g.setColor( MetalLookAndFeel.getControlShadow() ); 1091 g.drawRect( x, y, controlSize-2, controlSize-2); 1092 } 1093 1094 if (model.isSelected()) { 1095 drawCheck(c,g,x,y); 1096 } 1097 1098 } 1099 1100 protected void drawCheck(Component c, Graphics g, int x, int y) { 1101 int controlSize = getControlSize(); 1102 g.fillRect( x+3, y+5, 2, controlSize-8 ); 1103 g.drawLine( x+(controlSize-4), y+3, x+5, y+(controlSize-6) ); 1104 g.drawLine( x+(controlSize-4), y+4, x+5, y+(controlSize-5) ); 1105 } 1106 1107 public int getIconWidth() { 1108 return getControlSize(); 1109 } 1110 1111 public int getIconHeight() { 1112 return getControlSize(); 1113 } 1114 } 1116 private static class RadioButtonIcon implements Icon, UIResource , Serializable { 1118 public void paintOceanIcon(Component c, Graphics g, int x, int y) { 1119 ButtonModel model = ((JRadioButton)c).getModel(); 1120 boolean enabled = model.isEnabled(); 1121 boolean pressed = (enabled && model.isPressed() && 1122 model.isArmed()); 1123 boolean rollover = (enabled && model.isRollover()); 1124 1125 g.translate(x, y); 1126 if (enabled && !pressed) { 1127 MetalUtils.drawGradient(c, g, "RadioButton.gradient", 1130 1, 1, 10, 10, true); 1131 g.setColor(c.getBackground()); 1132 g.fillRect(1, 1, 1, 1); 1133 g.fillRect(10, 1, 1, 1); 1134 g.fillRect(1, 10, 1, 1); 1135 g.fillRect(10, 10, 1, 1); 1136 } 1137 else if (pressed || !enabled) { 1138 if (pressed) { 1139 g.setColor(MetalLookAndFeel.getPrimaryControl()); 1140 } 1141 else { 1142 g.setColor(MetalLookAndFeel.getControl()); 1143 } 1144 g.fillRect(2, 2, 8, 8); 1145 g.fillRect(4, 1, 4, 1); 1146 g.fillRect(4, 10, 4, 1); 1147 g.fillRect(1, 4, 1, 4); 1148 g.fillRect(10, 4, 1, 4); 1149 } 1150 1151 if (!enabled) { 1153 g.setColor(MetalLookAndFeel.getInactiveControlTextColor()); 1154 } 1155 else { 1156 g.setColor(MetalLookAndFeel.getControlDarkShadow()); 1157 } 1158 g.drawLine( 4, 0, 7, 0); 1159 g.drawLine( 8, 1, 9, 1); 1160 g.drawLine(10, 2, 10, 3); 1161 g.drawLine(11, 4, 11, 7); 1162 g.drawLine(10, 8, 10, 9); 1163 g.drawLine( 9,10, 8,10); 1164 g.drawLine( 7,11, 4,11); 1165 g.drawLine( 3,10, 2,10); 1166 g.drawLine( 1, 9, 1, 8); 1167 g.drawLine( 0, 7, 0, 4); 1168 g.drawLine( 1, 3, 1, 2); 1169 g.drawLine( 2, 1, 3, 1); 1170 1171 if (pressed) { 1172 g.fillRect(1, 4, 1, 4); 1173 g.fillRect(2, 2, 1, 2); 1174 g.fillRect(3, 2, 1, 1); 1175 g.fillRect(4, 1, 4, 1); 1176 } 1177 else if (rollover) { 1178 g.setColor(MetalLookAndFeel.getPrimaryControl()); 1179 g.fillRect(4, 1, 4, 2); 1180 g.fillRect(8, 2, 2, 2); 1181 g.fillRect(9, 4, 2, 4); 1182 g.fillRect(8, 8, 2, 2); 1183 g.fillRect(4, 9, 4, 2); 1184 g.fillRect(2, 8, 2, 2); 1185 g.fillRect(1, 4, 2, 4); 1186 g.fillRect(2, 2, 2, 2); 1187 } 1188 1189 if (model.isSelected()) { 1191 if (enabled) { 1192 g.setColor(c.getForeground()); 1193 } else { 1194 g.setColor(MetalLookAndFeel.getControlDarkShadow()); 1195 } 1196 g.fillRect(4, 4, 4, 4); 1197 g.drawLine(4, 3, 7, 3); 1198 g.drawLine(8, 4, 8, 7); 1199 g.drawLine(7, 8, 4, 8); 1200 g.drawLine(3, 7, 3, 4); 1201 } 1202 1203 g.translate(-x, -y); 1204 } 1205 1206 public void paintIcon(Component c, Graphics g, int x, int y) { 1207 if (MetalLookAndFeel.usingOcean()) { 1208 paintOceanIcon(c, g, x, y); 1209 return; 1210 } 1211 JRadioButton rb = (JRadioButton)c; 1212 ButtonModel model = rb.getModel(); 1213 boolean drawDot = model.isSelected(); 1214 1215 Color background = c.getBackground(); 1216 Color dotColor = c.getForeground(); 1217 Color shadow = MetalLookAndFeel.getControlShadow(); 1218 Color darkCircle = MetalLookAndFeel.getControlDarkShadow(); 1219 Color whiteInnerLeftArc = MetalLookAndFeel.getControlHighlight(); 1220 Color whiteOuterRightArc = MetalLookAndFeel.getControlHighlight(); 1221 Color interiorColor = background; 1222 1223 if ( !model.isEnabled() ) { 1225 whiteInnerLeftArc = whiteOuterRightArc = background; 1226 darkCircle = dotColor = shadow; 1227 } 1228 else if (model.isPressed() && model.isArmed() ) { 1229 whiteInnerLeftArc = interiorColor = shadow; 1230 } 1231 1232 g.translate(x, y); 1233 1234 g.setColor(interiorColor); 1236 g.fillRect(2,2, 9,9); 1237 1238 g.setColor(darkCircle); 1240 g.drawLine( 4, 0, 7, 0); 1241 g.drawLine( 8, 1, 9, 1); 1242 g.drawLine(10, 2, 10, 3); 1243 g.drawLine(11, 4, 11, 7); 1244 g.drawLine(10, 8, 10, 9); 1245 g.drawLine( 9,10, 8,10); 1246 g.drawLine( 7,11, 4,11); 1247 g.drawLine( 3,10, 2,10); 1248 g.drawLine( 1, 9, 1, 8); 1249 g.drawLine( 0, 7, 0, 4); 1250 g.drawLine( 1, 3, 1, 2); 1251 g.drawLine( 2, 1, 3, 1); 1252 1253 g.setColor(whiteInnerLeftArc); 1256 g.drawLine( 2, 9, 2, 8); 1257 g.drawLine( 1, 7, 1, 4); 1258 g.drawLine( 2, 2, 2, 3); 1259 g.drawLine( 2, 2, 3, 2); 1260 g.drawLine( 4, 1, 7, 1); 1261 g.drawLine( 8, 2, 9, 2); 1262 g.setColor(whiteOuterRightArc); 1265 g.drawLine(10, 1, 10, 1); 1266 g.drawLine(11, 2, 11, 3); 1267 g.drawLine(12, 4, 12, 7); 1268 g.drawLine(11, 8, 11, 9); 1269 g.drawLine(10,10, 10,10); 1270 g.drawLine( 9,11, 8,11); 1271 g.drawLine( 7,12, 4,12); 1272 g.drawLine( 3,11, 2,11); 1273 1274 if ( drawDot ) { 1276 g.setColor(dotColor); 1277 g.fillRect( 4, 4, 4, 4); 1278 g.drawLine( 4, 3, 7, 3); 1279 g.drawLine( 8, 4, 8, 7); 1280 g.drawLine( 7, 8, 4, 8); 1281 g.drawLine( 3, 7, 3, 4); 1282 } 1283 1284 g.translate(-x, -y); 1285 } 1286 1287 public int getIconWidth() { 1288 return 13; 1289 } 1290 1291 public int getIconHeight() { 1292 return 13; 1293 } 1294 } 1296 private static class TreeComputerIcon implements Icon, UIResource , Serializable { 1298 public void paintIcon(Component c, Graphics g, int x, int y) { 1299 g.translate(x, y); 1300 1301 g.setColor(MetalLookAndFeel.getPrimaryControl()); 1303 g.fillRect(5,4, 6,4); 1304 1305 g.setColor(MetalLookAndFeel.getPrimaryControlInfo()); 1307 g.drawLine( 2,2, 2,8); g.drawLine(13,2, 13,8); g.drawLine( 3,1, 12,1); g.drawLine(12,9, 12,9); g.drawLine( 3,9, 3,9); g.drawLine( 4,4, 4,7); g.drawLine( 5,3, 10,3); g.drawLine(11,4, 11,7); g.drawLine( 5,8, 10,8); g.drawLine( 1,10, 14,10); g.drawLine(14,10, 14,14); g.drawLine( 1,14, 14,14); g.drawLine( 1,10, 1,14); 1323 g.setColor(MetalLookAndFeel.getControlDarkShadow()); 1325 g.drawLine( 6,12, 8,12); g.drawLine(10,12, 12,12); 1328 g.translate(-x, -y); 1329 } 1330 1331 public int getIconWidth() { 1332 return 16; 1333 } 1334 1335 public int getIconHeight() { 1336 return 16; 1337 } 1338 } 1340 private static class TreeHardDriveIcon implements Icon, UIResource , Serializable { 1342 public void paintIcon(Component c, Graphics g, int x, int y) { 1343 g.translate(x, y); 1344 1345 g.setColor(MetalLookAndFeel.getPrimaryControlInfo()); 1347 g.drawLine(1,4, 1,5); g.drawLine(2,3, 3,3); 1350 g.drawLine(4,2, 11,2); g.drawLine(12,3, 13,3); 1352 g.drawLine(14,4, 14,5); g.drawLine(12,6, 13,6); 1354 g.drawLine(4,7, 11,7); g.drawLine(2,6, 3,6); 1356 g.drawLine(1,7, 1,8); g.drawLine(2,9, 3,9); 1359 g.drawLine(4,10, 11,10); g.drawLine(12,9, 13,9); 1361 g.drawLine(14,7, 14, 8); g.drawLine(1,10, 1,11); g.drawLine(2,12, 3,12); 1365 g.drawLine(4,13, 11,13); g.drawLine(12,12, 13,12); 1367 g.drawLine(14,10, 14,11); 1369 g.setColor(MetalLookAndFeel.getControlShadow()); 1371 g.drawLine(7,6, 7,6); 1373 g.drawLine(9,6, 9,6); 1374 g.drawLine(10,5, 10,5); 1375 g.drawLine(11,6, 11,6); 1376 g.drawLine(12,5, 13,5); 1377 g.drawLine(13,4, 13,4); 1378 g.drawLine(7,9, 7,9); 1380 g.drawLine(9,9, 9,9); 1381 g.drawLine(10,8, 10,8); 1382 g.drawLine(11,9, 11,9); 1383 g.drawLine(12,8, 13,8); 1384 g.drawLine(13,7, 13,7); 1385 g.drawLine(7,12, 7,12); 1387 g.drawLine(9,12, 9,12); 1388 g.drawLine(10,11, 10,11); 1389 g.drawLine(11,12, 11,12); 1390 g.drawLine(12,11, 13,11); 1391 g.drawLine(13,10, 13,10); 1392 1393 g.setColor(MetalLookAndFeel.getControlHighlight()); 1395 g.drawLine(4,3, 5,3); 1397 g.drawLine(7,3, 9,3); 1398 g.drawLine(11,3, 11,3); 1399 g.drawLine(2,4, 6,4); 1400 g.drawLine(8,4, 8,4); 1401 g.drawLine(2,5, 3,5); 1402 g.drawLine(4,6, 4,6); 1403 g.drawLine(2,7, 3,7); 1405 g.drawLine(2,8, 3,8); 1406 g.drawLine(4,9, 4,9); 1407 g.drawLine(2,10, 3,10); 1409 g.drawLine(2,11, 3,11); 1410 g.drawLine(4,12, 4,12); 1411 1412 g.translate(-x, -y); 1413 } 1414 1415 public int getIconWidth() { 1416 return 16; 1417 } 1418 1419 public int getIconHeight() { 1420 return 16; 1421 } 1422 } 1424 private static class TreeFloppyDriveIcon implements Icon, UIResource , Serializable { 1426 public void paintIcon(Component c, Graphics g, int x, int y) { 1427 g.translate(x, y); 1428 1429 g.setColor(MetalLookAndFeel.getPrimaryControl()); 1431 g.fillRect(2,2, 12,12); 1432 1433 g.setColor(MetalLookAndFeel.getPrimaryControlInfo()); 1435 g.drawLine( 1, 1, 13, 1); g.drawLine(14, 2, 14,14); g.drawLine( 1,14, 14,14); g.drawLine( 1, 1, 1,14); 1440 g.setColor(MetalLookAndFeel.getControlDarkShadow()); 1442 g.fillRect(5,2, 6,5); g.drawLine(4,8, 11,8); g.drawLine(3,9, 3,13); g.drawLine(12,9, 12,13); 1447 g.setColor(MetalLookAndFeel.getPrimaryControlHighlight()); 1449 g.fillRect(8,3, 2,3); g.fillRect(4,9, 8,5); 1452 g.setColor(MetalLookAndFeel.getPrimaryControlShadow()); 1454 g.drawLine(5,10, 9,10); 1455 g.drawLine(5,12, 8,12); 1456 1457 g.translate(-x, -y); 1458 } 1459 1460 public int getIconWidth() { 1461 return 16; 1462 } 1463 1464 public int getIconHeight() { 1465 return 16; 1466 } 1467 } 1469 1470 static private final Dimension folderIcon16Size = new Dimension( 16, 16 ); 1471 1472 1483 static class ImageCacher { 1484 1485 1487 Vector images = new Vector (1, 1); 1488 ImageGcPair currentImageGcPair; 1489 1490 class ImageGcPair { 1491 Image image; 1492 GraphicsConfiguration gc; 1493 ImageGcPair(Image image, GraphicsConfiguration gc) { 1494 this.image = image; 1495 this.gc = gc; 1496 } 1497 1498 boolean hasSameConfiguration(GraphicsConfiguration newGC) { 1499 if (((newGC != null) && (newGC.equals(gc))) || 1500 ((newGC == null) && (gc == null))) 1501 { 1502 return true; 1503 } 1504 return false; 1505 } 1506 1507 } 1508 1509 Image getImage(GraphicsConfiguration newGC) { 1510 if ((currentImageGcPair == null) || 1511 !(currentImageGcPair.hasSameConfiguration(newGC))) 1512 { 1513 Enumeration elements = images.elements(); 1514 while (elements.hasMoreElements()) { 1515 ImageGcPair imgGcPair = (ImageGcPair)elements.nextElement(); 1516 if (imgGcPair.hasSameConfiguration(newGC)) { 1517 currentImageGcPair = imgGcPair; 1518 return imgGcPair.image; 1519 } 1520 } 1521 return null; 1522 } 1523 return currentImageGcPair.image; 1524 } 1525 1526 void cacheImage(Image image, GraphicsConfiguration gc) { 1527 ImageGcPair imgGcPair = new ImageGcPair(image, gc); 1528 images.addElement(imgGcPair); 1529 currentImageGcPair = imgGcPair; 1530 } 1531 1532 } 1533 1534 1545 public static class FolderIcon16 implements Icon, Serializable { 1546 1547 ImageCacher imageCacher; 1548 1549 public void paintIcon(Component c, Graphics g, int x, int y) { 1550 GraphicsConfiguration gc = c.getGraphicsConfiguration(); 1551 if (imageCacher == null) { 1552 imageCacher = new ImageCacher(); 1553 } 1554 Image image = imageCacher.getImage(gc); 1555 if (image == null) { 1556 if (gc != null) { 1557 image = gc.createCompatibleImage(getIconWidth(), 1558 getIconHeight(), 1559 Transparency.BITMASK); 1560 } else { 1561 image = new BufferedImage (getIconWidth(), 1562 getIconHeight(), 1563 BufferedImage.TYPE_INT_ARGB); 1564 } 1565 Graphics imageG = image.getGraphics(); 1566 paintMe(c,imageG); 1567 imageG.dispose(); 1568 imageCacher.cacheImage(image, gc); 1569 } 1570 g.drawImage(image, x, y+getShift(), null); 1571 } 1572 1573 1574 private void paintMe(Component c, Graphics g) { 1575 1576 int right = folderIcon16Size.width - 1; 1577 int bottom = folderIcon16Size.height - 1; 1578 1579 g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() ); 1581 g.drawLine( right - 5, 3, right, 3 ); 1582 g.drawLine( right - 6, 4, right, 4 ); 1583 1584 g.setColor( MetalLookAndFeel.getPrimaryControl() ); 1586 g.fillRect( 2, 7, 13, 8 ); 1587 1588 g.setColor( MetalLookAndFeel.getPrimaryControlShadow() ); 1590 g.drawLine( right - 6, 5, right - 1, 5 ); 1591 1592 g.setColor( MetalLookAndFeel.getPrimaryControlInfo() ); 1594 g.drawLine( 0, 6, 0, bottom ); g.drawLine( 1, 5, right - 7, 5 ); g.drawLine( right - 6, 6, right - 1, 6 ); g.drawLine( right, 5, right, bottom ); g.drawLine( 0, bottom, right, bottom ); 1600 g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() ); 1602 g.drawLine( 1, 6, 1, bottom - 1 ); 1603 g.drawLine( 1, 6, right - 7, 6 ); 1604 g.drawLine( right - 6, 7, right - 1, 7 ); 1605 1606 } 1607 1608 public int getShift() { return 0; } 1609 public int getAdditionalHeight() { return 0; } 1610 1611 public int getIconWidth() { return folderIcon16Size.width; } 1612 public int getIconHeight() { return folderIcon16Size.height + getAdditionalHeight(); } 1613 } 1614 1615 1616 1627 public static class TreeFolderIcon extends FolderIcon16 { 1628 public int getShift() { return -1; } 1629 public int getAdditionalHeight() { return 2; } 1630 } 1631 1632 1633 static private final Dimension fileIcon16Size = new Dimension( 16, 16 ); 1634 1635 1646 public static class FileIcon16 implements Icon, Serializable { 1647 1648 ImageCacher imageCacher; 1649 1650 public void paintIcon(Component c, Graphics g, int x, int y) { 1651 GraphicsConfiguration gc = c.getGraphicsConfiguration(); 1652 if (imageCacher == null) { 1653 imageCacher = new ImageCacher(); 1654 } 1655 Image image = imageCacher.getImage(gc); 1656 if (image == null) { 1657 if (gc != null) { 1658 image = gc.createCompatibleImage(getIconWidth(), 1659 getIconHeight(), 1660 Transparency.BITMASK); 1661 } else { 1662 image = new BufferedImage (getIconWidth(), 1663 getIconHeight(), 1664 BufferedImage.TYPE_INT_ARGB); 1665 } 1666 Graphics imageG = image.getGraphics(); 1667 paintMe(c,imageG); 1668 imageG.dispose(); 1669 imageCacher.cacheImage(image, gc); 1670 } 1671 g.drawImage(image, x, y+getShift(), null); 1672 } 1673 1674 private void paintMe(Component c, Graphics g) { 1675 1676 int right = fileIcon16Size.width - 1; 1677 int bottom = fileIcon16Size.height - 1; 1678 1679 g.setColor( MetalLookAndFeel.getWindowBackground() ); 1681 g.fillRect( 4, 2, 9, 12 ); 1682 1683 g.setColor( MetalLookAndFeel.getPrimaryControlInfo() ); 1685 g.drawLine( 2, 0, 2, bottom ); g.drawLine( 2, 0, right - 4, 0 ); g.drawLine( 2, bottom, right - 1, bottom ); g.drawLine( right - 1, 6, right - 1, bottom ); g.drawLine( right - 6, 2, right - 2, 6 ); g.drawLine( right - 5, 1, right - 4, 1 ); g.drawLine( right - 3, 2, right - 3, 3 ); g.drawLine( right - 2, 4, right - 2, 5 ); 1694 g.setColor( MetalLookAndFeel.getPrimaryControl() ); 1696 g.drawLine( 3, 1, 3, bottom - 1 ); g.drawLine( 3, 1, right - 6, 1 ); g.drawLine( right - 2, 7, right - 2, bottom - 1 ); g.drawLine( right - 5, 2, right - 3, 4 ); g.drawLine( 3, bottom - 1, right - 2, bottom - 1 ); 1702 } 1703 1704 public int getShift() { return 0; } 1705 public int getAdditionalHeight() { return 0; } 1706 1707 public int getIconWidth() { return fileIcon16Size.width; } 1708 public int getIconHeight() { return fileIcon16Size.height + getAdditionalHeight(); } 1709 } 1710 1711 1712 public static class TreeLeafIcon extends FileIcon16 { 1713 public int getShift() { return 2; } 1714 public int getAdditionalHeight() { return 4; } 1715 } 1716 1717 1718 static private final Dimension treeControlSize = new Dimension( 18, 18 ); 1719 1720 1731 public static class TreeControlIcon implements Icon, Serializable { 1732 protected boolean isLight; 1736 1737 1738 public TreeControlIcon( boolean isCollapsed ) { 1739 isLight = isCollapsed; 1740 } 1741 1742 ImageCacher imageCacher; 1743 1744 transient boolean cachedOrientation = true; 1745 1746 public void paintIcon(Component c, Graphics g, int x, int y) { 1747 1748 GraphicsConfiguration gc = c.getGraphicsConfiguration(); 1749 1750 if (imageCacher == null) { 1751 imageCacher = new ImageCacher(); 1752 } 1753 Image image = imageCacher.getImage(gc); 1754 1755 if (image == null || cachedOrientation != MetalUtils.isLeftToRight(c)) { 1756 cachedOrientation = MetalUtils.isLeftToRight(c); 1757 if (gc != null) { 1758 image = gc.createCompatibleImage(getIconWidth(), 1759 getIconHeight(), 1760 Transparency.BITMASK); 1761 } else { 1762 image = new BufferedImage (getIconWidth(), 1763 getIconHeight(), 1764 BufferedImage.TYPE_INT_ARGB); 1765 } 1766 Graphics imageG = image.getGraphics(); 1767 paintMe(c,imageG,x,y); 1768 imageG.dispose(); 1769 imageCacher.cacheImage(image, gc); 1770 1771 } 1772 1773 if (MetalUtils.isLeftToRight(c)) { 1774 if (isLight) { g.drawImage(image, x+5, y+3, x+18, y+13, 1776 4,3, 17, 13, null); 1777 } 1778 else { 1779 g.drawImage(image, x+5, y+3, x+18, y+17, 1780 4,3, 17, 17, null); 1781 } 1782 } 1783 else { 1784 if (isLight) { g.drawImage(image, x+3, y+3, x+16, y+13, 1786 4, 3, 17, 13, null); 1787 } 1788 else { 1789 g.drawImage(image, x+3, y+3, x+16, y+17, 1790 4, 3, 17, 17, null); 1791 } 1792 } 1793 } 1794 1795 public void paintMe(Component c, Graphics g, int x, int y) { 1796 1797 g.setColor( MetalLookAndFeel.getPrimaryControlInfo() ); 1798 1799 int xoff = (MetalUtils.isLeftToRight(c)) ? 0 : 4; 1800 1801 g.drawLine( xoff + 4, 6, xoff + 4, 9 ); g.drawLine( xoff + 5, 5, xoff + 5, 5 ); g.drawLine( xoff + 6, 4, xoff + 9, 4 ); g.drawLine( xoff + 10, 5, xoff + 10, 5 ); g.drawLine( xoff + 11, 6, xoff + 11, 9 ); g.drawLine( xoff + 10, 10, xoff + 10, 10 ); g.drawLine( xoff + 6, 11, xoff + 9, 11 ); g.drawLine( xoff + 5, 10, xoff + 5, 10 ); 1811 g.drawLine( xoff + 7, 7, xoff + 8, 7 ); 1813 g.drawLine( xoff + 7, 8, xoff + 8, 8 ); 1814 1815 if ( isLight ) { if( MetalUtils.isLeftToRight(c) ) { 1818 g.drawLine( 12, 7, 15, 7 ); 1819 g.drawLine( 12, 8, 15, 8 ); 1820 } 1823 else { 1824 g.drawLine(4, 7, 7, 7); 1825 g.drawLine(4, 8, 7, 8); 1826 } 1827 } 1828 else { 1829 g.drawLine( xoff + 7, 12, xoff + 7, 15 ); 1830 g.drawLine( xoff + 8, 12, xoff + 8, 15 ); 1831 } 1834 1835 g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() ); 1837 g.drawLine( xoff + 5, 6, xoff + 5, 9 ); g.drawLine( xoff + 6, 5, xoff + 9, 5 ); 1840 g.setColor( MetalLookAndFeel.getPrimaryControlShadow() ); 1841 g.drawLine( xoff + 6, 6, xoff + 6, 6 ); g.drawLine( xoff + 9, 6, xoff + 9, 6 ); g.drawLine( xoff + 6, 9, xoff + 6, 9 ); g.drawLine( xoff + 10, 6, xoff + 10, 9 ); g.drawLine( xoff + 6, 10, xoff + 9, 10 ); 1847 g.setColor( MetalLookAndFeel.getPrimaryControl() ); 1848 g.drawLine( xoff + 6, 7, xoff + 6, 8 ); g.drawLine( xoff + 7, 6, xoff + 8, 6 ); g.drawLine( xoff + 9, 7, xoff + 9, 7 ); g.drawLine( xoff + 7, 9, xoff + 7, 9 ); 1853 g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() ); 1854 g.drawLine( xoff + 8, 9, xoff + 9, 9 ); 1855 g.drawLine( xoff + 9, 8, xoff + 9, 8 ); 1856 } 1857 1858 public int getIconWidth() { return treeControlSize.width; } 1859 public int getIconHeight() { return treeControlSize.height; } 1860 } 1861 1862 1866 static private final Dimension menuArrowIconSize = new Dimension( 4, 8 ); 1867 static private final Dimension menuCheckIconSize = new Dimension( 10, 10 ); 1868 static private final int xOff = 4; 1869 1870 private static class MenuArrowIcon implements Icon, UIResource , Serializable 1871 { 1872 public void paintIcon( Component c, Graphics g, int x, int y ) 1873 { 1874 JMenuItem b = (JMenuItem) c; 1875 ButtonModel model = b.getModel(); 1876 1877 g.translate( x, y ); 1878 1879 if ( !model.isEnabled() ) 1880 { 1881 g.setColor( MetalLookAndFeel.getMenuDisabledForeground() ); 1882 } 1883 else 1884 { 1885 if ( model.isArmed() || ( c instanceof JMenu && model.isSelected() ) ) 1886 { 1887 g.setColor( MetalLookAndFeel.getMenuSelectedForeground() ); 1888 } 1889 else 1890 { 1891 g.setColor( b.getForeground() ); 1892 } 1893 } 1894 if( MetalUtils.isLeftToRight(b) ) { 1895 g.drawLine( 0, 0, 0, 7 ); 1896 g.drawLine( 1, 1, 1, 6 ); 1897 g.drawLine( 2, 2, 2, 5 ); 1898 g.drawLine( 3, 3, 3, 4 ); 1899 } else { 1900 g.drawLine( 4, 0, 4, 7 ); 1901 g.drawLine( 3, 1, 3, 6 ); 1902 g.drawLine( 2, 2, 2, 5 ); 1903 g.drawLine( 1, 3, 1, 4 ); 1904 } 1905 1906 g.translate( -x, -y ); 1907 } 1908 1909 public int getIconWidth() { return menuArrowIconSize.width; } 1910 1911 public int getIconHeight() { return menuArrowIconSize.height; } 1912 1913 } 1915 private static class MenuItemArrowIcon implements Icon, UIResource , Serializable 1916 { 1917 public void paintIcon( Component c, Graphics g, int x, int y ) 1918 { 1919 } 1920 1921 public int getIconWidth() { return menuArrowIconSize.width; } 1922 1923 public int getIconHeight() { return menuArrowIconSize.height; } 1924 1925 } 1927 private static class CheckBoxMenuItemIcon implements Icon, UIResource , Serializable 1928 { 1929 public void paintOceanIcon(Component c, Graphics g, int x, int y) { 1930 ButtonModel model = ((JMenuItem)c).getModel(); 1931 boolean isSelected = model.isSelected(); 1932 boolean isEnabled = model.isEnabled(); 1933 boolean isPressed = model.isPressed(); 1934 boolean isArmed = model.isArmed(); 1935 1936 g.translate(x, y); 1937 if (isEnabled) { 1938 MetalUtils.drawGradient(c, g, "CheckBoxMenuItem.gradient", 1939 1, 1, 7, 7, true); 1940 if (isPressed || isArmed) { 1941 g.setColor(MetalLookAndFeel.getControlInfo()); 1942 g.drawLine( 0, 0, 8, 0 ); 1943 g.drawLine( 0, 0, 0, 8 ); 1944 g.drawLine( 8, 2, 8, 8 ); 1945 g.drawLine( 2, 8, 8, 8 ); 1946 1947 g.setColor(MetalLookAndFeel.getPrimaryControl()); 1948 g.drawLine( 9, 1, 9, 9 ); 1949 g.drawLine( 1, 9, 9, 9 ); 1950 } 1951 else { 1952 g.setColor(MetalLookAndFeel.getControlDarkShadow()); 1953 g.drawLine( 0, 0, 8, 0 ); 1954 g.drawLine( 0, 0, 0, 8 ); 1955 g.drawLine( 8, 2, 8, 8 ); 1956 g.drawLine( 2, 8, 8, 8 ); 1957 1958 g.setColor(MetalLookAndFeel.getControlHighlight()); 1959 g.drawLine( 9, 1, 9, 9 ); 1960 g.drawLine( 1, 9, 9, 9 ); 1961 } 1962 } 1963 else { 1964 g.setColor(MetalLookAndFeel.getMenuDisabledForeground()); 1965 g.drawRect( 0, 0, 8, 8 ); 1966 } 1967 if (isSelected) { 1968 if (isEnabled) { 1969 if (isArmed || ( c instanceof JMenu && isSelected)) { 1970 g.setColor( 1971 MetalLookAndFeel.getMenuSelectedForeground() ); 1972 } 1973 else { 1974 g.setColor(c.getForeground()); 1975 } 1976 } 1977 else { 1978 g.setColor( MetalLookAndFeel.getMenuDisabledForeground()); 1979 } 1980 1981 g.drawLine( 2, 2, 2, 6 ); 1982 g.drawLine( 3, 2, 3, 6 ); 1983 g.drawLine( 4, 4, 8, 0 ); 1984 g.drawLine( 4, 5, 9, 0 ); 1985 } 1986 g.translate( -x, -y ); 1987 } 1988 1989 public void paintIcon( Component c, Graphics g, int x, int y ) 1990 { 1991 if (MetalLookAndFeel.usingOcean()) { 1992 paintOceanIcon(c, g, x, y); 1993 return; 1994 } 1995 JMenuItem b = (JMenuItem) c; 1996 ButtonModel model = b.getModel(); 1997 1998 boolean isSelected = model.isSelected(); 1999 boolean isEnabled = model.isEnabled(); 2000 boolean isPressed = model.isPressed(); 2001 boolean isArmed = model.isArmed(); 2002 2003 g.translate( x, y ); 2004 2005 if ( isEnabled ) 2006 { 2007 if ( isPressed || isArmed ) 2008 { 2009 g.setColor( MetalLookAndFeel.getControlInfo() ); 2010 g.drawLine( 0, 0, 8, 0 ); 2011 g.drawLine( 0, 0, 0, 8 ); 2012 g.drawLine( 8, 2, 8, 8 ); 2013 g.drawLine( 2, 8, 8, 8 ); 2014 2015 g.setColor( MetalLookAndFeel.getPrimaryControl() ); 2016 g.drawLine( 1, 1, 7, 1 ); 2017 g.drawLine( 1, 1, 1, 7 ); 2018 g.drawLine( 9, 1, 9, 9 ); 2019 g.drawLine( 1, 9, 9, 9 ); 2020 } 2021 else 2022 { 2023 g.setColor( MetalLookAndFeel.getControlDarkShadow() ); 2024 g.drawLine( 0, 0, 8, 0 ); 2025 g.drawLine( 0, 0, 0, 8 ); 2026 g.drawLine( 8, 2, 8, 8 ); 2027 g.drawLine( 2, 8, 8, 8 ); 2028 2029 g.setColor( MetalLookAndFeel.getControlHighlight() ); 2030 g.drawLine( 1, 1, 7, 1 ); 2031 g.drawLine( 1, 1, 1, 7 ); 2032 g.drawLine( 9, 1, 9, 9 ); 2033 g.drawLine( 1, 9, 9, 9 ); 2034 } 2035 } 2036 else 2037 { 2038 g.setColor( MetalLookAndFeel.getMenuDisabledForeground() ); 2039 g.drawRect( 0, 0, 8, 8 ); 2040 } 2041 2042 if ( isSelected ) 2043 { 2044 if ( isEnabled ) 2045 { 2046 if ( model.isArmed() || ( c instanceof JMenu && model.isSelected() ) ) 2047 { 2048 g.setColor( MetalLookAndFeel.getMenuSelectedForeground() ); 2049 } 2050 else 2051 { 2052 g.setColor( b.getForeground() ); 2053 } 2054 } 2055 else 2056 { 2057 g.setColor( MetalLookAndFeel.getMenuDisabledForeground() ); 2058 } 2059 2060 g.drawLine( 2, 2, 2, 6 ); 2061 g.drawLine( 3, 2, 3, 6 ); 2062 g.drawLine( 4, 4, 8, 0 ); 2063 g.drawLine( 4, 5, 9, 0 ); 2064 } 2065 2066 g.translate( -x, -y ); 2067 } 2068 2069 public int getIconWidth() { return menuCheckIconSize.width; } 2070 2071 public int getIconHeight() { return menuCheckIconSize.height; } 2072 2073 } 2075 private static class RadioButtonMenuItemIcon implements Icon, UIResource , Serializable 2076 { 2077 public void paintOceanIcon(Component c, Graphics g, int x, int y) { 2078 ButtonModel model = ((JMenuItem)c).getModel(); 2079 boolean isSelected = model.isSelected(); 2080 boolean isEnabled = model.isEnabled(); 2081 boolean isPressed = model.isPressed(); 2082 boolean isArmed = model.isArmed(); 2083 2084 g.translate( x, y ); 2085 2086 if (isEnabled) { 2087 MetalUtils.drawGradient(c, g, "RadioButtonMenuItem.gradient", 2088 1, 1, 7, 7, true); 2089 if (isPressed || isArmed) { 2090 g.setColor(MetalLookAndFeel.getPrimaryControl()); 2091 } 2092 else { 2093 g.setColor(MetalLookAndFeel.getControlHighlight()); 2094 } 2095 g.drawLine( 2, 9, 7, 9 ); 2096 g.drawLine( 9, 2, 9, 7 ); 2097 g.drawLine( 8, 8, 8, 8 ); 2098 2099 if (isPressed || isArmed) { 2100 g.setColor(MetalLookAndFeel.getControlInfo()); 2101 } 2102 else { 2103 g.setColor(MetalLookAndFeel.getControlDarkShadow()); 2104 } 2105 } 2106 else { 2107 g.setColor( MetalLookAndFeel.getMenuDisabledForeground() ); 2108 } 2109 g.drawLine( 2, 0, 6, 0 ); 2110 g.drawLine( 2, 8, 6, 8 ); 2111 g.drawLine( 0, 2, 0, 6 ); 2112 g.drawLine( 8, 2, 8, 6 ); 2113 g.drawLine( 1, 1, 1, 1 ); 2114 g.drawLine( 7, 1, 7, 1 ); 2115 g.drawLine( 1, 7, 1, 7 ); 2116 g.drawLine( 7, 7, 7, 7 ); 2117 2118 if (isSelected) { 2119 if (isEnabled) { 2120 if (isArmed || (c instanceof JMenu && model.isSelected())){ 2121 g.setColor(MetalLookAndFeel. 2122 getMenuSelectedForeground() ); 2123 } 2124 else { 2125 g.setColor(c.getForeground()); 2126 } 2127 } 2128 else { 2129 g.setColor(MetalLookAndFeel.getMenuDisabledForeground()); 2130 } 2131 g.drawLine( 3, 2, 5, 2 ); 2132 g.drawLine( 2, 3, 6, 3 ); 2133 g.drawLine( 2, 4, 6, 4 ); 2134 g.drawLine( 2, 5, 6, 5 ); 2135 g.drawLine( 3, 6, 5, 6 ); 2136 } 2137 2138 g.translate( -x, -y ); 2139 } 2140 2141 public void paintIcon( Component c, Graphics g, int x, int y ) 2142 { 2143 if (MetalLookAndFeel.usingOcean()) { 2144 paintOceanIcon(c, g, x, y); 2145 return; 2146 } 2147 JMenuItem b = (JMenuItem) c; 2148 ButtonModel model = b.getModel(); 2149 2150 boolean isSelected = model.isSelected(); 2151 boolean isEnabled = model.isEnabled(); 2152 boolean isPressed = model.isPressed(); 2153 boolean isArmed = model.isArmed(); 2154 2155 g.translate( x, y ); 2156 2157 if ( isEnabled ) 2158 { 2159 if ( isPressed || isArmed ) 2160 { 2161 g.setColor( MetalLookAndFeel.getPrimaryControl() ); 2162 g.drawLine( 3, 1, 8, 1 ); 2163 g.drawLine( 2, 9, 7, 9 ); 2164 g.drawLine( 1, 3, 1, 8 ); 2165 g.drawLine( 9, 2, 9, 7 ); 2166 g.drawLine( 2, 2, 2, 2 ); 2167 g.drawLine( 8, 8, 8, 8 ); 2168 2169 g.setColor( MetalLookAndFeel.getControlInfo() ); 2170 g.drawLine( 2, 0, 6, 0 ); 2171 g.drawLine( 2, 8, 6, 8 ); 2172 g.drawLine( 0, 2, 0, 6 ); 2173 g.drawLine( 8, 2, 8, 6 ); 2174 g.drawLine( 1, 1, 1, 1 ); 2175 g.drawLine( 7, 1, 7, 1 ); 2176 g.drawLine( 1, 7, 1, 7 ); 2177 g.drawLine( 7, 7, 7, 7 ); 2178 } 2179 else 2180 { 2181 g.setColor( MetalLookAndFeel.getControlHighlight() ); 2182 g.drawLine( 3, 1, 8, 1 ); 2183 g.drawLine( 2, 9, 7, 9 ); 2184 g.drawLine( 1, 3, 1, 8 ); 2185 g.drawLine( 9, 2, 9, 7 ); 2186 g.drawLine( 2, 2, 2, 2 ); 2187 g.drawLine( 8, 8, 8, 8 ); 2188 2189 g.setColor( MetalLookAndFeel.getControlDarkShadow() ); 2190 g.drawLine( 2, 0, 6, 0 ); 2191 g.drawLine( 2, 8, 6, 8 ); 2192 g.drawLine( 0, 2, 0, 6 ); 2193 g.drawLine( 8, 2, 8, 6 ); 2194 g.drawLine( 1, 1, 1, 1 ); 2195 g.drawLine( 7, 1, 7, 1 ); 2196 g.drawLine( 1, 7, 1, 7 ); 2197 g.drawLine( 7, 7, 7, 7 ); 2198 } 2199 } 2200 else 2201 { 2202 g.setColor( MetalLookAndFeel.getMenuDisabledForeground() ); 2203 g.drawLine( 2, 0, 6, 0 ); 2204 g.drawLine( 2, 8, 6, 8 ); 2205 g.drawLine( 0, 2, 0, 6 ); 2206 g.drawLine( 8, 2, 8, 6 ); 2207 g.drawLine( 1, 1, 1, 1 ); 2208 g.drawLine( 7, 1, 7, 1 ); 2209 g.drawLine( 1, 7, 1, 7 ); 2210 g.drawLine( 7, 7, 7, 7 ); 2211 } 2212 2213 if ( isSelected ) 2214 { 2215 if ( isEnabled ) 2216 { 2217 if ( model.isArmed() || ( c instanceof JMenu && model.isSelected() ) ) 2218 { 2219 g.setColor( MetalLookAndFeel.getMenuSelectedForeground() ); 2220 } 2221 else 2222 { 2223 g.setColor( b.getForeground() ); 2224 } 2225 } 2226 else 2227 { 2228 g.setColor( MetalLookAndFeel.getMenuDisabledForeground() ); 2229 } 2230 2231 g.drawLine( 3, 2, 5, 2 ); 2232 g.drawLine( 2, 3, 6, 3 ); 2233 g.drawLine( 2, 4, 6, 4 ); 2234 g.drawLine( 2, 5, 6, 5 ); 2235 g.drawLine( 3, 6, 5, 6 ); 2236 } 2237 2238 g.translate( -x, -y ); 2239 } 2240 2241 public int getIconWidth() { return menuCheckIconSize.width; } 2242 2243 public int getIconHeight() { return menuCheckIconSize.height; } 2244 2245 } 2247private static class VerticalSliderThumbIcon implements Icon, Serializable , UIResource { 2248 protected static MetalBumps controlBumps; 2249 protected static MetalBumps primaryBumps; 2250 2251 public VerticalSliderThumbIcon() { 2252 controlBumps = new MetalBumps ( 6, 10, 2253 MetalLookAndFeel.getControlHighlight(), 2254 MetalLookAndFeel.getControlInfo(), 2255 MetalLookAndFeel.getControl() ); 2256 primaryBumps = new MetalBumps ( 6, 10, 2257 MetalLookAndFeel.getPrimaryControl(), 2258 MetalLookAndFeel.getPrimaryControlDarkShadow(), 2259 MetalLookAndFeel.getPrimaryControlShadow() ); 2260 } 2261 2262 public void paintIcon( Component c, Graphics g, int x, int y ) { 2263 JSlider slider = (JSlider)c; 2264 2265 boolean leftToRight = MetalUtils.isLeftToRight(slider); 2266 2267 g.translate( x, y ); 2268 2269 if ( slider.hasFocus() ) { 2271 g.setColor( MetalLookAndFeel.getPrimaryControlInfo() ); 2272 } 2273 else { 2274 g.setColor( slider.isEnabled() ? MetalLookAndFeel.getPrimaryControlInfo() : 2275 MetalLookAndFeel.getControlDarkShadow() ); 2276 } 2277 2278 if (leftToRight) { 2279 g.drawLine( 1,0 , 8,0 ); g.drawLine( 0,1 , 0,13 ); g.drawLine( 1,14 , 8,14 ); g.drawLine( 9,1 , 15,7 ); g.drawLine( 9,13 , 15,7 ); } 2285 else { 2286 g.drawLine( 7,0 , 14,0 ); g.drawLine( 15,1 , 15,13 ); g.drawLine( 7,14 , 14,14 ); g.drawLine( 0,7 , 6,1 ); g.drawLine( 0,7 , 6,13 ); } 2292 2293 if ( slider.hasFocus() ) { 2295 g.setColor( c.getForeground() ); 2296 } 2297 else { 2298 g.setColor( MetalLookAndFeel.getControl() ); 2299 } 2300 2301 if (leftToRight) { 2302 g.fillRect( 1,1 , 8,13 ); 2303 2304 g.drawLine( 9,2 , 9,12 ); 2305 g.drawLine( 10,3 , 10,11 ); 2306 g.drawLine( 11,4 , 11,10 ); 2307 g.drawLine( 12,5 , 12,9 ); 2308 g.drawLine( 13,6 , 13,8 ); 2309 g.drawLine( 14,7 , 14,7 ); 2310 } 2311 else { 2312 g.fillRect( 7,1, 8,13 ); 2313 2314 g.drawLine( 6,3 , 6,12 ); 2315 g.drawLine( 5,4 , 5,11 ); 2316 g.drawLine( 4,5 , 4,10 ); 2317 g.drawLine( 3,6 , 3,9 ); 2318 g.drawLine( 2,7 , 2,8 ); 2319 } 2320 2321 int offset = (leftToRight) ? 2 : 8; 2323 if ( slider.isEnabled() ) { 2324 if ( slider.hasFocus() ) { 2325 primaryBumps.paintIcon( c, g, offset, 2 ); 2326 } 2327 else { 2328 controlBumps.paintIcon( c, g, offset, 2 ); 2329 } 2330 } 2331 2332 if ( slider.isEnabled() ) { 2334 g.setColor( slider.hasFocus() ? MetalLookAndFeel.getPrimaryControl() 2335 : MetalLookAndFeel.getControlHighlight() ); 2336 if (leftToRight) { 2337 g.drawLine( 1, 1, 8, 1 ); 2338 g.drawLine( 1, 1, 1, 13 ); 2339 } 2340 else { 2341 g.drawLine( 8,1 , 14,1 ); g.drawLine( 1,7 , 7,1 ); } 2344 } 2345 2346 g.translate( -x, -y ); 2347 } 2348 2349 public int getIconWidth() { 2350 return 16; 2351 } 2352 2353 public int getIconHeight() { 2354 return 15; 2355 } 2356} 2357 2358private static class HorizontalSliderThumbIcon implements Icon, Serializable , UIResource { 2359 protected static MetalBumps controlBumps; 2360 protected static MetalBumps primaryBumps; 2361 2362 public HorizontalSliderThumbIcon() { 2363 controlBumps = new MetalBumps ( 10, 6, 2364 MetalLookAndFeel.getControlHighlight(), 2365 MetalLookAndFeel.getControlInfo(), 2366 MetalLookAndFeel.getControl() ); 2367 primaryBumps = new MetalBumps ( 10, 6, 2368 MetalLookAndFeel.getPrimaryControl(), 2369 MetalLookAndFeel.getPrimaryControlDarkShadow(), 2370 MetalLookAndFeel.getPrimaryControlShadow() ); 2371 } 2372 2373 public void paintIcon( Component c, Graphics g, int x, int y ) { 2374 JSlider slider = (JSlider)c; 2375 2376 g.translate( x, y ); 2377 2378 if ( slider.hasFocus() ) { 2380 g.setColor( MetalLookAndFeel.getPrimaryControlInfo() ); 2381 } 2382 else { 2383 g.setColor( slider.isEnabled() ? MetalLookAndFeel.getPrimaryControlInfo() : 2384 MetalLookAndFeel.getControlDarkShadow() ); 2385 } 2386 2387 g.drawLine( 1,0 , 13,0 ); g.drawLine( 0,1 , 0,8 ); g.drawLine( 14,1 , 14,8 ); g.drawLine( 1,9 , 7,15 ); g.drawLine( 7,15 , 14,8 ); 2393 if ( slider.hasFocus() ) { 2395 g.setColor( c.getForeground() ); 2396 } 2397 else { 2398 g.setColor( MetalLookAndFeel.getControl() ); 2399 } 2400 g.fillRect( 1,1, 13, 8 ); 2401 2402 g.drawLine( 2,9 , 12,9 ); 2403 g.drawLine( 3,10 , 11,10 ); 2404 g.drawLine( 4,11 , 10,11 ); 2405 g.drawLine( 5,12 , 9,12 ); 2406 g.drawLine( 6,13 , 8,13 ); 2407 g.drawLine( 7,14 , 7,14 ); 2408 2409 if ( slider.isEnabled() ) { 2411 if ( slider.hasFocus() ) { 2412 primaryBumps.paintIcon( c, g, 2, 2 ); 2413 } 2414 else { 2415 controlBumps.paintIcon( c, g, 2, 2 ); 2416 } 2417 } 2418 2419 if ( slider.isEnabled() ) { 2421 g.setColor( slider.hasFocus() ? MetalLookAndFeel.getPrimaryControl() 2422 : MetalLookAndFeel.getControlHighlight() ); 2423 g.drawLine( 1, 1, 13, 1 ); 2424 g.drawLine( 1, 1, 1, 8 ); 2425 } 2426 2427 g.translate( -x, -y ); 2428 } 2429 2430 public int getIconWidth() { 2431 return 15; 2432 } 2433 2434 public int getIconHeight() { 2435 return 16; 2436 } 2437} 2438 2439 private static class OceanVerticalSliderThumbIcon extends CachedPainter 2440 implements Icon, Serializable , UIResource { 2441 private static Polygon LTR_THUMB_SHAPE; 2443 private static Polygon RTL_THUMB_SHAPE; 2445 2446 static { 2447 LTR_THUMB_SHAPE = new Polygon(new int[] { 0, 8, 15, 8, 0}, 2448 new int[] { 0, 0, 7, 14, 14 }, 5); 2449 RTL_THUMB_SHAPE = new Polygon(new int[] { 15, 15, 7, 0, 7}, 2450 new int[] { 0, 14, 14, 7, 0}, 5); 2451 } 2452 2453 OceanVerticalSliderThumbIcon() { 2454 super(3); 2455 } 2456 2457 public void paintIcon(Component c, Graphics g, int x, int y) { 2458 if (!(g instanceof Graphics2D)) { 2459 return; 2460 } 2461 paint(c, g, x, y, getIconWidth(), getIconHeight(), 2462 MetalUtils.isLeftToRight(c), c.hasFocus(), c.isEnabled(), 2463 MetalLookAndFeel.getCurrentTheme()); 2464 } 2465 2466 protected void paintToImage(Component c, Graphics g2, 2467 int w, int h, Object [] args) { 2468 Graphics2D g = (Graphics2D)g2; 2469 boolean leftToRight = ((Boolean )args[0]).booleanValue(); 2470 boolean hasFocus = ((Boolean )args[1]).booleanValue(); 2471 boolean enabled = ((Boolean )args[2]).booleanValue(); 2472 2473 Rectangle clip = g.getClipBounds(); 2474 if (leftToRight) { 2475 g.clip(LTR_THUMB_SHAPE); 2476 } 2477 else { 2478 g.clip(RTL_THUMB_SHAPE); 2479 } 2480 if (!enabled) { 2481 g.setColor(MetalLookAndFeel.getControl()); 2482 g.fillRect(1, 1, 14, 14); 2483 } 2484 else if (hasFocus) { 2485 MetalUtils.drawGradient(c, g, "Slider.focusGradient", 2486 1, 1, 14, 14, false); 2487 } 2488 else { 2489 MetalUtils.drawGradient(c, g, "Slider.gradient", 2490 1, 1, 14, 14, false); 2491 } 2492 g.setClip(clip); 2493 2494 if (hasFocus) { 2496 g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); 2497 } 2498 else { 2499 g.setColor(enabled ? MetalLookAndFeel.getPrimaryControlInfo() : 2500 MetalLookAndFeel.getControlDarkShadow()); 2501 } 2502 2503 if (leftToRight) { 2504 g.drawLine( 1,0 , 8,0 ); g.drawLine( 0,1 , 0,13 ); g.drawLine( 1,14 , 8,14 ); g.drawLine( 9,1 , 15,7 ); g.drawLine( 9,13 , 15,7 ); } 2510 else { 2511 g.drawLine( 7,0 , 14,0 ); g.drawLine( 15,1 , 15,13 ); g.drawLine( 7,14 , 14,14 ); g.drawLine( 0,7 , 6,1 ); g.drawLine( 0,7 , 6,13 ); } 2517 2518 if (hasFocus && enabled) { 2519 g.setColor(MetalLookAndFeel.getPrimaryControl()); 2521 if (leftToRight) { 2522 g.drawLine( 1,1 , 8,1 ); g.drawLine( 1,1 , 1,13 ); g.drawLine( 1,13 , 8,13 ); g.drawLine( 9,2 , 14,7 ); g.drawLine( 9,12 , 14,7 ); } 2528 else { 2529 g.drawLine( 7,1 , 14,1 ); g.drawLine( 14,1 , 14,13 ); g.drawLine( 7,13 , 14,13 ); g.drawLine( 1,7 , 7,1 ); g.drawLine( 1,7 , 7,13 ); } 2535 } 2536 } 2537 2538 public int getIconWidth() { 2539 return 16; 2540 } 2541 2542 public int getIconHeight() { 2543 return 15; 2544 } 2545 2546 protected Image createImage(Component c, int w, int h, 2547 GraphicsConfiguration config) { 2548 return config.createCompatibleImage( 2549 w, h, Transparency.BITMASK); 2550 } 2551 } 2552 2553 2554 private static class OceanHorizontalSliderThumbIcon extends CachedPainter 2555 implements Icon, Serializable , UIResource { 2556 private static Polygon THUMB_SHAPE; 2558 2559 static { 2560 THUMB_SHAPE = new Polygon(new int[] { 0, 14, 14, 7, 0 }, 2561 new int[] { 0, 0, 8, 15, 8 }, 5); 2562 } 2563 2564 OceanHorizontalSliderThumbIcon() { 2565 super(3); 2566 } 2567 2568 public void paintIcon(Component c, Graphics g, int x, int y) { 2569 if (!(g instanceof Graphics2D)) { 2570 return; 2571 } 2572 paint(c, g, x, y, getIconWidth(), getIconHeight(), 2573 c.hasFocus(), c.isEnabled(), 2574 MetalLookAndFeel.getCurrentTheme()); 2575 } 2576 2577 2578 protected Image createImage(Component c, int w, int h, 2579 GraphicsConfiguration config) { 2580 return config.createCompatibleImage( 2581 w, h, Transparency.BITMASK); 2582 } 2583 2584 protected void paintToImage(Component c, Graphics g2, 2585 int w, int h, Object [] args) { 2586 Graphics2D g = (Graphics2D)g2; 2587 boolean hasFocus = ((Boolean )args[0]).booleanValue(); 2588 boolean enabled = ((Boolean )args[1]).booleanValue(); 2589 2590 Rectangle clip = g.getClipBounds(); 2592 g.clip(THUMB_SHAPE); 2593 if (!enabled) { 2594 g.setColor(MetalLookAndFeel.getControl()); 2595 g.fillRect(1, 1, 13, 14); 2596 } 2597 else if (hasFocus) { 2598 MetalUtils.drawGradient(c, g, "Slider.focusGradient", 2599 1, 1, 13, 14, true); 2600 } 2601 else { 2602 MetalUtils.drawGradient(c, g, "Slider.gradient", 2603 1, 1, 13, 14, true); 2604 } 2605 g.setClip(clip); 2606 2607 if (hasFocus) { 2609 g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); 2610 } 2611 else { 2612 g.setColor(enabled ? MetalLookAndFeel.getPrimaryControlInfo() : 2613 MetalLookAndFeel.getControlDarkShadow()); 2614 } 2615 2616 g.drawLine( 1,0 , 13,0 ); g.drawLine( 0,1 , 0,8 ); g.drawLine( 14,1 , 14,8 ); g.drawLine( 1,9 , 7,15 ); g.drawLine( 7,15 , 14,8 ); 2622 if (hasFocus && enabled) { 2623 g.setColor(MetalLookAndFeel.getPrimaryControl()); 2625 g.fillRect(1, 1, 13, 1); 2626 g.fillRect(1, 2, 1, 7); 2627 g.fillRect(13, 2, 1, 7); 2628 g.drawLine(2, 9, 7, 14); 2629 g.drawLine(8, 13, 12, 9); 2630 } 2631 } 2632 2633 public int getIconWidth() { 2634 return 15; 2635 } 2636 2637 public int getIconHeight() { 2638 return 16; 2639 } 2640 } 2641} 2642 | Popular Tags |