1 19 24 25 package org.netbeans.swing.plaf.gtk; 26 27 import javax.swing.*; 28 import javax.swing.border.Border ; 29 import javax.swing.plaf.ButtonUI ; 30 import javax.swing.plaf.ComponentUI ; 31 import javax.swing.plaf.basic.BasicToolBarUI ; 32 import java.awt.*; 33 import java.awt.event.ContainerEvent ; 34 import java.awt.event.ContainerListener ; 35 36 41 public class GtkToolbarUI extends BasicToolBarUI implements ContainerListener { 42 44 private GtkToolbarUI() { 45 } 46 47 public static ComponentUI createUI(JComponent c) { 48 return new GtkToolbarUI(); 49 } 50 51 public void installUI( JComponent c ) { 52 super.installUI(c); 53 c.setOpaque(false); 55 c.addContainerListener(this); 56 installButtonUIs (c); 57 } 58 59 public void uninstallUI (JComponent c) { 60 super.uninstallUI (c); 61 c.setBorder (null); 62 c.removeContainerListener(this); 63 } 64 65 public void paint(Graphics g, JComponent c) { 66 GradientPaint gp = new GradientPaint (0f, 0f, 67 UIManager.getColor("controlHighlight"), 0f, c.getHeight(), 69 UIManager.getColor("control")); ((Graphics2D) g).setPaint (gp); 71 Insets ins = c.getInsets(); 72 g.fillRect (ins.left, ins.top, c.getWidth() - (ins.left + ins.top), c.getHeight() - (ins.top + ins.bottom)); 73 } 74 75 76 protected Border createRolloverBorder() { 77 return BorderFactory.createEmptyBorder(2,2,2,2); 78 } 79 80 protected Border createNonRolloverBorder() { 81 return createRolloverBorder(); 82 } 83 84 private Border createNonRolloverToggleBorder() { 85 return createRolloverBorder(); 86 } 87 88 protected void setBorderToRollover(Component c) { 89 if (c instanceof AbstractButton) { 90 ((AbstractButton) c).setBorderPainted(false); 91 ((AbstractButton) c).setBorder(BorderFactory.createEmptyBorder()); 92 ((AbstractButton) c).setContentAreaFilled(false); 93 ((AbstractButton) c).setOpaque(false); 94 } 95 if (c instanceof JComponent) { 96 ((JComponent) c).setOpaque(false); 97 } 98 } 99 100 protected void setBorderToNormal(Component c) { 101 if (c instanceof AbstractButton) { 102 ((AbstractButton) c).setBorderPainted(false); 103 ((AbstractButton) c).setContentAreaFilled(false); 104 ((AbstractButton) c).setOpaque(false); 105 } 106 if (c instanceof JComponent) { 107 ((JComponent) c).setOpaque(false); 108 } 109 } 110 111 public void setFloating(boolean b, Point p) { 112 } 114 115 private void installButtonUI (Component c) { 116 if (c instanceof AbstractButton) { 117 ((AbstractButton) c).setUI(buttonui); 118 } 119 if (c instanceof JComponent) { 120 ((JComponent) c).setOpaque(false); 121 } 122 } 123 124 private void installButtonUIs (Container parent) { 125 Component[] c = parent.getComponents(); 126 for (int i=0; i < c.length; i++) { 127 installButtonUI(c[i]); 128 } 129 } 130 131 private static final ButtonUI buttonui = new GtkToolBarButtonUI(); 132 public void componentAdded(ContainerEvent e) { 133 installButtonUI (e.getChild()); 134 } 135 136 public void componentRemoved(ContainerEvent e) { 137 } 139 } 140 | Popular Tags |