1 30 31 package com.jgoodies.looks.common; 32 33 import java.awt.Color ; 34 import java.awt.Dimension ; 35 import java.awt.Graphics ; 36 37 import javax.swing.Icon ; 38 import javax.swing.JComponent ; 39 import javax.swing.UIManager ; 40 import javax.swing.plaf.ComponentUI ; 41 import javax.swing.plaf.basic.BasicMenuItemUI ; 42 43 53 54 public class ExtBasicMenuItemUI extends BasicMenuItemUI { 55 56 private static final int MINIMUM_WIDTH = 80; 57 58 private MenuItemRenderer renderer; 59 60 public static ComponentUI createUI(JComponent b) { 61 return new ExtBasicMenuItemUI(); 62 } 63 64 protected void installDefaults() { 65 super.installDefaults(); 66 renderer = 67 new MenuItemRenderer( 68 menuItem, 69 iconBorderEnabled(), 70 acceleratorFont, 71 selectionForeground, 72 disabledForeground, 73 acceleratorForeground, 74 acceleratorSelectionForeground); 75 Integer gap = 76 (Integer ) UIManager.get(getPropertyPrefix() + ".textIconGap"); 77 defaultTextIconGap = gap != null ? gap.intValue() : 2; 78 } 79 80 protected boolean iconBorderEnabled() { 82 return false; 83 } 84 85 protected void uninstallDefaults() { 86 super.uninstallDefaults(); 87 renderer = null; 88 } 89 90 protected Dimension getPreferredMenuItemSize( 91 JComponent c, 92 Icon aCheckIcon, 93 Icon anArrowIcon, 94 int textIconGap) { 95 Dimension size = 97 renderer.getPreferredMenuItemSize( 98 c, 99 aCheckIcon, 100 anArrowIcon, 101 textIconGap); 102 int width = Math.max(MINIMUM_WIDTH, size.width); 103 int height = size.height; 104 return new Dimension (width, height); 105 } 106 107 protected void paintMenuItem( 108 Graphics g, 109 JComponent c, 110 Icon aCheckIcon, 111 Icon anArrowIcon, 112 Color background, 113 Color foreground, 114 int textIconGap) { 115 renderer.paintMenuItem( 116 g, 117 c, 118 aCheckIcon, 119 anArrowIcon, 120 background, 121 foreground, 122 textIconGap); 123 } 124 125 } | Popular Tags |