1 30 31 package com.jgoodies.looks.common; 32 33 import java.awt.Color ; 34 import java.awt.Component ; 35 import java.awt.Graphics ; 36 37 import javax.swing.ButtonModel ; 38 import javax.swing.Icon ; 39 import javax.swing.JMenuItem ; 40 import javax.swing.UIManager ; 41 42 52 53 public final class MinimumSizedCheckIcon extends MinimumSizedIcon { 54 55 private final JMenuItem menuItem; 56 57 public MinimumSizedCheckIcon(Icon icon, JMenuItem menuItem) { 58 super(icon); 59 this.menuItem = menuItem; 60 } 61 62 63 public void paintIcon(Component c, Graphics g, int x, int y) { 64 paintState(g, x, y); 65 super.paintIcon(c, g, x, y); 66 } 67 68 private void paintState(Graphics g, int x, int y) { 69 ButtonModel model = menuItem.getModel(); 70 72 int w = getIconWidth(); 73 int h = getIconHeight(); 74 75 g.translate(x, y); 76 if (model.isSelected() || model.isArmed() ) { 77 Color background = model.isArmed() 78 ? UIManager.getColor("MenuItem.background") 79 : UIManager.getColor("ScrollBar.track"); 80 Color upColor = UIManager.getColor("controlLtHighlight"); 81 Color downColor = UIManager.getColor("controlDkShadow"); 82 83 g.setColor(background); 85 g.fillRect(0, 0, w, h); 86 g.setColor(model.isSelected() ? downColor : upColor); 88 g.drawLine(0, 0, w-2, 0); 89 g.drawLine(0, 0, 0, h-2); 90 g.setColor(model.isSelected() ? upColor: downColor); 92 g.drawLine(0, h-1, w-1, h-1); 93 g.drawLine(w-1, 0, w-1, h-1); 94 } 95 g.translate(-x, -y); 96 g.setColor(UIManager.getColor("textText")); 97 } 98 99 100 } | Popular Tags |