001: package net.xoetrope.samples.apps;
002:
003: import java.awt.Component;
004:
005: import net.xoetrope.awt.XButton;
006: import net.xoetrope.awt.XComboBox;
007: import net.xoetrope.awt.XEdit;
008: import net.xoetrope.xui.XPage;
009: import net.xoetrope.xui.XPageManager;
010: import net.xoetrope.xui.XResourceManager;
011: import net.xoetrope.xui.style.XStyleFactory;
012: import net.xoetrope.xui.data.XListBinding;
013: import net.xoetrope.xui.data.XTextBinding;
014: import net.xoetrope.xui.helper.BuddyHelper;
015: import net.xoetrope.xui.validation.XValidationFactory;
016: import net.xoetrope.xui.validation.XValidator;
017: import net.xoetrope.xui.validation.XValidationExceptionHandler;
018: import net.xoetrope.xui.XProjectManager;
019:
020: /**
021: * <p>Title: Xui</p>
022: * <p>Description: </p>
023: * <p>Copyright: Copyright (c) Xoetrope Ltd., 1998-2003</p>
024: * <p>Company: Xoetrope Ltd.</p>
025: * @author not attributable
026: * @version 1.0
027: */
028:
029: public class FirstPage extends XPage implements
030: XValidationExceptionHandler {
031: XEdit txtFirstname, txtSurname, txtAge;
032: XComboBox cmbOccupations, cmbGender;
033: XButton btnBack, btnNext;
034:
035: private boolean pageValidation = false;
036: private String validationText = "";
037:
038: public FirstPage() {
039: setExceptionHandler(this );
040: try {
041: setValidationFactory(new XValidationFactory(
042: XResourceManager.getBufferedReader(
043: "appvalidations.xml", null)));
044: } catch (Exception ex) {
045: ex.printStackTrace();
046: }
047:
048: BuddyHelper buddy = new BuddyHelper(
049: (XStyleFactory) componentFactory);
050:
051: componentFactory.addComponent(XPage.LABEL, 10, 10, 220, 25,
052: "Please enter customer details", "base/PageTitle");
053: txtFirstname = (XEdit) buddy.addComponent(XPage.EDIT, 20, 50,
054: 130, 25, "Firstname", "", null);
055: txtSurname = (XEdit) buddy.addComponent(XPage.EDIT, 20, 80,
056: 130, 25, "Surname", "", null);
057: txtAge = (XEdit) buddy.addComponent(XPage.EDIT, 20, 95, 130,
058: 110, 355, 25, "Age", "", "Years", null);
059: cmbOccupations = (XComboBox) buddy.addComponent(XPage.COMBO,
060: 20, 140, 130, 25, "Profession", "", null);
061: cmbGender = (XComboBox) buddy.addComponent(XPage.COMBO, 20,
062: 170, 130, 25, "Gender", "", null);
063: btnBack = (XButton) componentFactory.addComponent(XPage.BUTTON,
064: 20, 220, 60, 25, "Back");
065: btnNext = (XButton) componentFactory.addComponent(XPage.BUTTON,
066: 120, 220, 60, 25, "Next");
067: populateComponents();
068: mapEvents();
069: addValidations();
070: }
071:
072: public void addValidations() {
073: addValidation(txtAge, "age");
074: addValidation(txtFirstname, "firstname");
075: addValidation(txtSurname, "surname");
076: }
077:
078: public void mapEvents() {
079: addMouseHandler(btnBack, "previousScreen");
080: addMouseHandler(btnNext, "nextScreen");
081: }
082:
083: public void populateComponents() {
084: addBinding(new XTextBinding(txtFirstname, "customer1/firstname"));
085: addBinding(new XTextBinding(txtSurname, "customer1/surname"));
086: addBinding(new XTextBinding(txtAge, "customer1/age"));
087: addBinding(new XListBinding(cmbOccupations,
088: "general/professions"));
089: addBinding(new XListBinding(cmbGender, "general/gender"));
090: }
091:
092: public void previousScreen() {
093: if (wasMouseClicked()) {
094: XProjectManager.getPageManager().showPage("StartPage");
095: }
096: }
097:
098: public void nextScreen() {
099: if (wasMouseClicked()) {
100: pageValidation = true;
101: int ret = checkValidations();
102: pageValidation = false;
103: if (ret >= XValidator.LEVEL_WARNING) {
104: showMessage("Input error", validationText);
105: validationText = "";
106: } else
107: XProjectManager.getPageManager().showPage("SecondPage");
108: }
109: }
110:
111: public boolean handleException(Component comp, Exception ex,
112: XValidator validator) {
113: String msg = validator.getMessage();
114: System.out.println(msg);
115: if (!pageValidation)
116: showMessage("Input error", msg);
117: else if (validationText.length() > 0)
118: validationText += "\n";
119: validationText += msg;
120: return true;
121: }
122:
123: }
|