01: package net.xoetrope.samples.controls;
02:
03: import java.awt.Frame;
04:
05: import net.xoetrope.awt.XButton;
06: import net.xoetrope.awt.XEdit;
07: import net.xoetrope.xui.XPage;
08: import net.xoetrope.xui.helper.BuddyHelper;
09: import net.xoetrope.xui.style.XStyleFactory;
10:
11: /**
12: * <p>Title: Xui</p>
13: * <p>Description: </p>
14: * <p>Copyright: Copyright (c) Xoetrope Ltd., 1998-2003</p>
15: * <p>Company: Xoetrope Ltd.</p>
16: * @author not attributable
17: * @version 1.0
18: */
19:
20: public class BuddySample extends XPage {
21: XButton closeButton, visibleButton, enabledButton;
22: XEdit txtFirstname, txtSurname, txtAge;
23: Frame frame;
24: BuddyHelper buddy;
25:
26: public BuddySample() {
27: buddy = new BuddyHelper((XStyleFactory) componentFactory);
28:
29: frame = new Frame("BuddyHelper Sample");
30: frame.setLayout(null);
31: frame.setSize(640, 580);
32: String desc = "This example shows how the BuddyHelper class works. The idea is that when you create an input component such";
33: desc += " as a TextField or a Choice you usually precede it with a caption and possibly follow it with a units description.";
34: desc += " The BuddyHelper allows you to add them in a single line and returns the control. It's possible after that to use";
35: desc += " the BuddyHelper to enable and disable and set the visibility of all the controls in the set in one line of code";
36:
37: componentFactory.setParentComponent(frame);
38: componentFactory.addComponent(XPage.LABEL, 10, 50, 530, 100,
39: desc);
40:
41: txtFirstname = (XEdit) buddy.addComponent(XPage.EDIT, 20, 250,
42: 130, 25, "Firstname", "Joe", null);
43: txtSurname = (XEdit) buddy.addComponent(XPage.EDIT, 20, 280,
44: 130, 25, "Surname", "Bloggs", null);
45: txtAge = (XEdit) buddy.addComponent(XPage.EDIT, 20, 95, 130,
46: 310, 355, 25, "Age", "29", "Years", null);
47: visibleButton = (XButton) componentFactory
48: .addComponent(XPage.BUTTON, 10, 350, 230, 25,
49: "Toggle Age visibility");
50: enabledButton = (XButton) componentFactory.addComponent(
51: XPage.BUTTON, 10, 380, 230, 25,
52: "Toggle Surname enabled");
53: closeButton = (XButton) componentFactory.addComponent(
54: XPage.BUTTON, 10, 540, 130, 25, "Close");
55: setHandlers();
56: frame.setVisible(true);
57: frame.show();
58: }
59:
60: public void setHandlers() {
61: addMouseHandler(closeButton, "Close");
62: addMouseHandler(visibleButton, "toggle");
63: addMouseHandler(enabledButton, "enable");
64: }
65:
66: public static void main(String args[]) {
67: MetaSample compSample = new MetaSample();
68: }
69:
70: public void Close() {
71: if (wasMouseClicked()) {
72: frame.setVisible(false);
73: }
74: }
75:
76: public void toggle() {
77: if (wasMouseClicked()) {
78: buddy.setVisible(txtAge, !txtAge.isVisible());
79: }
80: }
81:
82: public void enable() {
83: if (wasMouseClicked()) {
84: buddy.setEnabled(txtSurname, !txtSurname.isEnabled());
85: }
86: }
87: }
|