Changeset 835 for trunk/quest-plugin-jfc/src/main/java/de/ugoe/cs/quest/plugin/jfc/guimodel/JFCGUIElementSpec.java
- Timestamp:
- 09/20/12 10:36:09 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-plugin-jfc/src/main/java/de/ugoe/cs/quest/plugin/jfc/guimodel/JFCGUIElementSpec.java
r832 r835 1 1 2 package de.ugoe.cs.quest.plugin.jfc.guimodel; 2 3 … … 6 7 import org.apache.commons.collections15.CollectionUtils; 7 8 9 import de.ugoe.cs.quest.eventcore.guimodel.IGUIElement; 8 10 import de.ugoe.cs.quest.eventcore.guimodel.IGUIElementSpec; 9 11 10 12 /** 11 13 * <p> 12 * TODO comment14 * Implements the specification of {@link IGUIElement} for {@link JFCGUIElement}s. 13 15 * </p> 14 16 * 15 * @version $Revision: $ $Date: 17.08.2012$16 * @author 2012, last modified by $Author: pharms$17 * @version 1.0 18 * @author Patrick Harms 17 19 */ 18 20 public class JFCGUIElementSpec implements IGUIElementSpec { 19 21 20 /** */ 22 /** 23 * <p> 24 * Id for object serialization. 25 * </p> 26 */ 21 27 private static final long serialVersionUID = 1L; 22 28 23 29 /** 24 30 * <p> 25 * current name of the GUI element31 * Current name of the GUI element 26 32 * </p> 27 33 */ … … 30 36 /** 31 37 * <p> 32 * previous names of the GUI element as it may have changed over time.38 * Previous names of the GUI element as it may have changed over time. 33 39 * </p> 34 40 */ 35 41 private List<String> formerNames = new ArrayList<String>(); 36 42 37 /** */ 43 /** 44 * <p> 45 * Type of the GUI element, i.e., its Java class. 46 * </p> 47 */ 38 48 private String type = null; 39 40 /** */ 49 50 /** 51 * <p> 52 * Icon associated with the GUI element. 53 * </p> 54 */ 41 55 private String icon = null; 42 43 /** */ 56 57 /** 58 * <p> 59 * Index of the GUI element in its parent element. 60 * </p> 61 */ 44 62 private int index = -1; 45 46 /** 47 * <p> 48 * hash code of the window element. Used as unique identifier during its existence.63 64 /** 65 * <p> 66 * Hash code of the window element. Used as unique identifier during its existence. 49 67 * </p> 50 68 */ … … 53 71 /** 54 72 * <p> 55 * previous handles of the window as the window may have been destroyed and recreated73 * Previous hashes of the window as the window may have been destroyed and recreated. 56 74 * </p> 57 75 */ 58 76 private List<Integer> formerElementHashes = new ArrayList<Integer>(); 59 77 60 /* (non-Javadoc) 61 * @see de.ugoe.cs.quest.eventcore.guimodel.IGUIElementSpec#getSecificationSimilarity(IGUIElementSpec) 78 /* 79 * (non-Javadoc) 80 * 81 * @see 82 * de.ugoe.cs.quest.eventcore.guimodel.IGUIElementSpec#getSecificationSimilarity(IGUIElementSpec 83 * ) 62 84 */ 63 85 @Override 64 86 public boolean getSimilarity(IGUIElementSpec other) { 65 if (this == other) 66 { 67 return true; 68 } 69 70 if (!(other instanceof JFCGUIElementSpec)) 71 { 87 if (this == other) { 88 return true; 89 } 90 91 if (!(other instanceof JFCGUIElementSpec)) { 72 92 return false; 73 93 } 74 94 75 95 JFCGUIElementSpec otherSpec = (JFCGUIElementSpec) other; 76 96 77 97 if ((type != otherSpec.type) && ((type != null) && (!type.equals(otherSpec.type)))) { 78 98 return false; … … 89 109 // a new element is added or another one is removed. If the element hash or the name stay 90 110 // the same, then similarity is given. Therefore these are the first two comparisons 91 111 92 112 if (elementHash == otherSpec.elementHash) { 93 113 return true; 94 114 } 95 115 96 116 if ((name != null) && (name.equals(otherSpec.name))) { 97 117 return true; 98 118 } 99 100 if ((((name == null) && (otherSpec.name == null)) || 101 (("".equals(name)) && ("".equals(otherSpec.name)))) && 102 (formerNames.size() == 0) && (otherSpec.formerNames.size() == 0)) 119 120 if ((((name == null) && (otherSpec.name == null)) || (("".equals(name)) && ("" 121 .equals(otherSpec.name)))) && 122 (formerNames.size() == 0) && 123 (otherSpec.formerNames.size() == 0)) 103 124 { 104 125 return true; 105 126 } 106 127 107 128 // if the id and the name did not stay the same, then the name should be checked first. 108 129 // One of all known names of one of the specs must be equal to one of the known names of the … … 117 138 return index == otherSpec.index; 118 139 } 119 140 120 141 if (CollectionUtils.containsAny(formerNames, otherSpec.formerNames)) { 121 142 return index == otherSpec.index; 122 143 } 123 144 124 145 // ok. Even the names do not match. This is usually a clear indication, that the elements 125 146 // are distinct. However, we check, if the former ids matched. This is very unlikely … … 135 156 return index == otherSpec.index; 136 157 } 137 158 138 159 if (CollectionUtils.containsAny(formerElementHashes, otherSpec.formerElementHashes)) { 139 160 return index == otherSpec.index; 140 161 } 141 162 142 163 // now we can be really sure, that the GUI elements differ 143 164 144 165 return false; 145 166 } 146 167 147 /* (non-Javadoc) 168 /* 169 * (non-Javadoc) 170 * 148 171 * @see de.ugoe.cs.quest.eventcore.guimodel.IGUIElementSpec#equals(IGUIElementSpec) 149 172 */ 150 173 @Override 151 174 public boolean equals(Object other) { 152 if (this == other) 153 { 154 return true; 155 } 156 157 if (!(other instanceof JFCGUIElementSpec)) 158 { 175 if (this == other) { 176 return true; 177 } 178 179 if (!(other instanceof JFCGUIElementSpec)) { 159 180 return false; 160 181 } 161 182 162 183 JFCGUIElementSpec otherSpec = (JFCGUIElementSpec) other; 163 164 return 165 ((name == otherSpec.name) || ((name != null) && (name.equals(otherSpec.name)))) && 184 185 return ((name == otherSpec.name) || ((name != null) && (name.equals(otherSpec.name)))) && 166 186 ((type == otherSpec.type) || ((type != null) && (type.equals(otherSpec.type)))) && 167 187 ((icon == otherSpec.icon) || ((icon != null) && (icon.equals(otherSpec.icon)))) && … … 169 189 } 170 190 171 /* (non-Javadoc) 191 /* 192 * (non-Javadoc) 193 * 172 194 * @see java.lang.Object#hashCode() 173 195 */ … … 178 200 179 201 /** 202 * <p> 203 * Returns the name of the specified GUI element. 204 * </p> 205 * 180 206 * @return the name 181 207 */ 182 208 public String getName() { 183 209 StringBuffer names = new StringBuffer(); 184 210 185 211 if (name != null) { 186 212 names.append('"'); … … 191 217 names.append("NOT_SET"); 192 218 } 193 219 194 220 if (formerNames.size() > 0) { 195 221 196 222 names.append(" (aka "); 197 223 198 224 for (int i = 0; i < formerNames.size(); i++) { 199 225 if (i > 0) { … … 205 231 names.append('"'); 206 232 } 207 233 208 234 names.append(")"); 209 235 } 210 236 211 237 return names.toString(); 212 238 } 213 239 214 240 /** 241 * <p> 242 * Returns the title of the specified GUI element. 243 * </p> 244 * 215 245 * @return the title 216 246 */ … … 220 250 221 251 /** 252 * <p> 253 * Returns the icon associated with the specified GUI element. 254 * </p> 255 * 222 256 * @return the icon 223 257 */ … … 227 261 228 262 /** 263 * <p> 264 * Returns the index of the specified GUI element in its parent element. 265 * </p> 266 * 229 267 * @return the index 230 268 */ … … 234 272 235 273 /** 274 * <p> 275 * Returns the object hash of the specified GUI element. 276 * </p> 277 * 236 278 * @return the elementHash 237 279 */ … … 241 283 242 284 /** 243 * @param name the name to set 285 * <p> 286 * Sets the name of the specified GUI element. 287 * </p> 288 * 289 * @param name 290 * the name 244 291 */ 245 292 public void setName(String newName) { 246 if ((this.name != null) && 247 (!this.name.equals(newName)) && 293 if ((this.name != null) && (!this.name.equals(newName)) && 248 294 (!this.formerNames.contains(this.name))) 249 295 { 250 296 this.formerNames.add(this.name); 251 297 } 252 298 253 299 this.name = newName; 254 300 } 255 301 256 302 /** 257 * @param title the title to set 303 * <p> 304 * Sets the type of the specified GUI element. 305 * </p> 306 * 307 * @param title 308 * the title 258 309 */ 259 310 public void setType(String type) { … … 262 313 263 314 /** 264 * @param icon the icon to set 315 * <p> 316 * Sets the icon associated with the specified GUI element. 317 * </p> 318 * 319 * @param icon 320 * the icon 265 321 */ 266 322 public void setIcon(String icon) { … … 269 325 270 326 /** 271 * @param index the index to set 327 * <p> 328 * Sets the index in its parent element of the specified GUI element. 329 * </p> 330 * 331 * @param index 332 * the index 272 333 */ 273 334 public void setIndex(int index) { … … 276 337 277 338 /** 278 * @param elementHash the elementHash to set 339 * <p> 340 * Sets the object hash of the specified GUI element. 341 * </p> 342 * 343 * @param elementHash 344 * the elementHash 279 345 */ 280 346 public void setElementHash(int newElementHash) { 281 if ((this.elementHash > -1) && 282 !this.formerElementHashes.contains(this.elementHash)) 283 { 347 if ((this.elementHash > -1) && !this.formerElementHashes.contains(this.elementHash)) { 284 348 this.formerElementHashes.add(this.elementHash); 285 349 } 286 350 287 351 this.elementHash = newElementHash; 288 352 } 289 290 /** 291 * <p> 292 * TODO: comment293 * </p> 294 * 353 354 /** 355 * <p> 356 * Updates the specification with another specification. 357 * </p> 358 * 295 359 * @param furtherSpec 360 * specification used to update the current specification 296 361 */ 297 362 void update(JFCGUIElementSpec other) { … … 309 374 } 310 375 311 if ((name != other.name) && (name != null) && (!name.equals(other.name))) 312 { 376 if ((name != other.name) && (name != null) && (!name.equals(other.name))) { 313 377 setName(other.name); 314 378 } … … 316 380 } 317 381 382 /* 383 * (non-Javadoc) 384 * 385 * @see java.lang.Object#toString() 386 */ 318 387 public String toString() { 319 return "[" + getName() + ";\"" + type + "\";\"" + icon + "\";" + index + ";" + 320 elementHash +"]";388 return "[" + getName() + ";\"" + type + "\";\"" + icon + "\";" + index + ";" + elementHash + 389 "]"; 321 390 } 322 391
Note: See TracChangeset
for help on using the changeset viewer.