package net.xoetrope.xui.test;
import java.util.Date;
import java.awt.Button;
import java.awt.Choice;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.awt.event.ItemEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.TextEvent;
import net.xoetrope.xui.XPage;
import net.xoetrope.xui.events.XEventHelper;
/**
* <p>Title: Xui</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) Xoetrope Ltd., 1998-2003</p>
* <p>Company: Xoetrope Ltd.</p>
* @author Xoetrope Ltd.
* @version 1.0
*/
public class PageTester extends XPage
{
boolean actionPerformed, focusGained, textChanged, keyPressed, itemChanged, mouseClicked, mouseMoved;
Button b;
TextField tf;
Choice c;
public PageTester()
{
// XStyleManager style = TestStyles.getStyles();
// XStyleFactory compfactory = new XStyleFactory(styleMgr);
// compfactory.setParentComponent( this );
b = (Button)componentFactory.addComponent( "java.awt.Button", 10, 10, 150, 25 );
b.setLabel( "Click to continue!" );
tf = (TextField)componentFactory.addComponent( "java.awt.TextField", 10, 50, 100, 25, null );
c = (Choice)componentFactory.addComponent( "java.awt.Choice", 10, 80, 100, 25, null );
}
public void checkHandlers()
{
actionPerformed = focusGained = textChanged = itemChanged = keyPressed = mouseClicked = mouseMoved = false;
XEventHelper.addActionHandler( this, b, "actionMethod" );
XEventHelper.addFocusHandler( this, b, "focusMethod" );
XEventHelper.addTextHandler( this, tf, "textMethod" );
XEventHelper.addItemHandler( this, c, "itemMethod" );
XEventHelper.addKeyHandler( this, tf, "keyMethod" );
XEventHelper.addMouseHandler( this, b, "mouseMethod" );
XEventHelper.addMouseMotionHandler( this, b, "mouseMotionMethod" );
ActionEvent aEvent = new ActionEvent( b, ActionEvent.ACTION_PERFORMED, "test" );
b.dispatchEvent( aEvent );
FocusEvent fEvent = new FocusEvent( b, FocusEvent.FOCUS_GAINED );
b.dispatchEvent( fEvent );
TextEvent tEvent = new TextEvent( tf, TextEvent.TEXT_VALUE_CHANGED );
tf.dispatchEvent( tEvent );
ItemEvent iEvent = new ItemEvent( c, ItemEvent.ITEM_STATE_CHANGED, c, 1 );
c.dispatchEvent( iEvent );
KeyEvent kEvent = new KeyEvent( tf, KeyEvent.KEY_PRESSED, new Date().getTime(), 0, KeyEvent.VK_A );
tf.dispatchEvent( kEvent );
MouseEvent mEvent = new MouseEvent( b, MouseEvent.MOUSE_CLICKED, new Date().getTime(), 0, 10, 10, 1, false );
b.dispatchEvent( mEvent );
MouseEvent mmEvent = new MouseEvent( b, MouseEvent.MOUSE_MOVED, new Date().getTime(), 0, 10, 10, 1, false );
b.dispatchEvent( mmEvent );
}
public void actionMethod()
{
actionPerformed = true;
}
public void focusMethod()
{
FocusEvent evt = (FocusEvent)getCurrentEvent();
System.out.println( evt.getID() == evt.FOCUS_LOST );
focusGained = true;
}
public void textMethod()
{
textChanged = true;
}
public void itemMethod()
{
itemChanged = true;
}
public void keyMethod()
{
keyPressed = true;
}
public void mouseMethod()
{
mouseClicked = true;
}
public void mouseMotionMethod()
{
mouseMoved = true;
}
}