001: package net.xoetrope.samples.controls;
002:
003: import java.io.File;
004:
005: import java.awt.Frame;
006:
007: import net.xoetrope.awt.XButton;
008: import net.xoetrope.awt.XComboBox;
009: import net.xoetrope.awt.XEdit;
010: import net.xoetrope.awt.XTable;
011: import net.xoetrope.data.XDataSource;
012: import net.xoetrope.xui.XPage;
013: import net.xoetrope.xui.XProjectManager;
014: import net.xoetrope.xui.XResourceManager;
015: import net.xoetrope.xui.data.XModel;
016: import net.xoetrope.xui.helper.BuddyHelper;
017: import net.xoetrope.xui.style.XStyleFactory;
018:
019: /**
020: * <p>Title: Xui</p>
021: * <p>Description: </p>
022: * <p>Copyright: Copyright (c) Xoetrope Ltd., 1998-2003</p>
023: * <p>Company: Xoetrope Ltd.</p>
024: * @author not attributable
025: * @version 1.0
026: */
027:
028: public class TableSample extends XPage {
029: XButton closeButton, saveButton;
030: Frame frame;
031: BuddyHelper buddy;
032: XEdit txtFirstname, txtSurname, txtAge;
033: XComboBox cmbOccupations;
034: private boolean pageValidation = false;
035: private String validationText = "";
036: private XDataSource modelDataSource;
037:
038: public TableSample() {
039: buddy = new BuddyHelper((XStyleFactory) componentFactory);
040:
041: XProjectManager.getStyleManager().load("testtablestyles.xml");
042: frame = new Frame("Validation Sample");
043: frame.setLayout(null);
044: frame.setSize(640, 580);
045: String desc = "This example shows how to render tabular data from the data model. First setup the table and specify";
046: desc += " the styles that are to be used for the table data and for the header. Next extract the segment of the XModel";
047: desc += " you wish to use in the table and use the setContent method to render the data within the table.";
048:
049: componentFactory.addComponent(XPage.LABEL, 10, 50, 530, 80,
050: desc);
051:
052: // txtFirstname = (XEdit)buddy.addNamedComponent( XPage.EDIT, 20, 250, 130, 25, "Firstname", "", null );
053: // txtSurname = (XEdit)buddy.addNamedComponent( XPage.EDIT, 20, 280, 130, 25, "Surname", "", null );
054: // txtAge = (XEdit)buddy.addNamedComponent( XPage.EDIT, 20, 95, 130, 310, 355, 25, "Age", "", "Years", null );
055: // cmbOccupations = ( XComboBox )buddy.addNamedComponent( XCOMBO, 20, 340, 130, 25, "Profession", "", null );
056: loadData();
057:
058: XTable table = new XTable();
059: table.setStyle("base/TableData");
060: table.setHeaderStyle("base/TableHeading");
061: XModel model = (XModel) XProjectManager.getModel().get(
062: "base/userlist/users");
063: table.setModel(model);
064: table.setBounds(20, 160, 400, 200);
065: add(table);
066:
067: // saveButton = (XButton)componentFactory.addNamedComponent( XPage.BUTTON, 10, 440, 130, 25, "Save" );
068: closeButton = (XButton) componentFactory.addComponent(
069: XPage.BUTTON, 10, 540, 130, 25, "Close");
070: setSize(frame.getSize());
071: mapEvents();
072:
073: frame.add(this );
074: frame.setVisible(true);
075: frame.show();
076: }
077:
078: private void mapEvents() {
079: addMouseHandler(closeButton, "Close");
080: }
081:
082: public static void main(String args[]) {
083: TableSample compSample = new TableSample();
084: }
085:
086: public void Close() {
087: if (wasMouseClicked()) {
088: frame.setVisible(false);
089: }
090: }
091:
092: private void loadData() {
093: modelDataSource = new XDataSource();
094: try {
095: String fileName = "sampledatasets.xml";
096: File source = new File(fileName);
097: if (source.exists())
098: modelDataSource.read(XResourceManager
099: .getBufferedReader(source, null));
100: else
101: modelDataSource.read(XResourceManager
102: .getBufferedReader(fileName, null));
103: } catch (Exception ex) {
104: ex.printStackTrace();
105: }
106: }
107: }
|