Changeset 714 for trunk/quest-plugin-jfc/src/main/java/de/ugoe
- Timestamp:
- 08/30/12 14:08:12 (12 years ago)
- Location:
- trunk/quest-plugin-jfc/src/main/java/de/ugoe/cs/quest/plugin/jfc/guimodel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-plugin-jfc/src/main/java/de/ugoe/cs/quest/plugin/jfc/guimodel/JFCGUIElement.java
r681 r714 69 69 * @return the hashCode 70 70 */ 71 StringgetElementHash() {71 int getElementHash() { 72 72 return specification.getElementHash(); 73 73 } … … 80 80 @Override 81 81 public void updateSpecification(IGUIElementSpec updateSpecification) { 82 if( updateSpecification instanceof JFCGUIElementSpec ) { 83 specification.setName(((JFCGUIElementSpec) updateSpecification).getName()); 84 specification.setElementHash(((JFCGUIElementSpec) updateSpecification).getElementHash()); 82 if (updateSpecification instanceof JFCGUIElementSpec) { 83 specification.update(((JFCGUIElementSpec) updateSpecification)); 85 84 } 86 85 } … … 107 106 @Override 108 107 public String toString() { 109 String str = getElementDescriptor() + "(" + getName() + ", " + getElementHash() + "," + getIcon() + "," + getIndex() +")"; 108 String str = getElementDescriptor() + "(" + getName() + "," + getElementHash() + "," + 109 getIcon() + "," + getIndex() +")"; 110 110 return str; 111 111 } -
trunk/quest-plugin-jfc/src/main/java/de/ugoe/cs/quest/plugin/jfc/guimodel/JFCGUIElementSpec.java
r655 r714 1 1 package de.ugoe.cs.quest.plugin.jfc.guimodel; 2 2 3 import java.util. LinkedList;3 import java.util.ArrayList; 4 4 import java.util.List; 5 5 … … 18 18 public class JFCGUIElementSpec implements IGUIElementSpec { 19 19 20 /** */ 21 private List<String> name = new LinkedList<String>(); 22 20 /** 21 * <p> 22 * current name of the GUI element 23 * </p> 24 */ 25 private String name; 26 27 /** 28 * <p> 29 * previous names of the GUI element as it may have changed over time. 30 * </p> 31 */ 32 private List<String> formerNames = new ArrayList<String>(); 33 23 34 /** */ 24 35 private String type = null; … … 30 41 private int index = -1; 31 42 32 /** */ 33 private List<String> elementHash = new LinkedList<String>(); 34 43 /** 44 * <p> 45 * hash code of the window elemt. Used as unique identifier during its existence. 46 * </p> 47 */ 48 private int elementHash = -1; 49 50 /** 51 * <p> 52 * previous handles of the window as the window may have been destroyed and recreated 53 * </p> 54 */ 55 private List<Integer> formerElementHashes = new ArrayList<Integer>(); 56 35 57 /* (non-Javadoc) 36 58 * @see de.ugoe.cs.quest.eventcore.guimodel.IGUIElementSpec#getSecificationSimilarity(IGUIElementSpec) … … 50 72 JFCGUIElementSpec otherSpec = (JFCGUIElementSpec) other; 51 73 52 boolean retVal = false; 53 54 boolean titleEqual = CollectionUtils.containsAny(name, otherSpec.name); 55 boolean hashEqual = CollectionUtils.containsAny(elementHash, otherSpec.elementHash); 56 57 if (type.equals("Class") ) { 58 retVal = type.equals(otherSpec.type) && (titleEqual || hashEqual); 59 } 60 else { 61 retVal = type.equals(otherSpec.type) && index==otherSpec.index && 62 (titleEqual || hashEqual); 63 } 64 65 return retVal; 74 if ((type != otherSpec.type) && ((type != null) && (!type.equals(otherSpec.type)))) { 75 return false; 76 } 77 78 if ((icon != otherSpec.icon) && ((icon != null) && (!icon.equals(otherSpec.icon)))) { 79 return false; 80 } 81 82 // up to now, we compared, if the basics match. Now lets compare the id, the name and the 83 // index. All may change. The name may be reset (e.g. the title of a frame using the 84 // asterisk in the case data was changed). The id may change if e.g. a dialog is closed 85 // and reopend, i.e. a new instance is created. The index may change, if later in a panel 86 // a new element is added or another one is removed. If the element hash or the name stay 87 // the same, then similarity is given. Therefore these are the first two comparisons 88 89 if (elementHash == otherSpec.elementHash) { 90 return true; 91 } 92 93 if ((name != null) && (name.equals(otherSpec.name))) { 94 return true; 95 } 96 97 if ((((name == null) && (otherSpec.name == null)) || 98 (("".equals(name)) && ("".equals(otherSpec.name)))) && 99 (formerNames.size() == 0) && (otherSpec.formerNames.size() == 0)) 100 { 101 return true; 102 } 103 104 // if the id and the name did not stay the same, then the name should be checked first. 105 // One of all known names of one of the specs must be equal to one of the known names of the 106 // respective other spec for similarity. Furthermore, if this is given, the index should 107 // have stayed the same. 108 109 if ((otherSpec.name != null) && formerNames.contains(otherSpec.name)) { 110 return index == otherSpec.index; 111 } 112 113 if ((name != null) && otherSpec.formerNames.contains(name)) { 114 return index == otherSpec.index; 115 } 116 117 if (CollectionUtils.containsAny(formerNames, otherSpec.formerNames)) { 118 return index == otherSpec.index; 119 } 120 121 // ok. Even the names do not match. This is usually a clear indication, that the elements 122 // are distinct. However, we check, if the former ids matched. This is very unlikely 123 // to happen. But it may occur, if a GUI element does not have a name or its name stays 124 // the empty string and if this GUI element is created, destroyed, and created again. 125 // Again we are restrictive and request the index to be equal as well. 126 127 if (formerElementHashes.contains(otherSpec.elementHash)) { 128 return index == otherSpec.index; 129 } 130 131 if (otherSpec.formerElementHashes.contains(elementHash)) { 132 return index == otherSpec.index; 133 } 134 135 if (CollectionUtils.containsAny(formerElementHashes, otherSpec.formerElementHashes)) { 136 return index == otherSpec.index; 137 } 138 139 // now we can be really sure, that the GUI elements differ 140 141 return false; 66 142 } 67 143 … … 102 178 */ 103 179 public String getName() { 104 // TODO for now always returns first matched name 105 if( name.isEmpty() ) { 106 return null; 107 } 108 return name.get(0); 180 StringBuffer names = new StringBuffer(); 181 182 if (name != null) { 183 names.append('"'); 184 names.append(name); 185 names.append('"'); 186 } 187 else { 188 names.append("NOT_SET"); 189 } 190 191 if (formerNames.size() > 0) { 192 193 names.append(" (aka "); 194 195 for (int i = 0; i < formerNames.size(); i++) { 196 if (i > 0) { 197 names.append("/"); 198 } 199 200 names.append('"'); 201 names.append(formerNames.get(i)); 202 names.append('"'); 203 } 204 205 names.append(")"); 206 } 207 208 return names.toString(); 109 209 } 110 210 … … 133 233 * @return the elementHash 134 234 */ 135 public String getElementHash() { 136 // TODO for now always returns the first hash value 137 if( elementHash.isEmpty() ) { 138 return null; 139 } 140 return elementHash.get(0); 235 public int getElementHash() { 236 return elementHash; 141 237 } 142 238 … … 144 240 * @param name the name to set 145 241 */ 146 public void setName(String name) { 147 if( !this.name.contains(name) && name!=null ) { 148 this.name.add(name); 149 } 242 public void setName(String newName) { 243 if ((this.name != null) && 244 (!this.name.equals(newName)) && 245 (!this.formerNames.contains(this.name))) 246 { 247 this.formerNames.add(this.name); 248 } 249 250 this.name = newName; 150 251 } 151 252 … … 174 275 * @param elementHash the elementHash to set 175 276 */ 176 public void setElementHash(String elementHash) { 177 if( !this.elementHash.contains(elementHash) ) { 178 this.elementHash.add(elementHash); 179 } 277 public void setElementHash(int newElementHash) { 278 if ((this.elementHash > -1) && 279 !this.formerElementHashes.contains(this.elementHash)) 280 { 281 this.formerElementHashes.add(this.elementHash); 282 } 283 284 this.elementHash = newElementHash; 180 285 } 181 286 287 /** 288 * <p> 289 * TODO: comment 290 * </p> 291 * 292 * @param furtherSpec 293 */ 294 void update(JFCGUIElementSpec other) { 295 if (other != this) { 296 for (int formerElementHash : other.formerElementHashes) { 297 setElementHash(formerElementHash); 298 } 299 300 if (elementHash != other.elementHash) { 301 elementHash = other.elementHash; 302 } 303 304 for (String formerName : other.formerNames) { 305 setName(formerName); 306 } 307 308 if ((name != other.name) && (name != null) && (!name.equals(other.name))) 309 { 310 setName(other.name); 311 } 312 } 313 } 314 182 315 public String toString() { 183 return "" + name.toString() + "," + elementHash.toString() + "," + type + "," + "icon"; 316 return "[" + getName() + ";\"" + type + "\";\"" + icon + "\";" + index + ";" + 317 elementHash + "]"; 184 318 } 185 319
Note: See TracChangeset
for help on using the changeset viewer.