01: package net.xoetrope.samples.simple;
02:
03: import net.xoetrope.awt.XButton;
04: import net.xoetrope.awt.XComboBox;
05: import net.xoetrope.awt.XEdit;
06: import net.xoetrope.awt.XPanel;
07: import net.xoetrope.xui.XPage;
08: import net.xoetrope.xui.data.XListBinding;
09: import net.xoetrope.xui.data.XTextBinding;
10:
11: public class DataBinding extends XPage {
12: XEdit txtFirstname, txtSurname, txtCarCost, txtDeposit, txtAdvance;
13: XComboBox cmbAge;
14: XPanel pnlClientInfo, pnlFinancialInfo, pnlButtons;
15: XButton btnOK, btnCancel;
16:
17: public DataBinding() {
18: pnlClientInfo = (XPanel) componentFactory.addComponent(
19: XPage.PANEL, 10, 10, 210, 80);
20: pnlFinancialInfo = (XPanel) componentFactory.addComponent(
21: XPage.PANEL, 10, 100, 210, 80);
22: pnlButtons = (XPanel) componentFactory.addComponent(
23: XPage.PANEL, 10, 200, 210, 40);
24: pnlClientInfo.setDrawFrame(XPanel.BORDER_BEVEL);
25: pnlFinancialInfo.setDrawFrame(XPanel.BORDER_BEVEL);
26: pnlButtons.setDrawFrame(XPanel.BORDER_BEVEL);
27: componentFactory.setParentComponent(pnlClientInfo);
28: componentFactory.addComponent(XPage.LABEL, 5, 10, 90, 20,
29: "Firstname:", "prompt");
30: txtFirstname = (XEdit) componentFactory.addComponent(
31: XPage.EDIT, 100, 10, 100, 20);
32: componentFactory.addComponent(XPage.LABEL, 5, 30, 90, 20,
33: "Surname:", "prompt");
34: txtSurname = (XEdit) componentFactory.addComponent(XPage.EDIT,
35: 100, 30, 100, 20);
36: componentFactory.addComponent(XPage.LABEL, 5, 50, 90, 20,
37: "Age:", "prompt");
38: cmbAge = (XComboBox) componentFactory.addComponent(XPage.COMBO,
39: 100, 50, 100, 20, null, "XEdit");
40:
41: componentFactory.setParentComponent(pnlFinancialInfo);
42: componentFactory.addComponent(XPage.LABEL, 5, 10, 90, 20,
43: "Car cost:", "prompt");
44: txtCarCost = (XEdit) componentFactory.addComponent(XPage.EDIT,
45: 100, 10, 100, 20);
46: componentFactory.addComponent(XPage.LABEL, 5, 30, 90, 20,
47: "Deposit:", "prompt");
48: txtDeposit = (XEdit) componentFactory.addComponent(XPage.EDIT,
49: 100, 30, 100, 20);
50: componentFactory.addComponent(XPage.LABEL, 5, 50, 90, 20,
51: "Advance:", "prompt");
52: txtAdvance = (XEdit) componentFactory.addComponent(XPage.EDIT,
53: 100, 50, 100, 20);
54: txtAdvance.setEnabled(false);
55:
56: componentFactory.setParentComponent(pnlButtons);
57: btnOK = (XButton) componentFactory.addComponent(XPage.BUTTON,
58: 40, 10, 60, 20, "Proceed");
59: btnCancel = (XButton) componentFactory.addComponent(
60: XPage.BUTTON, 110, 10, 60, 20, "Cancel", "BtnReverse");
61: addBindings();
62: addEvents();
63: }
64:
65: public void pageActivated() {
66: changeAdvance();
67: }
68:
69: private void addEvents() {
70: addTextHandler(txtCarCost, "changeAdvance");
71: addTextHandler(txtDeposit, "changeAdvance");
72: addMouseHandler(btnOK, "proceed");
73: }
74:
75: private void addBindings() {
76: addBinding(new XTextBinding(txtFirstname, "customer/firstname"));
77: addBinding(new XTextBinding(txtSurname, "customer/surname"));
78: addBinding(new XListBinding(cmbAge, "customer/ageRanges"));
79:
80: addBinding(new XTextBinding(txtCarCost, "financial/carcost"));
81: addBinding(new XTextBinding(txtDeposit, "financial/deposit"));
82: }
83:
84: public void changeAdvance() {
85: float cost = Float.valueOf(txtCarCost.getText()).floatValue();
86: float deposit = Float.valueOf(txtDeposit.getText())
87: .floatValue();
88: txtAdvance.setText(String.valueOf(cost - deposit));
89: }
90:
91: public void proceed() {
92: if (wasMouseClicked())
93: btnOK.setLabel("Clicked!");
94: }
95: }
|