1 package org.catacomb.druid.swing;
2
3 import org.catacomb.druid.event.LabelActor;
4 import org.catacomb.icon.IconLoader;
5
6 import java.awt.Color;
7 import java.awt.Font;
8 import java.awt.event.ActionEvent;
9 import java.awt.event.ActionListener;
10
11 import javax.swing.Icon;
12 import javax.swing.JButton;
13
14
15 public class DImageButton extends JButton implements ActionListener {
16
17 static final long serialVersionUID = 1001;
18
19
20
21 String actionCommand;
22
23 RolloverEffect rollover;
24
25 LabelActor lact;
26
27
28
29 public DImageButton(String image, String tooltip) {
30 super();
31
32 setToolTipText(tooltip);
33
34 Icon icon = IconLoader.createImageIcon(image);
35 if (icon == null) {
36 setText("err");
37 } else {
38 setIcon(icon);
39 }
40
41 setFont(new Font("sansserif", Font.PLAIN, 12));
42
43 rollover = new RolloverEffect(this, RolloverEffect.NONE, RolloverEffect.RAISED);
44
45 addMouseListener(rollover);
46
47
48
49
50
51 addActionListener(this);
52 setFocusPainted(false);
53
54 }
55
56
57
58 public void setBg(Color c) {
59 setBackground(c);
60 }
61
62
63 public void setActionCommand(String s) {
64 actionCommand = s;
65 }
66
67
68 public void setLabelActor(LabelActor la) {
69 lact = la;
70 }
71
72
73 public void actionPerformed(ActionEvent aev) {
74 if (lact == null) {
75 lact.labelAction(actionCommand, true);
76 }
77 }
78
79
80 public String toString() {
81 return "DImageButton ";
82 }
83
84
85
86 }