001package org.biojava.bio.gui.sequence;
002
003import org.biojava.bio.seq.FeatureHolder;
004import org.biojava.bio.symbol.SymbolList;
005
006/**
007 * A renderer context that allows some or all properties of another context to
008 * be over-ridden.
009 *
010 * @author Matthew Pocock
011 * @since 1.4
012 */
013public class SubCircularRendererContext
014implements CircularRendererContext {
015  private final CircularRendererContext delegate;
016  private final SymbolList symbols;
017  private final FeatureHolder features;
018  private final double radius;
019
020  /**
021   * Create a new sub context.
022   *
023   * <p>
024   * Supply the real values for symbols, features and radius if you want this
025   * context to mask the values of the parent context. Otherwise, provide the
026   * default values.
027   * </p>
028   *
029   * @param delegate  the original context to wrap
030   * @param symbols   the SymbolList to return for getSymbols(), or null
031   * @param features  the FeatureHolder to return for getFeatures(), or null
032   * @param radius    the radius to return for getRadius(), or NaN
033   * @throws NullPointerException  if delegate is null
034   */
035  public SubCircularRendererContext(
036          CircularRendererContext delegate,
037          SymbolList symbols,
038          FeatureHolder features,
039          double radius)
040  {
041    if(delegate == null) {
042      throw new NullPointerException("Delegate can not be null");
043    }
044
045    this.delegate = delegate;
046    this.symbols = symbols;
047    this.features = features;
048    this.radius = radius;
049  }
050
051  public double getOffset() {
052    return delegate.getOffset();
053  }
054
055  public double getAngle(int indx) {
056    return delegate.getAngle(indx);
057  }
058
059  public int getIndex(double angle) {
060    return 0;
061  }
062
063  public double getRadius() {
064    if(Double.isNaN(radius)) {
065      return delegate.getRadius();
066    } else {
067      return radius;
068    }
069  }
070
071  public SymbolList getSymbols() {
072    if(symbols == null) {
073      return delegate.getSymbols();
074    } else {
075      return symbols;
076    }
077  }
078
079  public FeatureHolder getFeatures() {
080    if(features == null) {
081      return delegate.getFeatures();
082    } else {
083      return features;
084    }
085  }
086}