1 7 8 package javax.swing.plaf.metal; 9 10 import java.awt.*; 11 import javax.swing.*; 12 import javax.swing.plaf.ComponentUI ; 13 import javax.swing.plaf.UIResource ; 14 import javax.swing.plaf.basic.*; 15 16 24 public class MetalMenuBarUI extends BasicMenuBarUI { 25 33 public static ComponentUI createUI(JComponent x) { 34 if (x == null) { 35 throw new NullPointerException ("Must pass in a non-null component"); 36 } 37 return new MetalMenuBarUI (); 38 } 39 40 47 public void installUI(JComponent c) { 48 super.installUI(c); 49 MetalToolBarUI.register(c); 50 } 51 52 59 public void uninstallUI(JComponent c) { 60 super.uninstallUI(c); 61 MetalToolBarUI.unregister(c); 62 } 63 64 76 public void update(Graphics g, JComponent c) { 77 boolean isOpaque = c.isOpaque(); 78 if (isOpaque && (c.getBackground() instanceof UIResource ) && 79 UIManager.get("MenuBar.gradient") != null) { 80 if (MetalToolBarUI.doesMenuBarBorderToolBar((JMenuBar)c)) { 81 JToolBar tb = (JToolBar)MetalToolBarUI. 82 findRegisteredComponentOfType(c, JToolBar.class); 83 if (tb.isOpaque() &&tb.getBackground() instanceof UIResource ) { 84 MetalUtils.drawGradient(c, g, "MenuBar.gradient", 0, 0, 85 c.getWidth(), c.getHeight() + 86 tb.getHeight(), true); 87 paint(g, c); 88 return; 89 } 90 } 91 MetalUtils.drawGradient(c, g, "MenuBar.gradient", 0, 0, 92 c.getWidth(), c.getHeight(),true); 93 paint(g, c); 94 } 95 else { 96 super.update(g, c); 97 } 98 } 99 } 100 | Popular Tags |