01: package org.uispec4j;
02:
03: import junit.framework.Assert;
04: import org.uispec4j.assertion.Assertion;
05:
06: import javax.swing.*;
07:
08: /**
09: * Base class for button-like components (toggle buttons, check boxes, etc.)
10: */
11: public abstract class AbstractButton extends AbstractUIComponent {
12: private javax.swing.AbstractButton abstractButton;
13:
14: protected AbstractButton(javax.swing.AbstractButton abstractButton) {
15: this .abstractButton = abstractButton;
16: }
17:
18: public void click() {
19: Assert.assertTrue(
20: "The button is not enabled, it cannot be activated",
21: abstractButton.isEnabled());
22: doClick(abstractButton);
23: }
24:
25: static void doClick(javax.swing.AbstractButton button) {
26: ButtonModel model = button.getModel();
27: model.setArmed(true);
28: model.setPressed(true);
29: model.setPressed(false);
30: model.setArmed(false);
31: }
32:
33: public Assertion textEquals(final String text) {
34: return new Assertion() {
35: public void check() {
36: Assert.assertEquals(text, abstractButton.getText()
37: .trim());
38: }
39: };
40: }
41:
42: public String getLabel() {
43: return abstractButton.getText();
44: }
45:
46: public Trigger triggerClick() {
47: return new Trigger() {
48: public void run() {
49: AbstractButton.this.click();
50: }
51: };
52: }
53: }
|