1 30 31 package com.jgoodies.looks.plastic; 32 33 import java.awt.Graphics ; 34 import java.awt.Rectangle ; 35 import java.beans.PropertyChangeEvent ; 36 import java.beans.PropertyChangeListener ; 37 38 import javax.swing.JComponent ; 39 import javax.swing.LookAndFeel ; 40 import javax.swing.plaf.ComponentUI ; 41 import javax.swing.plaf.basic.BasicMenuBarUI ; 42 43 import com.jgoodies.looks.BorderStyle; 44 import com.jgoodies.looks.HeaderStyle; 45 import com.jgoodies.looks.Options; 46 47 48 56 public final class PlasticMenuBarUI extends BasicMenuBarUI { 57 58 59 private PropertyChangeListener listener; 60 61 62 public static ComponentUI createUI(JComponent b) { 63 return new PlasticMenuBarUI(); 64 } 65 66 67 69 protected void installDefaults() { 70 super.installDefaults(); 71 installSpecialBorder(); 72 } 73 74 75 protected void installListeners() { 76 super.installListeners(); 77 listener = createBorderStyleListener(); 78 menuBar.addPropertyChangeListener(listener); 79 } 80 81 82 protected void uninstallListeners() { 83 menuBar.removePropertyChangeListener(listener); 84 super.uninstallListeners(); 85 } 86 87 88 private PropertyChangeListener createBorderStyleListener() { 89 return new PropertyChangeListener () { 90 91 public void propertyChange(PropertyChangeEvent e) { 92 String prop = e.getPropertyName(); 93 if(prop.equals(Options.HEADER_STYLE_KEY) || 94 prop.equals(PlasticLookAndFeel.BORDER_STYLE_KEY)) { 95 PlasticMenuBarUI.this.installSpecialBorder(); 96 } 97 } 98 99 }; 100 } 101 102 103 110 public void installSpecialBorder() { 111 String suffix; 112 BorderStyle borderStyle = BorderStyle.from(menuBar, 113 PlasticLookAndFeel.BORDER_STYLE_KEY); 114 if (borderStyle == BorderStyle.EMPTY) 115 suffix = "emptyBorder"; 116 else if (borderStyle == BorderStyle.ETCHED) 117 suffix = "etchedBorder"; 118 else if (borderStyle == BorderStyle.SEPARATOR) 119 suffix = "separatorBorder"; 120 else { 121 HeaderStyle headerStyle = HeaderStyle.from(menuBar); 122 if (headerStyle == HeaderStyle.BOTH) 123 suffix = "headerBorder"; 124 else if (headerStyle == HeaderStyle.SINGLE && is3D()) 125 suffix = "etchedBorder"; 126 else 127 return; 128 } 129 130 LookAndFeel.installBorder(menuBar, "MenuBar." + suffix); 131 } 132 133 134 136 public void update(Graphics g, JComponent c) { 137 if (c.isOpaque()) { 138 g.setColor(c.getBackground()); 139 g.fillRect(0, 0, c.getWidth(), c.getHeight()); 140 } 141 if (is3D()) 142 PlasticUtils.addLight3DEffekt(g, new Rectangle (0, 0, c.getWidth(), c.getHeight()), true); 143 144 paint(g, c); 145 } 146 147 148 151 private boolean is3D() { 152 if (PlasticUtils.force3D(menuBar)) 153 return true; 154 if (PlasticUtils.forceFlat(menuBar)) 155 return false; 156 return PlasticUtils.is3D("MenuBar.") && 157 (HeaderStyle.from(menuBar) != null) && 158 (BorderStyle.from(menuBar, PlasticLookAndFeel.BORDER_STYLE_KEY) 159 != BorderStyle.EMPTY); 160 } 161 162 } | Popular Tags |