1 23 24 package org.gjt.sp.jedit.gui; 25 26 import java.awt.*; 28 import java.awt.event.*; 29 import javax.swing.*; 30 import javax.swing.border.*; 31 import javax.swing.plaf.basic.BasicButtonUI ; 32 import org.gjt.sp.jedit.OperatingSystem; 33 35 46 public class RolloverButton extends JButton 47 { 48 52 public RolloverButton() 53 { 54 setContentAreaFilled(false); 55 56 addMouseListener(new MouseOverHandler()); 57 } 59 65 public RolloverButton(Icon icon) 66 { 67 this(); 68 69 setIcon(icon); 70 } 72 public void updateUI() 74 { 75 if(OperatingSystem.isWindows()) 76 { 77 78 setUI(new BasicButtonUI ()); 79 } 80 else 81 super.updateUI(); 82 83 setBorder(new EtchedBorder()); 84 setBorderPainted(false); 85 setMargin(new Insets(1,1,1,1)); 86 87 setRequestFocusEnabled(false); 88 } 90 public boolean isOpaque() 92 { 93 return false; 94 } 96 public void setEnabled(boolean b) 98 { 99 super.setEnabled(b); 100 setBorderPainted(false); 101 repaint(); 102 } 104 public void setBorderPainted(boolean b) 106 { 107 try 108 { 109 revalidateBlocked = true; 110 super.setBorderPainted(b); 111 } 112 finally 113 { 114 revalidateBlocked = false; 115 } 116 } 118 123 public void revalidate() 124 { 125 if(!revalidateBlocked) 126 super.revalidate(); 127 } 129 public void paint(Graphics g) 131 { 132 if(isEnabled()) 133 super.paint(g); 134 else 135 { 136 Graphics2D g2 = (Graphics2D)g; 137 g2.setComposite(c); 138 super.paint(g2); 139 } 140 } 142 private static final AlphaComposite c = AlphaComposite.getInstance( 144 AlphaComposite.SRC_OVER, 0.5f); 145 146 private boolean revalidateBlocked; 147 148 152 class MouseOverHandler extends MouseAdapter 153 { 154 public void mouseEntered(MouseEvent e) 155 { 156 if (isEnabled()) 157 setBorderPainted(true); 158 } 159 160 public void mouseExited(MouseEvent e) 161 { 162 setBorderPainted(false); 163 } 164 } } 166 | Popular Tags |