1 30 31 package com.jgoodies.looks.windows; 32 33 import java.awt.Component ; 34 import java.awt.Container ; 35 import java.beans.PropertyChangeEvent ; 36 import java.beans.PropertyChangeListener ; 37 38 import javax.swing.AbstractButton ; 39 import javax.swing.JComponent ; 40 import javax.swing.JToolBar ; 41 import javax.swing.LookAndFeel ; 42 import javax.swing.border.Border ; 43 import javax.swing.plaf.ComponentUI ; 44 import javax.swing.plaf.metal.MetalToolBarUI ; 45 46 import com.jgoodies.looks.BorderStyle; 47 import com.jgoodies.looks.HeaderStyle; 48 import com.jgoodies.looks.Options; 49 50 57 public final class WindowsToolBarUI extends MetalToolBarUI { 58 59 private PropertyChangeListener listener; 60 61 public static ComponentUI createUI(JComponent b) { 62 return new WindowsToolBarUI(); 63 } 64 65 67 protected void installDefaults() { 68 super.installDefaults(); 69 installSpecialBorder(); 70 } 71 72 protected void installListeners() { 73 super.installListeners(); 74 listener = createBorderStyleListener(); 75 toolBar.addPropertyChangeListener(listener); 76 } 77 78 protected void uninstallListeners() { 79 toolBar.removePropertyChangeListener(listener); 80 super.uninstallListeners(); 81 } 82 83 private PropertyChangeListener createBorderStyleListener() { 84 return new PropertyChangeListener () { 85 86 public void propertyChange(PropertyChangeEvent e) { 87 String prop = e.getPropertyName(); 88 if (prop.equals(Options.HEADER_STYLE_KEY) 89 || prop.equals(WindowsLookAndFeel.BORDER_STYLE_KEY)) { 90 WindowsToolBarUI.this.installSpecialBorder(); 91 } 92 } 93 94 }; 95 } 96 97 106 private void installSpecialBorder() { 107 String suffix; 108 BorderStyle borderStyle = 109 BorderStyle.from(toolBar, WindowsLookAndFeel.BORDER_STYLE_KEY); 110 if (borderStyle == BorderStyle.EMPTY) 111 suffix = "emptyBorder"; 112 else if (borderStyle == BorderStyle.SEPARATOR) 113 suffix = "separatorBorder"; 114 else if (borderStyle == BorderStyle.ETCHED) 115 suffix = "etchedBorder"; 116 else if (HeaderStyle.from(toolBar) == HeaderStyle.BOTH) 117 suffix = "headerBorder"; 118 else 119 return; 120 LookAndFeel.installBorder(toolBar, "ToolBar." + suffix); 121 } 122 123 protected DockingListener createDockingListener(JToolBar toolbar) { 124 return new DockingListener(toolbar); 125 } 126 127 129 protected Border createRolloverBorder() { 130 return WindowsBorders.getRolloverButtonBorder(); 131 } 132 133 protected void setBorderToRollover(Component c) { 134 if (c instanceof AbstractButton ) { 135 super.setBorderToRollover(c); 136 } else if (c instanceof Container ) { 137 Container cont = (Container ) c; 138 for (int i = 0; i < cont.getComponentCount(); i++) 139 super.setBorderToRollover(cont.getComponent(i)); 140 } 141 } 142 143 } | Popular Tags |