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 javax.swing.SwingConstants; 028 029import org.biojava.bio.seq.FeatureHolder; 030import org.biojava.bio.symbol.RangeLocation; 031import org.biojava.bio.symbol.SymbolList; 032import org.biojava.utils.ChangeType; 033 034/** 035 * A context within which sequence information may be rendered. It 036 * encapsulates the rendering direction, the size of the leading and 037 * trailing (header/footer, left/right areas), scale and the currently 038 * rendered symbols, features and region. 039 * 040 * @author Thomas Down 041 * @author Matthew Pocock 042 */ 043public interface SequenceRenderContext extends SwingConstants { 044 public static final ChangeType REPAINT = new ChangeType( 045 "Something that affects rendering has changed", 046 "org.biojava.bio.gui.sequence.SequenceRenderContext", 047 "REPAINT" 048 ); 049 050 public static final ChangeType LAYOUT = new ChangeType( 051 "Something that affects layout has changed", 052 "org.biojava.bio.gui.sequence.SequenceRenderContext", 053 "LAYOUT", 054 REPAINT 055 ); 056 057 /** 058 * Gets the direction in which this context expects sequences to be rendered 059 * - HORIZONTAL or VERTICAL. 060 * 061 * @return The Direction value 062 */ 063 int getDirection(); 064 065 /** 066 * Gets the scale as pixels per Symbol 067 * 068 * @return The scale value 069 */ 070 double getScale(); 071 072 /** 073 * Converts a sequence index into a graphical coordinate. You will need to 074 * use this in conjunction with getDirection to correctly lay graphics out. 075 * 076 * @param i Index within the sequence 077 * @return Equivalent graphical position in pixels 078 */ 079 double sequenceToGraphics(int i); 080 081 /** 082 * Converts a graphical position into a sequence coordinate. You will need 083 * to have used getDirection to decide whether to use the x or y coordinate. 084 * 085 * @param d A pixel position 086 * @return The corresponding sequence index 087 */ 088 int graphicsToSequence(double d); 089 090 /** 091 * Converts a graphical position into a sequence coordinate. This will 092 * use getDirection to decide whether to use the x or y coordinate. 093 * 094 * @param point a point representing the position 095 * @return the corresponding sequence index 096 */ 097 int graphicsToSequence(Point2D point); 098 099 /** 100 * The SymbolList that is currently rendered by this SequenceRenderContext. 101 * 102 * @return The Sequence value 103 */ 104 SymbolList getSymbols(); 105 106 /** 107 * The features to render. 108 * 109 * @return a FeatureHolder with the Features to render 110 */ 111 FeatureHolder getFeatures(); 112 113 /** 114 * The range of the SymbolList to render. 115 * 116 * @return the RangeLocation specifying which indices (inclusive) to render 117 */ 118 RangeLocation getRange(); 119 120 /** 121 * Gets the LeadingBorder attribute of the SequenceRenderContext object. 122 * This represents the space between the beginning of the rendering area and 123 * the beginning of the sequence. 124 * 125 * @return The LeadingBorder value 126 */ 127 Border getLeadingBorder(); 128 129 /** 130 * Gets the TrailingBorder attribute of the SequenceRenderContext object. 131 * This represents the space between the end of the sequence and the end of 132 * the rendering area. 133 * 134 * @return The TrailingBorder value 135 */ 136 Border getTrailingBorder(); 137 138 /** 139 * Gets the Font attribute of the SequenceRenderContext object 140 * 141 * @return The Font value 142 */ 143 Font getFont(); 144 145 /** 146 * The metric object for the 'border' area - the area between the extent of 147 * the rendered area and the beginning or end of the sequence. This provides 148 * information about its size, and hints about how to align information within 149 * the borders. 150 * 151 * @author Matthew Pocock 152 */ 153 public static class Border 154 implements java.io.Serializable, SwingConstants { 155 private double size = 0.0; 156 private int alignment = CENTER; 157 158 public Border() { 159 alignment = CENTER; 160 } 161 162 /** 163 * Sets the size of the border in number of pixels. 164 * 165 * @param size The new size in pixels 166 */ 167 public void setSize(double size) { 168 this.size = size; 169 } 170 171 /** 172 * Sets the Alignment attribute of the Border object. This will be one of 173 * the values LEADING, TRAILING or CENTER. 174 * 175 * @param alignment The new Alignment value 176 * @exception IllegalArgumentException Description of Exception 177 */ 178 public void setAlignment(int alignment) 179 throws IllegalArgumentException { 180 switch (alignment) { 181 case LEADING: 182 case TRAILING: 183 case CENTER: 184 this.alignment = alignment; 185 break; 186 default: 187 throw new IllegalArgumentException( 188 "Alignment must be one of the constants LEADING, TRAILING or CENTER" 189 ); 190 } 191 } 192 193 /** 194 * Gets the current size of the border in pixels. 195 * 196 * @return The Size value 197 */ 198 public double getSize() { 199 return size; 200 } 201 202 /** 203 * Gets the Alignment - one of LEADING, TRAILING or CENTER. 204 * 205 * @return The alignment value 206 */ 207 public int getAlignment() { 208 return alignment; 209 } 210 } 211}