1 package org.catacomb.druid.gui.edit;
2
3
4
5 import org.catacomb.druid.build.ContingencyGroup;
6 import org.catacomb.druid.build.GroupContingent;
7 import org.catacomb.druid.swing.DBaseButton;
8 import org.catacomb.druid.swing.DToggleButton;
9 import org.catacomb.icon.DImageIcon;
10 import org.catacomb.icon.IconLoader;
11 import org.catacomb.report.E;
12
13 import java.awt.Color;
14
15
16 public class DruToggleButton extends DruButton implements GroupContingent {
17
18 static final long serialVersionUID = 1001;
19
20
21 String value;
22 ContingencyGroup contingencyGroup;
23
24 DToggleButton toggleButton;
25
26
27
28 public DruToggleButton(String lab, String act) {
29 super(lab, act);
30 }
31
32
33
34 public DBaseButton makeButton(String lab) {
35 toggleButton = new DToggleButton(lab);
36 return toggleButton;
37 }
38
39 public void setToggle(String gr, String va) {
40
41 value = va;
42 }
43
44 public String getValue() {
45 return value;
46 }
47
48 public void setBg(Color c) {
49 toggleButton.setBg(c);
50 toggleButton.applyState();
51 }
52
53
54 public void setInitialValue(boolean b) {
55 toggleButton.setState(b);
56 }
57
58
59 public void labelAction(String s, boolean b) {
60
61 exportInfo();
62
63 applyEffects(b);
64
65
66 unstoredValueChange(b);
67
68 if (contingencyGroup != null && b) {
69 contingencyGroup.deselectOthers(this);
70
71 if (contingencyGroup.hasAction()) {
72 action(contingencyGroup.getAction(), getValue());
73 }
74 }
75 }
76
77
78
79 public void setContingencyGroup(ContingencyGroup cg) {
80 contingencyGroup = cg;
81 contingencyGroup.add(this);
82 }
83
84
85 public void select() {
86 E.info("dtb select ");
87 toggleButton.setState(true);
88 }
89
90
91 public void deselect() {
92 toggleButton.setState(false);
93 }
94
95
96
97 public void setOffImage(String iconName) {
98 DImageIcon icon = IconLoader.createImageIcon(iconName);
99 toggleButton.setOffIcon(icon);
100 }
101
102
103 public void setOnImage(String iconName) {
104 DImageIcon icon = IconLoader.createImageIcon(iconName);
105 toggleButton.setOnIcon(icon);
106 }
107
108
109
110 public void setGroupAction(String action) {
111 if (contingencyGroup != null) {
112 contingencyGroup.setAction(action);
113 } else {
114 E.warning("no contingency group?");
115 }
116 }
117
118
119
120 }