- Timestamp:
- 08/23/12 10:42:41 (12 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-core-events/src/main/java/de/ugoe/cs/quest/eventcore/guimodel/GUIModel.java
r576 r589 8 8 9 9 import java.util.ArrayList; 10 import java.util.LinkedList; 10 11 import java.util.List; 11 12 … … 106 107 IGUIElementSpec specToIntegrateElementFor = remainingPath.remove(0); 107 108 108 List<TreeNode> matchingChildren = new ArrayList<TreeNode>(); 109 int maximumSimilarity = 0; 109 List<TreeNode> matchingChildren = new LinkedList<TreeNode>(); 110 110 111 111 if (parentNode.children != null) { 112 112 for (TreeNode child : parentNode.children) { 113 int similarityLevel = getSimilarityLevel 114 (specToIntegrateElementFor, child.guiElement.getSpecification()); 115 116 if (similarityLevel >= maximumSimilarity) { 117 if (maximumSimilarity == 100) { 118 throw new GUIModelException 119 ("several children of gui element " + parentNode.guiElement + 120 " pretend to fully match specification " + specToIntegrateElementFor); 121 } 122 123 if (maximumSimilarity != similarityLevel) { 124 matchingChildren.clear(); 125 maximumSimilarity = similarityLevel; 126 } 127 113 if( specToIntegrateElementFor.getSimilarity(child.guiElement.getSpecification())) { 128 114 matchingChildren.add(child); 129 115 } 130 116 } 131 }132 133 // we do not see something as matching if the similarity level is below 80%134 if (maximumSimilarity < 80) {135 matchingChildren.clear();136 117 } 137 118 … … 150 131 151 132 if (remainingPath.size() > 0) { 133 // TODO update spec here matchingChildren.get(0).guiElement 134 matchingChildren.get(0).guiElement.updateSpecification(specToIntegrateElementFor); 152 135 return integratePath(matchingChildren.get(0), remainingPath, guiElementFactory); 153 136 } 154 137 else { 155 138 return matchingChildren.get(0).guiElement; 156 }157 }158 159 /**160 * <p>161 * TODO: comment162 * </p>163 *164 * @param spec1165 * @param spec2166 * @return167 * @throws GUIModelException168 */169 private int getSimilarityLevel(IGUIElementSpec spec1, IGUIElementSpec spec2)170 throws GUIModelException171 {172 if (spec1 == spec2) {173 return 100;174 }175 else if (spec1 != null) {176 int level = spec1.getSimilarity(spec2);177 178 if ((level < 0) || (100 < level)) {179 throw new GUIModelException("invalid tree node similarity provided (" + level +180 "). Must be between 0 and 100.");181 }182 183 return level;184 }185 else {186 return 0;187 139 } 188 140 } -
trunk/quest-core-events/src/main/java/de/ugoe/cs/quest/eventcore/guimodel/IGUIElement.java
r576 r589 32 32 */ 33 33 public int hashCode(); 34 35 public void updateSpecification(IGUIElementSpec specToIntegrateElementFor); 34 36 } -
trunk/quest-core-events/src/main/java/de/ugoe/cs/quest/eventcore/guimodel/IGUIElementSpec.java
r576 r589 33 33 * @return 34 34 */ 35 public intgetSimilarity(IGUIElementSpec otherParameters);35 public boolean getSimilarity(IGUIElementSpec otherParameters); 36 36 37 37 /** -
trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/testutils/DummyGUIElement.java
r577 r589 9 9 import de.ugoe.cs.quest.eventcore.guimodel.AbstractDefaultGUIElement; 10 10 import de.ugoe.cs.quest.eventcore.guimodel.IGUIElement; 11 import de.ugoe.cs.quest.eventcore.guimodel.IGUIElementSpec; 11 12 12 13 /** … … 59 60 } 60 61 62 @Override 63 public void updateSpecification(IGUIElementSpec specToIntegrateElementFor) { 64 // dummy 65 } 66 61 67 } -
trunk/quest-plugin-jfc/src/main/java/de/ugoe/cs/quest/plugin/jfc/guimodel/JFCGUIElement.java
r588 r589 8 8 9 9 import de.ugoe.cs.quest.eventcore.guimodel.AbstractDefaultGUIElement; 10 import de.ugoe.cs.quest.eventcore.guimodel.IGUIElementSpec; 10 11 11 12 /** … … 79 80 } 80 81 82 @Override 83 public void updateSpecification(IGUIElementSpec updateSpecification) { 84 if( updateSpecification instanceof JFCGUIElementSpec ) { 85 specification.setName(((JFCGUIElementSpec) updateSpecification).getName()); 86 specification.setElementHash(((JFCGUIElementSpec) updateSpecification).getElementHash()); 87 } 88 } 89 81 90 } -
trunk/quest-plugin-jfc/src/main/java/de/ugoe/cs/quest/plugin/jfc/guimodel/JFCGUIElementSpec.java
r588 r589 5 5 // Copyright : Patrick Harms, 2012 6 6 package de.ugoe.cs.quest.plugin.jfc.guimodel; 7 8 import java.util.LinkedList; 9 import java.util.List; 10 11 import org.apache.commons.collections15.CollectionUtils; 7 12 8 13 import de.ugoe.cs.quest.eventcore.guimodel.IGUIElementSpec; … … 19 24 20 25 /** */ 21 private String name = null;26 private List<String> name = new LinkedList<String>(); 22 27 23 28 /** */ … … 31 36 32 37 /** */ 33 private String elementHash = null;38 private List<String> elementHash = new LinkedList<String>(); 34 39 35 40 /* (non-Javadoc) … … 37 42 */ 38 43 @Override 39 public intgetSimilarity(IGUIElementSpec other) {44 public boolean getSimilarity(IGUIElementSpec other) { 40 45 if (this == other) 41 46 { 42 return 100;47 return true; 43 48 } 44 49 45 50 if (!(other instanceof JFCGUIElementSpec)) 46 51 { 47 return 0;52 return false; 48 53 } 49 54 50 55 JFCGUIElementSpec otherSpec = (JFCGUIElementSpec) other; 51 int result = 0; 52 53 if ((type == otherSpec.type) || ((type != null) && (type.equals(otherSpec.type)))) { 54 result += 50; 55 } 56 57 if ((icon == otherSpec.icon) || ((icon != null) && (icon.equals(otherSpec.icon)))) { 58 result += 10; 59 } 60 61 if (index == otherSpec.index) { 62 result += 10; 63 } 64 65 if ((name == otherSpec.name) || ((name != null) && (name.equals(otherSpec.name)))) { 66 result += 15; 67 } 68 69 if (elementHash == otherSpec.elementHash || ((elementHash!=null) && elementHash.equals(otherSpec.elementHash))) { 70 result += 15; 56 57 boolean retVal = false; 58 59 boolean titleEqual = CollectionUtils.containsAny(name, otherSpec.name); 60 boolean hashEqual = CollectionUtils.containsAny(elementHash, otherSpec.elementHash); 61 62 if( type.equals("Class") ) { 63 retVal = type.equals(otherSpec.type) && (titleEqual || hashEqual); 64 } else { 65 retVal = type.equals(otherSpec.type) && index==otherSpec.index && (titleEqual || hashEqual); 71 66 } 72 67 73 return re sult;68 return retVal; 74 69 } 75 70 … … 102 97 */ 103 98 public String getName() { 104 return name; 99 // TODO for now always returns first matched name 100 if( name.isEmpty() ) { 101 return null; 102 } 103 return name.get(0); 105 104 } 106 105 … … 130 129 */ 131 130 public String getElementHash() { 132 return elementHash; 131 // TODO for now always returns the first hash value 132 if( elementHash.isEmpty() ) { 133 return null; 134 } 135 return elementHash.get(0); 133 136 } 134 137 … … 137 140 */ 138 141 public void setName(String name) { 139 this.name = name; 142 if( !this.name.contains(name) && name!=null ) { 143 this.name.add(name); 144 } 140 145 } 141 146 … … 165 170 */ 166 171 public void setElementHash(String elementHash) { 167 this.elementHash = elementHash; 172 if( !this.elementHash.contains(elementHash) ) { 173 this.elementHash.add(elementHash); 174 } 168 175 } 169 176
Note: See TracChangeset
for help on using the changeset viewer.