public final void setNullModel(Distribution nullModel)
     throws IllegalAlphabetException, ChangeVetoException {
   if (nullModel.getAlphabet() != getAlphabet()) {
     throw new IllegalAlphabetException(
         "Could not use distribution "
             + nullModel
             + " as its alphabet is "
             + nullModel.getAlphabet().getName()
             + " and this distribution's alphabet is "
             + getAlphabet().getName());
   }
   Distribution oldModel = getNullModel();
   if (nullModelForwarder != null) {
     if (oldModel != null) {
       oldModel.removeChangeListener(nullModelForwarder);
     }
     nullModel.addChangeListener(nullModelForwarder);
   }
   if (!hasListeners()) {
     // if there are no listeners yet, don't go through the overhead of
     // synchronized regions or of trying to inform them.
     setNullModelImpl(nullModel);
   } else {
     // OK - so somebody is intereted in me. Do it properly this time.
     ChangeEvent ce = new ChangeEvent(this, Distribution.NULL_MODEL, nullModel, oldModel);
     ChangeSupport changeSupport = super.getChangeSupport(Distribution.NULL_MODEL);
     synchronized (changeSupport) {
       changeSupport.firePreChangeEvent(ce);
       setNullModelImpl(nullModel);
       changeSupport.firePostChangeEvent(ce);
     }
   }
 }
  /**
   * <code>setRenderer</code> sets the renderer.
   *
   * @param renderer a <code>PairwiseSequenceRenderer</code>.
   * @exception ChangeVetoException if the change is vetoed.
   */
  public void setRenderer(PairwiseSequenceRenderer renderer) throws ChangeVetoException {
    if (hasListeners()) {
      ChangeEvent ce = new ChangeEvent(this, RENDERER, renderer, this.renderer);

      ChangeSupport cs = getChangeSupport(RENDERER);
      synchronized (cs) {
        cs.firePreChangeEvent(ce);

        if (this.renderer instanceof Changeable) {
          Changeable c = (Changeable) this.renderer;
          c.removeChangeListener(rendererForwarder);
        }

        this.renderer = renderer;

        if (renderer instanceof Changeable) {
          Changeable c = (Changeable) renderer;
          c.addChangeListener(rendererForwarder);
        }
        cs.firePostChangeEvent(ce);
      }
    } else {
      this.renderer = renderer;
    }
  }
Esempio n. 3
0
 /** {@inheritDoc} */
 public void addName(String nameClass, String name)
     throws IllegalArgumentException, ChangeVetoException {
   if (name == null) throw new IllegalArgumentException("Name cannot be null");
   if (nameClass == null) throw new IllegalArgumentException("Name class cannot be null");
   SimpleNCBITaxonName n = new SimpleNCBITaxonName(nameClass, name);
   if (!this.hasListeners(NCBITaxon.NAMES)) {
     if (!this.namesMap.containsKey(nameClass)) this.namesMap.put(nameClass, new TreeSet());
     ((Set) this.namesMap.get(nameClass)).add(n);
     this.names.add(n);
   } else {
     ChangeEvent ce =
         new ChangeEvent(
             this,
             NCBITaxon.NAMES,
             name,
             ((Set) this.namesMap.get(nameClass)).contains(n) ? name : null);
     ChangeSupport cs = this.getChangeSupport(NCBITaxon.NAMES);
     synchronized (cs) {
       cs.firePreChangeEvent(ce);
       if (!this.namesMap.containsKey(nameClass)) this.namesMap.put(nameClass, new TreeSet());
       ((Set) this.namesMap.get(nameClass)).add(n);
       this.names.add(n);
       cs.firePostChangeEvent(ce);
     }
   }
 }
Esempio n. 4
0
 /** {@inheritDoc} */
 public void setRightValue(Integer rightValue) throws ChangeVetoException {
   if (!this.hasListeners(NCBITaxon.RIGHTVALUE)) {
     this.rightValue = rightValue;
   } else {
     ChangeEvent ce = new ChangeEvent(this, NCBITaxon.RIGHTVALUE, rightValue, this.rightValue);
     ChangeSupport cs = this.getChangeSupport(NCBITaxon.RIGHTVALUE);
     synchronized (cs) {
       cs.firePreChangeEvent(ce);
       this.rightValue = rightValue;
       cs.firePostChangeEvent(ce);
     }
   }
 }
Esempio n. 5
0
 /** {@inheritDoc} */
 public void setGeneticCode(Integer geneticCode) throws ChangeVetoException {
   if (!this.hasListeners(NCBITaxon.GENETICCODE)) {
     this.geneticCode = geneticCode;
   } else {
     ChangeEvent ce = new ChangeEvent(this, NCBITaxon.GENETICCODE, nodeRank, this.nodeRank);
     ChangeSupport cs = this.getChangeSupport(NCBITaxon.GENETICCODE);
     synchronized (cs) {
       cs.firePreChangeEvent(ce);
       this.geneticCode = geneticCode;
       cs.firePostChangeEvent(ce);
     }
   }
 }
Esempio n. 6
0
 /**
  * Setter for property nodeRank.
  *
  * @param nodeRank New value of property nodeRank.
  * @throws org.biojava.utils.ChangeVetoException in case of objections.
  */
 public void setNodeRank(String nodeRank) throws ChangeVetoException {
   if (!this.hasListeners(NCBITaxon.NODERANK)) {
     this.nodeRank = nodeRank;
   } else {
     ChangeEvent ce = new ChangeEvent(this, NCBITaxon.NODERANK, nodeRank, this.nodeRank);
     ChangeSupport cs = this.getChangeSupport(NCBITaxon.NODERANK);
     synchronized (cs) {
       cs.firePreChangeEvent(ce);
       this.nodeRank = nodeRank;
       cs.firePostChangeEvent(ce);
     }
   }
 }
Esempio n. 7
0
 /** {@inheritDoc} */
 public void setParentNCBITaxID(Integer parent) throws ChangeVetoException {
   if (!this.hasListeners(NCBITaxon.PARENT)) {
     this.parent = parent;
   } else {
     ChangeEvent ce = new ChangeEvent(this, NCBITaxon.PARENT, parent, this.parent);
     ChangeSupport cs = this.getChangeSupport(NCBITaxon.PARENT);
     synchronized (cs) {
       cs.firePreChangeEvent(ce);
       this.parent = parent;
       cs.firePostChangeEvent(ce);
     }
   }
 }
    public void postChange(ChangeEvent ce) {
      subContextCache.remove(fsc);
      cacheFlushers.remove(this);

      if (hasListeners()) {
        ChangeSupport cs = getChangeSupport(SequenceRenderContext.LAYOUT);
        synchronized (cs) {
          ChangeEvent ce2 =
              new ChangeEvent(PairwiseFilteringRenderer.this, SequenceRenderContext.LAYOUT);
          cs.firePostChangeEvent(ce2);
        }
      }
    }
 /**
  * <code>setFilter</code> sets the filter.
  *
  * @param filter a <code>FeatureFilter</code>.
  * @exception ChangeVetoException if the change is vetoed.
  */
 public void setFilter(FeatureFilter filter) throws ChangeVetoException {
   if (hasListeners()) {
     ChangeSupport cs = getChangeSupport(FILTER);
     synchronized (cs) {
       ChangeEvent ce = new ChangeEvent(this, FILTER, this.filter, filter);
       cs.firePreChangeEvent(ce);
       this.filter = filter;
       cs.firePostChangeEvent(ce);
     }
   } else {
     this.filter = filter;
   }
 }
 /**
  * <code>setRecurse</code> sets the recursion flag on the filter.
  *
  * @param recurse a <code>boolean</code>.
  * @exception ChangeVetoException if the change is vetoed.
  */
 public void setRecurse(boolean recurse) throws ChangeVetoException {
   if (hasListeners()) {
     ChangeSupport cs = getChangeSupport(RECURSE);
     synchronized (cs) {
       ChangeEvent ce =
           new ChangeEvent(this, RECURSE, new Boolean(recurse), new Boolean(this.recurse));
       cs.firePreChangeEvent(ce);
       this.recurse = recurse;
       cs.firePostChangeEvent(ce);
     }
   } else {
     this.recurse = recurse;
   }
 }
Esempio n. 11
0
 /*
  * (non-Javadoc)
  * @see com.bioperception.bio.taxa.NCBITaxon2#setTaxonHidden(boolean)
  */
 public final void setTaxonHidden(final boolean isTaxonHidden) throws ChangeVetoException {
   if (!this.hasListeners(HIDDEN)) {
     this.isTaxonHidden = isTaxonHidden;
   } else {
     final ChangeEvent ce =
         new ChangeEvent(
             this, HIDDEN, new Boolean(isTaxonHidden), new Boolean(this.isTaxonHidden));
     final ChangeSupport cs = this.getChangeSupport(HIDDEN);
     synchronized (cs) {
       cs.firePreChangeEvent(ce);
       this.isTaxonHidden = isTaxonHidden;
       cs.firePostChangeEvent(ce);
     }
   }
 }
 /**
  * Set the weight of a given symbol in this distribution.
  *
  * <p>This implementation informs all listeners of the change, and then calls setWeightImpl to
  * make the actual change. Sub-classes should over-ride setWeightImpl to implement the actual
  * storage of the weights.
  *
  * @param sym the Symbol to set the weight for
  * @param weight it's new weight
  * @throws IllegalSymbolException if sym is not known
  * @throws ChangeVetoException if the update was prevented
  */
 public final void setWeight(Symbol sym, double weight)
     throws IllegalSymbolException, ChangeVetoException {
   if (!hasListeners()) {
     doSetWeight(sym, weight);
   } else {
     ChangeEvent ce =
         new ChangeEvent(
             this,
             Distribution.WEIGHTS,
             new Object[] {sym, new Double(weight)},
             new Object[] {sym, new Double(getWeight(sym))});
     ChangeSupport changeSupport = super.getChangeSupport(Distribution.WEIGHTS);
     synchronized (changeSupport) {
       changeSupport.firePreChangeEvent(ce);
       doSetWeight(sym, weight);
       changeSupport.firePostChangeEvent(ce);
     }
   }
 }
 public void setProperty(Object key, Object value) throws ChangeVetoException {
   if (!hasListeners()) {
     getProperties().put(key, value);
   } else {
     Map properties = getProperties();
     ChangeEvent ce =
         new ChangeEvent(
             this,
             Annotation.PROPERTY,
             new Object[] {key, value},
             new Object[] {key, properties.get(key)});
     ChangeSupport cs = getChangeSupport(Annotation.PROPERTY);
     synchronized (cs) {
       cs.firePreChangeEvent(ce);
       properties.put(key, value);
       cs.firePostChangeEvent(ce);
     }
   }
 }
Esempio n. 14
0
 /** {@inheritDoc} */
 public boolean removeName(String nameClass, String name)
     throws IllegalArgumentException, ChangeVetoException {
   if (name == null) throw new IllegalArgumentException("Name cannot be null");
   if (nameClass == null) throw new IllegalArgumentException("Name class cannot be null");
   SimpleNCBITaxonName n = new SimpleNCBITaxonName(nameClass, name);
   if (!this.namesMap.containsKey(nameClass)) return false;
   boolean results;
   if (!this.hasListeners(NCBITaxon.NAMES)) {
     results = ((Set) this.namesMap.get(nameClass)).remove(n);
     this.names.remove(n);
   } else {
     ChangeEvent ce = new ChangeEvent(this, NCBITaxon.NAMES, null, name);
     ChangeSupport cs = this.getChangeSupport(NCBITaxon.NAMES);
     synchronized (cs) {
       cs.firePreChangeEvent(ce);
       results = ((Set) this.namesMap.get(nameClass)).remove(n);
       this.names.remove(n);
       cs.firePostChangeEvent(ce);
     }
   }
   return results;
 }
  public void removeProperty(Object key) throws ChangeVetoException, NoSuchElementException {
    if (!getProperties().containsKey(key)) {
      throw new NoSuchElementException("Can't remove key " + key.toString());
    }

    if (!hasListeners()) {
      getProperties().remove(key);
    } else {
      Map properties = getProperties();
      ChangeEvent ce =
          new ChangeEvent(
              this,
              Annotation.PROPERTY,
              new Object[] {key, null},
              new Object[] {key, properties.get(key)});
      ChangeSupport cs = getChangeSupport(Annotation.PROPERTY);
      synchronized (cs) {
        cs.firePreChangeEvent(ce);
        properties.remove(key);
        cs.firePostChangeEvent(ce);
      }
    }
  }