001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: package jacareto.trial;
025:
026: import jacareto.comp.AWTComponentHandler;
027: import jacareto.comp.Components;
028: import jacareto.comp.ContainerHandler;
029: import jacareto.comp.JComponentHandler;
030: import jacareto.comp.JFrameHandler;
031: import jacareto.comp.JPanelHandler;
032: import jacareto.convert.SelectionConverter;
033: import jacareto.convert.xml.XMLKeyEventConverter;
034: import jacareto.convert.xml.XMLMouseEventConverter;
035: import jacareto.convert.xml.XMLMouseMotionEventConverter;
036: import jacareto.examples.SwingComplexTest;
037: import jacareto.record.RecordException;
038: import jacareto.record.RecordTools;
039: import jacareto.record.VectorRecord;
040: import jacareto.record.XMLRecord;
041: import jacareto.replay.KeyEventReplayer;
042: import jacareto.replay.MouseEventReplayer;
043: import jacareto.replay.MouseMotionEventReplayer;
044: import jacareto.replay.Replay;
045: import jacareto.struct.Structure;
046: import jacareto.system.Environment;
047:
048: import org.apache.log4j.ConsoleAppender;
049: import org.apache.log4j.Level;
050: import org.apache.log4j.Logger;
051: import org.apache.log4j.PatternLayout;
052:
053: public class ReplayExample {
054: public ReplayExample() {
055: // Creating an empty environment
056: Environment env = new Environment();
057: ConsoleAppender appender = new ConsoleAppender(
058: new PatternLayout(), ConsoleAppender.SYSTEM_OUT);
059: Logger logger = env.getLogger();
060: logger.addAppender(appender);
061: logger.setLevel(Level.OFF);
062:
063: // Setting up the components instance
064: Components components = new Components(env,
065: Components.INIT_EMPTY);
066: components.addComponentHandler(new AWTComponentHandler(env,
067: components), 0);
068: components.addComponentHandler(new ContainerHandler(env,
069: components), 1);
070: components.addComponentHandler(new JComponentHandler(env,
071: components), 2);
072: components.addComponentHandler(new JPanelHandler(env,
073: components), 3);
074: components.addComponentHandler(new JFrameHandler(env,
075: components), 3);
076:
077: // Setting up the record
078: XMLRecord xmlRecord = new XMLRecord(env, "Record.xml",
079: XMLRecord.INIT_EMPTY);
080: SelectionConverter converter = xmlRecord
081: .getSelectionConverter();
082: converter.addConverter(new XMLMouseEventConverter(env));
083: converter.addConverter(new XMLMouseMotionEventConverter(env));
084: converter.addConverter(new XMLKeyEventConverter(env));
085:
086: VectorRecord record = new VectorRecord(env);
087:
088: try {
089: xmlRecord.open();
090: xmlRecord.setSaveBeforeClosing(false);
091: record.open();
092: RecordTools.write(xmlRecord, record);
093: xmlRecord.close();
094: } catch (RecordException r) {
095: System.err.println("Could not open the record");
096: System.exit(1);
097: }
098:
099: // Getting the structure of the record
100: Structure structure = new Structure(env, record);
101:
102: // Starting the target application
103: SwingComplexTest frame = new SwingComplexTest();
104: frame.setSize(500, 400);
105: frame.setVisible(true);
106:
107: // Setting up the replay instance
108: Replay replay = new Replay(env, components, structure,
109: Replay.INIT_EMPTY);
110: replay.addReplayer(new MouseEventReplayer(env, replay));
111: replay.addReplayer(new MouseMotionEventReplayer(env, replay));
112: replay.addReplayer(new KeyEventReplayer(env, replay));
113:
114: // Start replaying
115: replay.start();
116: }
117:
118: public static void main(String[] args) {
119: ReplayExample capture = new ReplayExample();
120: }
121: }
|