class CommentsView extends BaseView<CommentableModel> { @Bound(to = "comment") private JLabel countLabel = new JLabel(); public CommentsView(CommentableModel model) { super(model); panel.add(countLabel, BorderLayout.EAST); bindings.bind(this); } }
class BaseView<T extends BaseModel> { protected final T model; protected Bindings bindings = new Bindings(); protected JPanel panel = new JPanel(new BorderLayout()); // "model." is required to prevent subclasses from clobbering @Bound(to = "model.displayText") private final JLabel label = new JLabel(); public BaseView(T model) { this.model = model; panel.add(label, BorderLayout.CENTER); } }
public class CommentsView2 extends BaseView<CommentableModel> { private final CommentableModel commentableModel; @Bound(to="comment") private JLabel countLabel = new JLabel(); private Bindings bindings = new Bindings(); public CommentsView2(CommentableModel model) { super(model); this.commentableModel = model; panel.add(countLabel, BorderLayout.EAST); bindings.bind(this); } }
public class CantFindGetterSetterTest extends TestCase { final NegativeModel model = new NegativeModel(); @Bound(to = "cantFind") private final JRadioButton button = new JRadioButton("button"); final Bindings bindings = new Bindings(); public void testFailure() { try { bindings.bind(this); fail("should not allow binding if can't find getter or setter"); } catch (Exception e) { System.err.println(e.getMessage()); } } }
public class WrongTypeTest extends TestCase { final NegativeModel model = new NegativeModel(); @Bound(to = "badEnum") private final JRadioButton button = new JRadioButton("button"); final Bindings bindings = new Bindings(); public void testFailure() { try { bindings.bind(this); fail("should not allow binding to wrong type"); } catch (Exception e) { System.err.println(e.getMessage()); } } }
private static class BooleanComponent { final BooleanModel model; @Bound(to = "state") final JCheckBox box = new JCheckBox("State"); final Bindings bindings = new Bindings(); public BooleanComponent(BooleanModel model) { this.model = model; this.bindings.bind(this); } public JComponent getDisplayComponent() { return box; } public void dispose() { bindings.release(model); } }
public class BoundJCheckBoxMenuItemTest extends TestCase { final BooleanModel model = new BooleanModel(); @Bound(to = "state") final JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(); final Bindings bindings = Bindings.standard(); @Override protected void setUp() throws Exception { bindings.bind(this); } public void testSimple() { assertFalse(model.isState()); assertFalse(menuItem.isSelected()); model.setState(true); assertTrue(menuItem.isSelected()); assertTrue(model.isState()); menuItem.doClick(); assertFalse(model.isState()); assertFalse(menuItem.isSelected()); } }
public class BoundJCheckBoxTest extends TestCase { final BooleanModel model = new BooleanModel(); @Bound(to = "state") final JCheckBox box = new JCheckBox(); final Bindings bindings = Bindings.standard(); @Override protected void setUp() throws Exception { bindings.bind(this); } public void testSimple() { assertFalse(model.isState()); assertFalse(box.isSelected()); model.setState(true); assertTrue(box.isSelected()); assertTrue(model.isState()); box.doClick(); assertFalse(model.isState()); assertFalse(box.isSelected()); } }
@Bound(to = "value") private final JSlider slider = new JSlider();
@Bound(to = "string") private final JLabel label = new JLabel();
@Bound(to = "state", value = "true") private final JRadioButton on = new JRadioButton(); @Bound(to = "state", value = "false") private final JRadioButton off = new JRadioButton(); @Bound(to = "state") private final JToggleButton button = new JToggleButton(); @Bound(to = "value", value = "ONE") private final JToggleButton oneButton = new JToggleButton(); @Bound(to = "value", value = "TWO") private final JToggleButton twoButton = new JToggleButton(); @Bound(to = "value", value = "THREE") private final JToggleButton threeButton = new JToggleButton();
@Bound(to = "count") private final JSlider slider = new JSlider(1, 10);
@Bound(to = "someBoolean") private final JCheckBox box = new JCheckBox("Box"); @EnabledIf(to = "someBoolean")
@Bound(to = "comboList", nullValue = "NULL_VALUE") @BoundSelection(to = "selectedComboItem", nullValue = "NULL_VALUE") private final JComboBox nullConstantBox = new JComboBox(); @Bound(to = "comboList") @BoundSelection(to = "selectedComboItem") private final JComboBox noNullBox = new JComboBox(); @Bound(to = "comboList", nullValue = "null value") @BoundSelection(to = "selectedComboItem", nullValue = "null value") private final JComboBox directNullBox = new JComboBox();
private final Controller controller = new Controller(model); @Bound(to = "items") @BoundSelection(to = "selectedItems", multi = true) private final JList list = new JList(); private final JButton changeItems = new JButton("Change"); @Bound(to = "selectedString") private final JLabel selectedLabel = new JLabel(" ");
@Bindable public static class View { @Bound(to = "demoBoolean") // TODO: autodiscover bound variable name private final JCheckBox demoBooleanCheckBox = new JCheckBox("demoBoolean"); private final DemoController controller = new DemoController(demoModel); @Bound(to = "demoEnum", value = "FOO") private final JRadioButton fooButton = new JRadioButton("Foo"); @Bound(to = "demoEnum", value = "BAR") private final JRadioButton barButton = new JRadioButton("Bar"); @Bound(to = "demoEnum", value = "BAZ") private final JRadioButton bazButton = new JRadioButton("Baz (Red Background)"); private final JButton setToFooButton = new JButton("Foo"); @Bound(to = "demoList", on = "LIST") @BoundSelection(to = "selectedItem") private final JList demoList = new JList(); private final JButton dup2 = new JButton("dup2"); @Bound(to = "demoString") private final JTextField textField = new JTextField(); @Bound(to = "demoString") private final JLabel label = new JLabel();