Index: TopComponent.java
===================================================================
RCS file: /cvs/openide/src/org/openide/windows/TopComponent.java,v
retrieving revision 1.99.2.22
diff -u -r1.99.2.22 TopComponent.java
--- TopComponent.java 10 Oct 2003 13:17:38 -0000 1.99.2.22
+++ TopComponent.java 30 Oct 2003 08:32:08 -0000
@@ -112,9 +112,6 @@
/** Localized display name of this TopComponent
. */
private transient String displayName;
- /** Unique TopComponent ID */
- private transient String tcUniqueId;
-
/** identification of serialization version
* Used in CloneableTopComponent readObject method.
*/
@@ -402,28 +399,60 @@
}
/**
- * Subclasses are encouraged to override this method to provide preferred value
+ * Returns unique permanent TopComponent ID. Value is also persistent if TopComponent
+ * is also persistent.
+` * Subclasses are encouraged to override this method to provide preferred value
* for unique TopComponent Id returned by getID. Returned value is used as starting
* value for creating unique TopComponent ID.
- * Value should be preferably unique, but need not be.
+ * Value should be preferably unique, but need not be. Override and just do:
+ *
+ * public ID get () { + * return new ID ("yourPreferredName"); + * } + *+ * + * @return the ID handle */ - protected String preferredID () { - return getName(); + public ID getID () { + return new ID (getName ()); } - - /** - * Returns unique permanent TopComponent ID. Value is also persistent if TopComponent - * is also persistent. + + /** Represents unique ID of the TopComponent. */ - public final synchronized String getID () { - // looks up some global collection of TC's - // and chooses a unique ID based on - // preferredID, and remembers it - // will be the same after externalization - if (tcUniqueId == null) { - tcUniqueId = WindowManager.getDefault().topComponentID(this, preferredID()); + public final class ID extends Object { + private String preferredID; + + public ID (String preferredID) { + this.preferredID = preferredID; + } + + /** + * Returns unique permanent TopComponent ID. Value is also persistent if TopComponent + * is also persistent. + */ + public String getID () { + return WindowManager.getDefault().topComponentID(TopComponent.this, preferredID); + } + + public String toString () { + return getID (); + } + + public boolean equals (Object obj) { + if (obj instanceof ID) { + ID i = (ID)obj; + return tc () == i.tc (); + } + return false; + } + + private TopComponent tc () { + return TopComponent.this; + } + + public int hashCode () { + return System.identityHashCode (TopComponent.this) + 5; } - return tcUniqueId; } /** Called only when top component was closed on all workspaces before and