1 package org.catacomb.druid.swing;
2
3 import org.catacomb.interlish.structure.MouseSource;
4 import org.catacomb.report.E;
5
6
7 import java.awt.Color;
8 import java.awt.Font;
9 import java.awt.event.ActionEvent;
10 import java.awt.event.ActionListener;
11
12
13 public class DButton extends DBaseButton implements ActionListener, MouseSource {
14
15 static final long serialVersionUID = 1001;
16
17 int rolloverOffStyle = RolloverEffect.ETCHED_DOWN;
18 int rolloverOnStyle = RolloverEffect.ETCHED_UP;
19 RolloverEffect rollover;
20
21 public Color bufColor;
22
23
24
25 public DButton(String lab) {
26
27 if (lab != null && lab.length() > 0) {
28 setText(lab);
29 }
30 label = lab;
31
32 setFont(new Font("sansserif", Font.PLAIN, 12));
33
34 addActionListener(this);
35 setFocusPainted(false);
36 }
37
38
39 public void setTooltip(String s) {
40 String swas = getToolTipText();
41 if (swas != null) {
42 E.warning("replacing tool tip " + swas + " with " + s + " ... ?");
43 }
44 setToolTipText(s);
45 }
46
47
48 public void setRolloverPolicy(int inorm, int ihover) {
49 rolloverOffStyle = inorm;
50 rolloverOnStyle = ihover;
51 }
52
53 public void applyRollover() {
54 if (rollover != null) {
55 removeMouseListener(rollover);
56 }
57 rollover = new RolloverEffect(this, rolloverOffStyle, rolloverOnStyle);
58 addMouseListener(rollover);
59 }
60
61
62
63
64 public void setBg(Color c) {
65 setBackground(c);
66 if (rollover != null) {
67 rollover.setBg(c);
68 }
69 }
70
71
72 public void setFg(Color c) {
73 setForeground(c);
74 }
75
76
77
78 public void actionPerformed(ActionEvent aev) {
79 deliverAction(true);
80 deSuggest();
81 }
82
83
84 public void suggest() {
85 Color scol = Color.lightGray;
86 Color cbg = getBackground();
87 if (scol.equals(cbg)) {
88
89 } else {
90 bufColor = cbg;
91 setBg(scol);
92 }
93 }
94
95 public void deSuggest() {
96 if (bufColor != null) {
97 setBg(bufColor);
98 }
99 }
100
101 public String toString() {
102 return "DButton " + label;
103 }
104
105
106
107 public String getStringIdentifier() {
108 return label;
109 }
110
111
112
113 public void setPadding(int p) {
114 if (rollover == null) {
115 applyRollover();
116 }
117 rollover.setPadding(p);
118 }
119
120
121 public void setPadding(int pl, int pr, int pt, int pb) {
122 if (rollover == null) {
123 applyRollover();
124 }
125 rollover.setPadding(pl, pr, pt, pb);
126 }
127
128
129 }