001: package com.xoetrope.carousel.testpilot;
002:
003: import java.awt.Component;
004: import java.awt.Frame;
005:
006: import net.xoetrope.swing.XButton;
007: import net.xoetrope.swing.XTable;
008: import net.xoetrope.xui.PageSupport;
009: import net.xoetrope.xui.XProjectManager;
010: import net.xoetrope.xui.data.XBaseModel;
011: import net.xoetrope.xui.data.XModel;
012: import javax.swing.SwingUtilities;
013: import net.xoetrope.swing.XTable2;
014:
015: /**
016: * Support for running a script
017: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
018: * the GNU Public License (GPL), please see license.txt for more details. If
019: * you make commercial use of this software you must purchase a commercial
020: * license from Xoetrope.</p>
021: * <p> $Revision: 1.2 $</p>
022: */
023: public class ApplicationRunner extends ScriptPage {
024: private XTable2 table;
025: private XModel eventList;
026: private PlayerThread runnerThread;
027: private int cmdDelay = 0;
028: private int currentCommand = 0;
029:
030: private int passCount = 0, failCount = 0;
031: private boolean isSwing = false;
032:
033: public void ApplicationRunner() {
034: }
035:
036: public void pageCreated() {
037: table = (XTable2) this .findComponent("table");
038: table.setStyle("TableData");
039: table.setHeaderStyle("TableHeading");
040: table.setSelectedStyle("TableSelection");
041: table.setInteractiveTable(true);
042: btnStart = (XButton) findComponent("btnStart");
043: eventList = (XModel) rootModel.get("application/events/items");
044: XBaseModel delayModel = (XBaseModel) rootModel
045: .get("application/settings/cmd_delay");
046: table.setModel(eventList);
047: try {
048: cmdDelay = Integer.parseInt((String) delayModel.get());
049: } catch (NumberFormatException ex) {
050: }
051: }
052:
053: public void startScript() {
054: if (wasMouseClicked()) {
055: Component root = ((Frame) ApplicationConfig.mainClassObject)
056: .getComponent(0);
057: if (root.getClass().getName().indexOf("swing") >= 0)
058: isSwing = true;
059: else
060: isSwing = false;
061: PageSupport page = pageMgr.getPage("Welcome");
062:
063: currentCommand = 1;
064: passCount = failCount = 0;
065:
066: try {
067: runnerThread = new PlayerThread(this , eventList,
068: cmdDelay);
069: runnerThread.start();
070: } catch (Exception ex) {
071: }
072: }
073: }
074:
075: public void resumeScript() {
076: // runnerThread = new Thread( this );
077: // runnerThread.run();
078: }
079:
080: public boolean getConfirmResult() {
081: // String eventName = "", control = "";
082: // int counter = currentCommand;
083: // while ( eventName.compareTo( "confirm" ) != 0 ) {
084: // XBaseModel event = ( XBaseModel )eventList.get( counter );
085: // eventName = getAttrib( event, ScriptConverter.EVENT_NODE );
086: // control = getAttrib( event, ScriptConverter.CONTROL_NODE );
087: // counter--;
088: // }
089: // currentCommand++;
090: // doRun();
091: // return control.compareTo( "-1" ) == 0 ? true : false;
092: return false;
093: }
094:
095: public void setExecutedEvent(int i) {
096: final int idx = i;
097: try {
098: Runnable r = new Runnable() {
099: public void run() {
100: if (idx > -1) {
101: table
102: .setSelectedRow(Math.min(idx, Math
103: .max(table.getModel()
104: .getRowCount() - 1, 0)));
105: }
106: }
107: };
108: SwingUtilities.invokeLater(r);
109: } catch (Exception e) {
110: e.printStackTrace();
111: }
112: }
113:
114: private String getAttrib(XBaseModel model, int index) {
115: XBaseModel ret = (XBaseModel) model.get(index);
116: if (ret == null)
117: return null;
118:
119: Object retStr = ret.get();
120: if (retStr == null)
121: return null;
122: else
123: return retStr.toString();
124: }
125:
126: public void goBack() {
127: if (wasMouseClicked())
128: pageMgr.showPrevious();
129: }
130:
131: /**
132: * Set the instance of the class whose events are being recorded.
133: * @param obj
134: */
135: public void setMainClassObject(Object obj) {
136: if (mainClassObject != obj)
137: btnStart.setEnabled(obj != null);
138: mainClassObject = obj;
139: }
140: }
|