1 7 package javax.swing.plaf.synth; 8 9 import javax.swing.*; 10 import javax.swing.event.*; 11 import java.awt.Color ; 12 import java.awt.Component ; 13 import java.awt.Container ; 14 import java.awt.Dimension ; 15 import java.awt.Graphics ; 16 import java.awt.Insets ; 17 import java.awt.Point ; 18 import java.awt.Rectangle ; 19 import java.awt.event.*; 20 import java.beans.PropertyChangeEvent ; 21 import java.beans.PropertyChangeListener ; 22 23 import javax.swing.border.*; 24 import javax.swing.plaf.*; 25 import javax.swing.plaf.basic.*; 26 import sun.swing.plaf.synth.SynthUI; 27 28 34 class SynthMenuBarUI extends BasicMenuBarUI implements PropertyChangeListener , 35 SynthUI { 36 private SynthStyle style; 37 38 public static ComponentUI createUI(JComponent x) { 39 return new SynthMenuBarUI (); 40 } 41 42 protected void installDefaults() { 43 if (menuBar.getLayout() == null || 44 menuBar.getLayout() instanceof UIResource) { 45 menuBar.setLayout(new DefaultMenuLayout (menuBar,BoxLayout.LINE_AXIS)); 46 } 47 updateStyle(menuBar); 48 } 49 50 protected void installListeners() { 51 super.installListeners(); 52 menuBar.addPropertyChangeListener(this); 53 } 54 55 private void updateStyle(JMenuBar c) { 56 SynthContext context = getContext(c, ENABLED); 57 SynthStyle oldStyle = style; 58 style = SynthLookAndFeel.updateStyle(context, this); 59 if (style != oldStyle) { 60 if (oldStyle != null) { 61 uninstallKeyboardActions(); 62 installKeyboardActions(); 63 } 64 } 65 context.dispose(); 66 } 67 68 protected void uninstallDefaults() { 69 SynthContext context = getContext(menuBar, ENABLED); 70 71 style.uninstallDefaults(context); 72 context.dispose(); 73 style = null; 74 } 75 76 protected void uninstallListeners() { 77 super.uninstallListeners(); 78 menuBar.removePropertyChangeListener(this); 79 } 80 81 public SynthContext getContext(JComponent c) { 82 return getContext(c, getComponentState(c)); 83 } 84 85 private SynthContext getContext(JComponent c, int state) { 86 return SynthContext.getContext(SynthContext .class, c, 87 SynthLookAndFeel.getRegion(c), style, state); 88 } 89 90 private Region getRegion(JComponent c) { 91 return SynthLookAndFeel.getRegion(c); 92 } 93 94 private int getComponentState(JComponent c) { 95 return SynthLookAndFeel.getComponentState(c); 96 } 97 98 public void update(Graphics g, JComponent c) { 99 SynthContext context = getContext(c); 100 101 SynthLookAndFeel.update(context, g); 102 context.getPainter().paintMenuBarBackground(context, 103 g, 0, 0, c.getWidth(), c.getHeight()); 104 paint(context, g); 105 context.dispose(); 106 } 107 108 public void paint(Graphics g, JComponent c) { 109 SynthContext context = getContext(c); 110 111 paint(context, g); 112 context.dispose(); 113 } 114 115 protected void paint(SynthContext context, Graphics g) { 116 } 117 118 public void paintBorder(SynthContext context, Graphics g, int x, 119 int y, int w, int h) { 120 context.getPainter().paintMenuBarBorder(context, g, x, y, w, h); 121 } 122 123 public void propertyChange(PropertyChangeEvent e) { 124 if (SynthLookAndFeel.shouldUpdateStyle(e)) { 125 updateStyle((JMenuBar)e.getSource()); 126 } 127 } 128 } 129 | Popular Tags |