1 30 31 package com.jgoodies.looks.common; 32 33 import java.awt.Dimension ; 34 import java.awt.Graphics ; 35 import java.awt.Insets ; 36 37 import javax.swing.JComponent ; 38 import javax.swing.JSeparator ; 39 import javax.swing.UIManager ; 40 import javax.swing.plaf.ComponentUI ; 41 import javax.swing.plaf.basic.BasicPopupMenuSeparatorUI ; 42 43 51 public final class ExtBasicPopupMenuSeparatorUI extends BasicPopupMenuSeparatorUI { 52 53 private static final int SEPARATOR_HEIGHT = 2; 54 55 private Insets insets; 56 57 58 private static ComponentUI popupMenuSeparatorUI; 59 60 public static ComponentUI createUI(JComponent b) { 61 if (popupMenuSeparatorUI == null) { 62 popupMenuSeparatorUI = new ExtBasicPopupMenuSeparatorUI(); 63 } 64 return popupMenuSeparatorUI; 65 } 66 67 68 protected void installDefaults(JSeparator s) { 69 super.installDefaults(s); 70 insets = UIManager.getInsets("PopupMenuSeparator.margin"); 71 } 72 73 74 public void paint(Graphics g, JComponent c ) { 75 Dimension s = c.getSize(); 76 77 int topInset = insets.top; 78 int leftInset = insets.left; 79 int rightInset = insets.right; 80 81 g.setColor(UIManager.getColor("MenuItem.background")); 83 g.fillRect(0, 0, s.width, s.height); 84 85 91 92 g.translate(0, topInset); 93 g.setColor(c.getForeground()); 94 g.drawLine(leftInset, 0, s.width - rightInset, 0); 95 96 g.setColor(c.getBackground()); 97 g.drawLine(leftInset, 1, s.width -rightInset, 1); 98 g.translate(0, -topInset); 99 } 100 101 102 public Dimension getPreferredSize(JComponent c) { 103 return new Dimension (0, insets.top + SEPARATOR_HEIGHT + insets.bottom); 104 } 105 106 } | Popular Tags |