Index: /trunk/quest-plugin-jfc/src/main/java/de/ugoe/cs/quest/plugin/jfc/guimodel/JFCGUIElement.java
===================================================================
--- /trunk/quest-plugin-jfc/src/main/java/de/ugoe/cs/quest/plugin/jfc/guimodel/JFCGUIElement.java	(revision 713)
+++ /trunk/quest-plugin-jfc/src/main/java/de/ugoe/cs/quest/plugin/jfc/guimodel/JFCGUIElement.java	(revision 714)
@@ -69,5 +69,5 @@
      * @return the hashCode
      */
-    String getElementHash() {
+    int getElementHash() {
         return specification.getElementHash();
     }
@@ -80,7 +80,6 @@
     @Override
     public void updateSpecification(IGUIElementSpec updateSpecification) {
-        if( updateSpecification instanceof JFCGUIElementSpec ) {
-            specification.setName(((JFCGUIElementSpec) updateSpecification).getName());
-            specification.setElementHash(((JFCGUIElementSpec) updateSpecification).getElementHash());
+        if (updateSpecification instanceof JFCGUIElementSpec) {
+            specification.update(((JFCGUIElementSpec) updateSpecification));
         }
     }
@@ -107,5 +106,6 @@
     @Override
     public String toString() {
-        String str = getElementDescriptor() + "(" + getName() + ", " + getElementHash() + "," + getIcon() + "," + getIndex() +")";
+        String str = getElementDescriptor() + "(" + getName() + "," + getElementHash() + "," +
+            getIcon() + "," + getIndex() +")";
         return str;
     }
Index: /trunk/quest-plugin-jfc/src/main/java/de/ugoe/cs/quest/plugin/jfc/guimodel/JFCGUIElementSpec.java
===================================================================
--- /trunk/quest-plugin-jfc/src/main/java/de/ugoe/cs/quest/plugin/jfc/guimodel/JFCGUIElementSpec.java	(revision 713)
+++ /trunk/quest-plugin-jfc/src/main/java/de/ugoe/cs/quest/plugin/jfc/guimodel/JFCGUIElementSpec.java	(revision 714)
@@ -1,5 +1,5 @@
 package de.ugoe.cs.quest.plugin.jfc.guimodel;
 
-import java.util.LinkedList;
+import java.util.ArrayList;
 import java.util.List;
 
@@ -18,7 +18,18 @@
 public class JFCGUIElementSpec implements IGUIElementSpec {
 
-    /** */
-    private List<String> name = new LinkedList<String>();
-    
+    /**
+     * <p>
+     * current name of the GUI element
+     * </p>
+     */
+    private String name;
+
+    /**
+     * <p>
+     * previous names of the GUI element as it may have changed over time.
+     * </p>
+     */
+    private List<String> formerNames = new ArrayList<String>();
+
     /** */
     private String type = null;
@@ -30,7 +41,18 @@
     private int index = -1;
     
-    /** */
-    private List<String> elementHash = new LinkedList<String>();
-    
+    /**
+     * <p>
+     * hash code of the window elemt. Used as unique identifier during its existence.
+     * </p>
+     */
+    private int elementHash = -1;
+
+    /**
+     * <p>
+     * previous handles of the window as the window may have been destroyed and recreated
+     * </p>
+     */
+    private List<Integer> formerElementHashes = new ArrayList<Integer>();
+
     /* (non-Javadoc)
      * @see de.ugoe.cs.quest.eventcore.guimodel.IGUIElementSpec#getSecificationSimilarity(IGUIElementSpec)
@@ -50,18 +72,72 @@
         JFCGUIElementSpec otherSpec = (JFCGUIElementSpec) other;
         
-        boolean retVal = false;
-        
-        boolean titleEqual = CollectionUtils.containsAny(name, otherSpec.name);
-        boolean hashEqual = CollectionUtils.containsAny(elementHash, otherSpec.elementHash);
-        
-        if (type.equals("Class") ) {
-            retVal = type.equals(otherSpec.type) && (titleEqual || hashEqual);
-        }
-        else {
-            retVal = type.equals(otherSpec.type) && index==otherSpec.index &&
-                (titleEqual || hashEqual);
-        }
-        
-        return retVal;
+        if ((type != otherSpec.type) && ((type != null) && (!type.equals(otherSpec.type)))) {
+            return false;
+        }
+
+        if ((icon != otherSpec.icon) && ((icon != null) && (!icon.equals(otherSpec.icon)))) {
+            return false;
+        }
+
+        // up to now, we compared, if the basics match. Now lets compare the id, the name and the
+        // index. All may change. The name may be reset (e.g. the title of a frame using the
+        // asterisk in the case data was changed). The id may change if e.g. a dialog is closed
+        // and reopend, i.e. a new instance is created. The index may change, if later in a panel
+        // a new element is added or another one is removed. If the element hash or the name stay
+        // the same, then similarity is given. Therefore these are the first two comparisons
+        
+        if (elementHash == otherSpec.elementHash) {
+            return true;
+        }
+        
+        if ((name != null) && (name.equals(otherSpec.name))) {
+            return true;
+        }
+        
+        if ((((name == null) && (otherSpec.name == null)) ||
+             (("".equals(name)) && ("".equals(otherSpec.name)))) &&
+            (formerNames.size() == 0) && (otherSpec.formerNames.size() == 0))
+        {
+            return true;
+        }
+        
+        // if the id and the name did not stay the same, then the name should be checked first.
+        // One of all known names of one of the specs must be equal to one of the known names of the
+        // respective other spec for similarity. Furthermore, if this is given, the index should
+        // have stayed the same.
+
+        if ((otherSpec.name != null) && formerNames.contains(otherSpec.name)) {
+            return index == otherSpec.index;
+        }
+
+        if ((name != null) && otherSpec.formerNames.contains(name)) {
+            return index == otherSpec.index;
+        }
+        
+        if (CollectionUtils.containsAny(formerNames, otherSpec.formerNames)) {
+            return index == otherSpec.index;
+        }
+        
+        // ok. Even the names do not match. This is usually a clear indication, that the elements
+        // are distinct. However, we check, if the former ids matched. This is very unlikely
+        // to happen. But it may occur, if a GUI element does not have a name or its name stays
+        // the empty string and if this GUI element is created, destroyed, and created again.
+        // Again we are restrictive and request the index to be equal as well.
+
+        if (formerElementHashes.contains(otherSpec.elementHash)) {
+            return index == otherSpec.index;
+        }
+
+        if (otherSpec.formerElementHashes.contains(elementHash)) {
+            return index == otherSpec.index;
+        }
+        
+        if (CollectionUtils.containsAny(formerElementHashes, otherSpec.formerElementHashes)) {
+            return index == otherSpec.index;
+        }
+        
+        // now we can be really sure, that the GUI elements differ
+        
+        return false;
     }
 
@@ -102,9 +178,33 @@
      */
     public String getName() {
-        // TODO for now always returns first matched name
-        if( name.isEmpty() ) {
-            return null;
-        }
-        return name.get(0);
+        StringBuffer names = new StringBuffer();
+        
+        if (name != null) {
+            names.append('"');
+            names.append(name);
+            names.append('"');
+        }
+        else {
+            names.append("NOT_SET");
+        }
+        
+        if (formerNames.size() > 0) {
+            
+            names.append(" (aka ");
+            
+            for (int i = 0; i < formerNames.size(); i++) {
+                if (i > 0) {
+                    names.append("/");
+                }
+
+                names.append('"');
+                names.append(formerNames.get(i));
+                names.append('"');
+            }
+            
+            names.append(")");
+        }
+        
+        return names.toString();
     }
 
@@ -133,10 +233,6 @@
      * @return the elementHash
      */
-    public String getElementHash() {
-        // TODO for now always returns the first hash value
-        if( elementHash.isEmpty() ) {
-            return null;
-        }
-        return elementHash.get(0);
+    public int getElementHash() {
+        return elementHash;
     }
 
@@ -144,8 +240,13 @@
      * @param name the name to set
      */
-    public void setName(String name) {
-        if( !this.name.contains(name) && name!=null ) {
-            this.name.add(name);
-        }
+    public void setName(String newName) {
+        if ((this.name != null) &&
+            (!this.name.equals(newName)) &&
+            (!this.formerNames.contains(this.name)))
+        {
+            this.formerNames.add(this.name);
+        }
+        
+        this.name = newName;
     }
 
@@ -174,12 +275,45 @@
      * @param elementHash the elementHash to set
      */
-    public void setElementHash(String elementHash) {
-        if( !this.elementHash.contains(elementHash) ) {
-            this.elementHash.add(elementHash);
-        }
+    public void setElementHash(int newElementHash) {
+        if ((this.elementHash > -1) &&
+            !this.formerElementHashes.contains(this.elementHash))
+        {
+            this.formerElementHashes.add(this.elementHash);
+        }
+        
+        this.elementHash = newElementHash;
     }
     
+    /**
+     * <p>
+     * TODO: comment
+     * </p>
+     *
+     * @param furtherSpec
+     */
+    void update(JFCGUIElementSpec other) {
+        if (other != this) {
+            for (int formerElementHash : other.formerElementHashes) {
+                setElementHash(formerElementHash);
+            }
+
+            if (elementHash != other.elementHash) {
+                elementHash = other.elementHash;
+            }
+
+            for (String formerName : other.formerNames) {
+                setName(formerName);
+            }
+
+            if ((name != other.name) && (name != null) && (!name.equals(other.name)))
+            {
+                setName(other.name);
+            }
+        }
+    }
+
     public String toString() {
-        return "" + name.toString() + "," + elementHash.toString() + "," + type + "," + "icon";
+        return "[" + getName() + ";\"" + type + "\";\"" + icon + "\";" + index + ";" +
+                elementHash + "]";
     }
 
