1 7 8 package javax.swing.plaf.synth; 9 10 import javax.swing.*; 11 import javax.swing.event.*; 12 import javax.swing.plaf.*; 13 import javax.swing.plaf.basic.*; 14 import javax.swing.border.*; 15 16 import java.applet.Applet ; 17 18 import java.awt.Component ; 19 import java.awt.Container ; 20 import java.awt.Dimension ; 21 import java.awt.Graphics ; 22 import java.awt.KeyboardFocusManager ; 23 import java.awt.Window ; 24 import java.awt.event.*; 25 import java.awt.AWTEvent ; 26 import java.awt.Toolkit ; 27 28 import java.beans.PropertyChangeListener ; 29 import java.beans.PropertyChangeEvent ; 30 31 import java.util.*; 32 import sun.swing.plaf.synth.SynthUI; 33 34 42 class SynthPopupMenuUI extends BasicPopupMenuUI implements 43 PropertyChangeListener , SynthUI { 44 47 private int maxTextWidth; 48 49 53 private int maxAcceleratorWidth; 54 55 private SynthStyle style; 56 57 public static ComponentUI createUI(JComponent x) { 58 return new SynthPopupMenuUI (); 59 } 60 61 public void installDefaults() { 62 if (popupMenu.getLayout() == null || 63 popupMenu.getLayout() instanceof UIResource) { 64 popupMenu.setLayout(new DefaultMenuLayout ( 65 popupMenu, BoxLayout.Y_AXIS)); 66 } 67 updateStyle(popupMenu); 68 } 69 70 private void updateStyle(JComponent c) { 71 SynthContext context = getContext(c, ENABLED); 72 SynthStyle oldStyle = style; 73 style = SynthLookAndFeel.updateStyle(context, this); 74 if (style != oldStyle) { 75 if (oldStyle != null) { 76 uninstallKeyboardActions(); 77 installKeyboardActions(); 78 } 79 } 80 context.dispose(); 81 } 82 83 protected void installListeners() { 84 super.installListeners(); 85 popupMenu.addPropertyChangeListener(this); 86 } 87 88 protected void uninstallDefaults() { 89 SynthContext context = getContext(popupMenu, ENABLED); 90 91 style.uninstallDefaults(context); 92 context.dispose(); 93 style = null; 94 95 if (popupMenu.getLayout() instanceof UIResource) { 96 popupMenu.setLayout(null); 97 } 98 } 99 100 protected void uninstallListeners() { 101 super.uninstallListeners(); 102 popupMenu.removePropertyChangeListener(this); 103 } 104 105 public SynthContext getContext(JComponent c) { 106 return getContext(c, getComponentState(c)); 107 } 108 109 private SynthContext getContext(JComponent c, int state) { 110 return SynthContext.getContext(SynthContext .class, c, 111 SynthLookAndFeel.getRegion(c), style, state); 112 } 113 114 private Region getRegion(JComponent c) { 115 return SynthLookAndFeel.getRegion(c); 116 } 117 118 private int getComponentState(JComponent c) { 119 return SynthLookAndFeel.getComponentState(c); 120 } 121 122 125 void resetAcceleratorWidths() { 126 maxTextWidth = maxAcceleratorWidth = 0; 127 } 128 129 135 int adjustTextWidth(int width) { 136 maxTextWidth = Math.max(maxTextWidth, width); 137 return maxTextWidth; 138 } 139 140 146 int adjustAcceleratorWidth(int width) { 147 maxAcceleratorWidth = Math.max(maxAcceleratorWidth, width); 148 return maxAcceleratorWidth; 149 } 150 151 154 int getMaxTextWidth() { 155 return maxTextWidth; 156 } 157 158 161 int getMaxAcceleratorWidth() { 162 return maxAcceleratorWidth; 163 } 164 165 public void update(Graphics g, JComponent c) { 166 SynthContext context = getContext(c); 167 168 SynthLookAndFeel.update(context, g); 169 context.getPainter().paintPopupMenuBackground(context, 170 g, 0, 0, c.getWidth(), c.getHeight()); 171 paint(context, g); 172 context.dispose(); 173 } 174 175 public void paint(Graphics g, JComponent c) { 176 SynthContext context = getContext(c); 177 178 paint(context, g); 179 context.dispose(); 180 } 181 182 protected void paint(SynthContext context, Graphics g) { 183 } 184 185 public void paintBorder(SynthContext context, Graphics g, int x, 186 int y, int w, int h) { 187 context.getPainter().paintPopupMenuBorder(context, g, x, y, w, h); 188 } 189 190 public void propertyChange(PropertyChangeEvent e) { 191 if (SynthLookAndFeel.shouldUpdateStyle(e)) { 192 updateStyle(popupMenu); 193 } 194 } 195 } 196 | Popular Tags |