1 30 31 package com.jgoodies.looks.plastic; 32 33 import java.awt.Component ; 34 import java.awt.Container ; 35 import java.awt.Graphics ; 36 import java.awt.Rectangle ; 37 import java.beans.PropertyChangeEvent ; 38 import java.beans.PropertyChangeListener ; 39 40 import javax.swing.AbstractButton ; 41 import javax.swing.JComponent ; 42 import javax.swing.LookAndFeel ; 43 import javax.swing.border.Border ; 44 import javax.swing.plaf.ComponentUI ; 45 import javax.swing.plaf.metal.MetalToolBarUI ; 46 47 import com.jgoodies.looks.BorderStyle; 48 import com.jgoodies.looks.HeaderStyle; 49 import com.jgoodies.looks.Options; 50 51 61 62 public final class PlasticToolBarUI extends MetalToolBarUI { 63 64 private static final String PROPERTY_PREFIX = "ToolBar."; 65 66 private PropertyChangeListener listener; 67 68 public static ComponentUI createUI(JComponent b) { 69 return new PlasticToolBarUI(); 70 } 71 72 74 protected Border createRolloverBorder() { 75 return PlasticBorders.getRolloverButtonBorder(); 76 } 77 78 protected void setBorderToRollover(Component c) { 79 if (c instanceof AbstractButton ) { 80 super.setBorderToRollover(c); 81 } else if (c instanceof Container ) { 82 Container cont = (Container ) c; 83 for (int i = 0; i < cont.getComponentCount(); i++) 84 super.setBorderToRollover(cont.getComponent(i)); 85 } 86 } 87 88 90 93 protected void installDefaults() { 94 super.installDefaults(); 95 installSpecialBorder(); 96 } 97 98 protected void installListeners() { 99 super.installListeners(); 100 listener = createBorderStyleListener(); 101 toolBar.addPropertyChangeListener(listener); 102 } 103 104 protected void uninstallListeners() { 105 toolBar.removePropertyChangeListener(listener); 106 super.uninstallListeners(); 107 } 108 109 private PropertyChangeListener createBorderStyleListener() { 110 return new PropertyChangeListener () { 111 112 public void propertyChange(PropertyChangeEvent e) { 113 String prop = e.getPropertyName(); 114 if (prop.equals(Options.HEADER_STYLE_KEY) 115 || prop.equals(PlasticLookAndFeel.BORDER_STYLE_KEY)) { 116 PlasticToolBarUI.this.installSpecialBorder(); 117 } 118 } 119 120 }; 121 } 122 123 132 private void installSpecialBorder() { 133 String suffix; 134 BorderStyle borderStyle = 135 BorderStyle.from(toolBar, PlasticLookAndFeel.BORDER_STYLE_KEY); 136 if (borderStyle == BorderStyle.EMPTY) 137 suffix = "emptyBorder"; 138 else if (borderStyle == BorderStyle.ETCHED) 139 suffix = "etchedBorder"; 140 else if (borderStyle == BorderStyle.SEPARATOR) 141 suffix = "separatorBorder"; 142 else { 143 HeaderStyle headerStyle = HeaderStyle.from(toolBar); 144 if (headerStyle == HeaderStyle.BOTH) 145 suffix = "headerBorder"; 146 else if (headerStyle == HeaderStyle.SINGLE && is3D()) 147 suffix = "etchedBorder"; 148 else 149 return; 150 } 151 152 LookAndFeel.installBorder(toolBar, PROPERTY_PREFIX + suffix); 153 } 154 155 157 public void update(Graphics g, JComponent c) { 158 if (c.isOpaque()) { 159 g.setColor(c.getBackground()); 160 g.fillRect(0, 0, c.getWidth(), c.getHeight()); 161 } 162 if (is3D()) { 163 Rectangle bounds = 164 new Rectangle (0, 0, c.getWidth(), c.getHeight()); 165 PlasticUtils.addLight3DEffekt(g, bounds, true); 166 } 167 paint(g, c); 168 } 169 170 173 private boolean is3D() { 174 if (PlasticUtils.force3D(toolBar)) 175 return true; 176 if (PlasticUtils.forceFlat(toolBar)) 177 return false; 178 return PlasticUtils.is3D(PROPERTY_PREFIX) 179 && (HeaderStyle.from(toolBar) != null) 180 && (BorderStyle.from(toolBar, PlasticLookAndFeel.BORDER_STYLE_KEY) 181 != BorderStyle.EMPTY); 182 } 183 184 } | Popular Tags |