- Timestamp:
- 08/17/12 08:33:29 (12 years ago)
- Location:
- trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/manager
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/manager/ComponentManager.java
r439 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: ComponentManager.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 12.02.2012 $ … … 5 4 // Creation : 2012 by patrick 6 5 // Copyright : Patrick Harms, 2012 7 //------------------------------------------------------------------------------------------------- 6 8 7 package de.ugoe.cs.quest.tasktrees.manager; 9 8 10 9 import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEqualityRuleManager; 11 10 import de.ugoe.cs.quest.tasktrees.temporalrelation.TemporalRelationshipRuleManager; 12 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeBuilder;13 import de.ugoe.cs.quest.tasktrees.treeifc. TaskTreeNodeFactory;14 import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeBuilder Impl;15 import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeNodeFactory Impl;11 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 12 import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 13 import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeBuilder; 14 import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeNodeFactory; 16 15 17 //-------------------------------------------------------------------------------------------------18 16 /** 19 17 * TODO comment … … 22 20 * @author 2012, last modified by $Author: patrick$ 23 21 */ 24 // ------------------------------------------------------------------------------------------------- 25 public class ComponentManager 26 { 27 /** */ 28 private static ComponentManager sInstance; 22 public class ComponentManager { 23 24 /** */ 25 private static ComponentManager instance; 29 26 30 /** */ 31 private TemporalRelationshipRuleManager mTemporalRelationshipRuleManager; 32 33 /** */ 34 private NodeEqualityRuleManager mNodeEqualityRuleManager; 27 /** */ 28 private TemporalRelationshipRuleManager temporalRelationshipRuleManager; 35 29 36 /** */37 private TaskTreeBuilder mTaskTreeBuilder;30 /** */ 31 private NodeEqualityRuleManager nodeEqualityRuleManager; 38 32 39 /** */40 private TaskTreeNodeFactory mTaskTreeNodeFactory;33 /** */ 34 private ITaskTreeBuilder taskTreeBuilder; 41 35 42 //----------------------------------------------------------------------------------------------- 43 /** 44 * TODO: comment 45 * 46 * @return 47 */ 48 //----------------------------------------------------------------------------------------------- 49 public static TemporalRelationshipRuleManager getTemporalRelationshipRuleManager() 50 { 51 return getInstance().mTemporalRelationshipRuleManager; 52 } 36 /** */ 37 private ITaskTreeNodeFactory taskTreeNodeFactory; 53 38 54 //----------------------------------------------------------------------------------------------- 55 /** 56 * TODO: comment 57 * 58 * @return 59 */ 60 //----------------------------------------------------------------------------------------------- 61 public static NodeEqualityRuleManager getNodeEqualityRuleManager() 62 { 63 return getInstance().mNodeEqualityRuleManager; 64 } 39 /** 40 * TODO: comment 41 * 42 * @return 43 */ 44 public static TemporalRelationshipRuleManager getTemporalRelationshipRuleManager() { 45 return getInstance().temporalRelationshipRuleManager; 46 } 65 47 66 //----------------------------------------------------------------------------------------------- 67 /** 68 * TODO: comment 69 * 70 * @return 71 */ 72 //----------------------------------------------------------------------------------------------- 73 public static TaskTreeBuilder getDefaultTaskTreeBuilder() 74 { 75 return getInstance().mTaskTreeBuilder; 76 } 48 /** 49 * TODO: comment 50 * 51 * @return 52 */ 53 public static NodeEqualityRuleManager getNodeEqualityRuleManager() { 54 return getInstance().nodeEqualityRuleManager; 55 } 77 56 78 //----------------------------------------------------------------------------------------------- 79 /** 80 * TODO: comment 81 * 82 * @return 83 */ 84 //----------------------------------------------------------------------------------------------- 85 public static TaskTreeNodeFactory getDefaultTaskTreeNodeFactory() 86 { 87 return getInstance().mTaskTreeNodeFactory; 88 } 57 /** 58 * TODO: comment 59 * 60 * @return 61 */ 62 public static ITaskTreeBuilder getDefaultTaskTreeBuilder() { 63 return getInstance().taskTreeBuilder; 64 } 89 65 90 //----------------------------------------------------------------------------------------------- 91 /** 92 * TODO: comment 93 * 94 * @return 95 */ 96 //----------------------------------------------------------------------------------------------- 97 public static synchronized void clearInstance() 98 { 99 sInstance = null; 100 } 66 /** 67 * TODO: comment 68 * 69 * @return 70 */ 71 public static ITaskTreeNodeFactory getDefaultTaskTreeNodeFactory() { 72 return getInstance().taskTreeNodeFactory; 73 } 101 74 102 //----------------------------------------------------------------------------------------------- 103 /** 104 * TODO: comment 105 * 106 * @return 107 */ 108 //----------------------------------------------------------------------------------------------- 109 private static synchronized ComponentManager getInstance() 110 { 111 if (sInstance == null) 112 { 113 sInstance = new ComponentManager(); 114 sInstance.init(); 75 /** 76 * TODO: comment 77 * 78 * @return 79 */ 80 public static synchronized void clearInstance() { 81 instance = null; 115 82 } 116 return sInstance;117 }118 83 119 //----------------------------------------------------------------------------------------------- 120 /** 121 * TODO: comment 122 * 123 */ 124 //----------------------------------------------------------------------------------------------- 125 private void init() 126 { 127 mNodeEqualityRuleManager = new NodeEqualityRuleManager(); 128 mNodeEqualityRuleManager.init(); 129 130 mTemporalRelationshipRuleManager = 131 new TemporalRelationshipRuleManager(mNodeEqualityRuleManager); 132 mTemporalRelationshipRuleManager.init(); 84 /** 85 * TODO: comment 86 * 87 * @return 88 */ 89 private static synchronized ComponentManager getInstance() { 90 if (instance == null) { 91 instance = new ComponentManager(); 92 instance.init(); 93 } 94 return instance; 95 } 133 96 134 mTaskTreeBuilder = new TaskTreeBuilderImpl(); 135 mTaskTreeNodeFactory = new TaskTreeNodeFactoryImpl(); 136 } 97 /** 98 * TODO: comment 99 * 100 */ 101 private void init() { 102 nodeEqualityRuleManager = new NodeEqualityRuleManager(); 103 nodeEqualityRuleManager.init(); 104 105 temporalRelationshipRuleManager = 106 new TemporalRelationshipRuleManager(nodeEqualityRuleManager); 107 temporalRelationshipRuleManager.init(); 108 109 taskTreeBuilder = new TaskTreeBuilder(); 110 taskTreeNodeFactory = new TaskTreeNodeFactory(); 111 } 137 112 138 113 } -
trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/manager/TaskTreeManager.java
r451 r557 1 //-------------------------------------------------------------------------------------------------2 1 // Module : $RCSfile: TaskTreeManager.java,v $ 3 2 // Version : $Revision: 0.0 $ $Author: Patrick $ $Date: 06.11.2011 10:14:21 $ … … 5 4 // Creation : 2011 by Patrick 6 5 // Copyright : Patrick Harms, 2011 7 //-------------------------------------------------------------------------------------------------8 6 9 7 package de.ugoe.cs.quest.tasktrees.manager; 10 8 11 import java.util.Observable;12 import java.util.Observer;13 9 import java.util.logging.Logger; 14 10 15 import de.ugoe.cs.quest.eventcore.guimodel.GUIElement; 16 import de.ugoe.cs.quest.eventcore.userinteraction.InteractionEvent; 17 import de.ugoe.cs.quest.eventcore.userinteraction.KeyInteraction; 18 import de.ugoe.cs.quest.eventcore.userinteraction.KeyboardFocusChange; 19 import de.ugoe.cs.quest.eventcore.userinteraction.UserInteractionProvider; 20 import de.ugoe.cs.quest.tasktrees.treeifc.InteractionTask; 21 import de.ugoe.cs.quest.tasktrees.treeifc.Sequence; 22 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTree; 23 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeBuilder; 24 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNode; 25 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNodeFactory; 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; 26 21 27 //-------------------------------------------------------------------------------------------------28 22 /** 29 23 * TODO comment 30 * 24 * 31 25 * @version $Revision: $ $Date: $ 32 * @author 26 * @author 2011, last modified by $Author: $ 33 27 */ 34 //------------------------------------------------------------------------------------------------- 35 public class TaskTreeManager implements Observer 36 { 37 /** */ 38 private static final int MAX_INTERACTIONS_TILL_RULE_APPLICATION = 100; 28 public class TaskTreeManager { 29 30 /** */ 31 private static final int MAX_EVENTS_TILL_RULE_APPLICATION = 100; 39 32 40 /** */ 41 private static Logger LOG = Logger.getLogger(TaskTreeManager.class.getName()); 42 43 /** */ 44 private TaskTreeBuilder mTaskTreeBuilder = ComponentManager.getDefaultTaskTreeBuilder(); 45 46 /** */ 47 private TaskTreeNodeFactory mTaskTreeNodeFactory = 48 ComponentManager.getDefaultTaskTreeNodeFactory(); 49 50 /** */ 51 private int mInteractionsTillRuleApplication = MAX_INTERACTIONS_TILL_RULE_APPLICATION; 52 53 /** */ 54 private Sequence mRootSequence; 55 56 /** */ 57 private GUIElement mCurrentKeyboardFocusGUIElement; 33 /** */ 34 private static Logger LOG = Logger.getLogger(TaskTreeManager.class.getName()); 58 35 59 //----------------------------------------------------------------------------------------------- 60 /** 61 * TODO: comment 62 * 63 */ 64 //----------------------------------------------------------------------------------------------- 65 public TaskTreeManager() 66 { 67 mRootSequence = mTaskTreeNodeFactory.createNewSequence(); 68 } 36 /** */ 37 private ITaskTreeBuilder taskTreeBuilder = ComponentManager.getDefaultTaskTreeBuilder(); 69 38 70 //----------------------------------------------------------------------------------------------- 71 /* (non-Javadoc) 72 * @see java.util.Observer#update(java.util.Observable, java.lang.Object) 73 */ 74 //----------------------------------------------------------------------------------------------- 75 public void update(Observable observable, Object event) 76 { 77 if ((observable instanceof UserInteractionProvider) && 78 (event instanceof InteractionEvent)) 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(); 58 } 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 } 77 } 78 79 /** 80 * 81 */ 82 public synchronized ITaskTree getTaskTree() { 83 LOG.info("applying rules temporal relationship generation rules"); 84 85 ISequence currentRootSequence = rootSequence.clone(); 86 ComponentManager.getTemporalRelationshipRuleManager().applyRules 87 (currentRootSequence, taskTreeBuilder, taskTreeNodeFactory, true); 88 89 return taskTreeNodeFactory.createTaskTree(currentRootSequence); 90 } 91 92 /** 93 * @param task 94 */ 95 private synchronized void addEventTask(IEventTask task) { 96 handleEventTask(task); 97 } 98 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(); 108 } 109 else { 110 LOG.info("handling event task \"" + eventTask + "\""); 111 addTaskToSequence(eventTask, currentKeyboardFocusGUIElement); 112 } 113 } 114 115 /** 116 * 117 */ 118 private void addTaskToSequence(ITaskTreeNode task, IEventTarget currentKeyboardFocusGUIElement) 79 119 { 80 handleNewInteractionEvent((InteractionEvent) event); 120 taskTreeBuilder.addChild(rootSequence, task); 121 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 } 81 131 } 82 else83 {84 LOG.warning("could not handle notification of " + observable + " regarding " + event);85 }86 }87 88 //-----------------------------------------------------------------------------------------------89 /**90 *91 */92 //-----------------------------------------------------------------------------------------------93 public void handleNewInteractionEvent(InteractionEvent event)94 {95 if (event.getInteraction() instanceof KeyInteraction)96 {97 if (mCurrentKeyboardFocusGUIElement == null)98 {99 mCurrentKeyboardFocusGUIElement = event.getGUIElement();100 }101 102 addInteractionTask(mTaskTreeNodeFactory.createNewInteractionTask103 (mCurrentKeyboardFocusGUIElement, event.getInteraction()));104 }105 else106 {107 addInteractionTask(mTaskTreeNodeFactory.createNewInteractionTask108 (event.getGUIElement(), event.getInteraction()));109 }110 }111 112 //-----------------------------------------------------------------------------------------------113 /**114 *115 */116 //-----------------------------------------------------------------------------------------------117 public synchronized TaskTree getTaskTree()118 {119 LOG.info("applying rules temporal relationship generation rules");120 121 Sequence rootSequence = mRootSequence.clone();122 ComponentManager.getTemporalRelationshipRuleManager().applyRules123 (rootSequence, mTaskTreeBuilder, mTaskTreeNodeFactory, true);124 125 return mTaskTreeNodeFactory.createTaskTree(rootSequence);126 }127 128 //-----------------------------------------------------------------------------------------------129 /**130 * @param task131 */132 //-----------------------------------------------------------------------------------------------133 private synchronized void addInteractionTask(InteractionTask task)134 {135 handleInteractionTask(task);136 }137 138 //-----------------------------------------------------------------------------------------------139 /**140 * adds the task to the current or the new sequence. The decision depends on the type141 * of task. If the task finishes the current sequence, the sequence is marked as finished142 * If the task does not start a new sequence, it is added to the current sequence, before it143 * is marked s finished. Otherwise it is added to a new sequence.144 */145 //-----------------------------------------------------------------------------------------------146 private void handleInteractionTask(InteractionTask interactionTask)147 {148 if (interactionTask.getInteraction() instanceof KeyboardFocusChange)149 {150 mCurrentKeyboardFocusGUIElement = interactionTask.getGUIElement();151 }152 else153 {154 LOG.info("handling interaction task \"" + interactionTask + "\"");155 addTaskToSequence(interactionTask, mCurrentKeyboardFocusGUIElement);156 }157 }158 159 //-----------------------------------------------------------------------------------------------160 /**161 * TODO: comment162 *163 * @param interactionTask164 */165 //-----------------------------------------------------------------------------------------------166 /*private boolean handleAndCorrectFocusChanges(InteractionTask interactionTask)167 {168 GUIElement newGUIElement = interactionTask.getGUIElement();169 170 // find the identical parent element171 GUIElement identicalParentGUIElement = null;172 173 while ((identicalParentGUIElement == null) && (newGUIElement != null))174 {175 GUIElement currentGUIElement = mCurrentGUIElement;176 177 while ((identicalParentGUIElement == null) && (currentGUIElement != null))178 {179 if (newGUIElement.equals(currentGUIElement))180 {181 identicalParentGUIElement = newGUIElement;182 }183 else184 {185 currentGUIElement = currentGUIElement.getParent();186 }187 }188 189 newGUIElement = newGUIElement.getParent();190 }191 192 // now create focus lost interactions for each GUI element, that is not common with the193 // hierarchy of the new GUI element194 GUIElement currentGUIElement = mCurrentGUIElement;195 196 List<InteractionTask> tasksToBeAdded = new ArrayList<InteractionTask>();197 198 while ((currentGUIElement != null) &&199 ((identicalParentGUIElement == null) ||200 (!currentGUIElement.equals(identicalParentGUIElement))))201 {202 tasksToBeAdded.add203 (mTaskTreeNodeFactory.createNewInteractionTask(currentGUIElement, new FocusLost()));204 currentGUIElement = currentGUIElement.getParent();205 }206 207 // now create focus received interactions for each GUI element, that is not common with208 // with the old one. Ensure, that if the current interaction is a focus reception, that209 // it is used instead of a generated one210 newGUIElement = interactionTask.getGUIElement();211 212 int index = tasksToBeAdded.size();213 while ((newGUIElement != null) &&214 ((identicalParentGUIElement == null) ||215 (!newGUIElement.equals(identicalParentGUIElement))))216 {217 tasksToBeAdded.add(index, mTaskTreeNodeFactory.createNewInteractionTask218 (newGUIElement, new FocusReceived()));219 newGUIElement = newGUIElement.getParent();220 }221 222 // this part ensures, that the original focus reception, if any, is preserved as is.223 boolean taskAlreadyHandled = false;224 if (interactionTask.getInteraction() instanceof FocusReceived)225 {226 if (tasksToBeAdded.size() > 0)227 {228 tasksToBeAdded.set(tasksToBeAdded.size() - 1, interactionTask);229 }230 //else231 //{232 // in this case, we already have focus on the element to which the focus shall be changed.233 // therefore, we discard the new focus change on the same element.234 //}235 236 taskAlreadyHandled = true;237 }238 239 // now that all tasks are determined, add them to the sequence240 for (InteractionTask task : tasksToBeAdded)241 {242 addTaskToSequence(task);243 }244 245 mCurrentGUIElement = interactionTask.getGUIElement();246 247 return taskAlreadyHandled;248 }*/249 250 //-----------------------------------------------------------------------------------------------251 /**252 *253 */254 //-----------------------------------------------------------------------------------------------255 private void addTaskToSequence(TaskTreeNode task, GUIElement currentKeyboardFocusGUIElement)256 {257 mTaskTreeBuilder.addChild(mRootSequence, task);258 259 if (--mInteractionsTillRuleApplication == 0)260 {261 mInteractionsTillRuleApplication = MAX_INTERACTIONS_TILL_RULE_APPLICATION;262 263 LOG.info("applying rules temporal relationship generation rules");264 ComponentManager.getTemporalRelationshipRuleManager().applyRules265 (mRootSequence, mTaskTreeBuilder, mTaskTreeNodeFactory, false);266 }267 }268 132 269 133 }
Note: See TracChangeset
for help on using the changeset viewer.