1 30 31 package com.jgoodies.looks.windows; 32 33 import java.beans.PropertyChangeEvent ; 34 import java.beans.PropertyChangeListener ; 35 36 import javax.swing.JComponent ; 37 import javax.swing.LookAndFeel ; 38 import javax.swing.plaf.ComponentUI ; 39 40 import com.jgoodies.looks.BorderStyle; 41 import com.jgoodies.looks.HeaderStyle; 42 import com.jgoodies.looks.Options; 43 44 53 public final class WindowsMenuBarUI extends com.sun.java.swing.plaf.windows.WindowsMenuBarUI { 54 55 private PropertyChangeListener listener; 56 57 58 public static ComponentUI createUI(JComponent b) { 59 return new WindowsMenuBarUI(); 60 } 61 62 63 65 protected void installDefaults() { 66 super.installDefaults(); 67 installSpecialBorder(); 68 } 69 70 71 protected void installListeners() { 72 super.installListeners(); 73 listener = createBorderStyleListener(); 74 menuBar.addPropertyChangeListener(listener); 75 } 76 77 78 protected void uninstallListeners() { 79 menuBar.removePropertyChangeListener(listener); 80 super.uninstallListeners(); 81 } 82 83 84 private PropertyChangeListener createBorderStyleListener() { 85 return new PropertyChangeListener () { 86 87 public void propertyChange(PropertyChangeEvent e) { 88 String prop = e.getPropertyName(); 89 if(prop.equals(Options.HEADER_STYLE_KEY) || 90 prop.equals(WindowsLookAndFeel.BORDER_STYLE_KEY)) { 91 WindowsMenuBarUI.this.installSpecialBorder(); 92 } 93 } 94 95 }; 96 } 97 98 99 108 private void installSpecialBorder() { 109 String suffix; 110 BorderStyle borderStyle = BorderStyle.from(menuBar, 111 WindowsLookAndFeel.BORDER_STYLE_KEY); 112 if (borderStyle == BorderStyle.EMPTY) 113 suffix = "emptyBorder"; 114 else if (borderStyle == BorderStyle.ETCHED) 115 suffix = "etchedBorder"; 116 else if (borderStyle == BorderStyle.SEPARATOR) 117 suffix = "separatorBorder"; 118 else if (HeaderStyle.from(menuBar) == HeaderStyle.BOTH) 119 suffix = "headerBorder"; 120 else 121 return; 122 123 LookAndFeel.installBorder(menuBar, "MenuBar." + suffix); 124 } 125 126 } | Popular Tags |