Ejemplo n.º 1
0
        //-----------------------------------------------------------------------

        /**
         * Registers a cursor to be notified of changes to this list.
         *
         * @param cursor  the cursor to register
         */
        protected virtual void registerCursor(Cursor cursor)
        {
            // We take this opportunity to clean the cursors list
            // of WeakReference objects to garbage-collected cursors.
            for (java.util.Iterator <Object> it = cursors.iterator(); it.hasNext();)
            {
                java.lang.refj.WeakReference <Object> refJ = (java.lang.refj.WeakReference <Object>)it.next();
                if (refJ.get() == null)
                {
                    it.remove();
                }
            }
            cursors.add(new java.lang.refj.WeakReference <Object>(cursor));
        }
Ejemplo n.º 2
0
 /**
  * Informs all of my registered cursors that the specified
  * element was just added to my list.
  *
  * @param node  the node that was changed
  */
 protected virtual void broadcastNodeInserted(Node node)
 {
     java.util.Iterator <Object> it = cursors.iterator();
     while (it.hasNext())
     {
         java.lang.refj.WeakReference <Object> refJ = (java.lang.refj.WeakReference <Object>)it.next();
         Cursor cursor = (Cursor)refJ.get();
         if (cursor == null)
         {
             it.remove(); // clean up list
         }
         else
         {
             cursor.nodeInserted(node);
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Deregisters a cursor from the list to be notified of changes.
  *
  * @param cursor  the cursor to deregister
  */
 protected virtual void unregisterCursor(Cursor cursor)
 {
     for (java.util.Iterator <Object> it = cursors.iterator(); it.hasNext();)
     {
         java.lang.refj.WeakReference <Object> refJ = (java.lang.refj.WeakReference <Object>)it.next();
         Cursor cur = (Cursor)refJ.get();
         if (cur == null)
         {
             // some other unrelated cursor object has been
             // garbage-collected; let's take the opportunity to
             // clean up the cursors list anyway..
             it.remove();
         }
         else if (cur == cursor)
         {
             refJ.clear();
             it.remove();
             break;
         }
     }
 }