001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021
022package org.biojava.bio.gui.sequence;
023
024import java.awt.Font;
025import java.awt.Point;
026import java.awt.geom.Point2D;
027
028import org.biojava.bio.seq.FeatureHolder;
029import org.biojava.bio.symbol.RangeLocation;
030import org.biojava.bio.symbol.SymbolList;
031
032/**
033 * <p><code>SubPairwiseRenderContext</code> is a rendering context
034 * which wraps a delegate context and effectively hides some of the
035 * delegate's properties with its own. If any of the
036 * <code>SymbolList</code>, <code>FeatureHolder</code> or
037 * <code>RangeLocation</code> arguments are not null, their values are
038 * returned. Otherwise the delegate's method is called and its return
039 * value is returned instead.</p>
040 *
041 * @author Keith James
042 * @author Matthew Pocock
043 * @since 1.2
044 */
045public class SubPairwiseRenderContext implements PairwiseRenderContext
046{
047    private final PairwiseRenderContext context;
048    private final SymbolList            symbols;
049    private final SymbolList            secondarySymbols;
050    private final FeatureHolder         features;
051    private final FeatureHolder         secondaryFeatures;
052    private final RangeLocation         range;
053    private final RangeLocation         secondaryRange;
054
055    /**
056     * Creates a new <code>SubPairwiseRenderContext</code>.
057     *
058     * @param context a <code>PairwiseRenderContext</code> to
059     * wrap. This should not be null.
060     * @param symbols a <code>SymbolList</code> to use instead of the
061     * delegate's. May be null.
062     * @param secondarySymbols a <code>SymbolList</code> to use
063     * instead of the delegate's. May be null.
064     * @param features a <code>FeatureHolder</code> to use instead of
065     * the delegate's. May be null.
066     * @param secondaryFeatures a <code>FeatureHolder</code> to use
067     * instead of the delegate's. May be null.
068     * @param range a <code>RangeLocation</code> to use instead of the
069     * delegate's. May be null.
070     * @param secondaryRange a <code>RangeLocation</code> to use
071     * instead of the delegate's. May be null.
072     */
073    public SubPairwiseRenderContext(PairwiseRenderContext context,
074                                    SymbolList            symbols,
075                                    SymbolList            secondarySymbols,
076                                    FeatureHolder         features,
077                                    FeatureHolder         secondaryFeatures,
078                                    RangeLocation         range,
079                                    RangeLocation         secondaryRange)
080    {
081        this.context           = context;
082        this.symbols           = symbols;
083        this.secondarySymbols  = secondarySymbols;
084        this.features          = features;
085        this.secondaryFeatures = secondaryFeatures;
086        this.range             = range;
087        this.secondaryRange    = secondaryRange;
088    }
089
090    public SymbolList getSymbols()
091    {
092        if (symbols == null)
093        {
094            return context.getSymbols();
095        }
096        else
097        {
098            return symbols;
099        }
100    }
101
102    public SymbolList getSecondarySymbols()
103    {
104        if (secondarySymbols == null)
105        {
106            return context.getSecondarySymbols();
107        }
108        else
109        {
110            return secondarySymbols;
111        }
112    }
113
114    public FeatureHolder getFeatures()
115    {
116        if (features == null)
117        {
118            return context.getFeatures();
119        }
120        else
121        {
122            return features;
123        }
124    }
125
126    public FeatureHolder getSecondaryFeatures()
127    {
128        if (secondaryFeatures == null)
129        {
130            return context.getSecondaryFeatures();
131        }
132        else
133        {
134            return secondaryFeatures;
135        }
136    }
137
138    public RangeLocation getRange()
139    {
140        if (range == null)
141        {
142            return context.getRange();
143        }
144        else
145        {
146            return range;
147        }
148    }
149
150    public RangeLocation getSecondaryRange()
151    {
152        if (secondaryRange == null)
153        {
154            return context.getSecondaryRange();
155        }
156        else
157        {
158            return secondaryRange;
159        }
160    }
161
162    public int getDirection()
163    {
164        return context.getDirection();
165    }
166
167    public int getSecondaryDirection()
168    {
169        return context.getSecondaryDirection();
170    }
171
172    public double getScale()
173    {
174        return context.getScale();
175    }
176
177    public SequenceRenderContext.Border getLeadingBorder()
178    {
179        return context.getLeadingBorder();
180    }
181
182    public SequenceRenderContext.Border getTrailingBorder()
183    {
184        return context.getTrailingBorder();
185    }
186
187    public double sequenceToGraphics(int sequencePos)
188    {
189        return context.sequenceToGraphics(sequencePos);
190    }
191
192    public double secondarySequenceToGraphics(int sequencePos)
193    {
194        return context.secondarySequenceToGraphics(sequencePos);
195    }
196
197    public int graphicsToSequence(double graphicsPos)
198    {
199        return context.graphicsToSequence(graphicsPos);
200    }
201
202    public int graphicsToSequence(Point2D point)
203    {
204        return context.graphicsToSequence(point);
205    }
206
207    public int graphicsToSecondarySequence(double graphicsPos)
208    {
209        return context.graphicsToSecondarySequence(graphicsPos);
210    }
211
212    public int graphicsToSecondarySequence(Point point)
213    {
214        return context.graphicsToSecondarySequence(point);
215    }
216
217    public Font getFont()
218    {
219        return context.getFont();
220    }
221}