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.geom.Point2D; 026 027import org.biojava.bio.seq.FeatureHolder; 028import org.biojava.bio.symbol.RangeLocation; 029import org.biojava.bio.symbol.SymbolList; 030 031/** 032 * Allows a new renderer to "wrap" another one, replacing one or more values. 033 * 034 * <p> 035 * Use this when implementing SequenceRenderer classes that modify the data 036 * that is passed on to delegate renderers e.g. filtering the features, 037 * transforming the sequence or moving the rendering co-ordinates. 038 * </p> 039 * 040 * @author Matthew Pocock 041 */ 042public class SubSequenceRenderContext 043implements SequenceRenderContext { 044 private final SequenceRenderContext src; 045 private final SymbolList symbols; 046 private final FeatureHolder features; 047 private final RangeLocation range; 048 private final int symOffset; 049 050 public SubSequenceRenderContext( 051 SequenceRenderContext src, 052 SymbolList symbols, 053 FeatureHolder features, 054 RangeLocation range 055 ) { 056 this(src, symbols, features, range, 0); 057 } 058 059 public SubSequenceRenderContext( 060 SequenceRenderContext src, 061 SymbolList symbols, 062 FeatureHolder features, 063 RangeLocation range, 064 int symOffset 065 ) { 066 this.src = src; 067 this.symbols = symbols; 068 this.features = features; 069 this.range = range; 070 this.symOffset = symOffset; 071 } 072 073 public int getDirection() { 074 return src.getDirection(); 075 } 076 077 public double getScale() { 078 return src.getScale(); 079 } 080 081 public double sequenceToGraphics(int i) { 082 return src.sequenceToGraphics(i + symOffset); 083 } 084 085 public int graphicsToSequence(double d) { 086 return src.graphicsToSequence(d) - symOffset; 087 } 088 089 public int graphicsToSequence(Point2D point) { 090 return src.graphicsToSequence(point) - symOffset; 091 } 092 093 public SymbolList getSymbols() { 094 if(symbols == null) { 095 return src.getSymbols(); 096 } else { 097 return symbols; 098 } 099 } 100 101 public FeatureHolder getFeatures() { 102 if(features == null) { 103 return src.getFeatures(); 104 } else { 105 return features; 106 } 107 } 108 109 public RangeLocation getRange() { 110 if(range == null) { 111 return src.getRange(); 112 } else { 113 return range; 114 } 115 } 116 117 public SequenceRenderContext.Border getLeadingBorder() { 118 return src.getLeadingBorder(); 119 } 120 121 public SequenceRenderContext.Border getTrailingBorder() { 122 return src.getTrailingBorder(); 123 } 124 125 public Font getFont() { 126 return src.getFont(); 127 } 128}