[439] | 1 | // Module : $RCSfile: TaskTreeManager.java,v $
|
---|
| 2 | // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 06.11.2011 10:14:21 $
|
---|
| 3 | // Project : TaskTreePerformanceTest
|
---|
| 4 | // Creation : 2011 by Patrick
|
---|
| 5 | // Copyright : Patrick Harms, 2011
|
---|
| 6 |
|
---|
| 7 | package de.ugoe.cs.quest.tasktrees.manager;
|
---|
| 8 |
|
---|
| 9 | import java.util.logging.Logger;
|
---|
| 10 |
|
---|
[557] | 11 | import de.ugoe.cs.quest.eventcore.Event;
|
---|
| 12 | import de.ugoe.cs.quest.eventcore.IEventTarget;
|
---|
| 13 | import de.ugoe.cs.quest.eventcore.gui.KeyInteraction;
|
---|
| 14 | import de.ugoe.cs.quest.eventcore.gui.KeyboardFocusChange;
|
---|
| 15 | import de.ugoe.cs.quest.tasktrees.treeifc.IEventTask;
|
---|
| 16 | import de.ugoe.cs.quest.tasktrees.treeifc.ISequence;
|
---|
| 17 | import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTree;
|
---|
| 18 | import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder;
|
---|
| 19 | import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode;
|
---|
| 20 | import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory;
|
---|
[439] | 21 |
|
---|
| 22 | /**
|
---|
| 23 | * TODO comment
|
---|
[557] | 24 | *
|
---|
[439] | 25 | * @version $Revision: $ $Date: $
|
---|
[557] | 26 | * @author 2011, last modified by $Author: $
|
---|
[439] | 27 | */
|
---|
[557] | 28 | public class TaskTreeManager {
|
---|
| 29 |
|
---|
| 30 | /** */
|
---|
| 31 | private static final int MAX_EVENTS_TILL_RULE_APPLICATION = 100;
|
---|
[439] | 32 |
|
---|
[557] | 33 | /** */
|
---|
| 34 | private static Logger LOG = Logger.getLogger(TaskTreeManager.class.getName());
|
---|
[439] | 35 |
|
---|
[557] | 36 | /** */
|
---|
| 37 | private ITaskTreeBuilder taskTreeBuilder = ComponentManager.getDefaultTaskTreeBuilder();
|
---|
[439] | 38 |
|
---|
[557] | 39 | /** */
|
---|
| 40 | private ITaskTreeNodeFactory taskTreeNodeFactory =
|
---|
| 41 | ComponentManager.getDefaultTaskTreeNodeFactory();
|
---|
| 42 |
|
---|
| 43 | /** */
|
---|
| 44 | private int eventsTillRuleApplication = MAX_EVENTS_TILL_RULE_APPLICATION;
|
---|
| 45 |
|
---|
| 46 | /** */
|
---|
| 47 | private ISequence rootSequence;
|
---|
| 48 |
|
---|
| 49 | /** */
|
---|
| 50 | private IEventTarget currentKeyboardFocusGUIElement;
|
---|
| 51 |
|
---|
| 52 | /**
|
---|
| 53 | * TODO: comment
|
---|
| 54 | *
|
---|
| 55 | */
|
---|
| 56 | public TaskTreeManager() {
|
---|
| 57 | rootSequence = taskTreeNodeFactory.createNewSequence();
|
---|
[439] | 58 | }
|
---|
[557] | 59 |
|
---|
| 60 | /**
|
---|
| 61 | *
|
---|
| 62 | */
|
---|
| 63 | public void handleNewEvent(Event event) {
|
---|
| 64 | if (event.getType() instanceof KeyInteraction) {
|
---|
| 65 | if (currentKeyboardFocusGUIElement == null) {
|
---|
| 66 | currentKeyboardFocusGUIElement = event.getTarget();
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | addEventTask
|
---|
| 70 | (taskTreeNodeFactory.createNewEventTask
|
---|
| 71 | (event.getType(), currentKeyboardFocusGUIElement));
|
---|
| 72 | }
|
---|
| 73 | else {
|
---|
| 74 | addEventTask
|
---|
| 75 | (taskTreeNodeFactory.createNewEventTask(event.getType(), event.getTarget()));
|
---|
| 76 | }
|
---|
[439] | 77 | }
|
---|
| 78 |
|
---|
[557] | 79 | /**
|
---|
| 80 | *
|
---|
| 81 | */
|
---|
| 82 | public synchronized ITaskTree getTaskTree() {
|
---|
| 83 | LOG.info("applying rules temporal relationship generation rules");
|
---|
[439] | 84 |
|
---|
[557] | 85 | ISequence currentRootSequence = rootSequence.clone();
|
---|
| 86 | ComponentManager.getTemporalRelationshipRuleManager().applyRules
|
---|
| 87 | (currentRootSequence, taskTreeBuilder, taskTreeNodeFactory, true);
|
---|
[439] | 88 |
|
---|
[557] | 89 | return taskTreeNodeFactory.createTaskTree(currentRootSequence);
|
---|
[439] | 90 | }
|
---|
[557] | 91 |
|
---|
| 92 | /**
|
---|
| 93 | * @param task
|
---|
| 94 | */
|
---|
| 95 | private synchronized void addEventTask(IEventTask task) {
|
---|
| 96 | handleEventTask(task);
|
---|
[439] | 97 | }
|
---|
| 98 |
|
---|
[557] | 99 | /**
|
---|
| 100 | * adds the task to the current or the new sequence. The decision depends on the type of task.
|
---|
| 101 | * If the task finishes the current sequence, the sequence is marked as finished If the task
|
---|
| 102 | * does not start a new sequence, it is added to the current sequence, before it is marked s
|
---|
| 103 | * finished. Otherwise it is added to a new sequence.
|
---|
| 104 | */
|
---|
| 105 | private void handleEventTask(IEventTask eventTask) {
|
---|
| 106 | if (eventTask.getEventType() instanceof KeyboardFocusChange) {
|
---|
| 107 | currentKeyboardFocusGUIElement = eventTask.getEventTarget();
|
---|
[439] | 108 | }
|
---|
[557] | 109 | else {
|
---|
| 110 | LOG.info("handling event task \"" + eventTask + "\"");
|
---|
| 111 | addTaskToSequence(eventTask, currentKeyboardFocusGUIElement);
|
---|
[439] | 112 | }
|
---|
| 113 | }
|
---|
[557] | 114 |
|
---|
| 115 | /**
|
---|
| 116 | *
|
---|
| 117 | */
|
---|
| 118 | private void addTaskToSequence(ITaskTreeNode task, IEventTarget currentKeyboardFocusGUIElement)
|
---|
[439] | 119 | {
|
---|
[557] | 120 | taskTreeBuilder.addChild(rootSequence, task);
|
---|
[439] | 121 |
|
---|
[557] | 122 | if (--eventsTillRuleApplication == 0) {
|
---|
| 123 | eventsTillRuleApplication = MAX_EVENTS_TILL_RULE_APPLICATION;
|
---|
| 124 |
|
---|
| 125 | LOG.info("applying rules temporal relationship generation rules");
|
---|
| 126 | ComponentManager.getTemporalRelationshipRuleManager().applyRules(rootSequence,
|
---|
| 127 | taskTreeBuilder,
|
---|
| 128 | taskTreeNodeFactory,
|
---|
| 129 | false);
|
---|
| 130 | }
|
---|
[439] | 131 | }
|
---|
| 132 |
|
---|
| 133 | }
|
---|