- Timestamp:
- 02/21/13 18:39:48 (12 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/manager/ComponentManager.java
r1099 r1109 84 84 nodeEqualityRuleManager.init(); 85 85 86 temporalRelationshipRuleManager =87 new TemporalRelationshipRuleManager(nodeEqualityRuleManager);88 temporalRelationshipRuleManager.init();89 90 86 taskTreeBuilder = new TaskTreeBuilder(); 91 87 taskTreeNodeFactory = new TaskTreeNodeFactory(); 88 89 temporalRelationshipRuleManager = new TemporalRelationshipRuleManager 90 (nodeEqualityRuleManager, taskTreeNodeFactory, taskTreeBuilder); 91 temporalRelationshipRuleManager.init(); 92 92 } 93 93 -
trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/manager/TaskTreeManager.java
r922 r1109 2 2 3 3 import java.util.Collection; 4 import java.util.LinkedList; 4 5 import java.util.List; 5 6 import java.util.logging.Level; 6 7 7 8 import de.ugoe.cs.autoquest.eventcore.Event; 8 import de.ugoe.cs.autoquest.eventcore.gui.KeyboardFocusChange;9 9 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 10 10 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 11 11 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree; 12 12 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder; 13 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;14 13 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNodeFactory; 15 14 import de.ugoe.cs.util.console.Console; … … 24 23 25 24 /** */ 26 private static final int MAX_EVENTS_TILL_RULE_APPLICATION = 100;27 28 /** */29 25 private ITaskTreeBuilder taskTreeBuilder = ComponentManager.getDefaultTaskTreeBuilder(); 30 26 … … 34 30 35 31 /** */ 36 private int eventsTillRuleApplication = MAX_EVENTS_TILL_RULE_APPLICATION;32 private List<List<IEventTask>> sessions = null; 37 33 38 34 /** */ 39 private ISequence rootSequence;35 private List<IEventTask> currentSession = null; 40 36 41 37 /** 42 * TODO: comment 43 * 38 * 44 39 */ 45 40 public TaskTreeManager() { 46 rootSequence = taskTreeNodeFactory.createNewSequence();41 sessions = new LinkedList<List<IEventTask>>(); 47 42 } 48 43 49 44 /** 50 * <p>51 * TODO: comment52 * </p>53 45 * 54 * @param sequences55 * @return56 46 */ 57 public synchronized ITaskTree createTaskTree(Collection<List<Event>> sequences) { 47 public synchronized ITaskTree createTaskTree(Collection<List<Event>> newSessions) { 48 if ((currentSession != null) || (sessions.size() > 0)) { 49 throw new IllegalStateException("do not mix calls to this method with calls to the " + 50 "other methods for handling tasks. Use only one " + 51 "variant instead."); 52 } 58 53 59 for (List<Event> sequence : sequences) { 60 for (Event event : sequence) { 61 handleNewEvent(event); 54 for (List<Event> newSession : newSessions) { 55 if (newSession.size() > 0) { 56 for (Event event : newSession) { 57 handleNewEvent(event); 58 } 59 finishSession(); 62 60 } 63 61 } … … 70 68 */ 71 69 public void handleNewEvent(Event event) { 72 handleEventTask(taskTreeNodeFactory.createNewEventTask(event.getType(), event.getTarget())); 70 assertSessionSequence(); 71 currentSession.add 72 (taskTreeNodeFactory.createNewEventTask(event.getType(), event.getTarget())); 73 } 74 75 /** 76 * 77 */ 78 public void finishSession() { 79 if ((currentSession != null) && (currentSession.size() > 0)) { 80 sessions.add(currentSession); 81 currentSession = null; 82 } 73 83 } 74 84 … … 77 87 */ 78 88 public synchronized ITaskTree getTaskTree() { 89 finishSession(); 90 79 91 Console.traceln(Level.INFO, "applying temporal relationship generation rules"); 92 93 ISequence rootSequence = taskTreeNodeFactory.createNewSequence(); 94 taskTreeBuilder.setDescription(rootSequence, "root"); 95 96 for (List<IEventTask> session : sessions) { 97 ISequence sequence = taskTreeNodeFactory.createNewSequence(); 98 taskTreeBuilder.setDescription(sequence, "session"); 99 100 for (IEventTask eventTask : session) { 101 taskTreeBuilder.addChild(sequence, eventTask); 102 } 103 104 taskTreeBuilder.addChild(rootSequence, sequence); 105 } 106 107 108 ComponentManager.getTemporalRelationshipRuleManager().applyRules(rootSequence); 80 109 81 ISequence currentRootSequence = rootSequence.clone(); 82 ComponentManager.getTemporalRelationshipRuleManager().applyRules 83 (currentRootSequence, taskTreeBuilder, taskTreeNodeFactory, true); 84 85 return taskTreeNodeFactory.createTaskTree(currentRootSequence); 86 } 87 88 /** 89 * adds the task to the current or the new sequence. The decision depends on the type of task. 90 * If the task finishes the current sequence, the sequence is marked as finished If the task 91 * does not start a new sequence, it is added to the current sequence, before it is marked s 92 * finished. Otherwise it is added to a new sequence. 93 */ 94 private synchronized void handleEventTask(IEventTask eventTask) { 95 if (!(eventTask.getEventType() instanceof KeyboardFocusChange)) { 96 Console.traceln(Level.INFO, "handling interaction event task \"" + eventTask + "\""); 97 addTaskToSequence(eventTask); 98 } 110 return taskTreeNodeFactory.createTaskTree(rootSequence); 99 111 } 100 112 … … 102 114 * 103 115 */ 104 private void addTaskToSequence(ITaskTreeNode task) 105 { 106 taskTreeBuilder.addChild(rootSequence, task); 107 108 if (--eventsTillRuleApplication == 0) { 109 eventsTillRuleApplication = MAX_EVENTS_TILL_RULE_APPLICATION; 110 111 Console.traceln(Level.INFO, "applying temporal relationship generation rules"); 112 ComponentManager.getTemporalRelationshipRuleManager().applyRules(rootSequence, 113 taskTreeBuilder, 114 taskTreeNodeFactory, 115 false); 116 private void assertSessionSequence() { 117 if (currentSession == null) { 118 currentSession = new LinkedList<IEventTask>(); 116 119 } 117 120 }
Note: See TracChangeset
for help on using the changeset viewer.