1 | //------------------------------------------------------------------------------------------------- |
---|
2 | // Module : $RCSfile: DefaultSequenceDetectionRule.java,v $ |
---|
3 | // Version : $Revision: 0.0 $ $Author: patrick $ $Date: 18.03.2012 $ |
---|
4 | // Project : TaskTreeCreator |
---|
5 | // Creation : 2012 by patrick |
---|
6 | // Copyright : Patrick Harms, 2012 |
---|
7 | //------------------------------------------------------------------------------------------------- |
---|
8 | package de.ugoe.cs.quest.tasktrees.temporalrelation; |
---|
9 | |
---|
10 | import de.ugoe.cs.quest.eventcore.guimodel.GUIElement; |
---|
11 | import de.ugoe.cs.quest.eventcore.userinteraction.MouseButtonDown; |
---|
12 | import de.ugoe.cs.quest.eventcore.userinteraction.MouseButtonInteraction; |
---|
13 | import de.ugoe.cs.quest.eventcore.userinteraction.MouseButtonUp; |
---|
14 | import de.ugoe.cs.quest.eventcore.userinteraction.MouseClick; |
---|
15 | import de.ugoe.cs.quest.tasktrees.treeifc.InteractionTask; |
---|
16 | import de.ugoe.cs.quest.tasktrees.treeifc.Sequence; |
---|
17 | import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeBuilder; |
---|
18 | import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNode; |
---|
19 | import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNodeFactory; |
---|
20 | |
---|
21 | //------------------------------------------------------------------------------------------------- |
---|
22 | /** |
---|
23 | * TODO comment |
---|
24 | * |
---|
25 | * @version $Revision: $ $Date: 18.03.2012$ |
---|
26 | * @author 2012, last modified by $Author: patrick$ |
---|
27 | */ |
---|
28 | //------------------------------------------------------------------------------------------------- |
---|
29 | public class DefaultMouseClickReductionRule implements TemporalRelationshipRule |
---|
30 | { |
---|
31 | |
---|
32 | //----------------------------------------------------------------------------------------------- |
---|
33 | /* (non-Javadoc) |
---|
34 | * @see de.ugoe.cs.tasktree.temporalrelation.TemporalRelationshipRule#apply(TaskTreeNode, TaskTreeBuilder, TaskTreeNodeFactory) |
---|
35 | */ |
---|
36 | //----------------------------------------------------------------------------------------------- |
---|
37 | @Override |
---|
38 | public RuleApplicationResult apply(TaskTreeNode parent, |
---|
39 | TaskTreeBuilder builder, |
---|
40 | TaskTreeNodeFactory nodeFactory, |
---|
41 | boolean finalize) |
---|
42 | { |
---|
43 | if (!(parent instanceof Sequence)) |
---|
44 | { |
---|
45 | return null; |
---|
46 | } |
---|
47 | |
---|
48 | RuleApplicationResult result = new RuleApplicationResult(); |
---|
49 | |
---|
50 | int index = 0; |
---|
51 | while (index < parent.getChildren().size() - 2) // -2 because we don't need to go to the end |
---|
52 | { |
---|
53 | if (mouseClickSequenceFound(parent.getChildren().get(index), |
---|
54 | parent.getChildren().get(index + 1), |
---|
55 | parent.getChildren().get(index + 2))) |
---|
56 | { |
---|
57 | builder.removeChild((Sequence) parent, index); |
---|
58 | builder.removeChild((Sequence) parent, index); |
---|
59 | result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); |
---|
60 | return result; |
---|
61 | } |
---|
62 | else if ((parent.getChildren().get(index) instanceof Sequence) && |
---|
63 | (parent.getChildren().get(index).getChildren().size() == 2) && |
---|
64 | (mouseClickSequenceFound(parent.getChildren().get(index).getChildren().get(0), |
---|
65 | parent.getChildren().get(index).getChildren().get(1), |
---|
66 | parent.getChildren().get(index + 1)))) |
---|
67 | { |
---|
68 | builder.removeChild((Sequence) parent, index); |
---|
69 | result.setRuleApplicationStatus(RuleApplicationStatus.RULE_APPLICATION_FINISHED); |
---|
70 | return result; |
---|
71 | } |
---|
72 | |
---|
73 | index++; |
---|
74 | } |
---|
75 | |
---|
76 | return result; |
---|
77 | } |
---|
78 | |
---|
79 | //----------------------------------------------------------------------------------------------- |
---|
80 | /** |
---|
81 | * |
---|
82 | */ |
---|
83 | //----------------------------------------------------------------------------------------------- |
---|
84 | private boolean mouseClickSequenceFound(TaskTreeNode mouseButtonDown, |
---|
85 | TaskTreeNode mouseButtonUp, |
---|
86 | TaskTreeNode mouseClick) |
---|
87 | { |
---|
88 | // check the first in a row of three for validity |
---|
89 | if (!(mouseButtonDown instanceof InteractionTask)) |
---|
90 | { |
---|
91 | return false; |
---|
92 | } |
---|
93 | |
---|
94 | GUIElement guiElement = ((InteractionTask) mouseButtonDown).getGUIElement(); |
---|
95 | |
---|
96 | if (!(((InteractionTask) mouseButtonDown).getInteraction() instanceof MouseButtonDown)) |
---|
97 | { |
---|
98 | return false; |
---|
99 | } |
---|
100 | |
---|
101 | MouseButtonInteraction.Button button = |
---|
102 | ((MouseButtonDown) ((InteractionTask) mouseButtonDown).getInteraction()).getButton(); |
---|
103 | |
---|
104 | |
---|
105 | // check the second node for validity |
---|
106 | if (!(mouseButtonUp instanceof InteractionTask)) |
---|
107 | { |
---|
108 | return false; |
---|
109 | } |
---|
110 | |
---|
111 | if (!guiElement.equals(((InteractionTask) mouseButtonUp).getGUIElement())) |
---|
112 | { |
---|
113 | return false; |
---|
114 | } |
---|
115 | |
---|
116 | if (!(((InteractionTask) mouseButtonUp).getInteraction() instanceof MouseButtonUp)) |
---|
117 | { |
---|
118 | return false; |
---|
119 | } |
---|
120 | |
---|
121 | if (!button.equals |
---|
122 | (((MouseButtonUp) ((InteractionTask) mouseButtonUp).getInteraction()).getButton())) |
---|
123 | { |
---|
124 | return false; |
---|
125 | } |
---|
126 | |
---|
127 | |
---|
128 | // check the third node for validity |
---|
129 | if (!(mouseClick instanceof InteractionTask)) |
---|
130 | { |
---|
131 | return false; |
---|
132 | } |
---|
133 | |
---|
134 | if (!guiElement.equals(((InteractionTask) mouseClick).getGUIElement())) |
---|
135 | { |
---|
136 | return false; |
---|
137 | } |
---|
138 | |
---|
139 | if (!(((InteractionTask) mouseClick).getInteraction() instanceof MouseClick)) |
---|
140 | { |
---|
141 | return false; |
---|
142 | } |
---|
143 | |
---|
144 | if (!button.equals(((MouseClick) ((InteractionTask) mouseClick).getInteraction()).getButton())) |
---|
145 | { |
---|
146 | return false; |
---|
147 | } |
---|
148 | |
---|
149 | return true; |
---|
150 | } |
---|
151 | |
---|
152 | } |
---|