| 1 package rero.dck; 2 3 import java.awt.*; 4 import java.awt.event.*; 5 6 import javax.swing.*; 7 import javax.swing.border.*; 8 import java.util.*; 9 10 public class SmallButton extends JLabel 11 { 12 protected static String NORMAL = "<html><b>?</b></html>"; 13 protected static String ACTIVE = "<html><b>?</b></html>"; 14 15 protected JLabel label; 16 17 protected LinkedList listeners; 18 19 public SmallButton(Border border, String text) 20 { 21 super(NORMAL); 22 23 setToolTipText(text); 24 25 addMouseListener(new TakeAction()); 26 27 label = this; 28 29 listeners = new LinkedList(); 30 31 setBorder(border); 32 } 33 34 public void addActionListener(ActionListener l) 35 { 36 listeners.add(l); 37 } 38 39 public void fireEvent() 40 { 41 ActionEvent event = new ActionEvent(this, 0, "?"); 42 43 Iterator i = listeners.iterator(); 44 while (i.hasNext()) 45 { 46 ((ActionListener)i.next()).actionPerformed(event); 47 } 48 } 49 50 public class TakeAction extends MouseAdapter 51 { 52 protected Color original; 53 54 public void mouseClicked(MouseEvent ev) 55 { 56 fireEvent(); 57 } 58 59 public void mousePressed(MouseEvent ev) 60 { 61 original = label.getForeground(); 62 label.setForeground(UIManager.getColor("TextArea.selectionBackground")); 63 } 64 65 public void mouseReleased(MouseEvent ev) 66 { 67 label.setForeground(original); 68 } 69 70 public void mouseEntered(MouseEvent ev) 71 { 72 label.setText(ACTIVE); 73 } 74 75 public void mouseExited(MouseEvent ev) 76 { 77 label.setText(NORMAL); 78 } 79 } 80 } 81 | Popular Tags |