1 19 20 package org.netbeans.swing.tabcontrol.plaf; 21 22 import java.awt.Color ; 23 import java.awt.Component ; 24 import java.awt.Dimension ; 25 import java.awt.Font ; 26 import java.awt.FontMetrics ; 27 import java.awt.Graphics ; 28 import java.awt.Graphics2D ; 29 import java.awt.Insets ; 30 import java.awt.Rectangle ; 31 32 import javax.swing.plaf.basic.BasicToggleButtonUI ; 33 import java.awt.geom.AffineTransform ; 34 import javax.swing.AbstractButton ; 35 import javax.swing.BorderFactory ; 36 import javax.swing.ButtonModel ; 37 import javax.swing.Icon ; 38 import javax.swing.JButton ; 39 import javax.swing.JComponent ; 40 import javax.swing.JToggleButton ; 41 import javax.swing.JToolBar ; 42 import javax.swing.UIDefaults ; 43 import javax.swing.UIManager ; 44 import javax.swing.border.Border ; 45 import javax.swing.border.CompoundBorder ; 46 import javax.swing.plaf.ComponentUI ; 47 import javax.swing.plaf.basic.BasicGraphicsUtils ; 48 import org.netbeans.swing.tabcontrol.SlidingButton; 49 import org.netbeans.swing.tabcontrol.SlidingButtonUI; 50 51 57 public class WinXPSlidingButtonUI extends WindowsSlidingButtonUI { 58 59 private static final SlidingButtonUI INSTANCE = new WinXPSlidingButtonUI(); 61 62 private boolean defaults_initialized = false; 64 protected JToggleButton hiddenToggle; 65 66 67 WinXPSlidingButtonUI() { 68 } 69 70 public static ComponentUI createUI(JComponent c) { 71 return INSTANCE; 72 } 73 74 75 protected void installBorder (AbstractButton b) { 76 b.setBorder ( BorderFactory.createEmptyBorder(2, 2, 2, 2)); 79 } 80 81 public void installDefaults (AbstractButton b) { 82 super.installDefaults(b); 83 if(!defaults_initialized) { 84 hiddenToggle = new JToggleButton (); 85 hiddenToggle.setText(""); 86 JToolBar bar = new JToolBar (); 87 bar.add(hiddenToggle); 88 defaults_initialized = true; 89 } 90 } 91 92 protected void uninstallDefaults(AbstractButton b) { 93 super.uninstallDefaults(b); 94 defaults_initialized = false; 95 } 96 97 public void paint(Graphics g, JComponent c) { 98 ColorUtil.setupAntialiasing(g); 99 AbstractButton button = (AbstractButton )c; 100 hiddenToggle.setBorderPainted(button.isBorderPainted()); 101 hiddenToggle.setRolloverEnabled(button.isRolloverEnabled()); 102 hiddenToggle.setFocusable(button.isFocusable()); 103 hiddenToggle.setFocusPainted(button.isFocusPainted()); 104 hiddenToggle.setMargin(button.getMargin()); 105 hiddenToggle.setBorder(button.getBorder()); 106 hiddenToggle.getModel().setRollover(button.getModel().isRollover()); 107 hiddenToggle.getModel().setPressed(button.getModel().isPressed()); 108 hiddenToggle.getModel().setArmed(button.getModel().isArmed()); 109 hiddenToggle.getModel().setSelected(button.getModel().isSelected()); 110 111 hiddenToggle.setBounds(button.getBounds()); 112 super.paint(g, c); 113 } 114 115 protected void paintBackground(Graphics2D g, AbstractButton b) { 116 if (((SlidingButton) b).isBlinkState()) { 117 g.setColor(WinClassicEditorTabCellRenderer.ATTENTION_COLOR); 118 g.fillRect (0, 0, b.getWidth(), b.getHeight()); 119 hiddenToggle.setFont(b.getFont()); 120 } else { 121 hiddenToggle.paint(g); 122 } 123 } 124 125 protected void paintButtonPressed(Graphics g, AbstractButton b) { 126 hiddenToggle.paint(g); 127 } 128 } 129 | Popular Tags |