FileDocCategorySizeDatePackage
PersistentPanel.javaAPI DocExample2294Sat Feb 01 07:40:10 GMT 1997imaginary.gui

PersistentPanel.java

/**
 * The PersistentPanel class is a Java panel that observes changes in
 * Persistent instances.
 */
package imaginary.gui;

import imaginary.persist.Persistent;
import imaginary.persist.RemoteLockHolder;
import imaginary.persist.RemotePersistent;
import imaginary.util.RemoteObservable;
import imaginary.util.RemoteObserver;
import java.awt.Panel;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public abstract class PersistentPanel extends Panel
implements ChangeObserver, RemoteObserver {
    private RemoteLockHolder lock_holder = null;
    private RemotePersistent observed    = null;

    /**
     * Constructs a PersistentPanel for the specified lock holder.
     * @param h the lock holder owning this panel
     * @exception java.rmi.RemoteException An error occurred exporting the
     * panel.
     */
    public PersistentPanel(RemoteLockHolder h) throws RemoteException {
        super();
        UnicastRemoteObject.exportObject(this);
        observed = null;
        lock_holder = h;
    }
    
    /**
     * Constructs a PersistentPanel observing the specified persistent.
     * @param h the lock holder owning this panel
     * @param p the persistent being observed
     * @exception java.rmi.RemoteException An error occurred exporting the
     * panel.
     */
    public PersistentPanel(RemoteLockHolder h, RemotePersistent p)
    throws RemoteException {
        super();
        UnicastRemoteObject.exportObject(this);
        observed = p;
        lock_holder = h;
        p.addObserver(this);
    }

    /**
     * @return the lock holder
     */
    protected RemoteLockHolder getLockHolder() {
        return lock_holder;
    }

    /**
     * The persistent being observed
     */
    public RemotePersistent getObserved() {
        return observed;
    }

    /**
     * Implementation of the observer method for receiving updates.  This
     * in turn places the notification in an asynchronous queue that
     * allows it to be processed later.
     * @param target the changed object
     * @param arg any args passed to this for the change
     */
    public void update(RemoteObservable target, Object arg) {
	ChangeMonitor.postChange(this);
    }
}