Logo Search packages:      
Sourcecode: cdk version File versions  Download package

ChemModel.java
/* $RCSfile$    
 * $Author$    
 * $Date$    
 * $Revision$
 *
 * Copyright (C) 1997-2007  Christoph Steinbeck <steinbeck@users.sf.net>
 *
 * Contact: cdk-devel@lists.sourceforge.net
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 
 */

package org.openscience.cdk;

import org.openscience.cdk.interfaces.*;

import java.io.Serializable;

/** 
 * An object containing multiple MoleculeSet and 
 * the other lower level concepts like rings, sequences, 
 * fragments, etc.
 *
 * @cdk.module data
 * @cdk.githash
 */
00039 public class ChemModel extends ChemObject implements Serializable, IChemModel, IChemObjectListener, Cloneable
{

      /**
     * Determines if a de-serialized object is compatible with this class.
     *
     * This value must only be changed if and only if the new version
     * of this class is incompatible with the old version. See Sun docs
     * for <a href=http://java.sun.com/products/jdk/1.1/docs/guide
     * /serialization/spec/version.doc.html>details</a>.
       */
00050       private static final long serialVersionUID = -5213425310451366185L;

      /**
       *  A MoleculeSet.
       */
00055       protected IMoleculeSet setOfMolecules = null;

      /**
       *  A ReactionSet.
       */
00060       protected IReactionSet setOfReactions = null;

      /**
       *  A RingSet.
       */
00065       protected IRingSet ringSet = null;
      
    /**
       *  A Crystal.
       */
00070      protected ICrystal crystal = null;

      /**
       *  Constructs an new ChemModel with a null setOfMolecules.
       */
00075       public ChemModel() {}

      /**
       * Returns the MoleculeSet of this ChemModel.
       *
       * @return   The MoleculeSet of this ChemModel
     *
     * @see      #setMoleculeSet
       */
00084       public IMoleculeSet getMoleculeSet()
      {
            return this.setOfMolecules;
      }


      /**
       * Sets the MoleculeSet of this ChemModel.
       *
       * @param   setOfMolecules  the content of this model
     *
     * @see      #getMoleculeSet
       */
00097       public void setMoleculeSet(IMoleculeSet setOfMolecules)
      {
          if (this.setOfMolecules != null)
              this.setOfMolecules.removeListener(this);
            this.setOfMolecules = setOfMolecules;
            if (this.setOfMolecules != null)
                this.setOfMolecules.addListener(this);
            notifyChanged();
      }

      

      /**
       * Returns the RingSet of this ChemModel.
       *
       * @return the ringset of this model
     *
     * @see      #setRingSet
       */
00116       public IRingSet getRingSet() {
            return this.ringSet;
      }


      /**
       * Sets the RingSet of this ChemModel.
       *
       * @param   ringSet         the content of this model
     *
     * @see      #getRingSet
       */
00128       public void setRingSet(IRingSet ringSet)
      {
          if (this.ringSet != null)
              this.ringSet.removeListener(this);
            this.ringSet = ringSet;
            if (this.ringSet != null)
                this.ringSet.addListener(this);
            notifyChanged();
      }

    /**
     * Gets the Crystal contained in this ChemModel.
     *
     * @return The crystal in this model
     *
     * @see      #setCrystal
     */
00145     public ICrystal getCrystal() {
        return this.crystal;
    }

    /**
     * Sets the Crystal contained in this ChemModel.
     *
     * @param   crystal  the Crystal to store in this model
     *
     * @see      #getCrystal
     */
00156     public void setCrystal(ICrystal crystal) {
        if (this.crystal != null)
            this.crystal.removeListener(this);
        this.crystal = crystal;
        if (this.crystal != null)
            this.crystal.addListener(this);
        notifyChanged();
    }

    /**
     * Gets the ReactionSet contained in this ChemModel.
     *
     * @return The ReactionSet in this model
     *
     * @see      #setReactionSet
     */
00172     public IReactionSet getReactionSet() {
        return this.setOfReactions;
    }

    /**
     * Sets the ReactionSet contained in this ChemModel.
     *
     * @param sor the ReactionSet to store in this model
     *
     * @see       #getReactionSet
     */
00183     public void setReactionSet(IReactionSet sor) {
        if (this.setOfReactions != null)
            this.setOfReactions.removeListener(this);
        this.setOfReactions = sor;
        if (this.setOfReactions != null)
            this.setOfReactions.addListener(this);
        notifyChanged();
    }
    
    /**
     * Returns a String representation of the contents of this
     * IChemObject.
     *
     * @return String representation of content
     */
00198     public String toString() {
        StringBuffer buffer = new StringBuffer(64);
        buffer.append("ChemModel(");
        buffer.append(hashCode());
        if (getMoleculeSet() != null) {
            buffer.append(", ");
            buffer.append(getMoleculeSet().toString());
        }
        if (getCrystal() != null) {
            buffer.append(", ");
            buffer.append(getCrystal().toString());
        }
        if (getReactionSet() != null) {
            buffer.append(", ");
            buffer.append(getReactionSet().toString());
        }
        buffer.append(')');
        return buffer.toString();
    }

      /**
       * Clones this <code>ChemModel</code> and its content.
       *
       * @return  The cloned object
       */
00223       public Object clone() throws CloneNotSupportedException {
            ChemModel clone = (ChemModel)super.clone();
        // clone the content
        if (setOfMolecules != null) {
            clone.setOfMolecules = (MoleculeSet)((MoleculeSet)setOfMolecules).clone();
        } else {
            clone.setOfMolecules = null;
        }
        if (setOfReactions != null) {
            clone.setOfReactions = (IReactionSet)((ReactionSet)setOfReactions).clone();
        } else {
            clone.setOfReactions = null;
        }
        if (crystal != null) {
            clone.crystal = (Crystal)((Crystal)crystal).clone();
        } else {
            clone.crystal = null;
        }
        if (ringSet != null) {
            clone.ringSet = (RingSet)((RingSet)ringSet).clone();
        } else {
            clone.ringSet = null;
        }
            return clone;
      }
      
      /**
       *  Called by objects to which this object has
       *  registered as a listener.
       *
       *@param  event  A change event pointing to the source of the change
       */
00255       public void stateChanged(IChemObjectChangeEvent event)
      {
            notifyChanged(event);
      }
}


Generated by  Doxygen 1.6.0   Back to index