1 7 8 package com.sun.java.swing.plaf.windows; 9 10 import javax.swing.plaf.basic.*; 11 import javax.swing.border.*; 12 import javax.swing.plaf.*; 13 import javax.swing.*; 14 15 import java.awt.*; 16 import java.beans.PropertyChangeEvent ; 17 18 19 20 33 public class WindowsToggleButtonUI extends BasicToggleButtonUI 34 { 35 protected static int dashedRectGapX; 36 protected static int dashedRectGapY; 37 protected static int dashedRectGapWidth; 38 protected static int dashedRectGapHeight; 39 40 protected Color focusColor; 41 42 private final static WindowsToggleButtonUI windowsToggleButtonUI = new WindowsToggleButtonUI(); 43 44 private boolean defaults_initialized = false; 45 46 public static ComponentUI createUI(JComponent b) { 47 return windowsToggleButtonUI; 48 } 49 50 51 protected void installDefaults(AbstractButton b) { 55 super.installDefaults(b); 56 if(!defaults_initialized) { 57 String pp = getPropertyPrefix(); 58 dashedRectGapX = ((Integer )UIManager.get("Button.dashedRectGapX")).intValue(); 59 dashedRectGapY = ((Integer )UIManager.get("Button.dashedRectGapY")).intValue(); 60 dashedRectGapWidth = ((Integer )UIManager.get("Button.dashedRectGapWidth")).intValue(); 61 dashedRectGapHeight = ((Integer )UIManager.get("Button.dashedRectGapHeight")).intValue(); 62 focusColor = UIManager.getColor(pp + "focus"); 63 defaults_initialized = true; 64 } 65 66 XPStyle xp = XPStyle.getXP(); 67 if (xp != null) { 68 b.setBorder(xp.getBorder(b, WindowsButtonUI.getXPButtonType(b))); 69 LookAndFeel.installProperty(b, "opaque", Boolean.FALSE); 70 LookAndFeel.installProperty(b, "rolloverEnabled", Boolean.TRUE); 71 } 72 } 73 74 protected void uninstallDefaults(AbstractButton b) { 75 super.uninstallDefaults(b); 76 defaults_initialized = false; 77 } 78 79 80 protected Color getFocusColor() { 81 return focusColor; 82 } 83 84 85 89 protected void paintButtonPressed(Graphics g, AbstractButton b) { 90 if (XPStyle.getXP() == null && 91 b.isContentAreaFilled() && 92 !(b.getBorder() instanceof UIResource)) { 93 Color oldColor = g.getColor(); 96 97 int w = b.getWidth(); 98 int h = b.getHeight(); 99 UIDefaults table = UIManager.getLookAndFeelDefaults(); 100 101 Color shade = table.getColor("ToggleButton.shadow"); 102 Component p = b.getParent(); 103 if (p != null && p.getBackground().equals(shade)) { 104 shade = table.getColor("ToggleButton.darkShadow"); 105 } 106 g.setColor(shade); 107 g.drawRect(0, 0, w-1, h-1); 108 g.setColor(table.getColor("ToggleButton.highlight")); 109 g.drawLine(w-1, 0, w-1, h-1); 110 g.drawLine(0, h-1, w-1, h-1); 111 g.setColor(oldColor); 112 } 113 } 114 115 public void paint(Graphics g, JComponent c) { 116 if (XPStyle.getXP() != null) { 117 WindowsButtonUI.paintXPButtonBackground(g, c); 118 } 119 super.paint(g, c); 120 } 121 122 123 126 protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text) { 127 WindowsGraphicsUtils.paintText(g, b, textRect, text, getTextShiftOffset()); 128 } 129 130 protected void paintFocus(Graphics g, AbstractButton b, 131 Rectangle viewRect, Rectangle textRect, Rectangle iconRect) { 132 if (b.getParent() instanceof JToolBar) { 133 return; 135 } 136 g.setColor(getFocusColor()); 137 BasicGraphicsUtils.drawDashedRect(g, dashedRectGapX, dashedRectGapY, 138 b.getWidth() - dashedRectGapWidth, 139 b.getHeight() - dashedRectGapHeight); 140 } 141 142 public Dimension getPreferredSize(JComponent c) { 146 Dimension d = super.getPreferredSize(c); 147 148 151 AbstractButton b = (AbstractButton)c; 152 if (d != null && b.isFocusPainted()) { 153 if(d.width % 2 == 0) { d.width += 1; } 154 if(d.height % 2 == 0) { d.height += 1; } 155 } 156 return d; 157 } 158 } 159 160 | Popular Tags |