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