This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 36924
Collapse All | Expand All

(-)TopComponent.java (-19 / +48 lines)
Lines 112-120 Link Here
112
    /** Localized display name of this <code>TopComponent</code>. */
112
    /** Localized display name of this <code>TopComponent</code>. */
113
    private transient String displayName;
113
    private transient String displayName;
114
    
114
    
115
    /** Unique TopComponent ID */
116
    private transient String tcUniqueId;
117
    
118
    /** identification of serialization version
115
    /** identification of serialization version
119
    * Used in CloneableTopComponent readObject method.
116
    * Used in CloneableTopComponent readObject method.
120
    */
117
    */
Lines 402-429 Link Here
402
    }
399
    }
403
    
400
    
404
    /**
401
    /**
405
     * Subclasses are encouraged to override this method to provide preferred value
402
     * Returns unique permanent TopComponent ID. Value is also persistent if TopComponent
403
     * is also persistent.
404
`    * Subclasses are encouraged to override this method to provide preferred value
406
     * for unique TopComponent Id returned by getID. Returned value is used as starting
405
     * for unique TopComponent Id returned by getID. Returned value is used as starting
407
     * value for creating unique TopComponent ID.
406
     * value for creating unique TopComponent ID.
408
     * Value should be preferably unique, but need not be.
407
     * Value should be preferably unique, but need not be. Override and just do:
408
     * <PRE>
409
     *   public ID get () {
410
     *     return new ID ("yourPreferredName");
411
     *   }
412
     * </PRE>
413
     *
414
     * @return the ID handle
409
     */
415
     */
410
    protected String preferredID () {
416
    public ID getID () {
411
        return getName();
417
        return new ID (getName ());
412
    }
418
    }
413
    
419
414
    /**
420
    /** Represents unique ID of the TopComponent.
415
     * Returns unique permanent TopComponent ID. Value is also persistent if TopComponent
416
     * is also persistent.
417
     */
421
     */
418
    public final synchronized String getID () {
422
    public final class ID extends Object {
419
        // looks up some global collection of TC's
423
        private String preferredID;
420
        // and chooses a unique ID based on
424
421
        // preferredID, and remembers it
425
        public ID (String preferredID) {
422
        // will be the same after externalization
426
            this.preferredID = preferredID;
423
        if (tcUniqueId == null) {
427
        }
424
            tcUniqueId = WindowManager.getDefault().topComponentID(this, preferredID());
428
429
        /**
430
        * Returns unique permanent TopComponent ID. Value is also persistent if TopComponent
431
        * is also persistent.
432
        */
433
        public String getID () {
434
            return WindowManager.getDefault().topComponentID(TopComponent.this, preferredID);
435
        }
436
437
        public String toString () {
438
            return getID ();
439
        }
440
441
        public boolean equals (Object obj) {
442
            if (obj instanceof ID) {
443
                ID i = (ID)obj;
444
                return tc () == i.tc ();
445
            }
446
            return false;
447
        }
448
449
        private TopComponent tc () {
450
            return TopComponent.this;
451
        }
452
453
        public int hashCode () {
454
            return System.identityHashCode (TopComponent.this) + 5;
425
        }
455
        }
426
        return tcUniqueId;
427
    }
456
    }
428
    
457
    
429
    /** Called only when top component was closed on all workspaces before and
458
    /** Called only when top component was closed on all workspaces before and

Return to bug 36924