001: package net.xoetrope.xui.test;
002:
003: import java.util.Date;
004:
005: import java.awt.Button;
006: import java.awt.Choice;
007: import java.awt.TextField;
008: import java.awt.event.ActionEvent;
009: import java.awt.event.FocusEvent;
010: import java.awt.event.ItemEvent;
011: import java.awt.event.KeyEvent;
012: import java.awt.event.MouseEvent;
013: import java.awt.event.TextEvent;
014:
015: import net.xoetrope.xui.XPage;
016:
017: /**
018: * <p>Title: Xui</p>
019: * <p>Description: </p>
020: * <p>Copyright: Copyright (c) Xoetrope Ltd., 1998-2003</p>
021: * <p>Company: Xoetrope Ltd.</p>
022: * @author Xoetrope Ltd.
023: * @version 1.0
024: */
025:
026: public class PageTester extends XPage {
027: boolean actionPerformed, focusGained, textChanged, keyPressed,
028: itemChanged, mouseClicked, mouseMoved;
029:
030: Button b;
031: TextField tf;
032: Choice c;
033:
034: public PageTester() {
035: // XStyleManager style = TestStyles.getStyles();
036: // XStyleFactory compfactory = new XStyleFactory(styleMgr);
037: // compfactory.setParentComponent( this );
038:
039: b = (Button) componentFactory.addComponent("java.awt.Button",
040: 10, 10, 150, 25);
041: b.setLabel("Click to continue!");
042: tf = (TextField) componentFactory.addComponent(
043: "java.awt.TextField", 10, 50, 100, 25, null);
044: c = (Choice) componentFactory.addComponent("java.awt.Choice",
045: 10, 80, 100, 25, null);
046: }
047:
048: public void checkHandlers() {
049:
050: actionPerformed = focusGained = textChanged = itemChanged = keyPressed = mouseClicked = mouseMoved = false;
051:
052: addActionHandler(b, "actionMethod");
053: addFocusHandler(b, "focusMethod");
054: addTextHandler(tf, "textMethod");
055: addItemHandler(c, "itemMethod");
056: addKeyHandler(tf, "keyMethod");
057: addMouseHandler(b, "mouseMethod");
058: addMouseMotionHandler(b, "mouseMotionMethod");
059:
060: ActionEvent aEvent = new ActionEvent(b,
061: ActionEvent.ACTION_PERFORMED, "test");
062: b.dispatchEvent(aEvent);
063:
064: FocusEvent fEvent = new FocusEvent(b, FocusEvent.FOCUS_GAINED);
065: b.dispatchEvent(fEvent);
066:
067: TextEvent tEvent = new TextEvent(tf,
068: TextEvent.TEXT_VALUE_CHANGED);
069: tf.dispatchEvent(tEvent);
070:
071: ItemEvent iEvent = new ItemEvent(c,
072: ItemEvent.ITEM_STATE_CHANGED, c, 1);
073: c.dispatchEvent(iEvent);
074:
075: KeyEvent kEvent = new KeyEvent(tf, KeyEvent.KEY_PRESSED,
076: new Date().getTime(), 0, KeyEvent.VK_A);
077: tf.dispatchEvent(kEvent);
078:
079: MouseEvent mEvent = new MouseEvent(b, MouseEvent.MOUSE_CLICKED,
080: new Date().getTime(), 0, 10, 10, 1, false);
081: b.dispatchEvent(mEvent);
082:
083: MouseEvent mmEvent = new MouseEvent(b, MouseEvent.MOUSE_MOVED,
084: new Date().getTime(), 0, 10, 10, 1, false);
085: b.dispatchEvent(mmEvent);
086: }
087:
088: public void actionMethod() {
089: actionPerformed = true;
090: }
091:
092: public void focusMethod() {
093: FocusEvent evt = (FocusEvent) getCurrentEvent();
094: System.out.println(evt.getID() == evt.FOCUS_LOST);
095: focusGained = true;
096: }
097:
098: public void textMethod() {
099: textChanged = true;
100: }
101:
102: public void itemMethod() {
103: itemChanged = true;
104: }
105:
106: public void keyMethod() {
107: keyPressed = true;
108: }
109:
110: public void mouseMethod() {
111: mouseClicked = true;
112: }
113:
114: public void mouseMotionMethod() {
115: mouseMoved = true;
116: }
117: }
|